Skip to content

Commit 2986074

Browse files
committed
refactor: make owns mat grb_bool type
1 parent 5e09f05 commit 2986074

File tree

1 file changed

+33
-49
lines changed

1 file changed

+33
-49
lines changed

src/main.c

Lines changed: 33 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@ typedef struct
4747
} Card;
4848

4949
// edges
50-
51-
typedef struct
52-
{
53-
int days;
54-
} EdgeOwns;
55-
5650
typedef struct
5751
{
5852
double sum;
@@ -68,41 +62,41 @@ void check_user_age(bool *z, const User *x, GrB_Index _i, GrB_Index _j, const ui
6862
void check_payment_system(bool *z, const Card *x, GrB_Index _i, GrB_Index _j, const uint8_t *y)
6963
{
7064
{
71-
*z = ((x->system) == MIR);
65+
*z = ((x->system) == *y);
7266
}
7367
}
74-
void owns_bool_mult(bool *z, const bool *x, const EdgeOwns *y)
75-
{
76-
*z = *x;
77-
}
78-
79-
void owns_bool_add(bool *z, const bool *x, const bool *y)
80-
{
81-
*z = (*x || *y);
82-
}
8368

8469
void tx_bool_mult(EdgeTX *z, const bool *x, const EdgeTX *y)
8570
{
8671
if (*x) // вот этот иф не нужен в идеале, потому что мы проходимся только по значащим значениям
8772
*z = *y;
8873
else
89-
z->sum = 0, z->count = 0;
74+
{
75+
z->sum = 0;
76+
z->count = 0;
77+
}
9078
}
9179

9280
void tx_bool_mult_right(EdgeTX *z, const EdgeTX *x, const bool *y)
9381
{
9482
if (*y)
9583
*z = *x;
9684
else
97-
z->sum = 0, z->count = 0;
85+
{
86+
z->sum = 0;
87+
z->count = 0;
88+
}
9889
}
9990

10091
void tx_bool_add(EdgeTX *z, const EdgeTX *x, const EdgeTX *y)
10192
{
10293
if (x->count > 0 || y->count > 0)
10394
*z = (x->count > 0) ? *x : *y;
10495
else
105-
z->sum = 0, z->count = 0;
96+
{
97+
z->sum = 0;
98+
z->count = 0;
99+
}
106100
}
107101

108102
void tx_is_nonempty(bool *z, const EdgeTX *x)
@@ -158,20 +152,20 @@ GrB_Info init_edges(GrB_Matrix *tx_mat, GrB_Matrix *owns_mat)
158152
TRY(GrB_Matrix_setElement_UDT(*tx_mat, &edge129, 11, 8));
159153

160154
// fill owns_mat
161-
EdgeOwns edge45 = {45};
162-
EdgeOwns edge36 = {36};
163-
EdgeOwns edge19 = {19};
164-
EdgeOwns edge27 = {27};
165-
EdgeOwns edge28 = {28};
166-
EdgeOwns edge1011 = {21};
167-
EdgeOwns edge1012 = {22};
168-
TRY(GrB_Matrix_setElement_UDT(*owns_mat, &edge45, 3, 4));
169-
TRY(GrB_Matrix_setElement_UDT(*owns_mat, &edge36, 2, 5));
170-
TRY(GrB_Matrix_setElement_UDT(*owns_mat, &edge19, 0, 8));
171-
TRY(GrB_Matrix_setElement_UDT(*owns_mat, &edge27, 1, 6));
172-
TRY(GrB_Matrix_setElement_UDT(*owns_mat, &edge28, 1, 7));
173-
TRY(GrB_Matrix_setElement_UDT(*owns_mat, &edge1011, 9, 10));
174-
TRY(GrB_Matrix_setElement_UDT(*owns_mat, &edge1012, 9, 11));
155+
bool edge45 = true;
156+
bool edge36 = true;
157+
bool edge19 = true;
158+
bool edge27 = true;
159+
bool edge28 = true;
160+
bool edge1011 = true;
161+
bool edge1012 = true;
162+
TRY(GrB_Matrix_setElement_BOOL(*owns_mat, &edge45, 3, 4));
163+
TRY(GrB_Matrix_setElement_BOOL(*owns_mat, &edge36, 2, 5));
164+
TRY(GrB_Matrix_setElement_BOOL(*owns_mat, &edge19, 0, 8));
165+
TRY(GrB_Matrix_setElement_BOOL(*owns_mat, &edge27, 1, 6));
166+
TRY(GrB_Matrix_setElement_BOOL(*owns_mat, &edge28, 1, 7));
167+
TRY(GrB_Matrix_setElement_BOOL(*owns_mat, &edge1011, 9, 10));
168+
TRY(GrB_Matrix_setElement_BOOL(*owns_mat, &edge1012, 9, 11));
175169

176170
return info;
177171
}
@@ -227,17 +221,17 @@ int main()
227221
// init edge matrices
228222
// ------------------------------------------------------------------------
229223

230-
// custom types for edges
231-
GrB_Type tx_edge, owns_edge;
224+
// custom type for transaction edges
225+
GrB_Type tx_edge;
232226
TRY(GrB_Type_new(&tx_edge, sizeof(EdgeTX)));
233-
TRY(GrB_Type_new(&owns_edge, sizeof(EdgeOwns)));
234227

235228
// edge decomposition
236229

237230
GrB_Matrix tx_edge_mat, owns_edge_mat;
238231
TRY(GrB_Matrix_new(&tx_edge_mat, tx_edge, VERTICES_NUMBER, VERTICES_NUMBER));
239-
TRY(GrB_Matrix_new(&owns_edge_mat, owns_edge, VERTICES_NUMBER, VERTICES_NUMBER));
232+
TRY(GrB_Matrix_new(&owns_edge_mat, GrB_BOOL, VERTICES_NUMBER, VERTICES_NUMBER));
240233
init_edges(&tx_edge_mat, &owns_edge_mat);
234+
241235
// ------------------------------------------------------------------------
242236
// init vertices vectors
243237
// ------------------------------------------------------------------------
@@ -253,6 +247,7 @@ int main()
253247
GrB_Vector cards;
254248
TRY(GrB_Vector_new(&cards, card, VERTICES_NUMBER));
255249
TRY(init_vertices(&users, &cards));
250+
256251
// ------------------------------------------------------------------------
257252
// build user filters
258253
// ------------------------------------------------------------------------
@@ -274,22 +269,11 @@ int main()
274269
// ------------------------------------------------------------------------
275270
// apply user filters
276271
// ------------------------------------------------------------------------
277-
GrB_BinaryOp bool_add_op;
278-
TRY(GrB_BinaryOp_new(&bool_add_op, (GxB_binary_function)&owns_bool_add, GrB_BOOL, GrB_BOOL, GrB_BOOL));
279-
GrB_BinaryOp owns_bool_mul_op;
280-
TRY(GrB_BinaryOp_new(&owns_bool_mul_op, (GxB_binary_function)&owns_bool_mult, GrB_BOOL, GrB_BOOL, owns_edge));
281-
282-
GrB_Monoid owns_bool_monoid;
283-
bool owns_bool_identity = false;
284-
TRY(GrB_Monoid_new_BOOL(&owns_bool_monoid, bool_add_op, (void *)&owns_bool_identity));
285-
286-
GrB_Semiring owns_semiring_bool;
287-
TRY(GrB_Semiring_new(&owns_semiring_bool, owns_bool_monoid, owns_bool_mul_op));
288272

289273
GrB_Matrix owns_mat_filtered;
290274
TRY(GrB_Matrix_new(&owns_mat_filtered, GrB_BOOL, VERTICES_NUMBER, VERTICES_NUMBER));
291275
// apply filter
292-
TRY(GrB_mxm(owns_mat_filtered, NULL, NULL, owns_semiring_bool, ID, owns_edge_mat, NULL));
276+
TRY(GrB_mxm(owns_mat_filtered, NULL, NULL, GrB_LOR_LAND_SEMIRING_BOOL, ID, owns_edge_mat, NULL));
293277

294278
// ------------------------------------------------------------------------
295279
// get cards of filtered users

0 commit comments

Comments
 (0)