Skip to content

Commit

Permalink
Merge pull request #47 from JuliaLinearAlgebra/bounds
Browse files Browse the repository at this point in the history
Fix bug on small linear systems
  • Loading branch information
ranjanan authored Oct 8, 2018
2 parents 07b586a + fb32b34 commit 70b93bd
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/aggregation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ function smoothed_aggregation(A::TA,
end
bsr_flag = false
w = MultiLevelWorkspace(Val{bs}, eltype(A))
residual!(w, size(A, 1))

while length(levels) + 1 < max_levels && size(A, 1) > max_coarse
residual!(w, size(A, 1))
A, B, bsr_flag = extend_hierarchy!(levels, strength, aggregate, smooth,
improve_candidates, diagonal_dominance,
keep, A, B, symmetry, bsr_flag)
Expand All @@ -46,6 +46,7 @@ function smoothed_aggregation(A::TA,
#=if size(A, 1) <= max_coarse
break
end=#
residual!(w, size(A, 1))
end
#=A, B = extend_hierarchy!(levels, strength, aggregate, smooth,
improve_candidates, diagonal_dominance,
Expand Down
3 changes: 2 additions & 1 deletion src/classical.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ function ruge_stuben(_A::Union{TA, Symmetric{Ti, TA}, Hermitian{Ti, TA}},
end
end
w = MultiLevelWorkspace(Val{bs}, eltype(A))
residual!(w, size(A, 1))

while length(levels) + 1 < max_levels && size(A, 1) > max_coarse
residual!(w, size(A, 1))
A = extend_heirarchy!(levels, strength, CF, A, symmetric)
coarse_x!(w, size(A, 1))
coarse_b!(w, size(A, 1))
residual!(w, size(A, 1))
end

MultiLevel(levels, A, coarse_solver(A), presmoother, postsmoother, w)
Expand Down
2 changes: 2 additions & 0 deletions test/REQUIRE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
JLD2
FileIO
Binary file added test/bug.jld2
Binary file not shown.
16 changes: 16 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ using Compat, Compat.Test, Compat.LinearAlgebra
using Compat.SparseArrays, Compat.DelimitedFiles, Compat.Random
using IterativeSolvers, AlgebraicMultigrid
import AlgebraicMultigrid: Pinv, Classical
using JLD2
using FileIO

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

# Issue #46
for f in (smoothed_aggregation, ruge_stuben)

a = load("bug.jld2")["G"]
ml = f(a)
p = aspreconditioner(ml)
b = zeros(size(a,1))
b[1] = 1
b[2] = -1
@test sum(abs2, a * solve(ml, b) - b) < 1e-10
@test sum(abs2, a * cg(a, b, Pl = p, maxiter = 1000) - b) < 1e-10

end

end

0 comments on commit 70b93bd

Please sign in to comment.