diff --git a/lax/src/eig.rs b/lax/src/eig.rs index 2c24a842..710beb9c 100644 --- a/lax/src/eig.rs +++ b/lax/src/eig.rs @@ -1,4 +1,12 @@ //! Eigenvalue problem for general matricies +//! +//! LAPACK correspondance +//! ---------------------- +//! +//! | f32 | f64 | c32 | c64 | +//! |:------|:------|:------|:------| +//! | sgeev | dgeev | cgeev | zgeev | +//! use crate::{error::*, layout::MatrixLayout, *}; use cauchy::*; @@ -40,44 +48,6 @@ use num_traits::{ToPrimitive, Zero}; /// A^\dagger V = V Λ ⟺ V^\dagger A = Λ V^\dagger /// $$ /// -pub trait Eig_: Scalar { - /// Compute right eigenvalue and eigenvectors $Ax = \lambda x$ - /// - /// LAPACK correspondance - /// ---------------------- - /// - /// | f32 | f64 | c32 | c64 | - /// |:------|:------|:------|:------| - /// | sgeev | dgeev | cgeev | zgeev | - /// - fn eig( - calc_v: bool, - l: MatrixLayout, - a: &mut [Self], - ) -> Result<(Vec, Vec)>; -} - -macro_rules! impl_eig { - ($s:ty) => { - impl Eig_ for $s { - fn eig( - calc_v: bool, - l: MatrixLayout, - a: &mut [Self], - ) -> Result<(Vec, Vec)> { - let work = EigWork::<$s>::new(calc_v, l)?; - let EigOwned { eigs, vr, vl } = work.eval(a)?; - Ok((eigs, vr.or(vl).unwrap_or_default())) - } - } - }; -} -impl_eig!(c64); -impl_eig!(c32); -impl_eig!(f64); -impl_eig!(f32); - -/// Working memory for [Eig_] #[non_exhaustive] pub struct EigWork { /// Problem size diff --git a/lax/src/lib.rs b/lax/src/lib.rs index 397970f7..00393916 100644 --- a/lax/src/lib.rs +++ b/lax/src/lib.rs @@ -58,7 +58,7 @@ //! According to the property input metrix, //! there are several types of eigenvalue problem API //! -//! - [Eig_] trait provides methods for eigenvalue problem for general matrix. +//! - [eig] module for eigenvalue problem for general matrix. //! - [Eigh_] trait provides methods for eigenvalue problem for symmetric/hermite matrix. //! //! Singular Value Decomposition @@ -101,7 +101,6 @@ mod triangular; mod tridiagonal; pub use self::cholesky::*; -pub use self::eig::Eig_; pub use self::eigh::*; pub use self::flags::*; pub use self::least_squares::*; @@ -115,7 +114,7 @@ pub use self::svddc::*; pub use self::triangular::*; pub use self::tridiagonal::*; -use self::alloc::*; +use self::{alloc::*, error::*, layout::*}; use cauchy::*; use std::mem::MaybeUninit; @@ -130,16 +129,38 @@ pub trait Lapack: + Solve_ + Solveh_ + Cholesky_ - + Eig_ + Eigh_ + Triangular_ + Tridiagonal_ + Rcond_ + LeastSquaresSvdDivideConquer_ { + /// Compute right eigenvalue and eigenvectors + fn eig( + calc_v: bool, + l: MatrixLayout, + a: &mut [Self], + ) -> Result<(Vec, Vec)>; } -impl Lapack for f32 {} -impl Lapack for f64 {} -impl Lapack for c32 {} -impl Lapack for c64 {} +macro_rules! impl_lapack { + ($s:ty) => { + impl Lapack for $s { + /// Compute right eigenvalue and eigenvectors + fn eig( + calc_v: bool, + l: MatrixLayout, + a: &mut [Self], + ) -> Result<(Vec, Vec)> { + use eig::*; + let work = EigWork::<$s>::new(calc_v, l)?; + let EigOwned { eigs, vr, vl } = work.eval(a)?; + Ok((eigs, vr.or(vl).unwrap_or_default())) + } + } + }; +} +impl_lapack!(c64); +impl_lapack!(c32); +impl_lapack!(f64); +impl_lapack!(f32);