Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where number type in stopping criterion was derived from tol instead of real(eltype(H)) #137

Merged
merged 2 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/run.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,19 @@ be scale invariant: the matrix `B = αA` for some constant `α` has the same
eigenvectors with eigenvalue λα, so this scaling with `α` cancels in the
inequality.
"""
struct IsConverged{RV<:RitzValues,T}
ritz::RV
tol::T
H_frob_norm::RefValue{T}
struct IsConverged{Tv,Tr,Tt}
ritz::RitzValues{Tv,Tr}
tol::Tt
H_frob_norm::RefValue{Tr}

IsConverged(ritz::R, tol::T) where {R<:RitzValues,T} =
new{R,T}(ritz, tol, RefValue(zero(T)))
IsConverged(ritz::RitzValues{Tv,Tr}, tol::Tt) where {Tv,Tr,Tt} =
new{Tv,Tr,Tt}(ritz, tol, RefValue(zero(Tr)))
end

function (r::IsConverged{Tv,Tr})(i::Integer) where {Tv,Tr}
@inbounds r.ritz.rs[i] <= max(eps(Tr) * r.H_frob_norm[], r.tol * abs(r.ritz.λs[i]))
end

(r::IsConverged{RV,T})(i::Integer) where {RV,T} = @inbounds return r.ritz.rs[i] <=
max(eps(T) * r.H_frob_norm[], r.tol * abs(r.ritz.λs[i]))

"""
History(mvproducts, nconverged, converged, nev)
Expand Down
12 changes: 12 additions & 0 deletions test/partial_schur.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ using LinearAlgebra
end
end

@testset "Stopping criterion specified in different number type is fine" begin
A = spdiagm(
-1 => fill(-big(1.0), 99),
haampie marked this conversation as resolved.
Show resolved Hide resolved
0 => fill(big(2.0), 100),
1 => fill(big(-1.0), 99),
)
tol = 1e-30 # specified as Float64
schur, history = partialschur(A, tol = tol, maxdim = 30, nev = 2)
@test history.converged
@test norm(A * schur.Q - schur.Q * schur.R) < size(A, 1) * tol
end

@testset "Right number type" begin
A = [rand(Bool) ? 1 : 0 for i = 1:10, j = 1:10]
@inferred partialschur(A, nev = 2, mindim = 3, maxdim = 8)
Expand Down
Loading