Skip to content

Commit 34f14ca

Browse files
committed
Add Eigh_
1 parent 8a0d429 commit 34f14ca

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

src/impl2/eigh.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
use lapack::c;
3+
use num_traits::Zero;
4+
5+
use types::*;
6+
use error::*;
7+
use layout::Layout;
8+
9+
use super::{into_result, UPLO};
10+
11+
pub trait Eigh_: AssociatedReal {
12+
fn eigh(calc_eigenvec: bool, Layout, UPLO, a: &mut [Self]) -> Result<Vec<Self::Real>>;
13+
}
14+
15+
macro_rules! impl_eigh {
16+
($scalar:ty, $ev:path) => {
17+
impl Eigh_ for $scalar {
18+
fn eigh(calc_v: bool, l: Layout, uplo: UPLO, mut a: &mut [Self]) -> Result<Vec<Self::Real>> {
19+
let (n, _) = l.size();
20+
let jobz = if calc_v { b'V' } else { b'N' };
21+
let mut w = vec![Self::Real::zero(); n as usize];
22+
let info = $ev(l.lapacke_layout(), jobz, uplo as u8, n, &mut a, n, &mut w);
23+
into_result(info, w)
24+
}
25+
}
26+
}} // impl_eigh!
27+
28+
impl_eigh!(f64, c::dsyev);
29+
impl_eigh!(f32, c::ssyev);
30+
impl_eigh!(c64, c::zheev);
31+
impl_eigh!(c32, c::cheev);

src/impl2/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@ pub mod qr;
44
pub mod svd;
55
pub mod solve;
66
pub mod cholesky;
7+
pub mod eigh;
78

89
pub use self::opnorm::*;
910
pub use self::qr::*;
1011
pub use self::svd::*;
1112
pub use self::solve::*;
1213
pub use self::cholesky::*;
14+
pub use self::eigh::*;
1315

1416
use super::error::*;
1517

16-
pub trait LapackScalar: OperatorNorm_ + QR_ + SVD_ + Solve_ + Cholesky_ {}
17-
impl<A> LapackScalar for A where A: OperatorNorm_ + QR_ + SVD_ + Solve_ + Cholesky_ {}
18+
pub trait LapackScalar: OperatorNorm_ + QR_ + SVD_ + Solve_ + Cholesky_ + Eigh_ {}
19+
impl<A> LapackScalar for A where A: OperatorNorm_ + QR_ + SVD_ + Solve_ + Cholesky_ + Eigh_ {}
1820

1921
pub fn into_result<T>(info: i32, val: T) -> Result<T> {
2022
if info == 0 {

0 commit comments

Comments
 (0)