Skip to content

Commit 7b0ea59

Browse files
committed
Add sparse parameter to bench
1 parent 445f0b2 commit 7b0ea59

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

bench/ndarray/fancy_index.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
BLOSC = True
2929
ZARR = False
3030
HDF5 = False
31+
SPARSE = False
3132

3233
NDIMS = 2 # must be at least 2
3334

@@ -59,9 +60,10 @@ def genarray(r, ndims=2, verbose=True):
5960
for d in target_sizes:
6061
arr, arrsize = genarray(d, ndims=NDIMS)
6162
genuine_sizes += [arrsize]
62-
idx = rng.integers(low=0, high=arr.shape[0], size=(arr.shape[0]//4,))
63+
sparseness = 1000 if SPARSE else arr.shape[0]//4
64+
idx = rng.integers(low=0, high=arr.shape[0], size=(sparseness,))
6365
sorted_idx = np.sort(np.unique(idx))
64-
col = rng.integers(low=0, high=arr.shape[0], size=(arr.shape[0]//4,))
66+
col = rng.integers(low=0, high=arr.shape[0], size=(sparseness,))
6567
col_sorted = np.sort(np.unique(col))
6668
mask = rng.integers(low=0, high=2, size=(arr.shape[0],)) == 1
6769

@@ -134,7 +136,7 @@ def timer(arr):
134136
error_kw=dict(lw=2, capthick=2, ecolor='k'))
135137
labs+=label
136138

137-
filename = f"results{labs}{NDIMS}D"
139+
filename = f"results{labs}{NDIMS}D" + "sparse" if SPARSE else f"results{labs}{NDIMS}D"
138140

139141
with open(f"{filename}.pkl", 'wb') as f:
140142
pickle.dump(result_tuple, f)
@@ -143,7 +145,7 @@ def timer(arr):
143145
plt.legend()
144146
plt.xticks(x-width, np.round(genuine_sizes, 2))
145147
plt.ylabel("Time (s)")
146-
plt.title(f"Fancy indexing performance comparison, {NDIMS}D")
148+
plt.title(f"Fancy indexing performance comparison, {NDIMS}D" +f"{" sparse" if SPARSE else ""}")
147149
plt.gca().set_yscale('log')
148150
plt.savefig(f'plots/fancyIdx{filename}.png', format="png")
149151
plt.show()

0 commit comments

Comments
 (0)