Skip to content

Commit

Permalink
adjustments for DSP breakage (#352)
Browse files Browse the repository at this point in the history
  • Loading branch information
jverzani authored Jul 9, 2021
1 parent 60ba676 commit 6fba06b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 13 additions & 0 deletions src/polynomials/LaurentPolynomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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
##
Expand Down
2 changes: 1 addition & 1 deletion src/polynomials/Poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions test/StandardBasis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

2 comments on commit 6fba06b

@jverzani
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/40592

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v2.0.14 -m "<description of version>" 6fba06b65a0bfede3834de1779ac2553b151650c
git push origin v2.0.14

Please sign in to comment.