Skip to content

MAINT: Make numpy/lib/polynomial/polyval a bit faster. #5031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 2, 2014

Conversation

charris
Copy link
Member

@charris charris commented Sep 2, 2014

Multiplying a numpy_scalar times a numpy_array is much faster than
the other way around. This PR switches the order of multiplication
in the polyval function resulting in a speedup of about 5x for scalar
values of x.

Closes #4610.

Multiplying a numpy_scalar times a numpy_array is much faster than
the other way around. This PR switches the order of multiplication
in the polyval function resulting in a speedup of about 5x for scalar
values of x.

Closes numpy#4610.
@seberg
Copy link
Member

seberg commented Sep 2, 2014

Umm, ok, why not :).

seberg added a commit that referenced this pull request Sep 2, 2014
MAINT: Make numpy/lib/polynomial/polyval a bit faster.
@seberg seberg merged commit 138b3bf into numpy:master Sep 2, 2014
@charris charris deleted the speedup-old-polynomial-functions branch September 2, 2014 15:58
@juliantaylor
Copy link
Contributor

so simple its almost tempting to put that into 1.9 :)
would also be interesting to see why rmul is so slow

@filmor
Copy link

filmor commented Sep 3, 2014

Is there any documentation on how exactly Python resolves the multiplication? Calling __mul__ or __rmul__ explicitly is even slower.

@seberg
Copy link
Member

seberg commented Sep 3, 2014

I am sure there is some PEP somewhere. I believe it calls __mul__ and if that returns NotImplemented it tries __rmul__. There is one special case if the right hand side is a subclass, I think it calls __rmul__ directly.

@seberg
Copy link
Member

seberg commented Sep 3, 2014

Oh, you mention it is even slower. There are C-level slots for these operators as well in the number slots. Those make it somewhat faster then what you would write in python.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Polynomial.py Optimization
4 participants