Skip to content

Commit 23d0af1

Browse files
committed
add check GxB_VERSION and add comment
1 parent d4fe2d5 commit 23d0af1

3 files changed

Lines changed: 68 additions & 49 deletions

File tree

experimental/algorithm/LAGraph_CFL_AllPaths.c

Lines changed: 55 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,22 @@ GrB_Info get_nvals_all_paths2(GrB_Index *nvals, const GrB_Matrix A){
166166
return GrB_SUCCESS;
167167
}
168168

169+
// all_paths_ptr_t is a pointer to the type of elements of the outputs matrices.
170+
// Use GrB_free(all_paths_ptr_t) after you finish working with the outputs matrices.
169171
// Important: Do not free all_paths_ptr_t until all work with the output matrices is complete.
170172
// Accessing matrices after freeing their type is undefined behavior.
171-
//
172173
GrB_Info LAGraph_CFL_AllPaths(
173174
// Output
174175
GrB_Matrix *outputs, // Array of matrices containing results.
175176
// The size of the array must be equal to nonterms_count.
176-
//
177+
// Matrix elements are ordered arrays of intermediate vertices type AllPathsElem.
178+
// Before free outputs[k], you need to free arrays from all matrix elements.
179+
// For all values of M from the array of the matrix element
180+
// outputs[k] on the I row of the J column:
181+
// There are paths from I to M by nonterminal N1 and from M to J by nonterminal N2,
182+
// and A->N1 N2 where outputs[k] corresponds to nonterminal A.
183+
// GrB_INDEX_MAX in the array is a special value for A->eps and A->t.
184+
177185
// Input
178186
const GrB_Matrix *adj_matrices, // Array of adjacency matrices representing the graph.
179187
// The length of this array is equal to the count of
@@ -191,6 +199,9 @@ GrB_Info LAGraph_CFL_AllPaths(
191199
char *msg // Message string for error reporting.
192200
)
193201
{
202+
#if GxB_IMPLEMENTATION < GxB_VERSION(9, 4, 5)
203+
return (GrB_NOT_IMPLEMENTED);
204+
#else
194205
// Semiring components
195206
GrB_Type AllPaths_type = NULL;
196207
GrB_BinaryOp AllPaths_add = NULL;
@@ -202,82 +213,83 @@ GrB_Info LAGraph_CFL_AllPaths(
202213
GrB_BinaryOp AllPaths_set = NULL;
203214
GrB_Scalar Theta = NULL;
204215
GrB_Scalar bottom_scalar = NULL;
205-
216+
206217
GrB_free(all_paths_ptr_t);
207218
GRB_TRY(GrB_Type_new(all_paths_ptr_t, sizeof(AllPathsElem)));
208219
AllPaths_type = *all_paths_ptr_t;
209220
AllPaths_type_get_nvals = all_paths_ptr_t;
210221

211222
GRB_TRY(GrB_Scalar_new(&Theta, GrB_BOOL));
212223
GRB_TRY(GrB_Scalar_setElement_BOOL(Theta, false));
213-
224+
214225
AllPathsElem bottom = {0, NULL};
215226
GRB_TRY(GrB_Scalar_new(&bottom_scalar, AllPaths_type));
216227
GRB_TRY(GrB_Scalar_setElement_UDT(bottom_scalar, (void *)(&bottom)));
217228

218229
GRB_TRY(GrB_BinaryOp_new(
219-
&AllPaths_add,
220-
(void *)add_all_paths,
221-
AllPaths_type,
222-
AllPaths_type,
223-
AllPaths_type));
224-
230+
&AllPaths_add,
231+
(void *)add_all_paths,
232+
AllPaths_type,
233+
AllPaths_type,
234+
AllPaths_type));
235+
225236
GRB_TRY(GrB_Monoid_new(
226-
&AllPaths_monoid,
227-
AllPaths_add,
228-
(void *)(&bottom)));
237+
&AllPaths_monoid,
238+
AllPaths_add,
239+
(void *)(&bottom)));
229240

230241
GRB_TRY(GxB_IndexBinaryOp_new(
231-
&IAllPaths_mult,
232-
(void *)mult_all_paths,
233-
AllPaths_type,
234-
AllPaths_type,
235-
AllPaths_type,
236-
GrB_BOOL,
237-
"mult_all_paths",
238-
MULT_PATH_INDEX_DEFN));
239-
242+
&IAllPaths_mult,
243+
(void *)mult_all_paths,
244+
AllPaths_type,
245+
AllPaths_type,
246+
AllPaths_type,
247+
GrB_BOOL,
248+
"mult_all_paths",
249+
MULT_PATH_INDEX_DEFN));
250+
240251
GRB_TRY(GxB_BinaryOp_new_IndexOp(
241-
&AllPaths_mult,
242-
IAllPaths_mult,
243-
Theta));
244-
252+
&AllPaths_mult,
253+
IAllPaths_mult,
254+
Theta));
255+
245256
GRB_TRY(GrB_Semiring_new(
246-
&AllPaths_semiring,
247-
AllPaths_monoid,
248-
AllPaths_mult));
257+
&AllPaths_semiring,
258+
AllPaths_monoid,
259+
AllPaths_mult));
249260

