@@ -232,17 +232,17 @@ void matrix_free(Matrix *matrix) {
232232 TRY (GrB_free (& matrix -> base ));
233233}
234234
235- void matrix_to_format (Matrix * matrix , int32_t format , bool is_both ) {
235+ GrB_Info matrix_to_format (Matrix * matrix , int32_t format , bool is_both ) {
236236 // Matrix contain both formats so just switch base matrix
237237 if (matrix -> is_both ) {
238238 matrix -> base = format == GrB_ROWMAJOR ? matrix -> base_row : matrix -> base_col ;
239239 matrix -> format = format ;
240- return ;
240+ return GrB_SUCCESS ;
241241 }
242242
243243 // No changes required
244244 if (matrix -> format == format ) {
245- return ;
245+ return GrB_SUCCESS ;
246246 }
247247
248248 // Matrix contain just one matrix and format is not same
@@ -264,7 +264,7 @@ void matrix_to_format(Matrix *matrix, int32_t format, bool is_both) {
264264 matrix -> base = format == GrB_ROWMAJOR ? matrix -> base_row : matrix -> base_col ;
265265 format == GrB_ROWMAJOR ? TO_ROW (matrix -> base ) : TO_COL (matrix -> base );
266266 matrix -> format = format ;
267- return ;
267+ return GrB_SUCCESS ;
268268}
269269
270270GrB_Info matrix_clear (Matrix * A ) {
@@ -298,33 +298,35 @@ GrB_Info matrix_clear_empty(Matrix *A) {
298298 return matrix_clear_format (A );
299299}
300300
301- void block_matrix_hyper_rotate_i (Matrix * matrix , enum Matrix_block format ) {
301+ GrB_Info block_matrix_hyper_rotate_i (Matrix * matrix , enum Matrix_block format ) {
302302 if (matrix -> is_lazy ) {
303303 for (size_t i = 0 ; i < matrix -> base_matrices_count ; i ++ ) {
304- block_matrix_hyper_rotate_i (& matrix -> base_matrices [i ], format );
304+ TRY ( block_matrix_hyper_rotate_i (& matrix -> base_matrices [i ], format ) );
305305 }
306306
307307 matrix_update (matrix );
308- return ;
308+ return GrB_SUCCESS ;
309309 }
310310
311311 if (matrix -> block_type == CELL ) {
312- return ;
312+ return GrB_SUCCESS ;
313313 }
314314
315315 if (matrix -> block_type == format ) {
316- return ;
316+ return GrB_SUCCESS ;
317317 }
318318
319319 GrB_Scalar scalar_true ;
320- GrB_Scalar_new (& scalar_true , GrB_BOOL );
321- GrB_Scalar_setElement_BOOL (scalar_true , true);
320+ TRY ( GrB_Scalar_new (& scalar_true , GrB_BOOL ) );
321+ TRY ( GrB_Scalar_setElement_BOOL (scalar_true , true) );
322322
323323 if (matrix -> block_type == VEC_VERT ) {
324+ // fix: change to lagraph malloc
324325 GrB_Index * nrows = malloc (matrix -> nvals * sizeof (GrB_Index ));
325326 GrB_Index * ncols = malloc (matrix -> nvals * sizeof (GrB_Index ));
326327
327- GrB_Matrix_extractTuples_BOOL (nrows , ncols , NULL , & matrix -> nvals , matrix -> base );
328+ TRY (GrB_Matrix_extractTuples_BOOL (nrows , ncols , NULL , & matrix -> nvals ,
329+ matrix -> base ));
328330
329331 for (size_t i = 0 ; i < matrix -> nvals ; i ++ ) {
330332 ncols [i ] = ncols [i ] + nrows [i ] / matrix -> ncols * matrix -> ncols ;
@@ -339,14 +341,15 @@ void block_matrix_hyper_rotate_i(Matrix *matrix, enum Matrix_block format) {
339341 free (nrows );
340342 free (ncols );
341343 GrB_free (& scalar_true );
342- return ;
344+ return GrB_SUCCESS ;
343345 }
344346
345347 if (matrix -> block_type == VEC_HORIZ ) {
346348 GrB_Index * nrows = malloc (matrix -> nvals * sizeof (GrB_Index ));
347349 GrB_Index * ncols = malloc (matrix -> nvals * sizeof (GrB_Index ));
348350
349- GrB_Matrix_extractTuples_BOOL (nrows , ncols , NULL , & matrix -> nvals , matrix -> base );
351+ TRY (GrB_Matrix_extractTuples_BOOL (nrows , ncols , NULL , & matrix -> nvals ,
352+ matrix -> base ));
350353
351354 for (size_t i = 0 ; i < matrix -> nvals ; i ++ ) {
352355 nrows [i ] = nrows [i ] + ncols [i ] / matrix -> nrows * matrix -> nrows ;
@@ -361,7 +364,7 @@ void block_matrix_hyper_rotate_i(Matrix *matrix, enum Matrix_block format) {
361364 free (nrows );
362365 free (ncols );
363366 GrB_free (& scalar_true );
364- return ;
367+ return GrB_SUCCESS ;
365368 }
366369}
367370
@@ -517,16 +520,17 @@ GrB_Info matrix_combine_lazy(Matrix *A, size_t threshold) {
517520 Matrix * new_matrices = malloc (sizeof (Matrix ) * 50 );
518521 size_t new_size = 0 ;
519522
520- matrix_sort_lazy (A , false);
523+ TRY ( matrix_sort_lazy (A , false) );
521524
522525 for (size_t i = 0 ; i < A -> base_matrices_count ; i ++ ) {
523- if (A -> base_matrices [i ].nvals <= threshold && new_size > 0 ) {
524- matrix_wise_empty (& new_matrices [new_size - 1 ], & new_matrices [new_size - 1 ],
525- & A -> base_matrices [i ], false);
526- GrB_free (& A -> base_matrices [i ].base );
527- } else {
526+ if (new_size == 0 || A -> base_matrices [i ].nvals > threshold ) {
528527 new_matrices [new_size ++ ] = A -> base_matrices [i ];
528+ continue ;
529529 }
530+
531+ TRY (matrix_wise_empty (& new_matrices [new_size - 1 ], & new_matrices [new_size - 1 ],
532+ & A -> base_matrices [i ], false));
533+ GrB_free (& A -> base_matrices [i ].base );
530534 }
531535
532536 A -> base_matrices = new_matrices ;
@@ -867,8 +871,8 @@ GrB_Info matrix_rsub(Matrix *output, Matrix *mask) {
867871
868872GrB_Info matrix_rsub_format (Matrix * output , Matrix * mask ) {
869873 Matrix * larger_matrix = output -> nvals > mask -> nvals ? output : mask ;
870- matrix_to_format (output , larger_matrix -> format , false);
871- matrix_to_format (mask , larger_matrix -> format , false);
874+ TRY ( matrix_to_format (output , larger_matrix -> format , false) );
875+ TRY ( matrix_to_format (mask , larger_matrix -> format , false) );
872876
873877 if (!output -> is_both ) {
874878 return matrix_rsub (output , mask );
@@ -900,11 +904,11 @@ GrB_Info matrix_rsub_lazy(Matrix *output, Matrix *mask) {
900904 return matrix_rsub_empty (output , mask );
901905 }
902906
903- matrix_combine_lazy (mask , output -> nvals );
904- matrix_sort_lazy (mask , true);
907+ TRY ( matrix_combine_lazy (mask , output -> nvals ) );
908+ TRY ( matrix_sort_lazy (mask , true) );
905909
906910 for (size_t i = 0 ; i < mask -> base_matrices_count ; i ++ ) {
907- matrix_rsub_empty (output , & mask -> base_matrices [i ]);
911+ TRY ( matrix_rsub_empty (output , & mask -> base_matrices [i ]) );
908912 }
909913
910914 return GrB_SUCCESS ;
@@ -921,7 +925,7 @@ GrB_Info matrix_rsub_block(Matrix *output, Matrix *mask) {
921925 return matrix_rsub_lazy (output , mask );
922926 }
923927
924- block_matrix_hyper_rotate_i (output , mask -> block_type );
928+ TRY ( block_matrix_hyper_rotate_i (output , mask -> block_type ) );
925929 return matrix_rsub_lazy (output , mask );
926930}
927931
@@ -1391,7 +1395,7 @@ GrB_Info LAGraph_CFL_reachability_adv(
13911395 // printf("RSUB iteration: %ld i: %ld\n", iteration, i);
13921396 // matrix_print_lazy(A);
13931397 // matrix_print_lazy(C);
1394- rsub (C , A );
1398+ TRY ( rsub (C , A ) );
13951399 // matrix_print_lazy(C);
13961400 }
13971401 TIMER_STOP ("WISE 3 (MASK)" , & rsubt );
0 commit comments