Skip to content

Commit ba12f93

Browse files
committed
feat: [wip] support cardinality in rpqmatrix algo
1 parent 16d96af commit ba12f93

File tree

3 files changed

+74
-6
lines changed

3 files changed

+74
-6
lines changed

experimental/algorithm/LAGraph_RPQMatrix.c

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,44 @@ char msg[LAGRAPH_MSG_LEN] ;
129129
#include <stdbool.h>
130130
#include <stdio.h>
131131

132+
void cardinality_lor(GrB_Index *Crr, GrB_Index *Ccr, GrB_Index Arr, GrB_Index Acr, GrB_Index Brr, GrB_Index Bcr, GrB_Index dim, GrB_Index Annz, GrB_Index Bnnz) {
133+
GrB_Index Crr_result, Ccr_result ;
134+
135+
*Crr = Crr_result ;
136+
*Ccr = Ccr_result ;
137+
};
138+
139+
void cardinality_concat(GrB_Index *Crr, GrB_Index *Ccr, GrB_Index Arr, GrB_Index Acr, GrB_Index Brr, GrB_Index Bcr, GrB_Index dim, GrB_Index Annz, GrB_Index Bnnz) {
140+
GrB_Index Crr_result, Ccr_result ;
141+
142+
*Crr = Crr_result ;
143+
*Ccr = Ccr_result ;
144+
};
145+
146+
void cardinality_kleene(GrB_Index *Crr, GrB_Index *Ccr, GrB_Index Arr, GrB_Index Acr, GrB_Index Brr, GrB_Index Bcr, GrB_Index dim, GrB_Index Annz, GrB_Index Bnnz) {
147+
GrB_Index Crr_result, Ccr_result ;
148+
149+
*Crr = Crr_result ;
150+
*Ccr = Ccr_result ;
151+
};
152+
153+
GrB_Info LAGraph_RPQMatrix_reduce(GrB_Index *res, GrB_Matrix mat, uint8_t reduce_type){
154+
GrB_Index nvals ;
155+
GrB_Vector reduce ;
156+
if (reduce_type == 0)
157+
{
158+
GrB_Matrix_reduce_Monoid(reduce,NULL,NULL,GxB_ANY_BOOL_MONOID,mat,NULL) ;
159+
}
160+
else if (reduce_type == 1)
161+
{
162+
GrB_Matrix_reduce_Monoid(reduce, NULL,NULL,GxB_ANY_BOOL_MONOID,mat,GrB_DESC_T0) ;
163+
}
164+
GrB_Vector_nvals(&nvals,reduce) ;
165+
*res = nvals ;
166+
return (GrB_SUCCESS) ;
167+
}
168+
169+
132170
GrB_Info LAGraph_RPQMatrix_check(RPQMatrixPlan *plan, GrB_Index *dimension, char *msg)
133171
{
134172
if (plan == NULL)
@@ -137,7 +175,7 @@ GrB_Info LAGraph_RPQMatrix_check(RPQMatrixPlan *plan, GrB_Index *dimension, char
137175
}
138176
if (plan->op == RPQ_MATRIX_OP_LABEL)
139177
{
140-
LG_ASSERT(plan->mat != NULL, GrB_NULL_POINTER);
178+
LG_ASSERT(plan->mat != NULL, GrB_NULL_POINTER) ;
141179
GrB_Index nrows, ncols ;
142180
OK(GrB_Matrix_nrows(&nrows, plan->mat)) ;
143181
OK(GrB_Matrix_ncols(&ncols, plan->mat)) ;
@@ -224,7 +262,12 @@ static GrB_Info LAGraph_RPQMatrixLor(RPQMatrixPlan *plan, char *msg)
224262
GRB_TRY(GrB_eWiseAdd(res, GrB_NULL, GrB_NULL,
225263
op, lhs_mat, rhs_mat, GrB_DESC_R)) ;
226264
plan->res_mat = res ;
227-
265+
// GrB_Index n ;
266+
// GrB_Matrix_ncols(&n, lhs_mat) ;
267+
// GrB_Index Annz, Bnnz;
268+
// GrB_Matrix_nvals(&Annz, lhs_mat) ;
269+
// GrB_Matrix_nvals(&Bnnz, rhs_mat) ;
270+
// cardinality_lor(plan->row_reduce, plan->col_reduce, lhs->row_reduce, lhs->col_reduce, rhs->row_reduce, rhs->col_reduce, n, Annz, Bnnz) ;
228271
return (GrB_SUCCESS) ;
229272
}
230273

@@ -254,6 +297,12 @@ static GrB_Info LAGraph_RPQMatrixConcat(RPQMatrixPlan *plan, char *msg)
254297
GRB_TRY(GrB_mxm(res, GrB_NULL, GrB_NULL,
255298
sr, lhs_mat, rhs_mat, GrB_DESC_R)) ;
256299
plan->res_mat = res ;
300+
// GrB_Index n ;
301+
// GrB_Matrix_ncols(&n, lhs_mat) ;
302+
// GrB_Index Annz, Bnnz;
303+
// GrB_Matrix_nvals(&Annz, lhs_mat) ;
304+
// GrB_Matrix_nvals(&Bnnz, rhs_mat) ;
305+
// cardinality_concat(plan->row_reduce, plan->col_reduce, lhs->row_reduce, lhs->col_reduce, rhs->row_reduce, rhs->col_reduce, n, Annz, Bnnz) ;
257306

258307
return (GrB_SUCCESS) ;
259308
}

