Skip to content

Commit 8abda57

Browse files
Louvain test coverage
1 parent 0cdf981 commit 8abda57

File tree

3 files changed

+58
-44
lines changed

3 files changed

+58
-44
lines changed

experimental/algorithm/LAGraph_LouvainIS.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ void extract_k_if_gain(void *out, const void *in)
244244
" *k_out = a->comm;\n" \
245245
" }\n" \
246246
"}\n"
247+
247248
#undef LG_FREE_ALL
248249
#define LG_FREE_ALL \
249250
{ \
@@ -271,9 +272,16 @@ void extract_k_if_gain(void *out, const void *in)
271272
GrB_free(&argmax_0); \
272273
GrB_free(&Theta_UDT); \
273274
GrB_Type_free(&Tuple); \
274-
LAGraph_Free((void **)&d_copy, msg); \
275-
LAGraph_Free((void **)&c_copy, msg); \
275+
if (A_iset != NULL) \
276+
{ \
277+
for (int i = 0; i < loop; i++) \
278+
{ \
279+
GrB_free(&A_iset[i]); \
280+
} \
281+
LAGraph_Free ((void **) &A_iset, NULL) ; \
282+
} \
276283
}
284+
277285
#endif
278286

279287
int LAGraph_LouvainIS(
@@ -321,9 +329,9 @@ int LAGraph_LouvainIS(
321329
GrB_Monoid AM_mon = NULL;
322330
GrB_Semiring AM_Semiring = NULL;
323331
GrB_Type Theta_UDT = NULL;
324-
325-
double *d_copy = NULL;
326-
uint32_t *c_copy = NULL;
332+
333+
GrB_Matrix *A_iset = NULL ;
334+
GrB_Index loop = 0 ;
327335

328336
GRB_TRY(GxB_Type_new(&Theta_UDT, sizeof(Theta), "Theta", THETA_DEFN));
329337
GRB_TRY(GrB_Scalar_new(&argmax_0, Theta_UDT));
@@ -420,16 +428,12 @@ int LAGraph_LouvainIS(
420428
printf("Isolate Set calc time: %10.10f\n", tsimple);
421429
#endif
422430

423-
GrB_Index loop;
424431
GRB_TRY(GrB_Matrix_nrows(&loop, Miset));
425432

426433
// allocate an array of GrB_Matrix handles
427-
GrB_Matrix *A_iset = malloc(loop * sizeof(GrB_Matrix));
428-
if (A_iset == NULL)
429-
{
430-
fprintf(stderr, "Out of memory allocating A_iset\n");
431-
exit(1);
432-
}
434+
// GrB_Matrix *A_iset = malloc(loop * sizeof(GrB_Matrix));
435+
LG_TRY (LAGraph_Calloc ((void **) &A_iset, loop, sizeof (GrB_Matrix), msg)) ;
436+
433437
GrB_Index n_k_values;
434438
#ifdef TIMING
435439
double tsimple = LAGraph_WallClockTime();
@@ -521,10 +525,6 @@ int LAGraph_LouvainIS(
521525
printf("Iterations: %d\n", iter);
522526
#endif
523527

524-
for (int i = 0; i < loop; i++)
525-
{
526-
GrB_free(&A_iset[i]);
527-
}
528528
(*S_result) = S;
529529
S = NULL;
530530

experimental/test/test_IsolateSets.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ const matrix_info files[] = {
2525
void test_IsolateSets(void){
2626
LAGraph_Init(msg);
2727
printf("\n");
28-
for(int k = 0;;k++){
28+
for(int k = 0;;k++)
29+
{
2930
if (strlen(files[k].matrix_file) == 0)
3031
break;
3132
snprintf (filename, LEN, LG_DATA_DIR "%s", files[k].matrix_file) ;
@@ -58,12 +59,11 @@ void test_IsolateSets(void){
5859
GrB_Vector ignore_node=NULL;
5960

6061
double tsimple = LAGraph_WallClockTime ( ) ;
61-
6262
OK(LAGraph_IsolateSets(&MIset,G->A,1231245,msg));
6363
GxB_print(MIset,5);
6464
tsimple = LAGraph_WallClockTime ( ) - tsimple ;
6565
printf(" time: %f\n",tsimple);
66-
66+
GrB_free (&MIset) ;
6767

6868
}
6969
}

experimental/test/test_louvain.c

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,23 @@ void test_LouvainSeq(void)
6464
// check if the pattern is symmetric - if it isn't make it.
6565
OK(LAGraph_Cached_IsSymmetricStructure(G, msg));
6666
GrB_Matrix S = NULL;
67-
double tsimple = LAGraph_WallClockTime();
68-
OK(LAGraph_LouvainSeq(&S, G,seed, msg));
69-
70-
// OK(LAGraph_Louvain_res(&S,G,.3,msg));
71-
tsimple = LAGraph_WallClockTime() - tsimple;
72-
double Q = 0.0;
73-
OK(LAGr_Modularity2(&Q, 1.0, G->A, S, msg));
74-
printf("Q:%f\n", Q);
75-
// printf("Number of Communities: %d",comms);
76-
printf(" time: %f\n", tsimple);
67+
68+
for (int jit = 0 ; jit <= 1 ; jit++)
69+
{
70+
OK (LG_SET_JIT (jit ? GxB_JIT_ON : GxB_JIT_OFF)) ;
71+
72+
double tsimple = LAGraph_WallClockTime();
73+
OK(LAGraph_LouvainSeq(&S, G,seed, msg));
74+
75+
// OK(LAGraph_Louvain_res(&S,G,.3,msg));
76+
tsimple = LAGraph_WallClockTime() - tsimple;
77+
double Q = 0.0;
78+
OK(LAGr_Modularity2(&Q, 1.0, G->A, S, msg));
79+
printf("Q:%f\n", Q);
80+
// printf("Number of Communities: %d",comms);
81+
printf(" time: %f\n", tsimple);
82+
}
83+
7784
OK(LAGraph_Delete(&G, msg));
7885
}
7986
LAGraph_Finalize(msg);
@@ -103,20 +110,27 @@ void test_LouvainIS(void)
103110
// check if the pattern is symmetric - if it isn't make it.
104111
OK(LAGraph_Cached_IsSymmetricStructure(G, msg));
105112
GrB_Matrix S = NULL;
106-
double tsimple = LAGraph_WallClockTime();
107-
OK(LAGraph_LouvainIS(&S,seed, G, msg));
108-
109-
// OK(LAGraph_Louvain_res(&S,G,.3,msg));
110-
tsimple = LAGraph_WallClockTime() - tsimple;
111-
double Q = 0.0;
112-
double tsimple2 = LAGraph_WallClockTime();
113-
OK(LAGr_Modularity2(&Q, 1.0, G->A, S, msg));
114-
tsimple2 = LAGraph_WallClockTime() - tsimple2;
115-
116-
printf("Q:%f time to calc Q: %f\n", Q,tsimple2);
117-
// printf("Number of Communities: %d",comms);
118-
printf(" time: %f\n", tsimple);
119-
GrB_free(&S);
113+
114+
for (int jit = 0 ; jit <= 1 ; jit++)
115+
{
116+
OK (LG_SET_JIT (jit ? GxB_JIT_ON : GxB_JIT_OFF)) ;
117+
118+
double tsimple = LAGraph_WallClockTime();
119+
OK(LAGraph_LouvainIS(&S,seed, G, msg));
120+
121+
// OK(LAGraph_Louvain_res(&S,G,.3,msg));
122+
tsimple = LAGraph_WallClockTime() - tsimple;
123+
double Q = 0.0;
124+
double tsimple2 = LAGraph_WallClockTime();
125+
OK(LAGr_Modularity2(&Q, 1.0, G->A, S, msg));
126+
tsimple2 = LAGraph_WallClockTime() - tsimple2;
127+
128+
printf("Q:%f time to calc Q: %f\n", Q,tsimple2);
129+
// printf("Number of Communities: %d",comms);
130+
printf(" time: %f\n", tsimple);
131+
GrB_free(&S);
132+
}
133+
120134
OK(LAGraph_Delete(&G, msg));
121135

122136
}
@@ -133,4 +147,4 @@ TEST_LIST = {
133147

134148

135149

136-
150+

0 commit comments

Comments
 (0)