MAINT: Improve performance of polynomial operations (2) #24531
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For many polynomial operations (e.g. add, multiply, negate) the operation takes place on the coefficients of the operands and then a new
Polynomial
is created. For the creation of the newPolynomial
we can skip the validation of input arguments, as they are either passed from the operands (which have already been validated) or constructed with internal methods (which have validated output).Benchmark results:
with script:
Notes:
as_series
andABCPolyBase.__init__
have an additional flag_validate_input
. The default isTrue
(so the PR is backwards compatible), but for internal operations we set it toFalse
polyadd
and/orpolyutils._add
to have a_validate_input
flag as well. But this requires more refactoring and thepolyadd
is public, so this has not yet been done.__add__
,__neg__
,__mul__
and__rmul__
. If this PR is considered a merge candidate, we can modify other operations as well.