-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
polyval: Use Horner's algorithm + support chunked inputs (#6548)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Maximilian Roos <5635139+max-sixty@users.noreply.github.com> Co-authored-by: Deepak Cherian <dcherian@users.noreply.github.com>
- Loading branch information
1 parent
39bda44
commit 6fbeb13
Showing
4 changed files
with
220 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import numpy as np | ||
|
||
import xarray as xr | ||
|
||
from . import parameterized, randn, requires_dask | ||
|
||
NDEGS = (2, 5, 20) | ||
NX = (10**2, 10**6) | ||
|
||
|
||
class Polyval: | ||
def setup(self, *args, **kwargs): | ||
self.xs = {nx: xr.DataArray(randn((nx,)), dims="x", name="x") for nx in NX} | ||
self.coeffs = { | ||
ndeg: xr.DataArray( | ||
randn((ndeg,)), dims="degree", coords={"degree": np.arange(ndeg)} | ||
) | ||
for ndeg in NDEGS | ||
} | ||
|
||
@parameterized(["nx", "ndeg"], [NX, NDEGS]) | ||
def time_polyval(self, nx, ndeg): | ||
x = self.xs[nx] | ||
c = self.coeffs[ndeg] | ||
xr.polyval(x, c).compute() | ||
|
||
@parameterized(["nx", "ndeg"], [NX, NDEGS]) | ||
def peakmem_polyval(self, nx, ndeg): | ||
x = self.xs[nx] | ||
c = self.coeffs[ndeg] | ||
xr.polyval(x, c).compute() | ||
|
||
|
||
class PolyvalDask(Polyval): | ||
def setup(self, *args, **kwargs): | ||
requires_dask() | ||
super().setup(*args, **kwargs) | ||
self.xs = {k: v.chunk({"x": 10000}) for k, v in self.xs.items()} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters