Skip to content

Commit 70b93bd

Browse files
authored
Merge pull request #47 from JuliaLinearAlgebra/bounds
Fix bug on small linear systems
2 parents 07b586a + fb32b34 commit 70b93bd

File tree

5 files changed

+22
-2
lines changed

5 files changed

+22
-2
lines changed

src/aggregation.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ function smoothed_aggregation(A::TA,
3535
end
3636
bsr_flag = false
3737
w = MultiLevelWorkspace(Val{bs}, eltype(A))
38+
residual!(w, size(A, 1))
3839

3940
while length(levels) + 1 < max_levels && size(A, 1) > max_coarse
40-
residual!(w, size(A, 1))
4141
A, B, bsr_flag = extend_hierarchy!(levels, strength, aggregate, smooth,
4242
improve_candidates, diagonal_dominance,
4343
keep, A, B, symmetry, bsr_flag)
@@ -46,6 +46,7 @@ function smoothed_aggregation(A::TA,
4646
#=if size(A, 1) <= max_coarse
4747
break
4848
end=#
49+
residual!(w, size(A, 1))
4950
end
5051
#=A, B = extend_hierarchy!(levels, strength, aggregate, smooth,
5152
improve_candidates, diagonal_dominance,

src/classical.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@ function ruge_stuben(_A::Union{TA, Symmetric{Ti, TA}, Hermitian{Ti, TA}},
4040
end
4141
end
4242
w = MultiLevelWorkspace(Val{bs}, eltype(A))
43+
residual!(w, size(A, 1))
4344

4445
while length(levels) + 1 < max_levels && size(A, 1) > max_coarse
45-
residual!(w, size(A, 1))
4646
A = extend_heirarchy!(levels, strength, CF, A, symmetric)
4747
coarse_x!(w, size(A, 1))
4848
coarse_b!(w, size(A, 1))
49+
residual!(w, size(A, 1))
4950
end
5051

5152
MultiLevel(levels, A, coarse_solver(A), presmoother, postsmoother, w)

test/REQUIRE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
JLD2
2+
FileIO

test/bug.jld2

5.78 KB
Binary file not shown.

test/runtests.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ using Compat, Compat.Test, Compat.LinearAlgebra
22
using Compat.SparseArrays, Compat.DelimitedFiles, Compat.Random
33
using IterativeSolvers, AlgebraicMultigrid
44
import AlgebraicMultigrid: Pinv, Classical
5+
using JLD2
6+
using FileIO
57

68
if VERSION < v"0.7-"
79
const seed! = srand
@@ -304,4 +306,18 @@ for sz in [10, 5, 2]
304306
@test AlgebraicMultigrid.grid_complexity(ml) == 1
305307
end
306308

309+
# Issue #46
310+
for f in (smoothed_aggregation, ruge_stuben)
311+
312+
a = load("bug.jld2")["G"]
313+
ml = f(a)
314+
p = aspreconditioner(ml)
315+
b = zeros(size(a,1))
316+
b[1] = 1
317+
b[2] = -1
318+
@test sum(abs2, a * solve(ml, b) - b) < 1e-10
319+
@test sum(abs2, a * cg(a, b, Pl = p, maxiter = 1000) - b) < 1e-10
320+
321+
end
322+
307323
end

0 commit comments

Comments
 (0)