numpy / numpy

The fundamental package for scientific computing with Python.
https://numpy.org
Other
27.8k stars 9.98k forks source link

ENH: Reduce overhead of numpy.polynomial #24480

Open eendebakpt opened 1 year ago

eendebakpt commented 1 year ago

Proposed new feature or change:

The numpy.polynomial classes have quite some overhead in the calculations. This is a collection of ideas to reduce the overhead

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 timings are

2.51 seconds (main)
2.35 seconds (np.array_equal)
2.2 seconds (.all() )

The fastest option does assume the domain already is a numpy array. Current main and the np.array_equal option cast (with asarray). https://github.com/numpy/numpy/pull/24499

Profiling results on main (2023-8-22) for p * q with p=Polynomial([1,2,3]); q=Polynomial([3,0,3]): np_polynomial_mul

aijams commented 1 year ago

Hello, I would like to make a contribution to Numpy and I found this enhancement on the issue list. I don't have that much free time, so it would likely take a while for me to work on this issue.

I have a couple questions: Is this enhancement a high priority for Numpy development? Do you know of other issues that are likely a higher priority than this one?

For context, I'm a first-time contributor to this project, so I'm not really sure what the important issues are.

aijams commented 1 year ago

I just saw that you already have a PR out for this issue that hasn't yet been merged in. I will therefore let you continue working on this.

Do you still wish to get this PR merged?