Skip to content

Commit f5b20cd

Browse files
authored
remove buggy type computation in scalar_mult. (#485)
Also support efficient scalar multiplication with sparse coefficients
1 parent e3614f0 commit f5b20cd

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/common.jl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,17 +1032,14 @@ end
10321032
## -- multiplication
10331033

10341034

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

10421040
function scalar_mult(c::S, p::P) where {S, T, X, P<:AbstractPolynomial{T, X}}
1043-
R = Base.promote_op(*, T, S)
1044-
𝐏 = (P){R,X}
1045-
𝐏([c * pᵢ for pᵢ coeffs(p)])
1041+
result = (c,) .* coeffs(p)
1042+
(P){eltype(result), X}(result)
10461043
end
10471044

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

0 commit comments

Comments
 (0)