diff --git a/nalgebra-lapack/Cargo.toml b/nalgebra-lapack/Cargo.toml index 91517a8d..3f165f76 100644 --- a/nalgebra-lapack/Cargo.toml +++ b/nalgebra-lapack/Cargo.toml @@ -22,7 +22,7 @@ proptest-support = [ "nalgebra/proptest-support" ] arbitrary = [ "nalgebra/arbitrary" ] # For BLAS/LAPACK -default = ["netlib"] +default = ["openblas"] openblas = ["lapack-src/openblas"] netlib = ["lapack-src/netlib"] accelerate = ["lapack-src/accelerate"] @@ -36,6 +36,7 @@ simba = "0.7" serde = { version = "1.0", features = [ "derive" ], optional = true } lapack = { version = "0.19", default-features = false } lapack-src = { version = "0.8", default-features = false } +openblas-src = {version = "*", features = ["static"]} # clippy = "*" [dev-dependencies] @@ -44,3 +45,4 @@ proptest = { version = "1", default-features = false, features = ["std"] } quickcheck = "1" approx = "0.5" rand = "0.8" + diff --git a/nalgebra-lapack/examples/complex_eigen.rs b/nalgebra-lapack/examples/complex_eigen.rs new file mode 100644 index 00000000..8a359d69 --- /dev/null +++ b/nalgebra-lapack/examples/complex_eigen.rs @@ -0,0 +1,24 @@ +extern crate nalgebra as na; +extern crate nalgebra_lapack; +#[macro_use] +extern crate approx; // for assert_relative_eq + +use na::Matrix3; +use nalgebra_lapack::Eigen; +use num_complex::Complex; + + +fn main() { + let m = Matrix3::::new(4.0/5.0, -3.0/5.0, 0.0, 3.0/5.0, 4.0/5.0, 0.0, 1.0, 2.0, 2.0); + let eigen = Eigen::new(m,true,true).expect("Eigen Creation Failed!"); + let (some_eigenvalues, some_left_vec, some_right_vec) = eigen.get_complex_elements(); + let eigenvalues = some_eigenvalues.expect("Eigenvalues Failed"); + let left_eigenvectors = some_left_vec.expect("Left Eigenvectors Failed"); + let eigenvectors = some_right_vec.expect("Right Eigenvectors Failed"); + + assert_relative_eq!(eigenvalues[0].re, Complex::::new(4.0/5.0,3.0/5.0).re); + assert_relative_eq!(eigenvalues[0].im, Complex::::new(4.0/5.0,3.0/5.0).im); + assert_relative_eq!(eigenvalues[1].re, Complex::::new(4.0/5.0,-3.0/5.0).re); + assert_relative_eq!(eigenvalues[1].im, Complex::::new(4.0/5.0,-3.0/5.0).im); + +} \ No newline at end of file diff --git a/nalgebra-lapack/src/eigen.rs b/nalgebra-lapack/src/eigen.rs index 3a848d0a..d98c500d 100644 --- a/nalgebra-lapack/src/eigen.rs +++ b/nalgebra-lapack/src/eigen.rs @@ -171,7 +171,8 @@ where /// Returns a tuple of vectors. The elements of the tuple are the complex eigenvalues, complex left eigenvectors and complex right eigenvectors respectively. /// The elements appear as conjugate pairs within each vector, with the positive of the pair always being first. pub fn get_complex_elements(&self) -> (Option>>, Option, D>>>, Option, D>>>) where DefaultAllocator: Allocator, D> { - match !self.eigenvalues_are_real() { + + match self.eigenvalues_are_real() { true => (None, None, None), false => { let (number_of_elements, _) = self.eigenvalues_re.shape_generic(); diff --git a/nalgebra-lapack/tests/linalg/complex_eigen.rs b/nalgebra-lapack/tests/linalg/complex_eigen.rs new file mode 100644 index 00000000..10869470 --- /dev/null +++ b/nalgebra-lapack/tests/linalg/complex_eigen.rs @@ -0,0 +1,19 @@ +use std::cmp; + +use na::{Matrix3}; +use nalgebra_lapack::Eigen; + +use crate::proptest::*; +use proptest::{prop_assert, proptest}; + +proptest! { + //#[test] + // fn complex_eigen() { + // let n = cmp::max(1, cmp::min(n, 10)); + // let m = DMatrix::::new_random(n, n); + // let eig = SymmetricEigen::new(m.clone()); + // let recomp = eig.recompose(); + // prop_assert!(relative_eq!(m.lower_triangle(), recomp.lower_triangle(), epsilon = 1.0e-5)) + // } + +} diff --git a/nalgebra-lapack/tests/linalg/mod.rs b/nalgebra-lapack/tests/linalg/mod.rs index 251bbe7b..8fc8deeb 100644 --- a/nalgebra-lapack/tests/linalg/mod.rs +++ b/nalgebra-lapack/tests/linalg/mod.rs @@ -7,3 +7,4 @@ mod real_eigensystem; mod schur; mod svd; mod symmetric_eigen; +mod complex_eigen;