When trying to perform eigen decomposition on some matrices I run into an error. Here is a minimal example:
Cargo.toml:
[package]
name = "untitled"
version = "0.1.0"
edition = "2021"
[dependencies]
smartcore = "0.2.1"
main.rs:
fn main() {
use smartcore::linalg::naive::dense_matrix::*;
use smartcore::linalg::evd::*;
let A = DenseMatrix::from_2d_array(&[
&[-5.0, 2.0],
&[-7.0, 4.0],
]);
let evd = A.evd(false).unwrap();
let eigenvectors: DenseMatrix<f64> = evd.V;
let eigenvalues: Vec<f64> = evd.d;
println!("{:#?}", eigenvectors);
println!("{:#?}", eigenvalues);
}
This results in an error of: thread 'main' panicked at 'attempt to add with overflow', /Users/personal/.cargo/registry/src/github.laiyagushi.com-1ecc6299db9ec823/smartcore-0.2.1/src/linalg/evd.rs:805:22
My hunch is that changing some of the indices in evd.rs to (i + 1) as usize instead of i as usize + 1 will solve the issue.
When trying to perform eigen decomposition on some matrices I run into an error. Here is a minimal example:
Cargo.toml:main.rs:This results in an error of:
thread 'main' panicked at 'attempt to add with overflow', /Users/personal/.cargo/registry/src/github.laiyagushi.com-1ecc6299db9ec823/smartcore-0.2.1/src/linalg/evd.rs:805:22My hunch is that changing some of the indices in
evd.rsto(i + 1) as usizeinstead ofi as usize + 1will solve the issue.