experimental/test/test_RPQMatrix.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,28 @@ void test_RPQMatrix_CONCAT(void)
8888
LAGraph_Init(msg) ;
8989

9090
GrB_Matrix A, B ;
91+
GrB_Index nA, nB ;
92+
GrB_Matrix_nrows(&nA, A) ;
93+
GrB_Matrix_nrows(&nB, B) ;
9194
load_matrix(&A, "rpq_data/a.mtx") ;
9295
load_matrix(&B, "rpq_data/b.mtx") ;
93-
94-
RPQMatrixPlan planA = {.op = RPQ_MATRIX_OP_LABEL, .mat = A} ;
95-
RPQMatrixPlan planB = {.op = RPQ_MATRIX_OP_LABEL, .mat = B} ;
96+
GrB_Vector A_row_reduce, A_col_reduce, B_row_reduce, B_col_reduce ;
97+
GrB_Vector_new(A_row_reduce, GrB_BOOL, nA) ;
98+
GrB_Vector_new(A_col_reduce, GrB_BOOL, nA) ;
99+
GrB_Vector_new(B_row_reduce, GrB_BOOL, nB) ;
100+
GrB_Vector_new(B_col_reduce, GrB_BOOL, nB) ;
101+
GrB_Matrix_reduce_Monoid(A_row_reduce,NULL,NULL,GxB_ANY_BOOL_MONOID,A,NULL) ;
102+
GrB_Matrix_reduce_Monoid(A_col_reduce,NULL,NULL,GxB_ANY_BOOL_MONOID,A,GrB_DESC_T0) ;
103+
GrB_Matrix_reduce_Monoid(B_row_reduce,NULL,NULL,GxB_ANY_BOOL_MONOID,B,NULL) ;
104+
GrB_Matrix_reduce_Monoid(B_col_reduce,NULL,NULL,GxB_ANY_BOOL_MONOID,B,GrB_DESC_T0) ;
105+
106+
RPQMatrixPlan planA = {.op = RPQ_MATRIX_OP_LABEL, .mat = A, .col_reduced = A_col_reduce, .row_reduced = A_row_reduce} ;
107+
RPQMatrixPlan planB = {.op = RPQ_MATRIX_OP_LABEL, .mat = B, .col_reduced = B_col_reduce, .row_reduced = B_row_reduce} ;
96108
RPQMatrixPlan concat = {
97109
.op = RPQ_MATRIX_OP_CONCAT,
98110
.lhs = &planA,
99-
.rhs = &planB} ;
111+
.rhs = &planB
112+
} ;
100113
GrB_Index result_nnz ;
101114
OK(LAGraph_RPQMatrix(&result_nnz, &concat, msg)) ;
102115

include/LAGraphX.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,12 @@ typedef struct RPQMatrixPlan
946946
GrB_Matrix mat ; // adjacency matrix of label.
947947
// Only for leafes. Should be NULL
948948
// in other cases
949+
GrB_Index row_reduced ; // number of nonzero elements in
950+
// reduced by rows `mat` matrix.
951+
// Only for leafes
952+
GrB_Index col_reduced ; // number of nonzero elements in
953+
// reduced by columns `mat` matrix.
954+
// Only for leafes
949955
GrB_Matrix res_mat ; // result of subtree execution.
950956
// Should be NULL
951957
} RPQMatrixPlan ;

0 commit comments

Comments
 (0)