Skip to content

Commit 7b7e5d9

Browse files
committed
Reduce mem usage a little
1 parent b025aef commit 7b7e5d9

File tree

4 files changed

+20
-21
lines changed

4 files changed

+20
-21
lines changed

src/classical.jl

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@ function ruge_stuben(A::SparseMatrixCSC;
3030
end
3131

3232
function extend_heirarchy!(levels::Vector{Level}, strength, CF, A)
33-
S = strength_of_connection(strength, A)
34-
splitting = split_nodes(CF, S)
35-
P, R = direct_interpolation(A, S, splitting)
33+
S, T = strength_of_connection(strength, A)
34+
splitting = split_nodes(CF, S, T)
35+
P, R = direct_interpolation(A, T, splitting)
3636
push!(levels, Level(A, P, R))
3737
A = R * A * P
3838
end
3939

40-
function direct_interpolation{T,V}(A::T, S::T, splitting::Vector{V})
40+
function direct_interpolation(A, T, splitting)
4141

42-
fill!(S.nzval, 1.)
43-
S = A .* S
44-
Pp = rs_direct_interpolation_pass1(S, A, splitting)
42+
fill!(T.nzval, 1.)
43+
T = A .* T
44+
Pp = rs_direct_interpolation_pass1(T, A, splitting)
4545
Pp = Pp .+ 1
4646

47-
Px, Pj, Pp = rs_direct_interpolation_pass2(A, S, splitting, Pp)
47+
Px, Pj, Pp = rs_direct_interpolation_pass2(A, T, splitting, Pp)
4848

4949
# Px .= abs.(Px)
5050
Pj = Pj .+ 1
@@ -56,10 +56,9 @@ function direct_interpolation{T,V}(A::T, S::T, splitting::Vector{V})
5656
end
5757

5858

59-
function rs_direct_interpolation_pass1(S, A, splitting)
59+
function rs_direct_interpolation_pass1(T, A, splitting)
6060

6161
Bp = zeros(Int, size(A.colptr))
62-
T = S'
6362
#=Sp = S.colptr
6463
Sj = S.rowval
6564
n_nodes = size(A, 1)
@@ -97,12 +96,11 @@ function rs_direct_interpolation_pass1(S, A, splitting)
9796

9897

9998
function rs_direct_interpolation_pass2{Tv, Ti}(A::SparseMatrixCSC{Tv,Ti},
100-
S::SparseMatrixCSC{Tv,Ti},
99+
T::SparseMatrixCSC{Tv, Ti},
101100
splitting::Vector{Ti},
102101
Bp::Vector{Ti})
103102

104103

105-
T = S'
106104
Bx = zeros(Float64, Bp[end] - 1)
107105
Bj = zeros(Ti, Bp[end] - 1)
108106

src/splitting.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ const U_NODE = 2
44

55
struct RS
66
end
7-
8-
split_nodes(::RS, S::SparseMatrixCSC) = RS_CF_splitting(S - spdiagm(diag(S)))
9-
function RS_CF_splitting(S::SparseMatrixCSC)
7+
split_nodes(x, S) = split_nodes(x, S, S')
8+
split_nodes(::RS, S::SparseMatrixCSC, T::SparseMatrixCSC) = RS_CF_splitting(S - spdiagm(diag(S)), T - spdiagm(diag(T)))
9+
function RS_CF_splitting(S::SparseMatrixCSC, T::SparseMatrixCSC)
1010

1111
m,n = size(S)
1212

1313
n_nodes = n
1414
lambda = zeros(Int, n)
15-
T = S'
15+
1616
Tp = T.colptr
1717
Tj = T.rowval
1818
Sp = S.colptr

src/strength.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ function strength_of_connection{T}(c::Classical{T}, A::SparseMatrixCSC)
3939

4040
scale_cols_by_largest_entry!(S)
4141

42-
S'
42+
43+
S', S
4344
end
4445

4546
function find_max_off_diag(neighbors, col)

test/runtests.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ ref_split = readdlm("ref_split_test.txt")
1212

1313
# classical strength of connection
1414
A = poisson(5)
15-
S = strength_of_connection(Classical(0.2), A)
15+
S, T = strength_of_connection(Classical(0.2), A)
1616
@test full(S) == [ 1.0 0.5 0.0 0.0 0.0
1717
0.5 1.0 0.5 0.0 0.0
1818
0.0 0.5 1.0 0.5 0.0
1919
0.0 0.0 0.5 1.0 0.5
2020
0.0 0.0 0.0 0.5 1.0 ]
21-
S = strength_of_connection(Classical(0.25), graph)
21+
S, T = strength_of_connection(Classical(0.25), graph)
2222
diff = S - ref_S
2323
@test maximum(diff) < 1e-10
2424

@@ -34,12 +34,12 @@ S = sprand(10,10,0.1); S = S + S'
3434
@test split_nodes(RS(), S) == [0, 1, 1, 0, 0, 0, 0, 0, 1, 1]
3535

3636
a = load("thing.jld")["G"]
37-
S = AMG.strength_of_connection(AMG.Classical(0.25), a)
37+
S, T = AMG.strength_of_connection(AMG.Classical(0.25), a)
3838
@test split_nodes(RS(), S) == [0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0,
3939
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,
4040
1, 0]
4141

42-
@test split_nodes(RS(), ref_S) == Int.(vec(ref_split))
42+
@test split_nodes(RS(), ref_S, ref_S') == Int.(vec(ref_split))
4343

4444
end
4545

0 commit comments

Comments
 (0)