Skip to content

Commit 33e2dc3

Browse files
authored
Merge pull request #340 from rust-ndarray/merge-eig-trait-to-lapack
Merge `Eig_` trait into `Lapack` trait
2 parents e407602 + 3535eee commit 33e2dc3

File tree

2 files changed

+37
-46
lines changed

2 files changed

+37
-46
lines changed

lax/src/eig.rs

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
//! Eigenvalue problem for general matricies
2+
//!
3+
//! LAPACK correspondance
4+
//! ----------------------
5+
//!
6+
//! | f32 | f64 | c32 | c64 |
7+
//! |:------|:------|:------|:------|
8+
//! | sgeev | dgeev | cgeev | zgeev |
9+
//!
210
311
use crate::{error::*, layout::MatrixLayout, *};
412
use cauchy::*;
@@ -40,44 +48,6 @@ use num_traits::{ToPrimitive, Zero};
4048
/// A^\dagger V = V Λ ⟺ V^\dagger A = Λ V^\dagger
4149
/// $$
4250
///
43-
pub trait Eig_: Scalar {
44-
/// Compute right eigenvalue and eigenvectors $Ax = \lambda x$
45-
///
46-
/// LAPACK correspondance
47-
/// ----------------------
48-
///
49-
/// | f32 | f64 | c32 | c64 |
50-
/// |:------|:------|:------|:------|
51-
/// | sgeev | dgeev | cgeev | zgeev |
52-
///
53-
fn eig(
54-
calc_v: bool,
55-
l: MatrixLayout,
56-
a: &mut [Self],
57-
) -> Result<(Vec<Self::Complex>, Vec<Self::Complex>)>;
58-
}
59-
60-
macro_rules! impl_eig {
61-
($s:ty) => {
62-
impl Eig_ for $s {
63-
fn eig(
64-
calc_v: bool,
65-
l: MatrixLayout,
66-
a: &mut [Self],
67-
) -> Result<(Vec<Self::Complex>, Vec<Self::Complex>)> {
68-
let work = EigWork::<$s>::new(calc_v, l)?;
69-
let EigOwned { eigs, vr, vl } = work.eval(a)?;
70-
Ok((eigs, vr.or(vl).unwrap_or_default()))
71-
}
72-
}
73-
};
74-
}
75-
impl_eig!(c64);
76-
impl_eig!(c32);
77-
impl_eig!(f64);
78-
impl_eig!(f32);
79-
80-
/// Working memory for [Eig_]
8151
#[non_exhaustive]
8252
pub struct EigWork<T: Scalar> {
8353
/// Problem size

lax/src/lib.rs

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
//! According to the property input metrix,
5959
//! there are several types of eigenvalue problem API
6060
//!
61-
//! - [Eig_] trait provides methods for eigenvalue problem for general matrix.
61+
//! - [eig] module for eigenvalue problem for general matrix.
6262
//! - [Eigh_] trait provides methods for eigenvalue problem for symmetric/hermite matrix.
6363
//!
6464
//! Singular Value Decomposition
@@ -101,7 +101,6 @@ mod triangular;
101101
mod tridiagonal;
102102

103103
pub use self::cholesky::*;
104-
pub use self::eig::Eig_;
105104
pub use self::eigh::*;
106105
pub use self::flags::*;
107106
pub use self::least_squares::*;
@@ -115,7 +114,7 @@ pub use self::svddc::*;
115114
pub use self::triangular::*;
116115
pub use self::tridiagonal::*;
117116

118-
use self::alloc::*;
117+
use self::{alloc::*, error::*, layout::*};
119118
use cauchy::*;
120119
use std::mem::MaybeUninit;
121120

@@ -130,16 +129,38 @@ pub trait Lapack:
130129
+ Solve_
131130
+ Solveh_
132131
+ Cholesky_
133-
+ Eig_
134132
+ Eigh_
135133
+ Triangular_
136134
+ Tridiagonal_
137135
+ Rcond_
138136
+ LeastSquaresSvdDivideConquer_
139137
{
138+
/// Compute right eigenvalue and eigenvectors
139+
fn eig(
140+
calc_v: bool,
141+
l: MatrixLayout,
142+
a: &mut [Self],
143+
) -> Result<(Vec<Self::Complex>, Vec<Self::Complex>)>;
140144
}
141145

142-
impl Lapack for f32 {}
143-
impl Lapack for f64 {}
144-
impl Lapack for c32 {}
145-
impl Lapack for c64 {}
146+
macro_rules! impl_lapack {
147+
($s:ty) => {
148+
impl Lapack for $s {
149+
/// Compute right eigenvalue and eigenvectors
150+
fn eig(
151+
calc_v: bool,
152+
l: MatrixLayout,
153+
a: &mut [Self],
154+
) -> Result<(Vec<Self::Complex>, Vec<Self::Complex>)> {
155+
use eig::*;
156+
let work = EigWork::<$s>::new(calc_v, l)?;
157+
let EigOwned { eigs, vr, vl } = work.eval(a)?;
158+
Ok((eigs, vr.or(vl).unwrap_or_default()))
159+
}
160+
}
161+
};
162+
}
163+
impl_lapack!(c64);
164+
impl_lapack!(c32);
165+
impl_lapack!(f64);
166+
impl_lapack!(f32);

0 commit comments

Comments
 (0)