@@ -37,7 +37,8 @@ def genarray(r, ndims=2, verbose=True):
3737 chunks = (d // 4 ,) * ndims
3838 blocks = (max (d // 10 , 1 ),) * ndims
3939 t = time .time ()
40- arr = blosc2 .linspace (0 , 1000 , num = np .prod (shape ), shape = shape , dtype = np .float64 , urlpath = f'linspace{ r } { ndims } D.b2nd' , mode = 'w' )
40+ arr = blosc2 .linspace (0 , 1000 , num = np .prod (shape ), shape = shape , dtype = np .float64 ,
41+ urlpath = f'linspace{ r } { ndims } D.b2nd' , mode = 'w' )
4142 t = time .time () - t
4243 arrsize = np .prod (arr .shape ) * arr .dtype .itemsize / 2 ** 30
4344 if verbose :
@@ -48,6 +49,7 @@ def genarray(r, ndims=2, verbose=True):
4849
4950
5051target_sizes = np .int64 (np .array ([1 , 2 , 4 , 8 , 16 , 24 , 32 ]))
52+ # target_sizes = np.int64(np.array([1, 2, 4, 8])) # for quick testing
5153rng = np .random .default_rng ()
5254blosctimes = []
5355nptimes = []
@@ -97,23 +99,29 @@ def timer(arr):
9799 if NUMPY :
98100 nptimes += [timer (nparr )]
99101 if ZARR :
100- z_test = zarr .create_array (store = 'data/example.zarr' , shape = nparr .shape , dtype = nparr .dtype , overwrite = True )
102+ z_test = zarr .create_array (store = 'data/example.zarr' , shape = arr .shape , chunks = arr .chunks ,
103+ dtype = nparr .dtype , overwrite = True )
101104 z_test [:] = nparr
102105 zarrtimes += [timer (z_test )]
103106 if HDF5 :
104107 with h5py .File ('my_hdf5_file.h5' , 'w' ) as f :
105- dset = f .create_dataset ("init" , data = nparr )
108+ dset = f .create_dataset ("init" , data = nparr , chunks = arr . chunks )
106109 h5pytimes += [timer (dset )]
107110
108111blosctimes = np .array (blosctimes )
109112nptimes = np .array (nptimes )
110113zarrtimes = np .array (zarrtimes )
111114h5pytimes = np .array (h5pytimes )
112115labs = ''
113- result_tuple = (["Numpy" ,nptimes ,- 2 * width ],["Blosc2" ,blosctimes , - width ],["Zarr" ,zarrtimes , 0 ],["HDF5" ,h5pytimes , width ])
116+ width = 0.2
117+ result_tuple = (
118+ ["Numpy" , nptimes , - 2 * width ],
119+ ["Blosc2" , blosctimes , - width ],
120+ ["Zarr" , zarrtimes , 0 ],
121+ ["HDF5" , h5pytimes , width ]
122+ )
114123
115124x = np .arange (len (genuine_sizes ))
116- width = 0.2
117125# Create barplot for Numpy vs Blosc vs Zarr vs H5py
118126for i , r in enumerate (result_tuple ):
119127 if r [1 ].shape != (0 ,):
@@ -125,7 +133,7 @@ def timer(arr):
125133 error_kw = dict (lw = 2 , capthick = 2 , ecolor = 'k' ))
126134 labs += label
127135
128- filename = "results{labs}{NDIMS}D"
136+ filename = f "results{ labs } { NDIMS } D"
129137
130138with open (f"{ filename } .pkl" , 'wb' ) as f :
131139 pickle .dump (result_tuple , f )
@@ -134,7 +142,7 @@ def timer(arr):
134142plt .legend ()
135143plt .xticks (x - width , np .round (genuine_sizes , 2 ))
136144plt .ylabel ("Time (s)" )
137- plt .title (' Fancy indexing performance comparison, {NDIMS}D' )
145+ plt .title (f" Fancy indexing performance comparison, { NDIMS } D" )
138146plt .gca ().set_yscale ('log' )
139147plt .savefig (f'plots/fancyIdx{ filename } .png' , format = "png" )
140148plt .show ()
0 commit comments