@@ -29,28 +29,19 @@ def transitive_reduction(assigns, vertices_with_other_edges):
2929 endpoints = vertices_with_other_edges .diag (name = "endpoints" )
3030 assigns_transposed = Matrix (BOOL , assigns .ncols , assigns .ncols , name = "assigns_transposed" )
3131 assigns_transposed ("any" ) << assigns .T
32- frontier = vertices_with_other_edges .diag (name = "frontier" )
33- #filter("any") << frontier
32+ frontier = vertices_with_other_edges .diag (name = "frontier" )
3433 visited = Matrix (BOOL , assigns .ncols , assigns .ncols , name = "visited" )
3534 visited ("any" ) << frontier
3635 while True :
37- print ("Frontier nvals = " , frontier .nvals )
38- #print("Frontier: ", frontier)
36+ print ("Frontier nvals = " , frontier .nvals )
3937 if frontier .nvals == 0 :
4038 break
4139 new_frontier = Matrix (BOOL , assigns .ncols , assigns .ncols , name = "new_frontier" )
42- new_frontier (~ visited .S ) << Matrix .mxm (frontier , assigns , "any_pair" )
43- #print("New frontier: ", new_frontier)
44- filter = Matrix (BOOL , assigns .ncols , assigns .ncols , name = "filter" )
45- #print("Endpoints: ", endpoints)
40+ new_frontier (~ visited .S ) << Matrix .mxm (frontier , assigns , "any_pair" )
41+ filter = Matrix (BOOL , assigns .ncols , assigns .ncols , name = "filter" )
4642 x = new_frontier .reduce_rowwise ("any" ).diag ()
4743 filter (~ x .S ) << endpoints
4844
49- #print("Filter: ", filter)
50- #to_result = Matrix(BOOL, assigns.ncols, assigns.ncols, name = "to_result")
51- #to_result << (Matrix.mxm(new_frontier, filter, "any_pair"))
52- #print("To result: ", to_result)
53-
5445 result ("any" ) << (Matrix .mxm (new_frontier , filter , "any_pair" ))
5546
5647 print ("Result nvals = " , result .nvals )
@@ -59,12 +50,12 @@ def transitive_reduction(assigns, vertices_with_other_edges):
5950
6051 new_frontier_2 = Matrix (BOOL , assigns .ncols , assigns .ncols , name = "new_frontier_2" )
6152 new_frontier_2 (~ result .S ) << new_frontier
62- #print("New frontier 2: ", new_frontier_2)
53+
6354 frontier = new_frontier_2
6455
6556 return result
6657
67- def to_label_decomposed_graph (graph , automata_size , initial_graph_size ):
58+ def to_label_decomposed_graph (graph , automata_size , initial_graph_size , do_transitive_reduction = False ):
6859 vertex_count = graph .nrows
6960 alloc = Matrix (BOOL , graph .ncols , graph .nrows , name = "alloc_after_intersection" )
7061 alloc << graph .select (graphblas .select .select_alloc )
@@ -74,11 +65,11 @@ def to_label_decomposed_graph(graph, automata_size, initial_graph_size):
7465 alloc_r << alloc .T
7566 print ("Boolean matrix for alloc_r nvals: " , alloc_r .nvals )
7667
77- print ( "mask start" )
78- mask_v = Vector ( BOOL , graph . ncols , name = "mask_vector " )
79- ####exit_mask_v = Vector(BOOL, graph.ncols, name = "exit_mask_vector ")
80- mask_v ("any" ) << alloc .reduce_columnwise ("any" )
81- mask_v ("any" ) << alloc .reduce_rowwise ("any" )
68+ if ( do_transitive_reduction ):
69+ print ( "mask start " )
70+ mask_v = Vector (BOOL , graph .ncols , name = "mask_vector " )
71+ mask_v ("any" ) << alloc .reduce_columnwise ("any" )
72+ mask_v ("any" ) << alloc .reduce_rowwise ("any" )
8273
8374 print ("entrypoints start" )
8475
@@ -97,11 +88,12 @@ def to_label_decomposed_graph(graph, automata_size, initial_graph_size):
9788 store_i << graph .select (graphblas .select .select_store ).apply (graphblas .unary .decode_store )
9889 print ("Matrix for store_i nvals: " , store_i .nvals )
9990
100- mask_v ("any" ) << load_i .reduce_columnwise ("any" )
101- mask_v ("any" ) << load_i .reduce_rowwise ("any" )
91+ if (do_transitive_reduction ):
92+ mask_v ("any" ) << load_i .reduce_columnwise ("any" )
93+ mask_v ("any" ) << load_i .reduce_rowwise ("any" )
10294
103- mask_v ("any" ) << store_i .reduce_columnwise ("any" )
104- mask_v ("any" ) << store_i .reduce_rowwise ("any" )
95+ mask_v ("any" ) << store_i .reduce_columnwise ("any" )
96+ mask_v ("any" ) << store_i .reduce_rowwise ("any" )
10597
10698 store_block_count = store_i .reduce_scalar ("max" ).get (0 ) + 1
10799 load_block_count = load_i .reduce_scalar ("max" ).get (0 ) + 1
@@ -136,8 +128,8 @@ def to_label_decomposed_graph(graph, automata_size, initial_graph_size):
136128 assign << graph .select (graphblas .select .select_assign )
137129 print ("Boolean matrix for assign nvals: " , assign .nvals )
138130
139-
140- assign << transitive_reduction (assign , mask_v )
131+ if ( do_transitive_reduction ):
132+ assign << transitive_reduction (assign , mask_v )
141133
142134 assign_r = Matrix (BOOL , graph .ncols , graph .nrows , name = "assign_r_after_intersection" )
143135 assign_r << assign .T
@@ -184,7 +176,7 @@ def get_new_v_id(v_id):
184176 ncols = first_free_v_id , name = "remapped_graph" )
185177 return result
186178
187- def add_context (file_path , max_num_of_contexts , depth ):
179+ def add_context (file_path , max_num_of_contexts , depth , do_transitive_reduction ):
188180 load_graph_start = time .perf_counter ()
189181
190182 graph ,number_of_contexts = load_graph (file_path , max_num_of_contexts )
@@ -216,7 +208,7 @@ def add_context(file_path, max_num_of_contexts, depth):
216208 print ("Vertices in intersection: " , result .ncols )
217209 print ("Edges in intersection: " , result .nvals )
218210
219- decomposed_result = to_label_decomposed_graph (result , automata .nrows , graph .nrows )
211+ decomposed_result = to_label_decomposed_graph (result , automata .nrows , graph .nrows , do_transitive_reduction )
220212 decomposition_end = time .perf_counter ()
221213 print ("Graph decomposition completed in " , decomposition_end - vertices_remapping_end )
222214
0 commit comments