@@ -25,29 +25,33 @@ def indexed_to_boolean_decomposition(graph, block_count):
2525 ncols = vertex_count , name = "boolean_decomposition_of_indexed" )
2626 return result
2727
28- def transitive_reduction (assigns , mask , exit_mask ):
28+ def transitive_reduction (assigns , vertices_with_other_edges ):
2929 result = Matrix (BOOL , assigns .ncols , assigns .ncols , name = "reduced_assigns" )
30- result << Matrix .mxm (mask , assigns , "any_pair" )
31- total = Matrix (BOOL , assigns .ncols , assigns .ncols , name = "total_closure" )
32- unused_assigns = Matrix (BOOL , assigns .ncols , assigns .ncols , name = "unused_assigns" )
33- unused_assigns (~ result .S ) << assigns
34- closure = Matrix (BOOL , assigns .ncols , assigns .ncols , name = "closure" )
35- print ("exit" , exit_mask )
36- print ("unused assigns" , unused_assigns )
37- closure << Matrix .mxm (exit_mask , unused_assigns , "any_pair" )
38- total ("any" ) << closure
39- #while closure.nvals > 0:
30+ filter = Matrix (BOOL , assigns .ncols , assigns .ncols , name = "filter" )
31+ frontier = vertices_with_other_edges .diag (name = "frontier" )
32+ filter ("any" ) << frontier
33+ visited = Matrix (BOOL , assigns .ncols , assigns .ncols , name = "visited" )
34+ visited ("any" ) << frontier
4035 while True :
41- print ("Closure nvals = " , closure .nvals )
42- closure << Matrix .mxm (closure , unused_assigns , "any_pair" )
43- result ("any" ) << Matrix .mxm (closure , mask , "any_pair" )
44- new_closure = Matrix (BOOL , assigns .ncols , assigns .ncols , name = "closure" )
45- new_closure (~ result .S ) << closure
46- nnz = total .nvals
47- total ("any" ) << closure
48- closure = new_closure
49- if total .nvals == nnz :
36+ print ("Frontier nvals = " , frontier .nvals )
37+
38+ if frontier .nvals == 0 :
5039 break
40+ new_frontier = Matrix (BOOL , assigns .ncols , assigns .ncols , name = "new_frontier" )
41+ new_frontier (~ visited .S ) << Matrix .mxm (frontier , assigns , "any_pair" )
42+ to_result = Matrix (BOOL , assigns .ncols , assigns .ncols , name = "to_result" )
43+ to_result << (Matrix .mxm (filter , new_frontier , "any_pair" ))
44+
45+ result ("any" ) << to_result
46+
47+ print ("Result nvals = " , result .nvals )
48+
49+ visited ("any" ) << new_frontier
50+
51+ new_frontier_2 = Matrix (BOOL , assigns .ncols , assigns .ncols , name = "new_frontier_2" )
52+ new_frontier_2 (~ result .S ) << new_frontier
53+ frontier = new_frontier_2
54+
5155 return result
5256
5357def to_label_decomposed_graph (graph , automata_size , initial_graph_size ):
@@ -60,19 +64,19 @@ def to_label_decomposed_graph(graph, automata_size, initial_graph_size):
6064 alloc_r << alloc .T
6165 print ("Boolean matrix for alloc_r nvals: " , alloc_r .nvals )
6266
63- # print("mask start")
64- # mask_v = Vector(BOOL, graph.ncols, name = "mask_vector")
67+ print ("mask start" )
68+ mask_v = Vector (BOOL , graph .ncols , name = "mask_vector" )
6569 #exit_mask_v = Vector(BOOL, graph.ncols, name = "exit_mask_vector")
66- # mask_v(op.lor ) << alloc.reduce_columnwise("lor ")
67- #exit_mask_v(op.lor ) << alloc.reduce_rowwise("lor ")
70+ mask_v ("any" ) << alloc .reduce_columnwise ("any " )
71+ mask_v ( "any" ) << alloc .reduce_rowwise ("any " )
6872
69- # print("entrypoints start")
73+ print ("entrypoints start" )
7074
71- # entrypoints = Vector(bool,graph.nrows, name="entrypoints")
72- # entrypoints << graph.reduce_columnwise(op.lor)
75+ entrypoints = Vector (bool ,graph .nrows , name = "entrypoints" )
76+ entrypoints << graph .reduce_columnwise (op .lor )
7377 #mask_v(op.lor) << Vector.from_coo(list(set(range(0,graph.nrows)).difference(entrypoints.to_coo(values=False)[0])), values=True, dtype = BOOL)
7478
75- #exit_mask_v (op.lor) << Vector.from_coo([i * automata_size for i in range(0, initial_graph_size)], values=True, dtype = BOOL, size= graph.ncols)
79+ mask_v (op .lor ) << Vector .from_coo ([i * automata_size for i in range (0 , initial_graph_size )], values = True , dtype = BOOL , size = graph .ncols )
7680
7781 load_i = Matrix (UINT64 , graph .ncols , graph .nrows , name = "load_i_after_intersection" )
7882 load_i << graph .select (graphblas .select .select_load ).apply (graphblas .unary .decode_load )
@@ -82,11 +86,11 @@ def to_label_decomposed_graph(graph, automata_size, initial_graph_size):
8286 store_i << graph .select (graphblas .select .select_store ).apply (graphblas .unary .decode_store )
8387 print ("Matrix for store_i nvals: " , store_i .nvals )
8488
85- # mask_v(op.lor ) << load_i.reduce_columnwise("lor ")
86- #exit_mask_v(op.lor ) << load_i.reduce_rowwise("lor ")
89+ mask_v ("any" ) << load_i .reduce_columnwise ("any " )
90+ mask_v ( "any" ) << load_i .reduce_rowwise ("any " )
8791
88- # mask_v(op.lor ) << store_i.reduce_columnwise("lor ")
89- #exit_mask_v(op.lor ) << store_i.reduce_rowwise("lor ")
92+ mask_v ("any" ) << store_i .reduce_columnwise ("any " )
93+ mask_v ( "any" ) << store_i .reduce_rowwise ("any " )
9094
9195 store_block_count = store_i .reduce_scalar ("max" ).get (0 ) + 1
9296 load_block_count = load_i .reduce_scalar ("max" ).get (0 ) + 1
@@ -122,7 +126,7 @@ def to_label_decomposed_graph(graph, automata_size, initial_graph_size):
122126 print ("Boolean matrix for assign nvals: " , assign .nvals )
123127
124128
125- # assign << transitive_reduction(assign, assign_mask, exit_mask )
129+ assign << transitive_reduction (assign , mask_v )
126130
127131 #assign_res = Matrix(BOOL, graph.ncols, graph.nrows, name = "assign_after_transitive_reduction")
128132 #assign_1 = Matrix.mxm(assign_mask, assign, "land_lor")
@@ -201,7 +205,7 @@ def normalize(solver_result, initial_graph_nvertices):
201205 start_vertices = set ([i * c for i in range (0 ,initial_graph_nvertices )])
202206 edges = solver_result .to_edgelist ()
203207 edges = zip (edges [0 ], edges [1 ])
204- new_edges = [(_edg [0 ] // c , _edg [1 ] // c ) for (_edg , _lbl ) in edges if _edg [0 ] in start_vertices ]
208+ new_edges = set ( [(_edg [0 ] // c , _edg [1 ] // c ) for (_edg , _lbl ) in edges if _edg [0 ] in start_vertices ])
205209 result = Matrix .from_edgelist (new_edges , values = True , dtype = BOOL , nrows = initial_graph_nvertices ,
206210 ncols = initial_graph_nvertices , name = "normalized_solver_result" )
207211 normalization_end = time .perf_counter ()
0 commit comments