Skip to content

Commit df0de7c

Browse files
committed
Use fast compresssion for arange bench
1 parent 0b922d6 commit df0de7c

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

bench/ndarray/linear-constructor.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,38 @@
1212

1313
import blosc2
1414

15-
dtype = np.float64
15+
dtype = np.int64
1616
shape = (10_000, 10_000)
17+
start, stop = 1, 2
18+
cparams = blosc2.CParams(codec=blosc2.Codec.BLOSCLZ, clevel=1)
1719

1820
@blosc2.dsl_kernel
19-
def kernel_ramp(start):
20-
return start + _flat_idx # noqa: F821 # DSL index/shape symbols resolved by miniexpr
21+
def kernel_ramp(start, stop, nitems): # noqa
22+
step = (float(stop) - float(start)) / float(nitems - 1)
23+
return float(start) + _flat_idx * step # noqa: F821 # DSL index/shape symbols resolved by miniexpr
2124

2225
t0 = time()
23-
npa = np.arange(np.prod(shape), dtype=dtype).reshape(shape)
26+
npa = np.linspace(start, stop, np.prod(shape), dtype=dtype).reshape(shape)
2427
print("NumPy arange:", round(time() - t0, 3), "s")
28+
#print(npa)
2529

2630
t0 = time()
27-
a1 = blosc2.arange(0, np.prod(shape), dtype=dtype, shape=shape)
31+
a1 = blosc2.linspace(start, stop, np.prod(shape), dtype=dtype, shape=shape, cparams=cparams)
2832
print("Blosc2 arange:", round(time() - t0, 3), "s")
2933

34+
np.testing.assert_array_equal(a1, npa)
35+
3036
t0 = time()
31-
a2 = blosc2.lazyudf(kernel_ramp, (0, ), dtype=dtype, shape=shape)
37+
a2 = blosc2.lazyudf(kernel_ramp, (start, stop, np.prod(shape)), dtype=dtype, shape=shape)
3238
# a2 = blosc2.lazyudf(kernel_ramp, (0, ), dtype=dtype, shape=shape, jit_backend="cc")
33-
a3 = a2.compute(cparams=dict(clevel=1, codec=blosc2.Codec.LZ4))
39+
a3 = a2.compute(cparams=cparams)
3440
print("Blosc2 with DSL kernel (tcc jit backend):", round(time() - t0, 3), "s")
3541

36-
np.testing.assert_array_equal(npa, a3)
42+
np.testing.assert_array_equal(a3, npa)
3743

3844
t0 = time()
39-
a2 = blosc2.lazyudf(kernel_ramp, (0, ), dtype=dtype, shape=shape, jit_backend="cc")
40-
a3 = a2.compute(cparams=dict(clevel=1, codec=blosc2.Codec.LZ4))
45+
a2 = blosc2.lazyudf(kernel_ramp, (start, stop, np.prod(shape)), dtype=dtype, shape=shape, jit_backend="cc")
46+
a3 = a2.compute(cparams=cparams)
4147
print("Blosc2 with DSL kernel (cc jit backend):", round(time() - t0, 3), "s")
4248

43-
np.testing.assert_array_equal(npa, a3)
49+
np.testing.assert_array_equal(a3, npa)

0 commit comments

Comments
 (0)