Skip to content

Commit c0e7d98

Browse files
authored
Add files via upload
1 parent 0d6ea78 commit c0e7d98

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import blosc2
2+
import time
3+
4+
N, M = 5_000, 10_000
5+
dtype = blosc2.float64
6+
working_set = dtype().itemsize * (2 * N * M + N * N) / 2 ** 30
7+
print(f"Working set size of {round(working_set, 2)} GB")
8+
shape1 = (N, M)
9+
shape2 = (M, N)
10+
a = blosc2.ones(shape=shape1, urlpath="a.b2nd", mode='w', dtype=dtype)
11+
b = blosc2.full(fill_value=2., shape=shape2, urlpath="b.b2nd", mode='w', dtype=dtype)
12+
13+
# Expression
14+
t0 = time.time()
15+
# Define the operands and expression
16+
expression, operands = "matmul(a, b) + sin(b[2])", {"a": a, "b": b}
17+
# Create a lazy expression
18+
lexpr = blosc2.lazyexpr(expression, operands)
19+
print(f"Result of {expression} will have shape {lexpr.shape} and dtype {lexpr.dtype}")
20+
# Save the lazy expression to the specified path
21+
url_path = "my_expr.b2nd"
22+
lexpr.save(urlpath=url_path, mode="w")
23+
dt = time.time() - t0
24+
print(f"Defined expression, got metadata, and persisted it on disk in {round(dt * 1000, 3)} ms!")
25+
26+
# Reopen persistent expression, compute, and write to disk with blosc2
27+
t0 = time.time()
28+
lexpr = blosc2.open(urlpath=url_path)
29+
dt = time.time() - t0
30+
print(f"In {round(dt*1000, 3)} ms opened lazy expression: shape = {lexpr.shape}, dtype = {lexpr.dtype}")
31+
t1 = time.time()
32+
result1 = lexpr.compute(urlpath="result.b2nd", mode='w')
33+
t2 = time.time()
34+
print(f"blosc2 fetched operands from disk, computed {expression}, wrote to disk in: {t2 - t1:.3f} s")

0 commit comments

Comments
 (0)