55 */
66
77#include <assert.h>
8+ #include <binsparse/detail/allocator.h>
89#include <binsparse/hdf5_wrapper.h>
910#include <binsparse/matrix.h>
1011#include <binsparse/matrix_market/matrix_market_read.h>
@@ -147,12 +148,14 @@ bsp_matrix_t bsp_read_matrix_from_group_parallel(hid_t f, int num_threads) {
147148}
148149#endif
149150
150- bsp_matrix_t bsp_read_matrix_from_group (hid_t f ) {
151+ bsp_matrix_t bsp_read_matrix_from_group_allocator (hid_t f ,
152+ bsp_allocator_t allocator ) {
151153 bsp_matrix_t matrix ;
152- bsp_construct_default_matrix_t (& matrix );
154+ bsp_construct_default_matrix_t_allocator (& matrix , allocator );
153155
154156 char * json_string ;
155- bsp_error_t error = bsp_read_attribute (& json_string , f , (char * ) "binsparse" );
157+ bsp_error_t error = bsp_read_attribute_allocator (
158+ & json_string , f , (char * ) "binsparse" , allocator );
156159 if (error != BSP_SUCCESS ) {
157160 return matrix ;
158161 }
@@ -213,7 +216,8 @@ bsp_matrix_t bsp_read_matrix_from_group(hid_t f) {
213216 assert (data_types_ != NULL );
214217
215218 if (cJSON_HasObjectItem (data_types_ , "values" )) {
216- error = bsp_read_array (& matrix .values , f , (char * ) "values" );
219+ error = bsp_read_array_allocator (& matrix .values , f , (char * ) "values" ,
220+ allocator );
217221 if (error != BSP_SUCCESS ) {
218222 free (json_string );
219223 return matrix ;
@@ -236,7 +240,8 @@ bsp_matrix_t bsp_read_matrix_from_group(hid_t f) {
236240 }
237241
238242 if (cJSON_HasObjectItem (data_types_ , "indices_0" )) {
239- error = bsp_read_array (& matrix .indices_0 , f , (char * ) "indices_0" );
243+ error = bsp_read_array_allocator (& matrix .indices_0 , f , (char * ) "indices_0" ,
244+ allocator );
240245 if (error != BSP_SUCCESS ) {
241246 free (json_string );
242247 bsp_destroy_array_t (& matrix .values );
@@ -245,7 +250,8 @@ bsp_matrix_t bsp_read_matrix_from_group(hid_t f) {
245250 }
246251
247252 if (cJSON_HasObjectItem (data_types_ , "indices_1" )) {
248- error = bsp_read_array (& matrix .indices_1 , f , (char * ) "indices_1" );
253+ error = bsp_read_array_allocator (& matrix .indices_1 , f , (char * ) "indices_1" ,
254+ allocator );
249255 if (error != BSP_SUCCESS ) {
250256 free (json_string );
251257 bsp_destroy_array_t (& matrix .values );
@@ -255,7 +261,8 @@ bsp_matrix_t bsp_read_matrix_from_group(hid_t f) {
255261 }
256262
257263 if (cJSON_HasObjectItem (data_types_ , "pointers_to_1" )) {
258- error = bsp_read_array (& matrix .pointers_to_1 , f , (char * ) "pointers_to_1" );
264+ error = bsp_read_array_allocator (& matrix .pointers_to_1 , f ,
265+ (char * ) "pointers_to_1" , allocator );
259266 if (error != BSP_SUCCESS ) {
260267 free (json_string );
261268 bsp_destroy_array_t (& matrix .values );
@@ -278,6 +285,10 @@ bsp_matrix_t bsp_read_matrix_from_group(hid_t f) {
278285 return matrix ;
279286}
280287
288+ bsp_matrix_t bsp_read_matrix_from_group (hid_t f ) {
289+ return bsp_read_matrix_from_group_allocator (f , bsp_default_allocator );
290+ }
291+
281292static inline size_t bsp_final_dot (const char * str ) {
282293 size_t dot_idx = 0 ;
283294 for (size_t i = 0 ; str [i ] != '\0' ; i ++ ) {
@@ -315,13 +326,14 @@ bsp_matrix_t bsp_read_matrix_parallel(const char* file_name, const char* group,
315326}
316327#endif
317328
318- bsp_matrix_t bsp_read_matrix (const char * file_name , const char * group ) {
329+ bsp_matrix_t bsp_read_matrix_allocator (const char * file_name , const char * group ,
330+ bsp_allocator_t allocator ) {
319331 if (group == NULL ) {
320332 size_t idx = bsp_final_dot (file_name );
321333 if (strcmp (file_name + idx , ".hdf5" ) == 0 ||
322334 strcmp (file_name + idx , ".h5" ) == 0 ) {
323335 hid_t f = H5Fopen (file_name , H5F_ACC_RDONLY , H5P_DEFAULT );
324- bsp_matrix_t matrix = bsp_read_matrix_from_group ( f );
336+ bsp_matrix_t matrix = bsp_read_matrix_from_group_allocator ( f , allocator );
325337 H5Fclose (f );
326338 return matrix ;
327339 } else if (strcmp (file_name + idx , ".mtx" ) == 0 ) {
@@ -332,9 +344,13 @@ bsp_matrix_t bsp_read_matrix(const char* file_name, const char* group) {
332344 } else {
333345 hid_t f = H5Fopen (file_name , H5F_ACC_RDONLY , H5P_DEFAULT );
334346 hid_t g = H5Gopen1 (f , group );
335- bsp_matrix_t matrix = bsp_read_matrix_from_group ( g );
347+ bsp_matrix_t matrix = bsp_read_matrix_from_group_allocator ( g , allocator );
336348 H5Gclose (g );
337349 H5Fclose (f );
338350 return matrix ;
339351 }
340352}
353+
354+ bsp_matrix_t bsp_read_matrix (const char * file_name , const char * group ) {
355+ return bsp_read_matrix_allocator (file_name , group , bsp_default_allocator );
356+ }
0 commit comments