Skip to content

Commit

Permalink
Improve error messages from ARPACK. Fixes #13709
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasnoack committed Oct 26, 2015
1 parent e9cabd3 commit fa006bc
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 25 deletions.
32 changes: 16 additions & 16 deletions base/linalg/arnoldi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,20 @@ The following keyword arguments are supported:
=============== ================================== ==================================
```
"""
eigs(A; args...) = eigs(A, I; args...)
eigs{T<:BlasFloat}(A::AbstractMatrix{T}, ::UniformScaling; args...) = _eigs(A, I; args...)
eigs(A; kwargs...) = eigs(A, I; kwargs...)
eigs{T<:BlasFloat}(A::AbstractMatrix{T}, ::UniformScaling; kwargs...) = _eigs(A, I; kwargs...)

eigs{T<:BlasFloat}(A::AbstractMatrix{T}, B::AbstractMatrix{T}; args...) = _eigs(A, B; args...)
eigs(A::AbstractMatrix{BigFloat}, B::AbstractMatrix...; args...) = throw(MethodError(eigs, Any[A,B,args...]))
eigs(A::AbstractMatrix{BigFloat}, B::UniformScaling; args...) = throw(MethodError(eigs, Any[A,B,args...]))
function eigs{T}(A::AbstractMatrix{T}, ::UniformScaling; args...)
eigs{T<:BlasFloat}(A::AbstractMatrix{T}, B::AbstractMatrix{T}; kwargs...) = _eigs(A, B; kwargs...)
eigs(A::AbstractMatrix{BigFloat}, B::AbstractMatrix...; kwargs...) = throw(MethodError(eigs, Any[A,B,kwargs...]))
eigs(A::AbstractMatrix{BigFloat}, B::UniformScaling; kwargs...) = throw(MethodError(eigs, Any[A,B,kwargs...]))
function eigs{T}(A::AbstractMatrix{T}, ::UniformScaling; kwargs...)
Tnew = typeof(zero(T)/sqrt(one(T)))
eigs(convert(AbstractMatrix{Tnew}, A), I; args...)
eigs(convert(AbstractMatrix{Tnew}, A), I; kwargs...)
end
function eigs(A::AbstractMatrix, B::AbstractMatrix; args...)
function eigs(A::AbstractMatrix, B::AbstractMatrix; kwargs...)
T = promote_type(eltype(A), eltype(B))
Tnew = typeof(zero(T)/sqrt(one(T)))
eigs(convert(AbstractMatrix{Tnew}, A), convert(AbstractMatrix{Tnew}, B); args...)
eigs(convert(AbstractMatrix{Tnew}, A), convert(AbstractMatrix{Tnew}, B); kwargs...)
end
doc"""
```rst
Expand Down Expand Up @@ -106,7 +106,7 @@ The following keyword arguments are supported:
=============== ================================== ==================================
```
"""
eigs(A, B; args...) = _eigs(A, B; args...)
eigs(A, B; kwargs...) = _eigs(A, B; kwargs...)
function _eigs(A, B;
nev::Integer=6, ncv::Integer=max(20,2*nev+1), which=:LM,
tol=0.0, maxiter::Integer=300, sigma=nothing, v0::Vector=zeros(eltype(A),(0,)),
Expand Down Expand Up @@ -147,7 +147,7 @@ function _eigs(A, B;
end
if (which != :LM && which != :SM && which != :LR && which != :SR &&
which != :LI && which != :SI && which != :BE)
throw(ArgumentError("which must be :LM, :SM, :LR, :SR, :LI, :SI, or :BE, got $(repr(which))"))
throw(ArgumentError("which must be :LM, :SM, :LR, :SR, :LI, :SI, or :BE, got $(repr(which))"))
end
if which == :BE && !sym
throw(ArgumentError("which=:BE only possible for real symmetric problem"))
Expand Down Expand Up @@ -262,13 +262,13 @@ end
size(s::SVDOperator) = s.m + s.n, s.m + s.n
issym(s::SVDOperator) = true

svds{T<:BlasFloat}(A::AbstractMatrix{T}; args...) = _svds(A; args...)
svds(A::AbstractMatrix{BigFloat}; args...) = throw(MethodError(svds, Any[A, args...]))
function svds{T}(A::AbstractMatrix{T}; args...)
svds{T<:BlasFloat}(A::AbstractMatrix{T}; kwargs...) = _svds(A; kwargs...)
svds(A::AbstractMatrix{BigFloat}; kwargs...) = throw(MethodError(svds, Any[A, kwargs...]))
function svds{T}(A::AbstractMatrix{T}; kwargs...)
Tnew = typeof(zero(T)/sqrt(one(T)))
svds(convert(AbstractMatrix{Tnew}, A); args...)
svds(convert(AbstractMatrix{Tnew}, A); kwargs...)
end
svds(A; args...) = _svds(A; args...)
svds(A; kwargs...) = _svds(A; kwargs...)
function _svds(X; nsv::Int = 6, ritzvec::Bool = true, tol::Float64 = 0.0, maxiter::Int = 1000)
if nsv < 1
throw(ArgumentError("number of singular values (nsv) must be ≥ 1, got $nsv"))
Expand Down
22 changes: 14 additions & 8 deletions base/linalg/arpack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ function aupd_wrapper(T, matvecA::Function, matvecB::Function, solveSI::Function
elseif ido[1] == 99
break
else
error("Internal ARPACK error")
throw(ARPACKException("unexpected behavior"))
end
elseif mode == 3 && bmat == "I" # corresponds to dsdrv2, dndrv2 or zndrv2
if ido[1] == -1 || ido[1] == 1
workd[store_idx] = solveSI(x)
elseif ido[1] == 99
break
else
error("Internal ARPACK error")
throw(ARPACKException("unexpected behavior"))
end
elseif mode == 2 # corresponds to dsdrv3, dndrv3 or zndrv3
if ido[1] == -1 || ido[1] == 1
Expand All @@ -81,7 +81,7 @@ function aupd_wrapper(T, matvecA::Function, matvecB::Function, solveSI::Function
elseif ido[1] == 99
break
else
error("Internal ARPACK error")
throw(ARPACKException("unexpected behavior"))
end
elseif mode == 3 && bmat == "G" # corresponds to dsdrv4, dndrv4 or zndrv4
if ido[1] == -1
Expand All @@ -93,7 +93,7 @@ function aupd_wrapper(T, matvecA::Function, matvecB::Function, solveSI::Function
elseif ido[1] == 99
break
else
error("Internal ARPACK error")
throw(ARPACKException("unexpected behavior"))
end
else
throw(ArgumentError("ARPACK mode ($mode) not yet supported"))
Expand Down Expand Up @@ -133,7 +133,9 @@ function eupd_wrapper(T, n::Integer, sym::Bool, cmplx::Bool, bmat::ByteString,
neupd(ritzvec, howmny, select, d, v, ldv, sigmar, workev,
bmat, n, which, nev, TOL, resid, ncv, v, ldv,
iparam, ipntr, workd, workl, lworkl, rwork, info)
if info[1] != 0; throw(ARPACKException(info[1])); end
if info[1] != 0
throw(ARPACKException(info[1]))
end

p = sortperm(dmap(d[1:nev]), rev=true)
return ritzvec ? (d[p], v[1:n, p],iparam[5],iparam[3],iparam[9],resid) : (d[p],iparam[5],iparam[3],iparam[9],resid)
Expand All @@ -145,7 +147,9 @@ function eupd_wrapper(T, n::Integer, sym::Bool, cmplx::Bool, bmat::ByteString,
seupd(ritzvec, howmny, select, d, v, ldv, sigmar,
bmat, n, which, nev, TOL, resid, ncv, v, ldv,
iparam, ipntr, workd, workl, lworkl, info)
if info[1] != 0; throw(ARPACKException(info[1])); end
if info[1] != 0
throw(ARPACKException(info[1]))
end

p = sortperm(dmap(d), rev=true)
return ritzvec ? (d[p], v[1:n, p],iparam[5],iparam[3],iparam[9],resid) : (d,iparam[5],iparam[3],iparam[9],resid)
Expand All @@ -162,7 +166,9 @@ function eupd_wrapper(T, n::Integer, sym::Bool, cmplx::Bool, bmat::ByteString,
neupd(ritzvec, howmny, select, dr, di, v, ldv, sigmar, sigmai,
workev, bmat, n, which, nev, TOL, resid, ncv, v, ldv,
iparam, ipntr, workd, workl, lworkl, info)
if info[1] != 0; throw(ARPACKException(info[1])); end
if info[1] != 0
throw(ARPACKException(info[1]))
end
evec = complex(Array(T, n, nev+1), Array(T, n, nev+1))

j = 1
Expand All @@ -181,7 +187,7 @@ function eupd_wrapper(T, n::Integer, sym::Bool, cmplx::Bool, bmat::ByteString,
evec[:,j] = v[:,j]
j += 1
else
error("ARPACK unexpected behavior")
throw(ARPACKException("unexpected behavior"))
end
end

Expand Down
13 changes: 12 additions & 1 deletion base/linalg/exceptions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,18 @@ type LAPACKException <: Exception
end

type ARPACKException <: Exception
info::BlasInt
info::ByteString
end

function ARPACKException(i::Integer)
if i == -8
return ARPACKException("error return from calculation of a real Schur form.")

This comment has been minimized.

Copy link
@tkelman

tkelman Oct 27, 2015

Contributor

"error return" isn't very clear here

This comment has been minimized.

Copy link
@andreasnoack

andreasnoack Oct 27, 2015

Author Member

I agree, but the error message is copied from the source. I don't know why the error would occur or how to avoid it so it's not clear how to improve the message. I'm open for suggestions.

elseif i == -9
return ARPACKException("error return from calculation of eigenvectors.")
elseif i == -14
return ARPACKException("did not find any eigenvalues to sufficient accuracy. Try with a different starting vector or more Lanczos vectors by increasing the value of ncv.")
end
return ARPACKException("unspecified ARPACK error: $i")
end

type SingularException <: Exception
Expand Down

0 comments on commit fa006bc

Please sign in to comment.