Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

MAINT: Optimize performance of polynomial operations #24499

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
Loading
from

Conversation

eendebakpt
Copy link
Contributor

Improve the performance of polynomial operations by improving the internal _get_coefficients:

  • Reorder type check for the most common operation
  • Use all() method of numpy arrays instead of np.all for the window and domain attributes

Benchmark results

p + q: Mean +- std dev: [main] 35.7 us +- 1.3 us -> [pr] 31.8 us +- 0.6 us: 1.12x faster
p * q: Mean +- std dev: [main] 37.3 us +- 1.1 us -> [pr] 33.9 us +- 1.1 us: 1.10x faster

Geometric mean: 1.11x faster

with script

import pyperf
from numpy.polynomial import Polynomial

setup = """
from numpy.polynomial import Polynomial

p=Polynomial([.5,4,5])
q=Polynomial([1,0,5])
"""

runner = pyperf.Runner()
runner.timeit(name=f"p + q", stmt="_ = p + q", setup=setup)
runner.timeit(name=f"p * q", stmt="_ = p * q", setup=setup)

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

Successfully merging this pull request may close these issues.

2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.