From e51b40d57b0144b9905cd94d725fd39e2b662423 Mon Sep 17 00:00:00 2001 From: Toshiki Teramura Date: Sat, 24 Sep 2022 22:26:34 +0900 Subject: [PATCH] Merge Eig_ trait into Lapack trait --- lax/src/lib.rs | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/lax/src/lib.rs b/lax/src/lib.rs index 397970f7..27994ba3 100644 --- a/lax/src/lib.rs +++ b/lax/src/lib.rs @@ -115,7 +115,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 +130,37 @@ 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 { + 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);