-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathperformance.py
More file actions
45 lines (36 loc) · 1.06 KB
/
Copy pathperformance.py
File metadata and controls
45 lines (36 loc) · 1.06 KB
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
39
40
41
42
43
44
45
"""Functions that may be used to measure performance of a component."""
import dask.array as da
import numpy as np
import stratify
def src_data(shape=(400, 500, 100)):
z = np.tile(np.linspace(0, 100, shape[-1]), np.prod(shape[:2])).reshape(shape)
if lazy:
fz = da.arange(np.prod(shape), dtype=np.float64).reshape(shape)
else:
fz = np.arange(np.prod(shape), dtype=np.float64).reshape(shape)
return z, fz
def interp_and_extrap(
shape,
lazy,
interp=stratify.INTERPOLATE_LINEAR,
extrap=stratify.EXTRAPOLATE_NEAREST,
):
z, fz = src_data(shape, lazy)
tgt = np.linspace(-20, 120, 50)
result = stratify.interpolate(
tgt,
z,
fz,
interpolation=interp,
extrapolation=extrap,
)
if isinstance(result, da.Array):
print("lazy calculation")
print(result.chunks)
result.compute()
else:
print("non-lazy calculation")
if __name__ == "__main__":
import sys
lazy = "lazy" in sys.argv[1:]
interp_and_extrap(shape=(500, 600, 100), lazy=lazy)