Skip to content

Commit

Permalink
Implement the new mapcoefficients API (#76)
Browse files Browse the repository at this point in the history
* Updates

* Up
  • Loading branch information
blegat authored Nov 16, 2021
1 parent 7477722 commit 88586dc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "TypedPolynomials"
uuid = "afbbf031-7a57-5f58-a1b9-b774a0fad08d"
repo = "https://github.com/JuliaAlgebra/TypedPolynomials.jl.git"
version = "0.3.0"
version = "0.3.1"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand All @@ -13,7 +13,7 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[compat]
MacroTools = "0.5"
MultivariatePolynomials = "0.4"
MultivariatePolynomials = "0.4.1"
MutableArithmetics = "0.3"
NBInclude = "2"
julia = "1"
Expand Down
29 changes: 26 additions & 3 deletions src/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,39 @@ adjoint(m::Monomial) = m
adjoint(t::Term) = Term(adjoint(coefficient(t)), monomial(t))
adjoint(x::Polynomial) = Polynomial(adjoint.(terms(x)))

function MP.mapcoefficientsnz_to!(output::Polynomial, f::Function, p::Polynomial)
function MP.mapcoefficients(f::Function, p::Polynomial; nonzero = false)
terms = map(p.terms) do term
MP.mapcoefficients(f, term)
end
if !nonzero
filter!(!iszero, terms)
end
return Polynomial(terms)
end
function MP.mapcoefficients!(f::Function, p::Polynomial; nonzero = false)
for i in eachindex(p.terms)
t = p.terms[i]
p.terms[i] = Term(f(coefficient(t)), monomial(t))
end
if !nonzero
filter!(!iszero, p.terms)
end
return p
end

function MP.mapcoefficients_to!(output::Polynomial, f::Function, p::Polynomial; nonzero = false)
resize!(output.terms, nterms(p))
for i in eachindex(p.terms)
t = p.terms[i]
output.terms[i] = Term(f(coefficient(t)), monomial(t))
end
if !nonzero
filter!(!iszero, output.terms)
end
return output
end
function MP.mapcoefficientsnz_to!(output::Polynomial, f::Function, p::AbstractPolynomialLike)
return MP.mapcoefficientsnz_to!(output, f, polynomial(p))
function MP.mapcoefficients_to!(output::Polynomial, f::Function, p::AbstractPolynomialLike; nonzero = false)
return MP.mapcoefficients_to!(output, f, polynomial(p); nonzero = false)
end

function MA.operate!(::typeof(MP.removeleadingterm), p::Polynomial)
Expand Down

2 comments on commit 88586dc

@blegat
Copy link
Member Author

@blegat blegat commented on 88586dc Nov 16, 2021

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/48875

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 v0.3.1 -m "<description of version>" 88586dc455b51df9c8f0cd7ea651b57241193848
git push origin v0.3.1

Please sign in to comment.