Skip to content

Commit b323b00

Browse files
committed
Fix splitting algorithm and add a test
1 parent 5d83e64 commit b323b00

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

src/splitting.jl

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function RS_CF_splitting(S::SparseMatrixCSC)
2020

2121
# compute lambdas - number of neighbors
2222
for i = 1:n
23-
lambda[i] = Tp[i+1] - Tp[i]
23+
lambda[i] = Sp[i+1] - Sp[i]
2424
end
2525

2626
interval_ptr = zeros(Int, n+1)
@@ -30,7 +30,7 @@ function RS_CF_splitting(S::SparseMatrixCSC)
3030

3131
# Number of nodes with a certain neighbor count
3232
for i = 1:n
33-
interval_count[lambda[i]+1] += 1
33+
interval_count[lambda[i] + 1] += 1
3434
end
3535
csum = 0
3636
for i = 1:n
@@ -39,7 +39,7 @@ function RS_CF_splitting(S::SparseMatrixCSC)
3939
interval_count[i] = 0
4040
end
4141
for i = 1:n
42-
lambda_i = lambda[i]+1
42+
lambda_i = lambda[i] + 1
4343
index = interval_ptr[lambda_i] + interval_count[lambda_i]
4444
index_to_node[index+1] = i
4545
node_to_index[i] = index+1
@@ -54,10 +54,6 @@ function RS_CF_splitting(S::SparseMatrixCSC)
5454
splitting[i] = F_NODE
5555
end
5656
end
57-
@show lambda
58-
@show node_to_index
59-
@show index_to_node
60-
@show interval_ptr
6157

6258
for top_index = n_nodes:-1:1
6359
i = index_to_node[top_index]
@@ -107,7 +103,7 @@ function RS_CF_splitting(S::SparseMatrixCSC)
107103
# move j to the beginning of its current interval
108104
lambda_j = lambda[row] + 1
109105
old_pos = node_to_index[row]
110-
new_pos = interval_ptr[lambda_j]
106+
new_pos = interval_ptr[lambda_j] + 1
111107

112108
node_to_index[index_to_node[old_pos]] = new_pos
113109
node_to_index[index_to_node[new_pos]] = old_pos

test/REQUIRE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
JLD

test/runtests.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using AMG
22
using Base.Test
3+
using JLD
34

45
@testset "Strength of connection" begin
56

@@ -24,6 +25,12 @@ srand(0)
2425
S = sprand(10,10,0.1); S = S + S'
2526
@test split_nodes(RS(), S) == [0, 1, 1, 0, 0, 0, 0, 0, 1, 1]
2627

28+
a = load("thing.jld")["G"]
29+
S = AMG.strength_of_connection(AMG.Classical(0.25), a)
30+
split_nodes(RS(), S) == [0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0,
31+
0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0,
32+
1, 0]
33+
2734
end
2835

2936
@testset "Interpolation" begin

test/thing.jld

10.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)