Skip to content

Commit 5e86d19

Browse files
Merge pull request #287 from GraphBLAS/with_GraphBLAS_v10
more test coverage of experimental algorithms
2 parents 4eccb76 + f8695d3 commit 5e86d19

19 files changed

+730
-219
lines changed

data/karate_verysparse.mtx

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
%%MatrixMarket matrix coordinate pattern symmetric
2+
% Newman/karate matrix, but embedded in a much larger matrix
3+
3400 3400 78
4+
2 1
5+
3 1
6+
4 1
7+
5 1
8+
6 1
9+
7 1
10+
8 1
11+
9 1
12+
11 1
13+
12 1
14+
13 1
15+
14 1
16+
18 1
17+
20 1
18+
22 1
19+
32 1
20+
3 2
21+
4 2
22+
8 2
23+
14 2
24+
18 2
25+
20 2
26+
22 2
27+
31 2
28+
4 3
29+
8 3
30+
9 3
31+
10 3
32+
14 3
33+
28 3
34+
29 3
35+
33 3
36+
8 4
37+
13 4
38+
14 4
39+
7 5
40+
11 5
41+
7 6
42+
11 6
43+
17 6
44+
17 7
45+
31 9
46+
33 9
47+
34 9
48+
34 10
49+
34 14
50+
33 15
51+
34 15
52+
33 16
53+
34 16
54+
33 19
55+
34 19
56+
34 20
57+
33 21
58+
34 21
59+
33 23
60+
34 23
61+
26 24
62+
28 24
63+
30 24
64+
33 24
65+
34 24
66+
26 25
67+
28 25
68+
32 25
69+
32 26
70+
30 27
71+
34 27
72+
34 28
73+
32 29
74+
34 29
75+
33 30
76+
34 30
77+
33 31
78+
34 31
79+
33 32
80+
34 32
81+
34 33

experimental/algorithm/LAGr_EdgeBetweennessCentrality.c

+2-6
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,8 @@ int LAGr_EdgeBetweennessCentrality
286286
GRB_TRY (GrB_Vector_extractElement(&root, sources, i)) ;
287287

288288
// Verify the root index is valid
289-
if (root >= n)
290-
{
291-
// Skip invalid indices
292-
continue;
293-
}
294-
289+
LG_ASSERT (root < n, GrB_INVALID_VALUE) ;
290+
295291
depth = 0 ;
296292

297293
// root frontier: Search [0](root) = true

experimental/algorithm/LAGr_MarkovClustering.c

+7-65
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@
2929
GrB_free(&argmax_v); \
3030
GrB_free(&argmax_p); \
3131
GrB_free(&zero_FP32); \
32-
LAGraph_Free((void *)&pi, NULL); \
33-
LAGraph_Free((void *)&px, NULL); \
34-
LAGraph_Free((void *)&pi_new, NULL); \
35-
LAGraph_Free((void *)&px_new, NULL); \
3632
}
3733

