diff --git a/Project.toml b/Project.toml index 7af3aee1..d33211e1 100644 --- a/Project.toml +++ b/Project.toml @@ -2,7 +2,7 @@ name = "Polynomials" uuid = "f27b6e38-b328-58d1-80ce-0feddd5e7a45" license = "MIT" author = "JuliaMath" -version = "2.0.13" +version = "2.0.14" [deps] Intervals = "d8418881-c3e1-53bb-8760-2df7ec849ed5" diff --git a/src/polynomials/LaurentPolynomial.jl b/src/polynomials/LaurentPolynomial.jl index 4527dc6a..379d66da 100644 --- a/src/polynomials/LaurentPolynomial.jl +++ b/src/polynomials/LaurentPolynomial.jl @@ -132,6 +132,12 @@ function Base.convert(P::Type{<:Polynomial}, q::LaurentPolynomial) P([q[i] for i in 0:n], indeterminate(q)) end +# need to add p.m[], so abstract.jl method isn't sufficent +# XXX unlike abstract.jl, this uses Y variable in conversion; no error +# Used in DSP.jl +function Base.convert(::Type{LaurentPolynomial{S,Y}}, p::LaurentPolynomial{T,X}) where {T,X,S,Y} + LaurentPolynomial{S,Y}(p.coeffs, p.m[]) +end # work around for non-applicable convert(::Type{<:P}, p::P{T,X}) in abstract.jl struct OffsetCoeffs{V} @@ -451,6 +457,13 @@ function Base.:*(p1::P, p2::P) where {T,X,P<:LaurentPolynomial{T,X}} return p end +function scalar_mult(p::LaurentPolynomial{T,X}, c::Number) where {T,X} + LaurentPolynomial(p.coeffs .* c, p.m[], X) +end +function scalar_mult(c::Number, p::LaurentPolynomial{T,X}) where {T,X} + LaurentPolynomial(c .* p.coeffs, p.m[], X) +end + ## ## roots ## diff --git a/src/polynomials/Poly.jl b/src/polynomials/Poly.jl index 37a2b2c9..998bf787 100644 --- a/src/polynomials/Poly.jl +++ b/src/polynomials/Poly.jl @@ -63,7 +63,7 @@ Base.one(::Type{P}) where {P <: Poly} = Poly{_eltype(P), Polynomials.indetermina Base.one(::Type{P},var::Polynomials.SymbolLike) where {P <: Poly} = Poly(ones(_eltype(P),1), var) Polynomials.variable(::Type{P}) where {P <: Poly} = Poly{_eltype(P), Polynomials.indeterminate(P)}([0,1]) Polynomials.variable(::Type{P},var::Polynomials.SymbolLike) where {P <: Poly} = Poly(_eltype(P)[0,1], var) -function Polynomials.basis(P::Type{<:Poly}, k::Int, _var::Polynomials.SymbolLike=:x; var=_var) +function Polynomials.basis(P::Type{<:Poly}, k::Int, _var::Polynomials.SymbolLike=:x; var=_var) zs = zeros(Int, k+1) zs[end] = 1 Polynomials.constructorof(P){_eltype(P), Symbol(var)}(zs) diff --git a/test/StandardBasis.jl b/test/StandardBasis.jl index a83b6c5f..e7d89972 100644 --- a/test/StandardBasis.jl +++ b/test/StandardBasis.jl @@ -428,6 +428,12 @@ end @test p*q ==ᵟ P(im*[1,2,3]) end + # Laurent polynomials and scalar operations + cs = [1,2,3,4] + p = LaurentPolynomial(cs, -3) + @test p*3 == LaurentPolynomial(cs .* 3, -3) + @test 3*p == LaurentPolynomial(3 .* cs, -3) + # LaurentPolynomial has an inverse for monomials x = variable(LaurentPolynomial) @test Polynomials.isconstant(x * inv(x))