Skip to content

Commit ba2753e

Browse files
committed
New slices_eval_getitem() for accelerating evals with __getitem__
1 parent 8998c37 commit ba2753e

File tree

3 files changed

+499
-1
lines changed

3 files changed

+499
-1
lines changed

bench/ndarray/slice-expr.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Imports
2+
import numpy as np
3+
import blosc2
4+
import time
5+
6+
7+
file = "dset-ones.b2nd"
8+
# a = blosc2.open(file)
9+
# expr = blosc2.where(a < 5, a * 2**14, a)
10+
d = 200
11+
shape = (d,) * 4
12+
chunks = (d // 4,) * 4
13+
blocks = (d // 10,) * 4
14+
print(f"Creating a 4D array of shape {shape} with chunks {chunks} and blocks {blocks}...")
15+
t = time.time()
16+
#a = blosc2.linspace(0, d, num=d**4, shape=(d,) * 4, blocks=(d//10,) * 4, chunks=(d//2,) * 4, urlpath=file, mode="w")
17+
#a = blosc2.linspace(0, d, num = d**4, shape=(d,)*4, blocks=(d//10,)*4, chunks=(d//2,)*4)
18+
# a = blosc2.arange(0, d**4, shape=(d,) * 4, blocks=(d//10,) * 4, chunks=(d//2,) * 4, urlpath=file, mode="w")
19+
a = blosc2.ones(shape=shape, chunks=chunks, blocks=blocks) #, urlpath=file, mode="w")
20+
t = time.time() - t
21+
print(f"Time to create array: {t:.6f} seconds")
22+
t = time.time()
23+
#expr = a * 30
24+
expr = a * 2
25+
print(f"Time to create expression: {time.time() - t:.6f} seconds")
26+
27+
# dim0
28+
t = time.time()
29+
res = expr[1]
30+
t0 = time.time() - t
31+
print(f"Time to access dim0: {t0:.6f} seconds")
32+
33+
# dim1
34+
t = time.time()
35+
res = expr[:,1]
36+
t1 = time.time() - t
37+
print(f"Time to access dim1: {t1:.6f} seconds")
38+
39+
# dim2
40+
t = time.time()
41+
res = expr[:,:,1]
42+
t2 = time.time() - t
43+
print(f"Time to access dim2: {t2:.6f} seconds")
44+
45+
# dim3
46+
t = time.time()
47+
res = expr[:,:,:,1]
48+
#res = expr[1]
49+
t3 = time.time() - t
50+
51+
print(f"Time to access dim3: {t3:.6f} seconds")

0 commit comments

Comments
 (0)