3834
#define LG_FREE_ALL \
@@ -73,9 +69,6 @@ int LAGr_MarkovClustering(
7369

7470
GrB_Scalar zero_FP32 = NULL;
7571

76-
GrB_Index *pi = NULL, *px = NULL;
77-
GrB_Index *pi_new = NULL, *px_new = NULL;
78-
7972
//--------------------------------------------------------------------------
8073
// check inputs
8174
//--------------------------------------------------------------------------
@@ -106,7 +99,6 @@ int LAGr_MarkovClustering(
10699
GRB_TRY(GrB_Vector_new(&argmax_v, GrB_FP32, n));
107100
GRB_TRY(GrB_Vector_new(&argmax_p, GrB_INT64, n));
108101
GRB_TRY(GrB_Scalar_new(&zero_FP32, GrB_FP32));
109-
110102
GRB_TRY(GrB_Scalar_setElement(zero_FP32, 0));
111103

112104
// Create identity
@@ -198,72 +190,22 @@ int LAGr_MarkovClustering(
198190
GRB_TRY(GrB_mxv(argmax_p, NULL, NULL, GxB_MIN_SECONDI_INT64, CC, ones,
199191
GrB_DESC_T0));
200192

201-
// pi := array of argmax_p indices, px := array of argmax_p values
202-
GrB_Index p_nvals;
203-
GRB_TRY(GrB_Vector_nvals(&p_nvals, argmax_p));
204-
LG_TRY(LAGraph_Malloc((void **)&pi, p_nvals, sizeof(GrB_Index), msg));
205-
LG_TRY(LAGraph_Malloc((void **)&px, p_nvals, sizeof(GrB_Index), msg));
206-
GRB_TRY(GrB_Vector_extractTuples_INT64(pi, (int64_t *) px, &p_nvals, argmax_p));
207-
208193
// Sometimes (particularly, when the pruning threshold is high), some
209194
// columns in the steady-state T have no values, i.e., they are not
210195
// attracted to any vertex. In this case, fill in the missing values with
211196
// the index of the vertex (these vertices will be arbitrarily put in the
212197
// cluster of their index).
198+
GrB_Index p_nvals;
199+
GRB_TRY(GrB_Vector_nvals(&p_nvals, argmax_p));
213200
if (p_nvals < n)
214201
{
215-
LG_TRY(LAGraph_Malloc((void **)&pi_new, n, sizeof(GrB_Index), msg));
216-
LG_TRY(LAGraph_Malloc((void **)&px_new, n, sizeof(GrB_Index), msg));
217-
218-
GrB_Index j = 0;
219-
GrB_Index currentValue = pi[0];
220-
221-
for (int i = 0; i < p_nvals && j < n; ++i)
222-
{
223-
while (currentValue < pi[i] && j < n)
224-
{
225-
pi_new[j] = currentValue;
226-
px_new[j] = currentValue; // Fill skipped px values with their
227-
// index
228-
currentValue++;
229-
j++;
230-
}
231-
if (j < n)
232-
{
233-
pi_new[j] = pi[i];
234-
px_new[j] = px[i];
235-
currentValue++;
236-
j++;
237-
}
238-
}
239-
240-
// Handle any skipped values at the end
241-
while (j < n)
242-
{
243-
pi_new[j] = currentValue;
244-
px_new[j] = currentValue; // Fill remaining px values
245-
currentValue++;
246-
j++;
247-
}
248-
249-
LAGraph_Free((void **)&pi, NULL);
250-
LAGraph_Free((void **)&px, NULL);
251-
pi = pi_new;
252-
px = px_new;
253-
// Avoid double free
254-
pi_new = NULL;
255-
px_new = NULL;
202+
// argmax_p <!argmax_p> = 0:n-1
203+
GRB_TRY (GrB_apply (argmax_p, argmax_p, NULL, GrB_ROWINDEX_INT64,
204+
ones, 0, GrB_DESC_SC)) ;
256205
}
257206

258-
GrB_Vector c = NULL;
259-
GRB_TRY(GrB_Vector_new(&c, GrB_INT64, n));
260-
GRB_TRY(GrB_Vector_build_INT64(c, pi, (int64_t *) px, n, NULL));
261-
GrB_Vector_wait(c, GrB_MATERIALIZE);
262-
263-
LAGraph_Free((void *)&pi, NULL);
264-
LAGraph_Free((void *)&px, NULL);
265-
266-
(*c_f) = c; // Set output vector
207+
(*c_f) = argmax_p ; // Set output vector
208+
argmax_p = NULL ;
267209

268210
LG_FREE_WORK;
269211

experimental/algorithm/LAGr_TriangleCount_GPU.c

+4
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@
6969

7070
#include "LG_internal.h"
7171

72+
#if defined ( GRAPHBLAS_HAS_CUDA )
73+
7274
//------------------------------------------------------------------------------
7375
// tricount_prep: construct L and U for LAGr_TriangleCount
7476
//------------------------------------------------------------------------------
@@ -462,3 +464,5 @@ int LAGr_TriangleCount_GPU
462464
(*ntriangles) = (uint64_t) ntri ;
463465
return (GrB_SUCCESS) ;
464466
}
467+
468+
#endif

experimental/algorithm/LAGraph_Coarsen_Matching.c

+1-43
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,6 @@ static int LAGraph_Parent_to_S
259259
GrB_free(&edge_parent) ; \
260260
GrB_free(&node_parent) ; \
261261
GrB_free(&full) ; \
262-
LAGraph_Free ((void**)(&rows), msg) ; \
263-
LAGraph_Free ((void**)(&cols), msg) ; \
264-
LAGraph_Free ((void**)(&vals), msg) ; \
265262
LAGraph_Delete(&G_cpy, msg) ; \
266263
}
267264

@@ -309,11 +306,6 @@ int LAGraph_Coarsen_Matching
309306
GrB_Vector node_parent = NULL ; // points to parent (representative) node for each node
310307
GrB_Vector full = NULL ; // full vector
311308

312-
// used to build int64/fp64 A matrix if needed
313-
GrB_Index *rows = NULL ;
314-
GrB_Index *cols = NULL ;
315-
void *vals = NULL ;
316-
317309
GrB_Index nvals, nrows ;
318310
GrB_Type A_type ;
319311
// check properties (no self-loops, undirected)
@@ -346,46 +338,12 @@ int LAGraph_Coarsen_Matching
346338
printf("Rebuilding A with GrB_INT64/FP64, orig type was %s\n", typename);
347339
#endif
348340

349-
#if 0
350341

351-
// FIXME: fast and easy
342+
bool is_float = (type == GrB_FP32) ;
352343
GRB_TRY (GrB_Matrix_nrows (&nrows, G->A)) ;
353344
A_type = (is_float ? GrB_FP64 : GrB_INT64) ;
354345
GRB_TRY (GrB_Matrix_new (&A, A_type, nrows, nrows)) ;
355346
GRB_TRY (GrB_assign (A, NULL, NULL, G->A, GrB_ALL, nrows, GrB_ALL, nrows, NULL)) ;
356-
357-
#else
358-
359-
// FIXME: slow and hard
360-
bool is_float = (type == GrB_FP32) ;
361-
362-
GRB_TRY (GrB_Matrix_nvals (&nvals, G->A)) ;
363-
GRB_TRY (GrB_Matrix_nrows (&nrows, G->A)) ;
364-
365-
LG_TRY (LAGraph_Malloc ((void**)(&rows), nvals, sizeof(GrB_Index), msg)) ;
366-
LG_TRY (LAGraph_Malloc ((void**)(&cols), nvals, sizeof(GrB_Index), msg)) ;
367-
LG_TRY (LAGraph_Malloc ((void**)(&vals), nvals, is_float ? sizeof(double) : sizeof(int64_t), msg)) ;
368-
// extractTuples casts all entries to target type
369-
if (is_float) {
370-
GRB_TRY (GrB_Matrix_extractTuples_FP64 (rows, cols, vals, &nvals, G->A)) ;
371-
} else {
372-
GRB_TRY (GrB_Matrix_extractTuples_INT64 (rows, cols, vals, &nvals, G->A)) ;
373-
}
374-
375-
GRB_TRY (GrB_Matrix_new (&A, is_float ? GrB_FP64 : GrB_INT64, nrows, nrows)) ;
376-
377-
if (is_float) {
378-
GRB_TRY (GrB_Matrix_build_FP64 (A, rows, cols, vals, nvals, NULL)) ;
379-
} else {
380-
GRB_TRY (GrB_Matrix_build_INT64 (A, rows, cols, vals, nvals, NULL)) ;
381-
}
382-
383-
LG_TRY (LAGraph_Free ((void**)(&rows), msg)) ;
384-
LG_TRY (LAGraph_Free ((void**)(&cols), msg)) ;
385-
LG_TRY (LAGraph_Free ((void**)(&vals), msg)) ;
386-
A_type = (is_float ? GrB_FP64 : GrB_INT64) ;
387-
#endif
388-
389347
}
390348
}
391349
else

