-
Notifications
You must be signed in to change notification settings - Fork 387
Closed
Description
I need to check whether a matrix I am working with is singular, so I am placing a call to linalg_matrix_rank. Everything is fine when the matrix is full rank, but tch-rs panics if the matrix is at all singular.
Since the purpose of this function is to report on the rank of the matrix, which is not necessarily full rank, some other behavior is preferred. Most preferably, this function should never panic or error if the matrix is singular, because its purpose is to report on the numeric rank of the matrix.
let rank = my_tensor.reshape(&[1, 1, 1024, 1024]).linalg_matrix_rank(None, false);
println!("my_tensor linalg_matrix_rank: {:?}", &rank);
let rank2 = my_tensor.reshape(&[1, 1, 1024, 1024]).matrix_rank(false);
println!("my_tensor matrix_rank: {:?}", &rank2);
The result of running this looks like:
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Torch("svd_cuda: For batch 0: U(1025,1025) is zero, singular U.\nException raised from batchCheckErrors at /pytorch/aten/src/ATen/native/LinearAlgebraUtils.h:251
Metadata
Metadata
Assignees
Labels
No labels