Skip to content

Commit

Permalink
remove buggy type computation in scalar_mult. (#485)
Browse files Browse the repository at this point in the history
Also support efficient scalar multiplication with sparse coefficients
  • Loading branch information
LilithHafner authored Mar 15, 2023
1 parent e3614f0 commit f5b20cd
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1032,17 +1032,14 @@ end
## -- multiplication


# this fall back not necessarily efficient (e.g., sparse)
function scalar_mult(p::P, c::S) where {S, T, X, P<:AbstractPolynomial{T,X}}
R = Base.promote_op(*, T, S) # typeof(one(T)*one(S))?
𝐏 = (P){R,X}
𝐏([pᵢ * c for pᵢ coeffs(p)])
result = coeffs(p) .* (c,)
(P){eltype(result), X}(result)
end

function scalar_mult(c::S, p::P) where {S, T, X, P<:AbstractPolynomial{T, X}}
R = Base.promote_op(*, T, S)
𝐏 = (P){R,X}
𝐏([c * pᵢ for pᵢ coeffs(p)])
result = (c,) .* coeffs(p)
(P){eltype(result), X}(result)
end

scalar_mult(p1::AbstractPolynomial, p2::AbstractPolynomial) = error("scalar_mult(::$(typeof(p1)), ::$(typeof(p2))) is not defined.") # avoid ambiguity, issue #435
Expand Down

0 comments on commit f5b20cd

Please sign in to comment.