5
5
*/
6
6
7
7
#include <assert.h>
8
+ #include <binsparse/detail/allocator.h>
8
9
#include <binsparse/hdf5_wrapper.h>
9
10
#include <binsparse/matrix.h>
10
11
#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) {
147
148
}
148
149
#endif
149
150
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 ) {
151
153
bsp_matrix_t matrix ;
152
- bsp_construct_default_matrix_t (& matrix );
154
+ bsp_construct_default_matrix_t_allocator (& matrix , allocator );
153
155
154
156
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 );
156
159
if (error != BSP_SUCCESS ) {
157
160
return matrix ;
158
161
}
@@ -213,7 +216,8 @@ bsp_matrix_t bsp_read_matrix_from_group(hid_t f) {
213
216
assert (data_types_ != NULL );
214
217
215
218
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 );
217
221
if (error != BSP_SUCCESS ) {
218
222
free (json_string );
219
223
return matrix ;
@@ -236,7 +240,8 @@ bsp_matrix_t bsp_read_matrix_from_group(hid_t f) {
236
240
}
237
241
238
242
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 );
240
245
if (error != BSP_SUCCESS ) {
241
246
free (json_string );
242
247
bsp_destroy_array_t (& matrix .values );
@@ -245,7 +250,8 @@ bsp_matrix_t bsp_read_matrix_from_group(hid_t f) {
245
250
}
246
251
247
252
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 );
249
255
if (error != BSP_SUCCESS ) {
250
256
free (json_string );
251
257
bsp_destroy_array_t (& matrix .values );
@@ -255,7 +261,8 @@ bsp_matrix_t bsp_read_matrix_from_group(hid_t f) {
255
261
}
256
262
257
263
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 );
259
266
if (error != BSP_SUCCESS ) {
260
267
free (json_string );
261
268
bsp_destroy_array_t (& matrix .values );
@@ -278,6 +285,10 @@ bsp_matrix_t bsp_read_matrix_from_group(hid_t f) {
278
285
return matrix ;
279
286
}
280
287
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
+
281
292
static inline size_t bsp_final_dot (const char * str ) {
282
293
size_t dot_idx = 0 ;
283
294
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,
315
326
}
316
327
#endif
317
328
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 ) {
319
331
if (group == NULL ) {
320
332
size_t idx = bsp_final_dot (file_name );
321
333
if (strcmp (file_name + idx , ".hdf5" ) == 0 ||
322
334
strcmp (file_name + idx , ".h5" ) == 0 ) {
323
335
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 );
325
337
H5Fclose (f );
326
338
return matrix ;
327
339
} 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) {
332
344
} else {
333
345
hid_t f = H5Fopen (file_name , H5F_ACC_RDONLY , H5P_DEFAULT );
334
346
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 );
336
348
H5Gclose (g );
337
349
H5Fclose (f );
338
350
return matrix ;
339
351
}
340
352
}
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