dimforge / dimforge/nalgebra

NaN and inf with nalgebra::linalg::SymmetricEigen

Open
#379 2 comments 1 reaction 0 assignees View on GitHub
bug P-medium
Dominant language
Rust
Stars
4.8k
Forks
565
PR merge metrics
No merged PRs in 30d

Description

Hi,

I have a weird behaviour using SymmetricEigen. In my algorithm I want to diagonalize a covariance matrix, but it produces NaN and inf eigenvalues.
What is weird is when I try to reproduce the same behaviour printing my matrix using the same precision for the float values, SymmetricEigen seems to work well and give the right decomposition.

I double-checked my result using numpy and matlab

Here is the piece of code which tries to reproduct the weird behaviour without any success :

```
extern crate nalgebra;
use nalgebra as na;

fn main() {
let m = na::DMatrix::from_row_slice(10,10,
&[ 0.29094839096069335937500000000000, 0.0, 0.00125074386596679687500000000000, 0.0, 0.0, 0.0, 0.0, 0.23951797187328338623046875000000, 0.0, -0.53172069787979125976562500000000,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.00125074386596679687500000000000, 0.0, 0.00000604706247031572274863719940, 0.0, 0.0, 0.0, 0.0, 0.00115719600580632686614990234375, 0.0, -0.00241400394588708877563476562500,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.23951797187328338623046875000000, 0.0, 0.00115719600580632686614990234375, 0.0, 0.0, 0.0, 0.0, 0.22160133719444274902343750000000, 0.0, -0.46227973699569702148437500000000,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
-0.53172069787979125976562500000000, 0.0, -0.00241400394588708877563476562500, 0.0, 0.0, 0.0, 0.0, -0.46227973699569702148437500000000, 0.0, 0.99642109870910644531250000000000]
);
println!("The matrix {}", m);
let eigen_decomposition = na::linalg::SymmetricEigen::new(m);
println!("Eigenvalues : {}", eigen_decomposition.eigenvalues);

}
```

Thanks for your future answers or hints on what happen there.

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.