Line data Source code
1 :
2 : #include "LG_internal.h"
3 : #include <LG_Xtest.h>
4 :
5 : #undef LG_FREE_ALL
6 : #undef LG_FREE_WORK
7 :
8 : #define LG_FREE_WORK \
9 : { \
10 : GrB_free(&flow_r); \
11 : GrB_free(&flow_c); \
12 : GrB_free(&result_vec); \
13 : }
14 :
15 :
16 : #define LG_FREE_ALL \
17 : { \
18 : LG_FREE_WORK; \
19 : }
20 :
21 :
22 14 : int LG_check_flow(const GrB_Matrix flow_mtx, char* msg)
23 : {
24 14 : GrB_Vector flow_r=NULL, flow_c=NULL, result_vec=NULL ;
25 : GrB_Index n ;
26 14 : double net_flow = -1;
27 14 : LG_TRY(GrB_Matrix_nrows(&n, flow_mtx));
28 14 : LG_TRY(GrB_Vector_new(&flow_r, GrB_FP64, n));
29 14 : LG_TRY(GrB_Vector_new(&flow_c, GrB_FP64, n));
30 14 : LG_TRY(GrB_Vector_new(&result_vec, GrB_FP64, n));
31 14 : LG_TRY(GrB_reduce(flow_c, NULL, NULL, GrB_PLUS_MONOID_FP64, flow_mtx, NULL));
32 14 : LG_TRY(GrB_reduce(flow_r, NULL, NULL, GrB_PLUS_MONOID_FP64, flow_mtx, GrB_DESC_T1));
33 14 : LG_TRY(GrB_eWiseAdd(result_vec, NULL, NULL, GrB_MINUS_FP64, flow_r, flow_c, NULL));
34 14 : LG_TRY(GrB_reduce(&net_flow, NULL, GrB_PLUS_MONOID_FP64, result_vec, NULL));
35 14 : LG_ASSERT_MSG(net_flow == 0, GrB_INVALID_VALUE, "Flow conservation is not followed");
36 14 : LG_FREE_WORK ;
37 14 : return GrB_SUCCESS;
38 : }
|