-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
polyfit.py
38 lines (29 loc) · 1021 Bytes
/
polyfit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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()}