dimforge / dimforge/nalgebra

SVD::solve quietly produces invalid solution for certain matrices

Open
#1,117 10 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
4.8k
Forks
565
PR merge metrics
No merged PRs in 30d

Description

Example ([playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=2014f0f649d78eb052d58e422ecaf93e)):

```rust
let matrix = nalgebra::matrix![
1., 0., 2.;
3., 0., 4.;
5., 0., 6.
];

let svd = matrix.svd(true, true);
let solution = svd.solve(&matrix, 0.0).unwrap();

println!("solution for self: {:.3}", solution);
/*
Output:

solution for self:
┌ ┐
│ 1.000 0.000 -0.000 │
│ 18014398509481988.000 0.000 18014398509481988.000 │
│ 4.000 0.000 5.000 │
└ ┘
*/

println!("apply solution: {:.3}", matrix * solution);
/*
Output:

apply solution:
┌ ┐
│ 9.000 0.000 10.000 │
│ 19.000 0.000 20.000 │
│ 29.000 0.000 30.000 │
└ ┘
*/
```

I'm not deeply familiar with matrix decompositions, so I don't know if this is a fundamental limitation of SVD and whether it's possible to fix it to produce a correct result in this case, but at least I would expect the `.solve()` to return an error in this case instead of quietly returning invalid solution.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.