250261
GRB_TRY(GrB_BinaryOp_new(
251262
&AllPaths_set,
252263
(void *)set_all_paths,
253-
AllPaths_type,
254-
AllPaths_type,
255-
GrB_BOOL));
264+
AllPaths_type,
265+
AllPaths_type,
266+
GrB_BOOL));
256267

257268
GRB_TRY(GrB_BinaryOp_new(
258-
&AllPaths_add_get_nvals,
259-
(void *)add_get_nvals_all_paths,
260-
AllPaths_type,
261-
AllPaths_type,
262-
AllPaths_type));
263-
269+
&AllPaths_add_get_nvals,
270+
(void *)add_get_nvals_all_paths,
271+
AllPaths_type,
272+
AllPaths_type,
273+
AllPaths_type));
274+
264275
GRB_TRY(GrB_Monoid_new(
265-
&AllPaths_monoid_get_nvals,
266-
AllPaths_add_get_nvals,
267-
(void *)(&bottom)));
268-
276+
&AllPaths_monoid_get_nvals,
277+
AllPaths_add_get_nvals,
278+
(void *)(&bottom)));
279+
269280
CFL_Semiring semiring = {.type = AllPaths_type,
270281
.semiring = AllPaths_semiring,
271282
.add = AllPaths_add,
272283
.mult = AllPaths_mult,
273284
.init_path = AllPaths_set,
274285
.bottom_scalar = bottom_scalar,
275-
.get_nvals = get_nvals_all_paths};
286+
.get_nvals = get_nvals_all_paths};
276287

277288
LG_TRY(LAGraph_CFPQ_core(outputs, adj_matrices, terms_count, nonterms_count, rules, rules_count, &semiring, msg));
278289

279290
AllPaths_type = NULL;
280291
AllPaths_type_get_nvals = NULL;
281292
LG_FREE_WORK;
282293
return GrB_SUCCESS;
294+
#endif
283295
}

experimental/test/test_CFL_AllPaths.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -762,17 +762,17 @@ void test_CFL_AllPaths_null_pointers(void) {
762762
#endif
763763
}
764764

765-
TEST_LIST = {{"CFL_AllPaths_complex_grammar", test_CFL_AllPaths_complex_grammar},
765+
TEST_LIST = {
766+
#if GxB_IMPLEMENTATION >= GxB_VERSION(9, 4, 5)
767+
{"CFL_AllPaths_complex_grammar", test_CFL_AllPaths_complex_grammar},
766768
{"CFL_AllPaths_cycle", test_CFL_AllPaths_cycle},
767769
{"CFL_AllPaths_two_cycle", test_CFL_AllPaths_two_cycle},
768-
{"CFL_AllPaths_labels_more_than_nonterms",
769-
test_CFL_AllPaths_labels_more_than_nonterms},
770+
{"CFL_AllPaths_labels_more_than_nonterms", test_CFL_AllPaths_labels_more_than_nonterms},
770771
{"CFL_AllPaths_tree", test_CFL_AllPaths_tree},
771772
{"CFL_AllPaths_line", test_CFL_AllPaths_line},
772773
{"CFL_AllPaths_two_nodes_cycle", test_CFL_AllPaths_two_nodes_cycle},
773774
{"CFL_AllPaths_basic_invalid_rules", test_CFL_AllPaths_invalid_rules},
774775
{"CFL_AllPaths_with_empty_adj_matrix", test_CFL_AllPaths_with_empty_adj_matrix},
775-
#if !defined ( GRAPHBLAS_HAS_CUDA )
776776
{"CFL_AllPaths_null_pointers", test_CFL_AllPaths_null_pointers},
777777
#endif
778778
{NULL, NULL}};

include/LAGraphX.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,11 +1142,18 @@ GrB_Info LAGraph_CFPQ_core
11421142
char *msg // Message string for error reporting.
11431143
);
11441144

1145+
// all_paths_ptr_t is a pointer to the type of elements of the outputs matrices.
1146+
// Use GrB_free(all_paths_ptr_t) after you finish working with the outputs matrices.
11451147
// Important: Do not free all_paths_ptr_t until all work with the output matrices is complete.
11461148
// Accessing matrices after freeing their type is undefined behavior.
1147-
//
11481149
GrB_Info LAGraph_CFL_AllPaths(
1149-
GrB_Matrix *outputs,
1150+
GrB_Matrix *outputs, // Matrix elements are ordered arrays of intermediate vertices type AllPathsElem.
1151+
// Before free outputs[k], you need to free arrays from all matrix elements.
1152+
// For all values of M from the array of the matrix element
1153+
// outputs[k] on the I row of the J column:
1154+
// There are paths from I to M by nonterminal N1 and from M to J by nonterminal N2,
1155+
// and A->N1 N2 where outputs[k] corresponds to nonterminal A.
1156+
// GrB_INDEX_MAX in the array is a special value for A->eps and A->t.
11501157
const GrB_Matrix *adj_matrices,
11511158
GrB_Type *all_paths_ptr_t, // AllPaths type - elements of the output matrices
11521159
int64_t terms_count,

0 commit comments

Comments
 (0)