1616import zarr
1717import h5py
1818import pickle
19+ import os
1920plt .rcParams .update ({'text.usetex' :False ,'font.serif' : ['cm' ],'font.size' :16 })
2021plt .rcParams ['figure.dpi' ] = 1000
2122plt .rcParams ['savefig.dpi' ] = 1000
2223plt .rc ('text' , usetex = False )
2324plt .rc ('font' ,** {'serif' :['cm' ]})
2425plt .style .use ('seaborn-v0_8-paper' )
2526
26- NUMPY_BLOSC = True
27- NUMPY_BLOSC_ZARR = False
27+ NUMPY_BLOSC = True # activate NUMPY and BLOSC tests
28+ NUMPY_BLOSC_ZARR = False # activate NUMPY, BLOSC and Zarr tests
29+ # default if both are false is to run tests for Numpy, Blosc, Zarr and HDF5
2830
2931def genarray (r , ndims = 1 , verbose = True ):
3032 d = int ((r * 2 ** 30 / 8 )** (1 / ndims ))
3133 shape = (d ,) * ndims
3234 chunks = (d // 4 ,) * ndims
3335 blocks = (max (d // 10 , 1 ),) * ndims
3436 t = time .time ()
35- arr = blosc2 .ones (shape = shape , dtype = np .int64 )
37+ if os .path .exists (f'linspace{ r } .b2nd' ):
38+ arr = blosc2 .open (urlpath = f'linspace{ r } .b2nd' )
39+ else :
40+ arr = blosc2 .linspace (0 , 1000 , num = np .prod (shape ), shape = shape , dtype = np .float64 , urlpath = f'linspace{ r } .b2nd' , mode = 'w' )
3641 t = time .time () - t
3742 if verbose :
3843 print (f"Array shape: { arr .shape } " )
@@ -41,15 +46,15 @@ def genarray(r, ndims=1, verbose=True):
4146 return arr
4247
4348
44- sizes = np .int64 (np .array ([1 , 2 , 4 , 8 , 16 ]))
49+ sizes = np .int64 (np .array ([1 , 2 , 4 , 8 , 16 , 24 ]))
4550rng = np .random .default_rng ()
4651blosctimes = []
4752nptimes = []
4853zarrtimes = []
4954h5pytimes = []
5055x = np .arange (len (sizes ))
5156width = 0.2
52- labs = 'NumpyBlosc2' if NUMPY_BLOSC else 'NumpyBlosc2ZarrHDF5'
57+ labs = 'NumpyBlosc2' if NUMPY_BLOSC else 'NumpyBlosc2ZarrHDF5'
5358labs = 'NumpyBlosc2Zarr' if NUMPY_BLOSC_ZARR else labs
5459try :
5560 with open (f"results{ labs } .pkl" , 'rb' ) as f :
@@ -118,8 +123,8 @@ def timer(arr, row=row, col=col):
118123 z_test [:] = arr
119124 zarrtimes += [timer (z_test )]
120125 with h5py .File ('my_hdf5_file.h5' , 'w' ) as f :
121- dset = f .create_dataset ("init" , data = arr )
122- h5pytimes += [timer (dset )]
126+ dset = f .create_dataset ("init" , data = arr )
127+ h5pytimes += [timer (dset )]
123128
124129 blosctimes = np .array (blosctimes )
125130 nptimes = np .array (nptimes )
@@ -135,8 +140,8 @@ def timer(arr, row=row, col=col):
135140 c = ['b' , 'r' , 'g' , 'm' ][i ]
136141 mean = times .mean (axis = 1 )
137142 err = (mean - times .min (axis = 1 ), times .max (axis = 1 )- mean )
138- plt .bar (x + w , mean , width , color = c , label = label , yerr = err , capsize = 5 , ecolor = 'k' ,
139- error_kw = dict (lw = 2 , capthick = 2 , ecolor = 'k' ))
143+ plt .bar (x + w , mean , width , color = c , label = label , yerr = err , capsize = 5 , ecolor = 'k' ,
144+ error_kw = dict (lw = 2 , capthick = 2 , ecolor = 'k' ))
140145 labs += label
141146
142147 with open (f"results{ labs } .pkl" , 'wb' ) as f :
@@ -147,7 +152,8 @@ def timer(arr, row=row, col=col):
147152plt .xticks (x - width , np .round (sizes , 2 ))
148153plt .ylabel ("Time (s)" )
149154plt .title ('Fancy indexing performance comparison' )
150- plt .ylim ([0 ,10 ])
155+ # plt.ylim([0,10])
156+ plt .gca ().set_yscale ('log' )
151157plt .savefig (f'plots/fancyIdx{ labs } .png' , format = "png" )
152158plt .show ()
153159
0 commit comments