experimental/algorithm/LAGraph_RegularPathQuery.c

+4
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ int LAGraph_RegularPathQuery
197197
B[i] = R[i]->A ;
198198
if (R[i]->is_symmetric_structure == LAGraph_TRUE)
199199
{
200+
// FIXME: this case is not tested
201+
// by experimental/test/test_RegularPathQuery.c
200202
BT[i] = B[i] ;
201203
}
202204
else
@@ -321,6 +323,8 @@ int LAGraph_RegularPathQuery
321323
}
322324
else
323325
{
326+
// FIXME: this case is not tested
327+
// by experimental/test/test_RegularPathQuery.c
324328
GRB_TRY (GrB_mxm (symbol_frontier, GrB_NULL, GrB_NULL,
325329
GrB_LOR_LAND_SEMIRING_BOOL, B[i], frontier, GrB_DESC_RT0)) ;
326330
}

experimental/algorithm/LAGraph_argminmax.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// FIXME: not ready for src, but close
1+
// FIXME: not ready for src, need to use IndexBinaryOps instead.
2+
// See argmin/argmax in GraphBLAS/@GrB/*/*/gbargminmax.c.
3+
4+
// FIXME: make x and p GrB_Vectors
25

36
#include "LG_internal.h"
47
#include "LAGraphX.h"
@@ -356,7 +359,6 @@ int LAGraph_argminmax
356359
// return result
357360
//--------------------------------------------------------------------------
358361

