Skip to content

Commit 7f710e4

Browse files
Merge pull request #288 from GraphBLAS/with_GraphBLAS_v10
testing diameter, multibfs, and maximum/maximal matching
2 parents 5e86d19 + e94b1d3 commit 7f710e4

9 files changed

+340
-16
lines changed

experimental/algorithm/LAGr_MaximumMatching.c

+4
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ invert_2(GrB_Vector out, // input/output
451451
GrB_free(&getRootsOp); \
452452
GrB_free(&parentsUpdate); \
453453
GrB_free(&ufrontierR); \
454+
GrB_free(&mateC); \
454455
GrB_free(&mateR); \
455456
GrB_free(&rootsufR); \
456457
GrB_free(&pathUpdate); \
@@ -945,13 +946,16 @@ int LAGr_MaximumMatching(
945946
} while (npath); // only in the first and last iteration should this
946947
// condition be false
947948

949+
// return result
948950
if (mateC_handle != NULL)
949951
{
950952
(*mateC_handle) = mateC;
953+
mateC = NULL ;
951954
}
952955
if (mateR_handle != NULL)
953956
{
954957
(*mateR_handle) = mateR;
958+
mateR = NULL ;
955959
}
956960
LG_FREE_WORK;
957961

experimental/algorithm/LAGraph_EstimateDiameter.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
//------------------------------------------------------------------------------
1313

1414
// FIXME: almost ready for src; need to handle GxB
15-
// FIXME: need the CI test for this method
1615

1716
// Takes in a graph and estimates the diameter
1817
// and optionally also finds pseudo-peripheral nodes of the graph
@@ -157,6 +156,8 @@ int LAGraph_EstimateDiameter
157156
else
158157
{
159158
// srcs = randomized, still of size nsrcs-1, values in range 0 to UINT64_MAX
159+
// FIXME: if the graph is very sparse, select nodes at random with at
160+
// least one out-going edge.
160161
LAGRAPH_TRY (LAGraph_Random_Seed (srcs, seed, msg)) ;
161162
GRB_TRY (GxB_BinaryOp_new (&Mod,
162163
(n > INT32_MAX) ? ((GxB_binary_function)mod64) :

experimental/algorithm/LAGraph_ExactDiameter.c

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
//------------------------------------------------------------------------------
1313

1414
// FIXME: almost ready for src; says it's not vanilla but should be OK
15-
// FIXME: need the CI test for this method
1615

1716
// Takes in a graph and finds the diameter
1817
// and optionally also the peripheral nodes of the graph

experimental/algorithm/LAGraph_MaximalIndependentSet.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,8 @@ int LAGraph_MaximalIndependentSet // maximal independent set
300300
// This case is nearly untestable since it can almost never occur.
301301
nstall++ ;
302302
// terminate if the method has stalled too many times
303-
LG_ASSERT_MSG (nstall <= 32, -111, "stall") ;
303+
LG_ASSERT_MSG (nstall <= 32, LAGRAPH_CONVERGENCE_FAILURE,
304+
"method has stalled") ;
304305
// recreate the random number seeds with a new starting seed
305306
LG_TRY (LAGraph_Random_Seed (Seed, seed + nstall, msg)) ;
306307
}

experimental/algorithm/LAGraph_MaximalMatching.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,16 @@ int LAGraph_MaximalMatching
240240

241241
if (max_degree > 1) {
242242
nfailures++ ;
243+
LG_ASSERT_MSG (nfailures <= MAX_FAILURES, LAGRAPH_CONVERGENCE_FAILURE,
244+
"method has stalled") ;
245+
#if 0
243246
if (nfailures > MAX_FAILURES) {
244247
#ifdef dbg
245248
printf("[DBG] hit max failures %d\n", nfailures);
246249
#endif
247-
break ; // FIXME: test coverage doesn't test this case. Is it possible?
250+
break ; // test coverage doesn't test this case. Is it possible?
248251
}
252+
#endif
249253
// regen seed and seed vector
250254
LG_TRY (LAGraph_Random_Seed (Seed, seed + nfailures, msg)) ;
251255
continue ;

experimental/algorithm/LAGraph_MultiSourceBFS.c

+11-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
//------------------------------------------------------------------------------
1313

1414
// FIXME: almost ready for src; need a vanilla method
15-
// FIXME: need the CI test for this method
1615

1716
// Takes in a vector of source nodes and finds level and/or parent vectors for each,
1817
// stored together in a matrix
@@ -74,16 +73,17 @@ int LAGraph_MultiSourceBFS
7473
GrB_Matrix A = G->A ;
7574

7675
GrB_Index nsrc; // holds the number of source nodes
77-
GrB_Index n;
76+
GrB_Index n, nvals ;
7877
GRB_TRY (GrB_Matrix_nrows (&n, A)) ;
78+
GRB_TRY (GrB_Matrix_nvals (&nvals, A)) ;
7979
GRB_TRY (GrB_Vector_size (&nsrc, src)) ;
8080
for (int64_t s = 0; s < nsrc; s++)
8181
{
8282
GrB_Index currsrc;
8383
GRB_TRY (GrB_Vector_extractElement (&currsrc, src, s)) ;
8484
LG_ASSERT_MSG (currsrc < n, GrB_INVALID_INDEX, "invalid source node") ;
8585
}
86-
86+
bool very_sparse = (nvals <= n/16) ;
8787

8888
// determine the semiring type
8989
GrB_Type int_type = (n > INT32_MAX) ? GrB_INT64 : GrB_INT32 ;
@@ -98,7 +98,10 @@ int LAGraph_MultiSourceBFS
9898

9999
// create the parent matrix. pi(i, j) is the parent id of node j in source i's BFS
100100
GRB_TRY (GrB_Matrix_new (&pi, int_type, nsrc, n)) ;
101-
GRB_TRY (LG_SET_FORMAT_HINT (pi, LG_BITMAP + LG_FULL)) ;
101+
if (!very_sparse)
102+
{
103+
GRB_TRY (LG_SET_FORMAT_HINT (pi, LG_BITMAP + LG_FULL)) ;
104+
}
102105

103106
// pi (i, src) = src denotes the root of that row's BFS tree
104107
for (int64_t s = 0; s < nsrc; s++)
@@ -143,7 +146,10 @@ int LAGraph_MultiSourceBFS
143146
// create the level matrix. v(i,j) is the level of node j in source i's BFS
144147
// v (s, src) = 0 denotes the source node of that row
145148
GRB_TRY (GrB_Matrix_new (&v, int_type, nsrc, n)) ;
146-
GRB_TRY (LG_SET_FORMAT_HINT (v, LG_BITMAP + LG_FULL)) ;
149+
if (!very_sparse)
150+
{
151+
GRB_TRY (LG_SET_FORMAT_HINT (v, LG_BITMAP + LG_FULL)) ;
152+
}
147153
for (int64_t s = 0; s < nsrc; s++)
148154
{
149155
GrB_Index currsrc;

experimental/test/test_MaximalIndependentSet.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ void test_MIS (void)
225225
result = LAGraph_MaximalIndependentSet (&mis, G, 0, NULL, msg) ;
226226
random_hack = false ;
227227
printf ("hack msg: %d %s\n", result, msg) ;
228-
TEST_CHECK (result == -111 || result == 0) ;
228+
TEST_CHECK (result == LAGRAPH_CONVERGENCE_FAILURE || result == 0) ;
229229
if (result == 0)
230230
{
231231
OK (LG_check_mis (G->A, mis, NULL, msg)) ;

experimental/test/test_MaximumMatching.c

+58-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ const char *filenames[NTESTS] = {"random_weighted_bipartite2.mtx",
1919
"lp_afiro_structure.mtx", "sources_7.mtx"};
2020
const uint64_t spranks[NTESTS] = {298, 2009, 14, 27, 1};
2121

22+
#if 0
23+
#undef OK
24+
#define OK(method) \
25+
{ \
26+
GrB_Info info2 = method ; \
27+
if (info2 != GrB_SUCCESS) \
28+
{ \
29+
printf ("info: %d, msg: %s\n", info2, msg) ; \
30+
TEST_CHECK (false) ; \
31+
} \
32+
}
33+
#endif
34+
2235
void test_MCM(void)
2336
{
2437
LAGraph_Init(msg);
@@ -32,6 +45,7 @@ void test_MCM(void)
3245
for (uint64_t test = 0; test < NTESTS; test++)
3346
{
3447

48+
printf ("\n%s =======================\n", filenames [test]) ;
3549
GrB_Matrix A = NULL;
3650
GrB_Matrix AT = NULL;
3751
snprintf(filename, LEN, LG_DATA_DIR "%s", filenames[test]);
@@ -71,12 +85,16 @@ void test_MCM(void)
7185
OK(GrB_Vector_new(&mateC, GrB_UINT64, ncols));
7286

7387
GrB_Vector mateC_init = NULL;
88+
GrB_Vector mateR_init = NULL;
7489

7590
if (!strcmp(filenames[test], "lp_afiro_structure.mtx"))
7691
{
7792
OK(GrB_Vector_new(&mateC_init, GrB_UINT64, ncols));
93+
OK(GrB_Vector_new(&mateR_init, GrB_UINT64, nrows));
7894
OK(GrB_Vector_setElement_UINT64(
7995
mateC_init, 0, 19)); // col 20 matched with row 1 (1-based)
96+
OK(GrB_Vector_setElement_UINT64(
97+
mateR_init, 19, 0)); // col 20 matched with row 1 (1-based)
8098
OK(GrB_Matrix_new(&AT, GrB_BOOL, ncols,
8199
nrows)); // transpose matrix has the reverse
82100
// dimensions from the original
@@ -85,7 +103,7 @@ void test_MCM(void)
85103

86104
OK(LAGr_MaximumMatching(&mateC, NULL, A, AT, mateC_init, true,
87105
msg));
88-
printf("\nmsg: %s\n", msg);
106+
// printf("\nmsg: %s\n", msg);
89107

90108
GrB_Index nmatched = 0;
91109

@@ -105,6 +123,7 @@ void test_MCM(void)
105123
// if nvals of mateC and mateR don't match, then there's at least
106124
// one row that is used in at least one matching
107125
TEST_CHECK(nmatched == nmateR);
126+
printf ("# of matches: %" PRIu64 "\n", nmatched) ;
108127

109128
// pack matched values in a matrix
110129
GrB_Matrix M = NULL;
@@ -128,11 +147,44 @@ void test_MCM(void)
128147
// sprank must be equal to nvals of mateC (nmatched)
129148
TEST_CHECK(nmatched == spranks[test]);
130149

131-
OK(GrB_Vector_free(&mateC));
132-
OK(GrB_Vector_free(&mateR));
133-
OK(GrB_Matrix_free(&M));
134-
OK(GrB_Matrix_free(&A));
135-
OK(GrB_Matrix_free(&AT));
150+
OK(GrB_free(&mateC));
151+
OK(GrB_free(&mateR));
152+
OK(GrB_free(&M));
153+
154+
// return both mateR and mateC
155+
OK(LAGr_MaximumMatching(&mateC, &mateR, A, AT, mateC_init, true,
156+
msg));
157+
GrB_Index nmateC = 0 ;
158+
nmateR = 0 ;
159+
OK(GrB_Vector_nvals(&nmateC, mateC));
160+
OK(GrB_Vector_nvals(&nmateR, mateR));
161+
TEST_CHECK(nmateC == nmateR);
162+
TEST_CHECK(nmateC == nmatched);
163+
OK(GrB_free(&mateC));
164+
OK(GrB_free(&mateR));
165+
166+
// ensure AT exists, and pass in AT only, and use mateR_init
167+
if (AT == NULL)
168+
{
169+
OK(GrB_Matrix_new(&AT, GrB_BOOL, ncols, nrows));
170+
OK(GrB_transpose(AT, NULL, NULL, A, NULL));
171+
}
172+
OK(LAGr_MaximumMatching(&mateC, &mateR, NULL, AT, mateR_init, false,
173+
msg));
174+
nmateC = 0 ;
175+
nmateR = 0 ;
176+
OK(GrB_Vector_nvals(&nmateC, mateC));
177+
OK(GrB_Vector_nvals(&nmateR, mateR));
178+
TEST_CHECK(nmateC == nmateR);
179+
TEST_CHECK(nmateC == nmatched);
180+
OK(GrB_free(&mateC));
181+
OK(GrB_free(&mateR));
182+
183+
OK(GrB_free(&mateC_init));
184+
OK(GrB_free(&mateR_init));
185+
OK(GrB_free(&A));
186+
OK(GrB_free(&AT));
187+
136188
}
137189
}
138190
LAGraph_Finalize(msg);

0 commit comments

Comments
 (0)