Content-Length: 325883 | pFad | http://github.com/numpy/numpy/pull/26885/files

96 ENH: Improve polyval performance by using inplace operations by eendebakpt · Pull Request #26885 · numpy/numpy · GitHub
Skip to content

ENH: Improve polyval performance by using inplace operations #26885

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 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion benchmarks/benchmarks/bench_polynomial.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from .common import Benchmark

import numpy as np

from numpy.polynomial.polynomial import polyval

class Polynomial(Benchmark):

def setup(self):
self.polynomial_degree2 = np.polynomial.Polynomial(np.array([1, 2]))
self.array3 = np.linspace(0, 1, 3)
self.array1000 = np.linspace(0, 1, 10_000)
self.array1M = np.linspace(0, 1, 1_000_000)
self.float64 = np.float64(1.0)

def time_polynomial_evaluation_scalar(self):
Expand All @@ -23,5 +24,12 @@ def time_polynomial_evaluation_array_3(self):
def time_polynomial_evaluation_array_1000(self):
self.polynomial_degree2(self.array1000)

def time_polynomial_evaluation_array_1_000_000(self):
self.polynomial_degree2(self.array1M)

def time_polyval(self):
polyval(self.array1M, self.polynomial_degree2.coef)

def time_polynomial_addition(self):
_ = self.polynomial_degree2 + self.polynomial_degree2

3 changes: 2 additions & 1 deletion numpy/polynomial/polynomial.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,8 @@ def polyval(x, c, tensor=True):

c0 = c[-1] + x * 0
for i in range(2, len(c) + 1):
c0 = c[-i] + c0 * x
c0 *= x
c0 += c[-i]
return c0


Expand Down
Loading








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/numpy/numpy/pull/26885/files

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy