@@ -190,16 +190,39 @@ adjoint(m::Monomial) = m
190190adjoint (t:: Term ) = Term (adjoint (coefficient (t)), monomial (t))
191191adjoint (x:: Polynomial ) = Polynomial (adjoint .(terms (x)))
192192
193- function MP. mapcoefficientsnz_to! (output:: Polynomial , f:: Function , p:: Polynomial )
193+ function MP. mapcoefficients (f:: Function , p:: Polynomial ; nonzero = false )
194+ terms = map (p. terms) do term
195+ MP. mapcoefficients (f, term)
196+ end
197+ if ! nonzero
198+ filter! (! iszero, terms)
199+ end
200+ return Polynomial (terms)
201+ end
202+ function MP. mapcoefficients! (f:: Function , p:: Polynomial ; nonzero = false )
203+ for i in eachindex (p. terms)
204+ t = p. terms[i]
205+ p. terms[i] = Term (f (coefficient (t)), monomial (t))
206+ end
207+ if ! nonzero
208+ filter! (! iszero, p. terms)
209+ end
210+ return p
211+ end
212+
213+ function MP. mapcoefficients_to! (output:: Polynomial , f:: Function , p:: Polynomial ; nonzero = false )
194214 resize! (output. terms, nterms (p))
195215 for i in eachindex (p. terms)
196216 t = p. terms[i]
197217 output. terms[i] = Term (f (coefficient (t)), monomial (t))
198218 end
219+ if ! nonzero
220+ filter! (! iszero, output. terms)
221+ end
199222 return output
200223end
201- function MP. mapcoefficientsnz_to ! (output:: Polynomial , f:: Function , p:: AbstractPolynomialLike )
202- return MP. mapcoefficientsnz_to ! (output, f, polynomial (p))
224+ function MP. mapcoefficients_to ! (output:: Polynomial , f:: Function , p:: AbstractPolynomialLike ; nonzero = false )
225+ return MP. mapcoefficients_to ! (output, f, polynomial (p); nonzero = false )
203226end
204227
205228function MA. operate! (:: typeof (MP. removeleadingterm), p:: Polynomial )
0 commit comments