You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For several operations on polynomials (e.g. addition, substraction) the ABCPolyBase._get_coefficients takes time. The check np.all(self.domain == other.domain) can be replaced with either np.array_equal(self.domain, other.domain).all() or (self.domain == other.domain).all() (and similar for the window). For benchmark
from numpy.polynomial import Polynomial
import timeit
p = Polynomial([1,2,3])
q = Polynomial([3,2,1])
dt=timeit.timeit('p + p - q', globals={'p': p, 'q': q}, number=40_000)
print(dt)
The fastest option does assume the domain already is a numpy array. Current main and the np.array_equal option cast (with asarray). #24499
The numpy.polynomial.polyutils.as_series is called in many places. Also in internal methods where many of the input checks (e.g. on input dimensions) are not required. We can add a flag internal : bool to as_series than will skip several of the checks. Draft PR: MAINT: Improve performance of polynomial operations (2) #24531
Profiling results on main (2023-8-22) for p * q with p=Polynomial([1,2,3]); q=Polynomial([3,0,3]):
Proposed new feature or change:
The
numpy.polynomialclasses have quite some overhead in the calculations. This is a collection of ideas to reduce the overheadABCPolyBase._get_coefficientstakes time. The checknp.all(self.domain == other.domain)can be replaced with eithernp.array_equal(self.domain, other.domain).all()or(self.domain == other.domain).all()(and similar for thewindow). For benchmarkthe timings are
The fastest option does assume the
domainalready is a numpy array. Current main and thenp.array_equaloption cast (withasarray). #24499numpy.polynomial.polyutils.as_seriesis called in many places. Also in internal methods where many of the input checks (e.g. on input dimensions) are not required. We can add a flaginternal : booltoas_seriesthan will skip several of the checks. Draft PR: MAINT: Improve performance of polynomial operations (2) #24531Profiling results on main (2023-8-22) for

p * qwithp=Polynomial([1,2,3]); q=Polynomial([3,0,3]):