File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ using SparseArrays
2
+ include (" custom_graph.jl" )
3
+
4
+ """
5
+ matrix2graph(SparseMatrix)
6
+
7
+ A utility function to generate a graph from input
8
+ sparse matrix, columns are represented with vertices
9
+ and 2 vertices are connected with an edge only if
10
+ the two columns are mutually orthogonal.
11
+ """
12
+ function matrix2graph (SparseMatrix:: SparseMatrixCSC{Int64,Int64} )
13
+ dropzeros (SparseMatrix)
14
+ (rows_index, cols_index, val) = findnz (SparseMatrix)
15
+
16
+ V = col = size (SparseMatrix, 2 )
17
+ row = size (SparseMatrix, 1 )
18
+
19
+ vertices = zeros (Int64, 0 )
20
+ edges = [Vector {Int64} () for _ in 1 : V]
21
+
22
+ graph = CGraph (vertices, edges)
23
+ for i = 1 : V
24
+ push! (vertices, i)
25
+ end
26
+
27
+ for i = 1 : length (cols_index)
28
+ cur_col = cols_index[i]
29
+ for j = 1 : (i- 1 )
30
+ next_col = cols_index[j]
31
+ if cur_col != next_col
32
+ if row_index[i] == row_index[j]
33
+ # add edge
34
+ add_edge! (graph, i, j)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ return graph
40
+ end
You can’t perform that action at this time.
0 commit comments