359-
GRB_TRY (GrB_Matrix_free (&A)) ;
360362
return (GrB_SUCCESS) ;
361363
}
362364

experimental/algorithm/LAGraph_cdlp_withsort.c

+1-4
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,7 @@ int LAGraph_cdlp_withsort
175175
// check inputs
176176
//--------------------------------------------------------------------------
177177

178-
if (CDLP_handle == NULL)
179-
{
180-
return GrB_NULL_POINTER;
181-
}
178+
LG_ASSERT (CDLP_handle != NULL, GrB_NULL_POINTER) ;
182179

183180
//--------------------------------------------------------------------------
184181
// ensure input is binary and has no self-edges

experimental/test/CMakeLists.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ if ( LAGRAPH_HAS_OPENMP )
8383
endif ( )
8484
endif ( )
8585

86-
8786
#-------------------------------------------------------------------------------
8887
# This will only build tests from files with the name "test_*.c"
8988
#-------------------------------------------------------------------------------
@@ -104,6 +103,10 @@ foreach( testsourcefile ${TEST_SOURCES} )
104103
target_link_libraries( ${testname}
105104
LAGraphX_static LAGraph_static lagraphxtest_static lagraphtest_static GraphBLAS::GraphBLAS )
106105
endif ( )
106+
107+
# add libm
108+
target_link_libraries ( ${testname} m )
109+
107110
string( REPLACE "test_" "LAGraphX_" ctestname ${testname})
108111
add_test( NAME ${ctestname} COMMAND $<TARGET_FILE:${testname}> )
109112
# add_test( NAME ${ctestname} COMMAND valgrind $<TARGET_FILE:${testname}> )

experimental/test/test_AllKCore.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void test_AllKCore (void)
5959
const char *aname = files [k].name ;
6060
uint64_t kmax = files [k].kmax ;
6161
if (strlen (aname) == 0) break;
62-
printf ("\n================================== %s: ==================================\n", aname) ;
62+
printf ("\n %s: ==================================\n", aname) ;
6363
TEST_CASE (aname) ;
6464
snprintf (filename, LEN, LG_DATA_DIR "%s", aname) ;
6565
FILE *f = fopen (filename, "r") ;

0 commit comments

Comments
 (0)