Skip to content

Commit

Permalink
Merge Eig_ trait into Lapack trait
Browse files Browse the repository at this point in the history
  • Loading branch information
termoshtt committed Sep 24, 2022
1 parent e407602 commit 1334d85
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 45 deletions.
38 changes: 0 additions & 38 deletions lax/src/eig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,44 +40,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<Self::Complex>, Vec<Self::Complex>)>;
}

macro_rules! impl_eig {
($s:ty) => {
impl Eig_ for $s {
fn eig(
calc_v: bool,
l: MatrixLayout,
a: &mut [Self],
) -> Result<(Vec<Self::Complex>, Vec<Self::Complex>)> {
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<T: Scalar> {
/// Problem size
Expand Down
34 changes: 27 additions & 7 deletions lax/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand All @@ -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;

Expand All @@ -130,16 +129,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<Self::Complex>, Vec<Self::Complex>)>;
}

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<Self::Complex>, Vec<Self::Complex>)> {
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);

0 comments on commit 1334d85

Please sign in to comment.