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

Cannot compute the SVD of an empty matrix. #1353

Open
Lishen1 opened this issue Jan 16, 2024 · 2 comments
Open

Cannot compute the SVD of an empty matrix. #1353

Lishen1 opened this issue Jan 16, 2024 · 2 comments

Comments

@Lishen1
Copy link

Lishen1 commented Jan 16, 2024

let m = DMatrix::<f64>::identity(0, 1); // any zero dimension
let _ = nalgebra::linalg::SVD::try_new_unordered(m, true, true, 0.0, 10); // panic here

probably, from try_ interface expected panic-free behavior independent on input. just return None if input is incorrect.

@Andlon
Copy link
Sponsor Collaborator

Andlon commented Jan 16, 2024

I will chime in here to say that I think the correct behavior here is for the SVD to succeed, not return None. Handling empty/zero-sized matrices is an important corner case that sometimes happens in applications. For example, say that your matrix is an mxn matrix with n observations. In this case it may still make sense for the case of n == 0 observations.

My understanding of try_... in the context of SVD is that it will only fail if the iterative process fails (which technically should not happen but can still happen in practice, in rare instances).

@tpdickso
Copy link
Collaborator

I think that aligns with my intuitions; a matrix with a 0 dimension does have a SVD since you can always express it with valid UΣV* matrices. I think all the function needs to do here is return (identity, original matrix, identity) with at least one of those identity matrices being 0x0 matching the 0-dimension of the input matrix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants