Skip to content

Commit

Permalink
Close #1862
Browse files Browse the repository at this point in the history
  • Loading branch information
ViralBShah committed Jan 1, 2013
1 parent 0a7d5fd commit ffcb07f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion base/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,13 @@ trace(A::AbstractMatrix) = sum(diag(A))

#det(a::AbstractMatrix)
inv(a::AbstractMatrix) = a \ one(a)
cond(a::AbstractMatrix) = (s = svdvals(a); max(s) / min(s))

function cond(a::AbstractMatrix)
s = svdvals(a)
condno = max(s) / min(s)
# Return Inf if condno is NaN (input is all zeros)
isnan(condno) ? Inf : condno
end

function cond(a::AbstractMatrix, p)
if p == 2
Expand Down

2 comments on commit ffcb07f

@stevengj
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ViralBShah, it's at all clear to me that it should Inf for all-zero inputs. See my comments in #1862: inspection of the definition of cond(A) suggests that NaN may be correct here. Matlab gives inf, but that seems wrong to me.

Another way of putting it: suppose we take the limit as the matrix A goes to zero. Depending on how one takes the limit, one can get cond(A) approaching infinity, or 1, or anything in between. This is the classic case in which a NaN is called for.

@ViralBShah
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I saw your comment. I just reopened the issue.

Please sign in to comment.