@@ -12,12 +12,13 @@ function RS_CF_splitting(S::SparseMatrixCSC)
12
12
13
13
n_nodes = n
14
14
lambda = zeros (Int, n)
15
- Tp = S. colptr
16
- Tj = S. rowval
17
- Sp = Tp
18
- Sj = Tj
15
+ T = S'
16
+ Tp = T. colptr
17
+ Tj = T. rowval
18
+ Sp = S. colptr
19
+ Sj = S. rowval
19
20
20
- # compute lambdas
21
+ # compute lambdas - number of neighbors
21
22
for i = 1 : n
22
23
lambda[i] = Tp[i+ 1 ] - Tp[i]
23
24
end
@@ -27,6 +28,7 @@ function RS_CF_splitting(S::SparseMatrixCSC)
27
28
index_to_node = zeros (Int,n)
28
29
node_to_index = zeros (Int,n)
29
30
31
+ # Number of nodes with a certain neighbor count
30
32
for i = 1 : n
31
33
interval_count[lambda[i]+ 1 ] += 1
32
34
end
@@ -52,9 +54,83 @@ function RS_CF_splitting(S::SparseMatrixCSC)
52
54
splitting[i] = F_NODE
53
55
end
54
56
end
57
+ @show lambda
58
+ @show node_to_index
59
+ @show index_to_node
60
+ @show interval_ptr
61
+
62
+ for top_index = n_nodes: - 1 : 1
63
+ i = index_to_node[top_index]
64
+ lambda_i = lambda[i] + 1
65
+ interval_count[lambda_i] -= 1
66
+ if splitting[i] == F_NODE
67
+ continue
68
+ else
69
+ @assert splitting[i] == U_NODE
70
+ splitting[i] = C_NODE
71
+ for j in nzrange (T, i)
72
+ row = T. rowval[j]
73
+ if splitting[row] == U_NODE
74
+ splitting[row] = F_NODE
75
+
76
+ for k in nzrange (S, row)
77
+ rowk = S. rowval[k]
78
+ if splitting[rowk] == U_NODE
79
+ lambda[rowk] >= n_nodes - 1 && continue
80
+ lambda_k = lambda[rowk] + 1
81
+ old_pos = node_to_index[rowk]
82
+ new_pos = interval_ptr[lambda_k] + interval_count[lambda_k]# - 1
83
+
84
+ node_to_index[index_to_node[old_pos]] = new_pos
85
+ node_to_index[index_to_node[new_pos]] = old_pos
86
+ (index_to_node[old_pos], index_to_node[new_pos]) = (index_to_node[new_pos], index_to_node[old_pos])
87
+
88
+ # update intervals
89
+ interval_count[lambda_k] -= 1
90
+ interval_count[lambda_k + 1 ] += 1 # invalid write!
91
+ interval_ptr[lambda_k + 1 ] = new_pos - 1
92
+
93
+ # increment lambda_k
94
+ lambda[rowk] += 1
95
+ end
96
+ end
97
+ end
98
+ end
99
+ for j in nzrange (S, i)
100
+ row = S. rowval[j]
101
+ if splitting[row] == U_NODE
102
+
103
+ lambda[row] == 0 && continue
104
+
105
+ # assert(lambda[j] > 0);//this would cause problems!
106
+
107
+ # move j to the beginning of its current interval
108
+ lambda_j = lambda[row] + 1
109
+ old_pos = node_to_index[row]
110
+ new_pos = interval_ptr[lambda_j]
111
+
112
+ node_to_index[index_to_node[old_pos]] = new_pos
113
+ node_to_index[index_to_node[new_pos]] = old_pos
114
+ (index_to_node[old_pos],index_to_node[new_pos]) = (index_to_node[new_pos],index_to_node[old_pos])
115
+
116
+ # update intervals
117
+ interval_count[lambda_j] -= 1
118
+ interval_count[lambda_j- 1 ] += 1
119
+ interval_ptr[lambda_j] += 1
120
+ interval_ptr[lambda_j- 1 ] = interval_ptr[lambda_j] - interval_count[lambda_j- 1 ]
121
+
122
+ # decrement lambda_j
123
+ lambda[row] -= 1
124
+ end
125
+ end
126
+ end
127
+ end
128
+ splitting
129
+ end
130
+
55
131
56
132
# Now add elements to C and F, in descending order of lambda
57
- for top_index = n_nodes: - 1 : 1
133
+ #= for top_index = n_nodes:-1:1
58
134
i = index_to_node[top_index]
59
135
lambda_i = lambda[i] + 1
60
136
@@ -74,6 +150,7 @@ function RS_CF_splitting(S::SparseMatrixCSC)
74
150
75
151
# For each j in S^T_i /\ U
76
152
for jj = Tp[i]:Tp[i+1]-1
153
+ #jj > length(Tp) && continue
77
154
78
155
j = Tj[jj]
79
156
@@ -82,6 +159,7 @@ function RS_CF_splitting(S::SparseMatrixCSC)
82
159
83
160
# For each k in S_j /\ U
84
161
for kk = Sp[j]: Sp[j+1]-1
162
+ # kk > length(Sj) && continue
85
163
k = Sj[kk]
86
164
87
165
if splitting[k] == U_NODE
@@ -109,7 +187,8 @@ function RS_CF_splitting(S::SparseMatrixCSC)
109
187
end
110
188
111
189
# For each j in S_i /\ U
112
- for jj = Sp[i]: Sp[i+ 1 ]- 1
190
+ for jj = Sp[i]: Sp[i+1] - 1
191
+ # jj > length(Sj) && continue
113
192
114
193
j = Sj[jj]
115
194
@@ -141,4 +220,4 @@ function RS_CF_splitting(S::SparseMatrixCSC)
141
220
end
142
221
end
143
222
splitting
144
- end
223
+ end=#
0 commit comments