Skip to content

Commit 8084a3e

Browse files
authored
Merge pull request #14 from ranjanan/optstr
Optimize strength calc
2 parents a29e7f0 + e6d9b10 commit 8084a3e

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

src/strength.jl

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,27 @@ function strength_of_connection{T, Ti, Tv}(c::Classical{T}, A::SparseMatrixCSC{T
99
θ = c.θ
1010

1111
m, n = size(A)
12-
nz = nnz(A)
13-
I = zeros(Ti, nz)
14-
J = zeros(Ti, nz)
15-
V = zeros(float(Tv), nz)
16-
k = 1
12+
S = deepcopy(A)
1713

1814
for i = 1:n
1915
_m = find_max_off_diag(A, i)
2016
threshold = θ * _m
2117
for j in nzrange(A, i)
2218
row = A.rowval[j]
2319
val = A.nzval[j]
24-
if abs(val) >= threshold
25-
if row != i
26-
I[k] = row
27-
J[k] = i
28-
V[k] = abs(val)
29-
k += 1
20+
21+
if row != i
22+
if abs(val) >= threshold
23+
S.nzval[j] = abs(val)
24+
else
25+
S.nzval[j] = 0
3026
end
3127
end
3228

33-
if row == i
34-
I[k] = row
35-
J[k] = i
36-
V[k] = val
37-
k += 1
38-
end
3929
end
4030
end
41-
deleteat!(I, k:nz)
42-
deleteat!(J, k:nz)
43-
deleteat!(V, k:nz)
4431

45-
S = sparse(I, J, V, m, n)
32+
dropzeros!(S)
4633

4734
scale_cols_by_largest_entry!(S)
4835

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ ref_split = readdlm("ref_split_test.txt")
1414

1515
# classical strength of connection
1616
A = poisson(5)
17+
A = float.(A)
1718
S, T = strength_of_connection(Classical(0.2), A)
1819
@test full(S) == [ 1.0 0.5 0.0 0.0 0.0
1920
0.5 1.0 0.5 0.0 0.0

0 commit comments

Comments
 (0)