@@ -190,16 +190,39 @@ adjoint(m::Monomial) = m
190
190
adjoint (t:: Term ) = Term (adjoint (coefficient (t)), monomial (t))
191
191
adjoint (x:: Polynomial ) = Polynomial (adjoint .(terms (x)))
192
192
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 )
194
214
resize! (output. terms, nterms (p))
195
215
for i in eachindex (p. terms)
196
216
t = p. terms[i]
197
217
output. terms[i] = Term (f (coefficient (t)), monomial (t))
198
218
end
219
+ if ! nonzero
220
+ filter! (! iszero, output. terms)
221
+ end
199
222
return output
200
223
end
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 )
203
226
end
204
227
205
228
function MA. operate! (:: typeof (MP. removeleadingterm), p:: Polynomial )
0 commit comments