|
12 | 12 |
|
13 | 13 | import blosc2 |
14 | 14 |
|
15 | | -dtype = np.float64 |
| 15 | +dtype = np.int64 |
16 | 16 | shape = (10_000, 10_000) |
| 17 | +start, stop = 1, 2 |
| 18 | +cparams = blosc2.CParams(codec=blosc2.Codec.BLOSCLZ, clevel=1) |
17 | 19 |
|
18 | 20 | @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 |
21 | 24 |
|
22 | 25 | 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) |
24 | 27 | print("NumPy arange:", round(time() - t0, 3), "s") |
| 28 | +#print(npa) |
25 | 29 |
|
26 | 30 | 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) |
28 | 32 | print("Blosc2 arange:", round(time() - t0, 3), "s") |
29 | 33 |
|
| 34 | +np.testing.assert_array_equal(a1, npa) |
| 35 | + |
30 | 36 | 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) |
32 | 38 | # 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) |
34 | 40 | print("Blosc2 with DSL kernel (tcc jit backend):", round(time() - t0, 3), "s") |
35 | 41 |
|
36 | | -np.testing.assert_array_equal(npa, a3) |
| 42 | +np.testing.assert_array_equal(a3, npa) |
37 | 43 |
|
38 | 44 | 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) |
41 | 47 | print("Blosc2 with DSL kernel (cc jit backend):", round(time() - t0, 3), "s") |
42 | 48 |
|
43 | | -np.testing.assert_array_equal(npa, a3) |
| 49 | +np.testing.assert_array_equal(a3, npa) |
0 commit comments