We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
cond
1 parent 9bc292d commit 76176a6Copy full SHA for 76176a6
src/dense.jl
@@ -1779,6 +1779,7 @@ Condition number of the matrix `M`, computed using the operator `p`-norm. Valid
1779
"""
1780
function cond(A::AbstractMatrix, p::Real=2)
1781
if p == 2
1782
+ isempty(A) && return zero(real(eigtype(eltype(A))))
1783
v = svdvals(A)
1784
maxv = maximum(v)
1785
return iszero(maxv) ? oftype(real(maxv), Inf) : maxv / minimum(v)
test/dense.jl
@@ -56,6 +56,19 @@ Random.seed!(1234323)
56
@test cond(Mars, 2) ≈ 6.181867355918493
57
@test cond(Mars, Inf) ≈ 7.1
58
end
59
+ @testset "Empty matrices" begin
60
+ @test cond(zeros(Int, 0, 0), 1) === 0.0
61
+ @test cond(zeros(Int, 0, 0), 2) === 0.0
62
+ @test cond(zeros(Int, 0, 0), Inf) === 0.0
63
+ @test cond(zeros(0, 0), 1) === 0.0
64
+ @test cond(zeros(0, 0), 2) === 0.0
65
+ @test cond(zeros(0, 0), Inf) === 0.0
66
+ @test cond(zeros(ComplexF64, 0, 0), 1) === 0.0
67
+ @test cond(zeros(ComplexF64, 0, 0), 2) === 0.0
68
+ @test cond(zeros(ComplexF64, 0, 0), Inf) === 0.0
69
+ @test cond(zeros(10, 0)) === 0.0
70
+ @test cond(zeros(0, 10)) === 0.0
71
+ end
72
73
74
areal = randn(n,n)/2
0 commit comments