Skip to content

Commit e8b010a

Browse files
author
Marcus P S
committed
Check sparse matrix is square before computing condition number
Fixed JuliaLang#12731
1 parent 7994909 commit e8b010a

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

base/sparse/linalg.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ end
490490

491491
# cond
492492
function cond(A::SparseMatrixCSC, p::Real=2)
493+
chksquare(A)
493494
if p == 1
494495
normA = norm(A, 1)
495496
normAinv = normestinv(A)

test/sparsedir/sparse.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,6 +1078,7 @@ Ar = sprandn(20,20,.5)
10781078
@test_approx_eq_eps cond(Ac,Inf) cond(full(Ac),Inf) 1e-4
10791079
@test_throws ArgumentError cond(A,2)
10801080
@test_throws ArgumentError cond(A,3)
1081+
@test_throws DimensionMismatch cond(spzeros(3,2))
10811082

10821083
# test sparse matrix normestinv
10831084
Ac = sprandn(20,20,.5) + im* sprandn(20,20,.5)

0 commit comments

Comments
 (0)