1616#include "LG_internal.h"
1717#include <LAGraphX.h>
1818
19+ //Merging two ordered arrays of internal vertices in the add function
1920static GrB_Index * merge_all_paths (GrB_Index * n , const void * left , const GrB_Index na , const void * right , const GrB_Index nb ){
2021 GrB_Index * a = (GrB_Index * ) left ;
2122 GrB_Index * b = (GrB_Index * ) right ;
@@ -68,6 +69,7 @@ void clear_elem_all_paths(AllPathsElem *z){
6869
6970void add_all_paths (AllPathsElem * z , AllPathsElem * x , AllPathsElem * y )
7071{
72+ //temp is needed to avoid freeing the memory of z in case z == x or z == y
7173 AllPathsElem temp ;
7274 temp .middle = merge_all_paths (& temp .n , x -> middle , x -> n , y -> middle , y -> n );
7375 clear_elem_all_paths (x );
@@ -95,7 +97,7 @@ void set_all_paths(AllPathsElem *z, const AllPathsElem *x, const bool *edge_exis
9597 if (edge_exist && * edge_exist ){
9698 temp .middle = malloc (sizeof (GrB_Index ));
9799 temp .n = 1 ;
98- temp .middle [0 ] = GrB_INDEX_MAX ;
100+ temp .middle [0 ] = GrB_INDEX_MAX ; //GrB_INDEX_MAX - marker of A->eps and A->t
99101 }
100102
101103 z -> middle = merge_all_paths (& z -> n , x -> middle , x -> n , temp .middle , temp .n );
@@ -113,16 +115,18 @@ void set_all_paths(AllPathsElem *z, const AllPathsElem *x, const bool *edge_exis
113115" z->n = 1; \n" \
114116"}"
115117
118+ //Adding the count of all internal vertices in a reduction
116119void add_get_nvals_all_paths (AllPathsElem * z , const AllPathsElem * x , const AllPathsElem * y )
117120{
118121 z -> n = x -> n + y -> n ;
119122 z -> middle = NULL ;
120123}
121124
125+ //Made global so that the get_nvals_all_paths matches the GrB_Matrix_nvals signature
122126static GrB_Type * AllPaths_type_get_nvals = NULL ;
123127static GrB_Monoid AllPaths_monoid_get_nvals = NULL ;
124128
125- //A function that replaces GrB_Matrix_nvals for counting non-zero elements
129+ //A function that replaces GrB_Matrix_nvals in Reachability to check if new vertices have been added to the matrix.
126130GrB_Info get_nvals_all_paths (GrB_Index * nvals , const GrB_Matrix A ){
127131 GrB_Scalar s = NULL ;
128132 GrB_Scalar_new (& s , * AllPaths_type_get_nvals );
@@ -141,6 +145,28 @@ GrB_Info get_nvals_all_paths(GrB_Index *nvals, const GrB_Matrix A){
141145 return GrB_SUCCESS ;
142146}
143147
148+ //To test the non-reduction approach in the future
149+ GrB_Info get_nvals_all_paths2 (GrB_Index * nvals , const GrB_Matrix A ){
150+ GrB_Index accum = 0 ;
151+ GxB_Iterator iterator ;
152+ GxB_Iterator_new (& iterator );
153+ GrB_Info info = GxB_Matrix_Iterator_attach (iterator , A , NULL );
154+ info = GxB_Matrix_Iterator_seek (iterator , 0 );
155+ AllPathsElem val ;
156+
157+ while (info != GxB_EXHAUSTED )
158+ {
159+ GxB_Iterator_get_UDT (iterator , (void * ) & val );
160+ accum += val .n ;
161+ info = GxB_Matrix_Iterator_next (iterator );
162+ }
163+
164+ GrB_free (& iterator );
165+ * nvals = accum ;
166+
167+ return GrB_SUCCESS ;
168+ }
169+
144170GrB_Info LAGraph_CFL_AllPaths (
145171 // Output
146172 GrB_Matrix * outputs , // Array of matrices containing results.
0 commit comments