4444 } \
4545 }
4646
47- #define ADD_INDEX_TO_ERROR_RULE (rule , i ) \
48- { \
49- rule.len_indexes_str += snprintf( \
50- rule.indexes_str + rule.len_indexes_str, \
51- LAGRAPH_MSG_LEN - rule.len_indexes_str, \
52- rule.count == 0 ? "%" PRId64 : ", %" PRId64, i); \
53- rule.count++; \
54- }
55-
5647#include "LG_internal.h"
5748#include <LAGraphX.h>
5849
@@ -287,25 +278,25 @@ GrB_Info LAGraph_CFL_AllPaths(
287278 int8_t mode // mode = 0 - postprocessing(prefer), mode = 1 - CFPQ Core
288279)
289280{
290- LG_CLEAR_MSG ;
291- size_t msg_len = 0 ; // For error formatting
292- GrB_Matrix * T = NULL ;
293- GrB_Scalar false_scalar = NULL ;
294- GrB_Matrix * outputs_reachability = NULL ;
295- bool * t_empty_flags = NULL ; // t_empty_flags[i] == true <=> T[i] is empty
296- // Arrays for processing rules
297- size_t * eps_rules = NULL , eps_rules_count = 0 ; // [Variable -> eps]
298- size_t * term_rules = NULL , term_rules_count = 0 ; // [Variable -> term]
299- size_t * bin_rules = NULL , bin_rules_count = 0 ; // [Variable -> AB]
281+ LG_CLEAR_MSG ;
282+ size_t msg_len = 0 ; // For error formatting
283+ GrB_Matrix * T = NULL ;
284+ GrB_Scalar false_scalar = NULL ;
285+ GrB_Matrix * outputs_reachability = NULL ;
286+ bool * t_empty_flags = NULL ; // t_empty_flags[i] == true <=> T[i] is empty
287+ // Arrays for processing rules
288+ size_t * eps_rules = NULL , eps_rules_count = 0 ; // [Variable -> eps]
289+ size_t * term_rules = NULL , term_rules_count = 0 ; // [Variable -> term]
290+ size_t * bin_rules = NULL , bin_rules_count = 0 ; // [Variable -> AB]
300291
301292
302- GrB_Matrix identity_matrix = NULL ;
303- GrB_Vector v_diag = NULL ;
293+ GrB_Matrix identity_matrix = NULL ;
294+ GrB_Vector v_diag = NULL ;
304295
305296#if GxB_IMPLEMENTATION < GxB_VERSION (9 , 4 , 5 )
306297 return (GrB_NOT_IMPLEMENTED );
307298#else
308- // Create a semiring for the CFPQ core and postprocessing modes
299+ // Create a semiring for the CFPQ core and postprocessing modes
309300 GrB_BinaryOp AllPaths_add = NULL ;
310301 GrB_BinaryOp AllPaths_add_get_nvals = NULL ;
311302 GrB_Monoid AllPaths_monoid = NULL ;
@@ -315,98 +306,98 @@ GrB_Vector v_diag = NULL;
315306 GrB_BinaryOp AllPaths_set = NULL ;
316307 GrB_Scalar Theta = NULL ;
317308 GrB_Scalar bottom_scalar = NULL ;
318-
309+
319310 GrB_free (all_paths_ptr_t );
320311 GRB_TRY (GrB_Type_new (all_paths_ptr_t , sizeof (AllPathsElem )));
321312 AllPaths_type = * all_paths_ptr_t ;
322-
313+
323314 GRB_TRY (GrB_Scalar_new (& Theta , GrB_BOOL ));
324315 GRB_TRY (GrB_Scalar_setElement_BOOL (Theta , false));
325-
326- AllPathsElem bottom = {0 };
316+
317+ AllPathsElem bottom = { 0 };
327318 GRB_TRY (GrB_Scalar_new (& bottom_scalar , AllPaths_type ));
328- GRB_TRY (GrB_Scalar_setElement_UDT (bottom_scalar , (void * )(& bottom )));
329-
319+ GRB_TRY (GrB_Scalar_setElement_UDT (bottom_scalar , (void * )(& bottom )));
320+
330321 GRB_TRY (GrB_BinaryOp_new (
331- & AllPaths_add ,
332- (void * )add_all_paths ,
333- AllPaths_type ,
334- AllPaths_type ,
335- AllPaths_type ));
336-
322+ & AllPaths_add ,
323+ (void * )add_all_paths ,
324+ AllPaths_type ,
325+ AllPaths_type ,
326+ AllPaths_type ));
327+
337328 GRB_TRY (GrB_Monoid_new (
338- & AllPaths_monoid ,
339- AllPaths_add ,
340- (void * )(& bottom )));
329+ & AllPaths_monoid ,
330+ AllPaths_add ,
331+ (void * )(& bottom )));
341332 //CFPQ core
342- if (mode == 1 ){
343- GRB_TRY (GxB_IndexBinaryOp_new (
344- & IAllPaths_mult ,
345- (void * )mult_all_paths ,
346- AllPaths_type ,
347- AllPaths_type ,
348- AllPaths_type ,
349- GrB_BOOL ,
350- "mult_all_paths" ,
351- MULT_PATH_INDEX_DEFN ));
333+ if (mode == 1 ) {
334+ GRB_TRY (GxB_IndexBinaryOp_new (
335+ & IAllPaths_mult ,
336+ (void * )mult_all_paths ,
337+ AllPaths_type ,
338+ AllPaths_type ,
339+ AllPaths_type ,
340+ GrB_BOOL ,
341+ "mult_all_paths" ,
342+ MULT_PATH_INDEX_DEFN ));
352343 }
353344 //postprocessing
354- else if (mode == 0 ){
355- GRB_TRY (GxB_IndexBinaryOp_new (
356- & IAllPaths_mult ,
357- (void * )mult_all_paths_post ,
358- AllPaths_type ,
359- GrB_BOOL ,
360- GrB_BOOL ,
361- GrB_BOOL ,
362- "mult_all_paths_post" ,
363- MULT_PATH_POST_INDEX_DEFN ));
345+ else if (mode == 0 ) {
346+ GRB_TRY (GxB_IndexBinaryOp_new (
347+ & IAllPaths_mult ,
348+ (void * )mult_all_paths_post ,
349+ AllPaths_type ,
350+ GrB_BOOL ,
351+ GrB_BOOL ,
352+ GrB_BOOL ,
353+ "mult_all_paths_post" ,
354+ MULT_PATH_POST_INDEX_DEFN ));
364355 }
365356 else {
366357 ADD_TO_MSG ("Mode must be 0(postprocessing) or 1(CFPQ Core)" );
367358 return GrB_INVALID_VALUE ;
368359 }
369-
360+
370361 GRB_TRY (GxB_BinaryOp_new_IndexOp (
371- & AllPaths_mult ,
372- IAllPaths_mult ,
373- Theta ));
374-
362+ & AllPaths_mult ,
363+ IAllPaths_mult ,
364+ Theta ));
365+
375366 GRB_TRY (GrB_Semiring_new (
376- & AllPaths_semiring ,
377- AllPaths_monoid ,
378- AllPaths_mult ));
379-
367+ & AllPaths_semiring ,
368+ AllPaths_monoid ,
369+ AllPaths_mult ));
370+
380371 GRB_TRY (GrB_BinaryOp_new (
381- & AllPaths_set ,
382- (void * )set_all_paths ,
383- AllPaths_type ,
384- AllPaths_type ,
385- GrB_BOOL ));
386-
372+ & AllPaths_set ,
373+ (void * )set_all_paths ,
374+ AllPaths_type ,
375+ AllPaths_type ,
376+ GrB_BOOL ));
377+
387378 GRB_TRY (GrB_BinaryOp_new (
388- & AllPaths_add_get_nvals ,
389- (void * )add_get_nvals_all_paths ,
390- AllPaths_type ,
391- AllPaths_type ,
392- AllPaths_type ));
393-
379+ & AllPaths_add_get_nvals ,
380+ (void * )add_get_nvals_all_paths ,
381+ AllPaths_type ,
382+ AllPaths_type ,
383+ AllPaths_type ));
384+
394385 GRB_TRY (GrB_Monoid_new (
395- & AllPaths_monoid_get_nvals ,
396- AllPaths_add_get_nvals ,
397- (void * )(& bottom )));
398-
386+ & AllPaths_monoid_get_nvals ,
387+ AllPaths_add_get_nvals ,
388+ (void * )(& bottom )));
389+
399390 CFL_Semiring semiring = {
400391 .type = AllPaths_type ,
401392 .semiring = AllPaths_semiring ,
402393 .add = AllPaths_add ,
403394 .mult = AllPaths_mult ,
404395 .init_path = AllPaths_set ,
405396 .bottom_scalar = bottom_scalar ,
406- .get_nvals = get_nvals_all_paths };
407-
397+ .get_nvals = get_nvals_all_paths };
398+
408399 // CFPQ core mode
409- if (mode == 1 ){
400+ if (mode == 1 ) {
410401 LG_TRY (LAGraph_CFPQ_core (outputs , adj_matrices , terms_count , nonterms_count , rules , rules_count , & semiring , msg ));
411402 }
412403 // postprocessing mode
@@ -419,7 +410,7 @@ GrB_Vector v_diag = NULL;
419410 LG_TRY (LAGraph_CFL_reachability (outputs_reachability , adj_matrices , terms_count , \
420411 nonterms_count , rules , rules_count , \
421412 msg ));
422-
413+
423414 LG_TRY (LAGraph_Calloc ((void * * )& T , nonterms_count , sizeof (GrB_Matrix ), msg ));
424415 GRB_TRY (GrB_Scalar_new (& false_scalar , GrB_BOOL ));
425416 GRB_TRY (GrB_Scalar_setElement_BOOL (false_scalar , false));
@@ -449,21 +440,18 @@ GrB_Vector v_diag = NULL;
449440 if (is_rule_eps )
450441 {
451442 eps_rules [eps_rules_count ++ ] = i ;
452-
453443 continue ;
454444 }
455445 // [Variable -> term]
456446 if (is_rule_term )
457447 {
458448 term_rules [term_rules_count ++ ] = i ;
459-
460449 continue ;
461450 }
462451 // [Variable -> A B]
463452 if (is_rule_bin )
464453 {
465454 bin_rules [bin_rules_count ++ ] = i ;
466-
467455 continue ;
468456 }
469457 }
@@ -519,23 +507,20 @@ GrB_Vector v_diag = NULL;
519507 LAGraph_rule_WCNF bin_rule = rules [bin_rules [i ]];
520508
521509 // If one of matrices is empty then their product will be empty
522- if (t_empty_flags [bin_rule .prod_A ] || t_empty_flags [bin_rule .prod_B ])
523- {
524- continue ;
525- }
510+ if (t_empty_flags [bin_rule .prod_A ] || t_empty_flags [bin_rule .prod_B ]) continue ;
526511
527512 GrB_BinaryOp acc_op = t_empty_flags [bin_rule .nonterm ] ? GrB_NULL : semiring .add ;
528513 GRB_TRY (GrB_mxm (T [bin_rule .nonterm ], GrB_NULL , acc_op ,
529514 semiring .semiring , outputs_reachability [bin_rule .prod_A ], outputs_reachability [bin_rule .prod_B ],
530515 GrB_NULL ))
531516 }
532517
533- for (size_t i = 0 ; i < nonterms_count ; i ++ )
534- {
535- outputs [i ] = T [i ];
536- GrB_free (& outputs_reachability [i ]);
537- }
538- } // End of postprocessing mode
518+ for (size_t i = 0 ; i < nonterms_count ; i ++ )
519+ {
520+ outputs [i ] = T [i ];
521+ GrB_free (& outputs_reachability [i ]);
522+ }
523+ } // End of postprocessing mode
539524 LG_FREE_WORK ;
540525 return GrB_SUCCESS ;
541526#endif
0 commit comments