forked from inaos/iron-array-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_array.py
More file actions
60 lines (47 loc) · 1.65 KB
/
Copy pathfunction_array.py
File metadata and controls
60 lines (47 loc) · 1.65 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# This uses different computation methods inside (and outside) iarray and compares performance.
from time import time
import iarray as ia
import numpy as np
import numexpr as ne
# Define array params
dtype = np.float64
shape = [10000, 8000]
cshape = [1000, 800]
bshape = [100, 100]
storage = ia.StorageProperties(backend="blosc", chunkshape=cshape, blockshape=bshape,
enforce_frame=False, filename=None)
kwargs = dict(eval_method=ia.EVAL_ITERBLOSC, storage=storage)
# Create initial arrays
ia1 = ia.linspace(ia.dtshape(shape, dtype), 0, 10, **kwargs)
np1 = ia.iarray2numpy(ia1)
t0 = time()
np2 = np.cos(np1)
t1 = time()
print("Time for numpy evaluation: %.3f" % (t1 - t0))
t0 = time()
np3_ = ne.evaluate("cos(np1)")
t1 = time()
print("Time for numexpr evaluation: %.3f" % (t1 - t0))
t0 = time()
expr = ia.Expr(**kwargs)
expr.bind("x", ia1)
expr.bind_out_properties(ia.dtshape(shape, dtype), storage=storage)
expr.compile("cos(x)")
ia2 = expr.eval()
t1 = time()
print("Time for iarray evaluation: %.3f (cratio: %.2fx)" % ((t1 - t0), ia2.cratio))
np3 = ia.iarray2numpy(ia2)
ia.cmp_arrays(np3, np2, "OK. Results are the same.")
t0 = time()
ia3 = ia.cos(ia1).eval(**kwargs)
t1 = time()
print("Time for iarray via lazy evaluation: %.3f (cratio: %.2fx)" % ((t1 - t0), ia3.cratio))
np4 = ia.iarray2numpy(ia3)
ia.cmp_arrays(np4, np2, "OK. Results are the same.")
t0 = time()
ia4 = ia1.cos().eval(**kwargs)
# ia4 = ia1.cos().eval(method="numexpr", **kwargs)
t1 = time()
print("Time for iarray via lazy evaluation (method): %.3f (cratio: %.2fx)" % ((t1 - t0), ia3.cratio))
np5 = ia.iarray2numpy(ia4)
ia.cmp_arrays(np5, np2, "OK. Results are the same.")