Skip to content

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

Merged
seberg merged 1 commit into
numpy:masterfrom
charris:speedup-old-polynomial-functions
Sep 2, 2014
Merged

seberg merged 1 commit into
numpy:masterfrom
charris:speedup-old-polynomial-functions

Conversation

@charris

@charris charris commented Sep 2, 2014

Copy link
Copy Markdown
Member

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

seberg commented Sep 2, 2014

Copy link
Copy Markdown
Member

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
Copy Markdown
Contributor

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

@filmor

filmor commented Sep 3, 2014

Copy link
Copy Markdown

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

@seberg

seberg commented Sep 3, 2014

Copy link
Copy Markdown
Member

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

seberg commented Sep 3, 2014

Copy link
Copy Markdown
Member

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