Skip to content

Commit 2118019

Browse files
committed
Feat: delete seperate rmxm method
1 parent fdc3d03 commit 2118019

File tree

1 file changed

+31
-11
lines changed

1 file changed

+31
-11
lines changed

experimental/algorithm/LAGraph_CFL_reachability_advanced.c

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -270,36 +270,55 @@ GrB_Info matrix_dup_empty(Matrix *output, Matrix *input) {
270270
return matrix_dup_format(output, input);
271271
}
272272

273-
GrB_Info matrix_mxm(Matrix *output, Matrix *first, Matrix *second, bool accum) {
273+
GrB_Info matrix_wise_empty(Matrix *output, Matrix *first, Matrix *second, bool accum);
274+
275+
GrB_Info matrix_mxm(Matrix *output, Matrix *first, Matrix *second, bool accum,
276+
bool swap) {
277+
Matrix *left = swap ? second : first;
278+
Matrix *right = swap ? first : second;
279+
274280
GrB_Info result = GrB_mxm(output->base, GrB_NULL, accum ? GxB_ANY_BOOL : GrB_NULL,
275-
GxB_ANY_PAIR_BOOL, first->base, second->base, GrB_NULL);
281+
GxB_ANY_PAIR_BOOL, left->base, right->base, GrB_NULL);
276282
IS_ISO(output->base, "MXM output");
277283
matrix_update(output);
278284
return result;
279285
}
280286

281-
GrB_Info matrix_mxm_format(Matrix *output, Matrix *first, Matrix *second, bool accum) {
287+
GrB_Info matrix_mxm_format(Matrix *output, Matrix *first, Matrix *second, bool accum,
288+
bool swap) {
289+
if (swap) {
290+
Matrix *temp = first;
291+
first = second;
292+
second = temp;
293+
}
294+
282295
int32_t desired_orientation =
283296
first->nvals > second->nvals ? GrB_COLMAJOR : GrB_ROWMAJOR;
284297

298+
if (swap) {
299+
desired_orientation =
300+
desired_orientation == GrB_ROWMAJOR ? GrB_COLMAJOR : GrB_ROWMAJOR;
301+
}
302+
285303
if (!first->is_both && first->format != desired_orientation &&
286304
!(first->nvals > second->nvals / 3.0)) {
287-
GrB_Info result = matrix_mxm(output, first, second, accum);
305+
GrB_Info result = matrix_mxm(output, first, second, accum, swap);
288306
return result;
289307
}
290308

291309
matrix_to_format(first, desired_orientation, true);
292310
matrix_to_format(second, desired_orientation, false);
293311
matrix_to_format(output, desired_orientation, false);
294-
GrB_Info result = matrix_mxm(output, first, second, accum);
312+
GrB_Info result = matrix_mxm(output, first, second, accum, swap);
295313
return result;
296314
}
297315

298-
GrB_Info matrix_mxm_empty(Matrix *output, Matrix *first, Matrix *second, bool accum) {
316+
GrB_Info matrix_mxm_empty(Matrix *output, Matrix *first, Matrix *second, bool accum,
317+
bool swap) {
299318
if (first->nvals == 0 || second->nvals == 0)
300319
return GrB_SUCCESS;
301320

302-
return matrix_mxm_format(output, first, second, accum);
321+
return matrix_mxm_format(output, first, second, accum, swap);
303322
}
304323

305324
GrB_Info matrix_rmxm_format(Matrix *output, Matrix *first, Matrix *second, bool accum) {
@@ -395,6 +414,7 @@ GrB_Info matrix_wise_empty(Matrix *output, Matrix *first, Matrix *second, bool a
395414
return matrix_wise_format(output, first, second, accum);
396415
}
397416

417+
printf("");
398418
GrB_Info matrix_rsub(Matrix *output, Matrix *mask) {
399419
GrB_Info result = GrB_eWiseAdd(output->base, mask->base, GrB_NULL, GxB_ANY_BOOL,
400420
output->base, output->base, GrB_DESC_RSC);
@@ -720,7 +740,7 @@ GrB_Info LAGraph_CFL_reachability_adv(
720740
LAGraph_rule_WCNF bin_rule = rules[bin_rules[i]];
721741

722742
matrix_mxm_empty(&temp_matrices[bin_rule.nonterm], &matrices[bin_rule.prod_A],
723-
&delta_matrices[bin_rule.prod_B], false);
743+
&delta_matrices[bin_rule.prod_B], false, false);
724744
}
725745
TIMER_STOP("MXM 1", &mxm1);
726746

@@ -734,9 +754,9 @@ GrB_Info LAGraph_CFL_reachability_adv(
734754
for (size_t i = 0; i < bin_rules_count; i++) {
735755
LAGraph_rule_WCNF bin_rule = rules[bin_rules[i]];
736756

737-
matrix_rmxm_empty(&temp_matrices[bin_rule.nonterm],
738-
&delta_matrices[bin_rule.prod_A],
739-
&matrices[bin_rule.prod_B], true);
757+
matrix_mxm_empty(&temp_matrices[bin_rule.nonterm],
758+
&delta_matrices[bin_rule.prod_A], &matrices[bin_rule.prod_B],
759+
true, true);
740760
}
741761
TIMER_STOP("MXM 2", &mxm2);
742762

0 commit comments

Comments
 (0)