Skip to content

Override dot with scalars #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
matbesancon opened this issue Feb 26, 2021 · 1 comment
Open

Override dot with scalars #65

matbesancon opened this issue Feb 26, 2021 · 1 comment

Comments

@matbesancon
Copy link

@polyvar X[1:N]
current = 1
xs = [xi * c for xi in x for c in current]
10-element Vector{Term{Int64, M} where M<:Monomial}:
 X₁
 X₂
 X₃
 X₄
 
 X₈
 X₉
 X₁₀

julia> dot(xs, rand(10))
ERROR: MethodError: no method matching zero(::Type{Any})
Closest candidates are:
  zero(::Type{Union{Missing, T}}) where T at missing.jl:105
  zero(::Union{Type{P}, P}) where P<:Dates.Period at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Dates/src/periods.jl:53
  zero(::Union{Monomial, Polynomial, Term, Variable}) at /home/mbesancon/.julia/packages/TypedPolynomials/0HQcW/src/operators.jl:5
  ...
Stacktrace:
 [1] zero(#unused#::Type{Any})
   @ Base ./missing.jl:106
 [2] zero(#unused#::Type{Term{Int64, M} where M<:Monomial})
   @ MultivariatePolynomials ~/.julia/packages/MultivariatePolynomials/bsuXE/src/term.jl:152
 [3] promote_operation(op::typeof(*), #unused#::Type{Term{Int64, M} where M<:Monomial}, #unused#::Type{Float64})
   @ MutableArithmetics ~/.julia/packages/MutableArithmetics/bPWR4/src/interface.jl:24
 [4] promote_sum_mul(T::Type, S::Type)
   @ MutableArithmetics ~/.julia/packages/MutableArithmetics/bPWR4/src/linear_algebra.jl:169
 [5] operate(#unused#::typeof(dot), x::Vector{Term{Int64, M} where M<:Monomial}, y::Vector{Float64})
   @ MutableArithmetics ~/.julia/packages/MutableArithmetics/bPWR4/src/linear_algebra.jl:430
 [6] dot(lhs::Vector{Term{Int64, M} where M<:Monomial}, rhs::Vector{Float64})
   @ MutableArithmetics ~/.julia/packages/MutableArithmetics/bPWR4/src/dispatch.jl:13
@blegat
Copy link
Member

blegat commented Feb 27, 2021

The issue is that the eltype of xs is not concrete so zero does not work.
This is because the vector comprehension widen the eltype instead of promoting the elements to a common type.
Anotating the eltype to the promoted type should make it work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants