Skip to content

Commit 6fba06b

Browse files
authored
adjustments for DSP breakage (#352)
1 parent 60ba676 commit 6fba06b

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name = "Polynomials"
22
uuid = "f27b6e38-b328-58d1-80ce-0feddd5e7a45"
33
license = "MIT"
44
author = "JuliaMath"
5-
version = "2.0.13"
5+
version = "2.0.14"
66

77
[deps]
88
Intervals = "d8418881-c3e1-53bb-8760-2df7ec849ed5"

src/polynomials/LaurentPolynomial.jl

+13
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ function Base.convert(P::Type{<:Polynomial}, q::LaurentPolynomial)
132132
P([q[i] for i in 0:n], indeterminate(q))
133133
end
134134

135+
# need to add p.m[], so abstract.jl method isn't sufficent
136+
# XXX unlike abstract.jl, this uses Y variable in conversion; no error
137+
# Used in DSP.jl
138+
function Base.convert(::Type{LaurentPolynomial{S,Y}}, p::LaurentPolynomial{T,X}) where {T,X,S,Y}
139+
LaurentPolynomial{S,Y}(p.coeffs, p.m[])
140+
end
135141

136142
# work around for non-applicable convert(::Type{<:P}, p::P{T,X}) in abstract.jl
137143
struct OffsetCoeffs{V}
@@ -451,6 +457,13 @@ function Base.:*(p1::P, p2::P) where {T,X,P<:LaurentPolynomial{T,X}}
451457
return p
452458
end
453459

460+
function scalar_mult(p::LaurentPolynomial{T,X}, c::Number) where {T,X}
461+
LaurentPolynomial(p.coeffs .* c, p.m[], X)
462+
end
463+
function scalar_mult(c::Number, p::LaurentPolynomial{T,X}) where {T,X}
464+
LaurentPolynomial(c .* p.coeffs, p.m[], X)
465+
end
466+
454467
##
455468
## roots
456469
##

src/polynomials/Poly.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Base.one(::Type{P}) where {P <: Poly} = Poly{_eltype(P), Polynomials.indetermina
6363
Base.one(::Type{P},var::Polynomials.SymbolLike) where {P <: Poly} = Poly(ones(_eltype(P),1), var)
6464
Polynomials.variable(::Type{P}) where {P <: Poly} = Poly{_eltype(P), Polynomials.indeterminate(P)}([0,1])
6565
Polynomials.variable(::Type{P},var::Polynomials.SymbolLike) where {P <: Poly} = Poly(_eltype(P)[0,1], var)
66-
function Polynomials.basis(P::Type{<:Poly}, k::Int, _var::Polynomials.SymbolLike=:x; var=_var)
66+
function Polynomials.basis(P::Type{<:Poly}, k::Int, _var::Polynomials.SymbolLike=:x; var=_var)
6767
zs = zeros(Int, k+1)
6868
zs[end] = 1
6969
Polynomials.constructorof(P){_eltype(P), Symbol(var)}(zs)

test/StandardBasis.jl

+6
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,12 @@ end
428428
@test p*q ==P(im*[1,2,3])
429429
end
430430

431+
# Laurent polynomials and scalar operations
432+
cs = [1,2,3,4]
433+
p = LaurentPolynomial(cs, -3)
434+
@test p*3 == LaurentPolynomial(cs .* 3, -3)
435+
@test 3*p == LaurentPolynomial(3 .* cs, -3)
436+
431437
# LaurentPolynomial has an inverse for monomials
432438
x = variable(LaurentPolynomial)
433439
@test Polynomials.isconstant(x * inv(x))

0 commit comments

Comments
 (0)