Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1742,7 +1742,7 @@ function opnormestinv(A::AbstractSparseMatrixCSC{T}, t::Integer = min(2,maximum(
repeated = true
end
end
if !repeated
if !repeated && n > 2
saux2 = S[1:n,j]' * S_old[1:n,1:t]
if _any_abs_eq(saux2,n)
repeated = true
Expand Down
18 changes: 11 additions & 7 deletions test/linalg_solvers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,24 @@ end

@testset "sparse matrix cond" begin
local A = sparse(reshape([1.0], 1, 1))
Ac = sprandn(20, 20,.5) + im*sprandn(20, 20,.5)
Ar = sprandn(20, 20,.5) + eps()*I
@test cond(A, 1) == 1.0
# For a discussion of the tolerance, see #14778
@test 0.99 <= cond(Ar, 1) \ opnorm(Ar, 1) * opnorm(inv(Array(Ar)), 1) < 3
@test 0.99 <= cond(Ac, 1) \ opnorm(Ac, 1) * opnorm(inv(Array(Ac)), 1) < 3
@test 0.99 <= cond(Ar, Inf) \ opnorm(Ar, Inf) * opnorm(inv(Array(Ar)), Inf) < 3
@test 0.99 <= cond(Ac, Inf) \ opnorm(Ac, Inf) * opnorm(inv(Array(Ac)), Inf) < 3
@test_throws ArgumentError cond(A,2)
@test_throws ArgumentError cond(A,3)
Arect = spzeros(10, 6)
@test_throws DimensionMismatch cond(Arect, 1)
@test_throws ArgumentError cond(Arect,2)
@test_throws DimensionMismatch cond(Arect, Inf)
Ac = sprandn(20, 20,.5) + im*sprandn(20, 20,.5)
Ar = sprandn(20, 20,.5) + eps()*I
# For a discussion of the tolerance, see #14778
@test 0.99 <= cond(Ar, 1) \ opnorm(Ar, 1) * opnorm(inv(Array(Ar)), 1) < 3
@test 0.99 <= cond(Ac, 1) \ opnorm(Ac, 1) * opnorm(inv(Array(Ac)), 1) < 3
@test 0.99 <= cond(Ar, Inf) \ opnorm(Ar, Inf) * opnorm(inv(Array(Ar)), Inf) < 3
@test 0.99 <= cond(Ac, Inf) \ opnorm(Ac, Inf) * opnorm(inv(Array(Ac)), Inf) < 3
#issue 680
A22 = sparse(randn(2,2))
@test 0.99 ≤ cond(Array(A22), 1) / cond(A22, 1) < 3
@test 0.99 ≤ cond(Array(A22), Inf) / cond(A22, Inf) < 3
end

@testset "sparse matrix opnormestinv" begin
Expand Down
Loading