|
13 | 13 |
|
14 | 14 | import blosc2 |
15 | 15 |
|
16 | | -shape = (4_000, 5_000) |
| 16 | +shape = (40_000, 5_000) |
17 | 17 | chunks = (10, 5_000) |
18 | 18 | blocks = (1, 1000) |
19 | 19 | # Comment out the next line to force chunks and blocks above |
|
33 | 33 | t0 = time() |
34 | 34 | npc = npa**2 + npb**2 > 2 * npa * npb + 1 |
35 | 35 | npd = np.where(npc, 0, 1) |
36 | | -t = time() - t0 |
| 36 | +tref = t = time() - t0 |
37 | 37 | print(f"Time to compute where expression (NumPy): {t:.3f} s; {nps.nbytes/2**30/t:.3f} GB/s") |
38 | 38 |
|
39 | 39 | t0 = time() |
40 | 40 | npc = ne.evaluate('where(a**2 + b**2 > 2 * a * b + 1, 0, 1)', local_dict={'a': npa, 'b': npb}) |
41 | 41 | t = time() - t0 |
42 | | -print(f"Time to compute where expression (NumExpr): {t:.3f} s; {nps.nbytes/2**30/t:.3f} GB/s") |
| 42 | +print(f"Time to compute where expression (NumExpr): {t:.3f} s; {nps.nbytes/2**30/t:.3f} GB/s; {tref / t:.1f}x wrt NumPy") |
43 | 43 |
|
44 | 44 | s = blosc2.asarray(nps, chunks=chunks, blocks=blocks, cparams=cparams) |
45 | 45 | print(f"*** Working with NDArray with shape: {s.shape}, chunks: {s.chunks}, blocks: {s.blocks}," |
|
53 | 53 | c = a**2 + b**2 > 2 * a * b + 1 |
54 | 54 | d = c.where(0, 1).compute(cparams=cparams) |
55 | 55 | t = time() - t0 |
56 | | -print(f"Time to compute where expression (compute): {t:.3f} s; {nps.nbytes/2**30/t:.3f} GB/s") |
| 56 | +print(f"Time to compute where expression (compute): {t:.3f} s; {nps.nbytes/2**30/t:.3f} GB/s; {tref / t:.1f}x wrt NumPy") |
57 | 57 |
|
58 | 58 | # Compute the whole slice: output is a NumPy array |
59 | 59 | t0 = time() |
60 | 60 | c = a**2 + b**2 > 2 * a * b + 1 |
61 | 61 | npd = c.where(0, 1)[:] |
62 | 62 | t = time() - t0 |
63 | | -print(f"Time to compute where expression (getitem): {t:.3f} s; {nps.nbytes/2**30/t:.3f} GB/s") |
| 63 | +print(f"Time to compute where expression (getitem): {t:.3f} s; {nps.nbytes/2**30/t:.3f} GB/s; {tref / t:.1f}x wrt NumPy") |
64 | 64 |
|
65 | 65 | print("*** Extracting rows") |
66 | 66 | # Compute and get row values: NumPy |
67 | 67 | t0 = time() |
68 | 68 | npc = npa**2 + npb**2 > 2 * npa * npb + 1 |
69 | 69 | npd = nps[npc] |
70 | | -t = time() - t0 |
| 70 | +tref = t = time() - t0 |
71 | 71 | print(f"Time to get row values (NumPy): {t:.3f} s; {nps.nbytes/2**30/t:.3f} GB/s") |
72 | 72 |
|
73 | 73 | # Compute and get row values: output is a NDArray |
74 | 74 | t0 = time() |
75 | 75 | npd = s[a**2 + b**2 > 2 * a * b + 1].compute(cparams=cparams) |
76 | 76 | t = time() - t0 |
77 | | -print(f"Time to get row values (compute): {t:.3f} s; {nps.nbytes/2**30/t:.3f} GB/s") |
| 77 | +print(f"Time to get row values (compute): {t:.3f} s; {nps.nbytes/2**30/t:.3f} GB/s; {tref / t:.1f}x wrt NumPy") |
78 | 78 |
|
79 | 79 | # Compute and get row values: output is a NDArray |
80 | 80 | t0 = time() |
81 | 81 | npd = s['a**2 + b**2 > 2 * a * b + 1'].compute(cparams=cparams) |
82 | 82 | t = time() - t0 |
83 | | -print(f"Time to get row values (compute, string): {t:.3f} s; {nps.nbytes/2**30/t:.3f} GB/s") |
| 83 | +print(f"Time to get row values (compute, string): {t:.3f} s; {nps.nbytes/2**30/t:.3f} GB/s; {tref / t:.1f}x wrt NumPy") |
84 | 84 |
|
85 | 85 | # Compute and get row values: output is a NumPy array |
86 | 86 | t0 = time() |
87 | 87 | npd = s[a**2 + b**2 > 2 * a * b + 1][:] |
88 | 88 | t = time() - t0 |
89 | | -print(f"Time to get row values (getitem): {t:.3f} s; {nps.nbytes/2**30/t:.3f} GB/s") |
| 89 | +print(f"Time to get row values (getitem): {t:.3f} s; {nps.nbytes/2**30/t:.3f} GB/s; {tref / t:.1f}x wrt NumPy") |
90 | 90 |
|
91 | 91 | # Compute and get row values: output is a NumPy array |
92 | 92 | t0 = time() |
93 | 93 | npd = s['a**2 + b**2 > 2 * a * b + 1'][:] |
94 | 94 | t = time() - t0 |
95 | | -print(f"Time to get row values (getitem, string): {t:.3f} s; {nps.nbytes/2**30/t:.3f} GB/s") |
| 95 | +print(f"Time to get row values (getitem, string): {t:.3f} s; {nps.nbytes/2**30/t:.3f} GB/s; {tref / t:.1f}x wrt NumPy") |
0 commit comments