JuliaLinearAlgebra / AlgebraicMultigrid.jl

Algebraic Multigrid in Julia
Other
117 stars 22 forks source link

BoundsError on small linear systems #46

Closed omalled closed 6 years ago

omalled commented 6 years ago

I am trying to migrate to AlgebraicMultigrid.jl from PyAMG.jl which is apparently being abandoned based on the discussion here. The first thing I want to do is get the tests working for my project which relies on a Ruge-Stuben preconditioner. The tests involve solving small linear systems, and I ran into a problem with AlgebraicMultigrid.jl for these systems. The same problem occurs with a slight modification of the example code from the README, and seems to arise when there is only 1 level in the MultiLevel object. Here's a minimal example that illustrates the issue:

using AlgebraicMultigrid
function f(n)
    A = poisson(n)
    ml = ruge_stuben(A)
    return solve(ml, A * ones(n))
end
for i = 10:-1:1
    print("starting $(2^i) ")
    f(2^i)
    println("done with $(2^i)")
end

and here is the output I see

starting 1024 done with 1024
starting 512 done with 512
starting 256 done with 256
starting 128 done with 128
starting 64 done with 64
starting 32 done with 32
starting 16 done with 16
starting 8 ERROR: LoadError: BoundsError: attempt to access 0-element Array{Array{Float64,1},1} at index [1]
Stacktrace:
 [1] getindex at ./array.jl:731 [inlined]
 [2] #solve!#12(::Int64, ::Float64, ::Bool, ::Bool, ::Bool, ::Function, ::Array{Float64,1}, ::AlgebraicMultigrid.MultiLevel{AlgebraicMultigrid.Pinv{Float64},GaussSeidel{SymmetricSweep},GaussSeidel{SymmetricSweep},SparseArrays.SparseMatrixCSC{Float64,Int64},LinearAlgebra.Adjoint{Float64,SparseArrays.SparseMatrixCSC{Float64,Int64}},SparseArrays.SparseMatrixCSC{Float64,Int64},AlgebraicMultigrid.MultiLevelWorkspace{Array{Float64,1},1}}, ::Array{Float64,1}, ::AlgebraicMultigrid.V) at /Users/omalled/.julia/packages/AlgebraicMultigrid/p0Evn/src/multilevel.jl:161
 [3] #solve#11 at /Users/omalled/.julia/packages/AlgebraicMultigrid/p0Evn/src/multilevel.jl:151 [inlined]
 [4] solve at /Users/omalled/.julia/packages/AlgebraicMultigrid/p0Evn/src/multilevel.jl:138 [inlined]
 [5] f(::Int64) at /Users/omalled/blah/amg/runtests.jl:5
 [6] top-level scope at /Users/omalled/blah/amg/runtests.jl:9 [inlined]
 [7] top-level scope at ./none:0
 [8] include at ./boot.jl:317 [inlined]
 [9] include_relative(::Module, ::String) at ./loading.jl:1038
 [10] include(::Module, ::String) at ./sysimg.jl:29
 [11] include(::String) at ./client.jl:398
 [12] top-level scope at none:0
in expression starting at /Users/omalled/blah/amg/runtests.jl:7

I am using julia v0.7.0 and AlgebraicMultigrid v0.2.0.

ranjanan commented 6 years ago

@omalled thanks for posting this issue, and thanks a ton for the MWE. I will fix this as soon as I finish submitting a couple of assignments that I have due here 😄

ranjanan commented 6 years ago

Could you please checkout the master branch? It should work now.

omalled commented 6 years ago

That did the trick. Thanks!