1717
1818#define LG_FREE_WORK \
1919 { \
20- LAGraph_Free((void **)&nnzs, msg); \
21- GrB_free(&true_scalar); \
2220 GrB_free(&identity_matrix); \
23- LAGraph_Free((void **)&indexes, msg); \
2421 }
2522
2623#define LG_FREE_ALL \
126123#define OPT_LAZY (1 << 2)
127124#define OPT_BLOCK (1 << 3)
128125
129- #define SKIP_IF_NULL (matrix ) \
130- GrB_Matrix_nvals(&new_nnz, matrix); \
131- if (new_nnz == 0) { \
132- continue; \
133- }
134-
135126#define TRY (GrB_method ) \
136127 { \
137128 GrB_Info LG_GrB_Info = GrB_method; \
141132 } \
142133 }
143134
144- typedef CFL_Matrix Matrix ;
145- typedef enum CFL_Matrix_block Matrix_block ;
146-
147- #define IS_NONTERM (index ) \
148- { \
149- for (size_t m = 0; m < rules_count; m++) { \
150- if (rules[m].nonterm == index) \
151- return true; \
152- } \
153- \
154- return false; \
155- }
156-
157- bool is_nonterm (int index , const LAGraph_rule_WCNF * rules , size_t rules_count ) {
158- for (size_t i = 0 ; i < rules_count ; i ++ ) {
159- if (rules [i ].nonterm == index ) {
160- return true;
161- }
162- }
163-
164- return false;
165- }
166-
167135// LAGraph_CFL_reachability: Context-Free Language Reachability Matrix-Based Algorithm
168136//
169137// This function determines the set of vertex pairs (u, v) in a graph (represented by
@@ -230,22 +198,17 @@ GrB_Info LAGraph_CFL_reachability_adv(
230198 int8_t optimizations // Optimizations flags
231199) {
232200 // Declare workspace and clear the msg string, if not NULL
233- Matrix * delta_matrices ;
234- Matrix * matrices ;
235- Matrix * temp_matrices ;
201+ CFL_Matrix * delta_matrices , * matrices , * temp_matrices ;
202+ CFL_Matrix iden ;
236203 GrB_Matrix identity_matrix = NULL ;
237- uint64_t * nnzs = NULL ;
238204 LG_CLEAR_MSG ;
239205 size_t msg_len = 0 ; // For error formatting
240- GrB_Index * indexes = NULL ;
241206
242- GrB_Scalar true_scalar ;
243- GrB_Scalar_new (& true_scalar , GrB_BOOL );
244- GrB_Scalar_setElement_BOOL (true_scalar , true);
245-
246- LG_TRY (LAGraph_Calloc ((void * * )& delta_matrices , symbols_amount , sizeof (Matrix ), msg ));
247- LG_TRY (LAGraph_Calloc ((void * * )& matrices , symbols_amount , sizeof (Matrix ), msg ));
248- LG_TRY (LAGraph_Calloc ((void * * )& temp_matrices , symbols_amount , sizeof (Matrix ), msg ));
207+ LG_TRY (LAGraph_Calloc ((void * * )& delta_matrices , symbols_amount , sizeof (CFL_Matrix ),
208+ msg ));
209+ LG_TRY (LAGraph_Calloc ((void * * )& matrices , symbols_amount , sizeof (CFL_Matrix ), msg ));
210+ LG_TRY (
211+ LAGraph_Calloc ((void * * )& temp_matrices , symbols_amount , sizeof (CFL_Matrix ), msg ));
249212
250213 LG_ASSERT_MSG (symbols_amount > 0 , GrB_INVALID_VALUE ,
251214 "The number of symbols must be greater than zero." );
@@ -289,8 +252,7 @@ GrB_Info LAGraph_CFL_reachability_adv(
289252 GrB_Index ncols ;
290253 GrB_Matrix_ncols (& ncols , adj_matrices [i ]);
291254
292- GrB_Matrix_dup (& delta_matrices [i ].base , adj_matrices [i ]);
293- delta_matrices [i ] = CFL_matrix_from_base (delta_matrices [i ].base );
255+ delta_matrices [i ] = CFL_matrix_from_base (adj_matrices [i ]);
294256
295257 GRB_TRY (GrB_Matrix_new (& matrix , GrB_BOOL , nrows , ncols ));
296258 matrices [i ] = ((optimizations & OPT_LAZY ) || (optimizations & OPT_BLOCK ))
@@ -385,8 +347,8 @@ GrB_Info LAGraph_CFL_reachability_adv(
385347 // Rule [Variable -> term]
386348 for (size_t i = 0 ; i < term_rules_count ; i ++ ) {
387349 LAGraph_rule_WCNF term_rule = rules [term_rules [i ]];
388- Matrix * nonterm_matrix = & delta_matrices [term_rule .nonterm ];
389- Matrix * term_matrix = & delta_matrices [term_rule .prod_A ];
350+ CFL_Matrix * nonterm_matrix = & delta_matrices [term_rule .nonterm ];
351+ CFL_Matrix * term_matrix = & delta_matrices [term_rule .prod_A ];
390352
391353 GRB_TRY (
392354 CFL_wise (nonterm_matrix , nonterm_matrix , term_matrix , true, optimizations ));
@@ -402,13 +364,13 @@ GrB_Info LAGraph_CFL_reachability_adv(
402364 GRB_TRY (GrB_Vector_assign_BOOL (v_diag , GrB_NULL , GrB_NULL , true, GrB_ALL , n , NULL ));
403365 GRB_TRY (GrB_Matrix_diag (& identity_matrix , v_diag , 0 ));
404366 GRB_TRY (GrB_free (& v_diag ));
405- Matrix iden = CFL_matrix_from_base (identity_matrix );
367+ iden = CFL_matrix_from_base (identity_matrix );
406368
407369 // Rule [Variable -> eps]
408370 for (size_t i = 0 ; i < eps_rules_count ; i ++ ) {
409371 LAGraph_rule_WCNF eps_rule = rules [eps_rules [i ]];
410372
411- Matrix * nonterm_matrix = & delta_matrices [eps_rule .nonterm ];
373+ CFL_Matrix * nonterm_matrix = & delta_matrices [eps_rule .nonterm ];
412374
413375 CFL_wise (nonterm_matrix , nonterm_matrix , & iden , true, optimizations );
414376
@@ -419,8 +381,6 @@ GrB_Info LAGraph_CFL_reachability_adv(
419381 }
420382
421383 // Rule [Variable -> Variable1 Variable2]
422- LG_TRY (LAGraph_Calloc ((void * * )& nnzs , symbols_amount , sizeof (uint64_t ), msg ));
423-
424384 double start_time , end_time ;
425385 bool changed = true;
426386 size_t iteration = 0 ;
@@ -447,9 +407,9 @@ GrB_Info LAGraph_CFL_reachability_adv(
447407 TIMER_START ();
448408 for (size_t i = 0 ; i < bin_rules_count ; i ++ ) {
449409 LAGraph_rule_WCNF bin_rule = rules [bin_rules [i ]];
450- Matrix * A = & matrices [bin_rule .prod_A ];
451- Matrix * B = & delta_matrices [bin_rule .prod_B ];
452- Matrix * C = & temp_matrices [bin_rule .nonterm ];
410+ CFL_Matrix * A = & matrices [bin_rule .prod_A ];
411+ CFL_Matrix * B = & delta_matrices [bin_rule .prod_B ];
412+ CFL_Matrix * C = & temp_matrices [bin_rule .nonterm ];
453413
454414 // printf("MXM 1 iteration: %ld i: %ld\n", iteration, i);
455415 // matrix_print_lazy(A);
@@ -465,8 +425,8 @@ GrB_Info LAGraph_CFL_reachability_adv(
465425
466426 TIMER_START ()
467427 for (size_t i = 0 ; i < symbols_amount ; i ++ ) {
468- Matrix * A = & delta_matrices [i ];
469- Matrix * C = & matrices [i ];
428+ CFL_Matrix * A = & delta_matrices [i ];
429+ CFL_Matrix * C = & matrices [i ];
470430
471431 // printf("WISE 1 iteration: %ld i: %ld\n", iteration, i);
472432 // matrix_print_lazy(A);
@@ -482,9 +442,9 @@ GrB_Info LAGraph_CFL_reachability_adv(
482442 TIMER_START ()
483443 for (size_t i = 0 ; i < bin_rules_count ; i ++ ) {
484444 LAGraph_rule_WCNF bin_rule = rules [bin_rules [i ]];
485- Matrix * A = & matrices [bin_rule .prod_B ];
486- Matrix * B = & delta_matrices [bin_rule .prod_A ];
487- Matrix * C = & temp_matrices [bin_rule .nonterm ];
445+ CFL_Matrix * A = & matrices [bin_rule .prod_B ];
446+ CFL_Matrix * B = & delta_matrices [bin_rule .prod_A ];
447+ CFL_Matrix * C = & temp_matrices [bin_rule .nonterm ];
488448
489449 // printf("MXM 2 iteration: %ld i: %ld\n", iteration, i);
490450 // matrix_print_lazy(A);
@@ -501,8 +461,8 @@ GrB_Info LAGraph_CFL_reachability_adv(
501461 // Rule [Variable -> term]
502462 for (size_t i = 0 ; i < term_rules_count ; i ++ ) {
503463 LAGraph_rule_WCNF term_rule = rules [term_rules [i ]];
504- Matrix * A = & temp_matrices [term_rule .nonterm ];
505- Matrix * B = & delta_matrices [term_rule .prod_A ];
464+ CFL_Matrix * A = & temp_matrices [term_rule .nonterm ];
465+ CFL_Matrix * B = & delta_matrices [term_rule .prod_A ];
506466
507467 // printf("Simple rules iteration: %ld i: %ld\n", iteration, i);
508468 // matrix_print_lazy(A);
@@ -526,8 +486,8 @@ GrB_Info LAGraph_CFL_reachability_adv(
526486
527487 TIMER_START ();
528488 for (size_t i = 0 ; i < symbols_amount ; i ++ ) {
529- Matrix * A = & matrices [i ];
530- Matrix * C = & delta_matrices [i ];
489+ CFL_Matrix * A = & matrices [i ];
490+ CFL_Matrix * C = & delta_matrices [i ];
531491
532492 // printf("RSUB iteration: %ld i: %ld\n", iteration, i);
533493 // matrix_print_lazy(A);
0 commit comments