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

Base.cond and Base.SparseMatrix.cond don't not always check if input matrix is square #12731

Closed
marcusps opened this issue Aug 21, 2015 · 2 comments
Labels
sparse Sparse arrays

Comments

@marcusps
Copy link
Contributor

When attempting to compute the condition number of a rectangular matrix, Base.cond does not always fail, but when it fails it does not always fail for the right reasons:

julia> cond(randn(3,2))
1.6361841239391517

julia> cond(randn(3,2),1)
ERROR: DimensionMismatch("matrix is not square")
 in chksquare at ./linalg.jl:179
 in cond at linalg/dense.jl:511

julia> cond(randn(3,2),Inf)
ERROR: DimensionMismatch("matrix is not square")
 in chksquare at ./linalg.jl:179
 in cond at linalg/dense.jl:511

julia> cond(sprandn(3,2,.2))
ERROR: ArgumentError: 2-norm condition number is not implemented for sparse matrices, try cond(full(A), 2) instead
 in cond at sparse/linalg.jl:515
 in cond at sparse/linalg.jl:506

julia> cond(sprandn(3,2,.2),1)
ERROR: BoundsError: attempt to access 2x2 Array{Float64,2}:
 0.0        0.0     
 0.739339  -0.739339
  at index [1:3,1]
 in throw_boundserror at abstractarray.jl:153
 in normestinv at sparse/linalg.jl:570
 in cond at sparse/linalg.jl:508

julia> cond(sprandn(3,2,.2),Inf)
ERROR: DimensionMismatch("Q matrix size 2 and dense matrix has 3 rows")
 in qmult at sparse/spqr.jl:130
 in \ at sparse/spqr.jl:144
 in normestinv at sparse/linalg.jl:566
 in cond at sparse/linalg.jl:512

For rectangular matrices cond simply return Inf or raise an error (although I think ArgumentError would be more appropriate).

@andreasnoack
Copy link
Member

It is pretty standard to allow the 2 condition number of rectangular matrices so I think the main thing we'll have to change is to add a chksquare in the sparse condition number function. Feel free to open a pr.

@kshyatt kshyatt added the sparse Sparse arrays label Aug 21, 2015
@marcusps
Copy link
Contributor Author

Ah, just learned something about condition numbers after reading #1862.

I'll patch the sparse matrix implementation.

On Fri, Aug 21, 2015, 2:23 PM Andreas Noack [email protected]
wrote:

It is pretty standard to allow the 2 condition number of rectangular
matrices so I think the main thing we'll have to change is to add a
chksquare in the sparse condition number function. Feel free to open a pr.


Reply to this email directly or view it on GitHub
#12731 (comment).

@marcusps marcusps changed the title Base.cond and Base.SparseMatrix.cond don't not always check is input matrix is square Base.cond and Base.SparseMatrix.cond don't not always check if input matrix is square Aug 22, 2015
marcusps pushed a commit to marcusps/julia that referenced this issue Aug 22, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sparse Sparse arrays
Projects
None yet
Development

No branches or pull requests

3 participants