Skip to content

Commit 3efbf7e

Browse files
committed
Add Eigh
1 parent 34f14ca commit 3efbf7e

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/eigh.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
use ndarray::*;
3+
4+
use super::error::*;
5+
use super::layout::*;
6+
7+
use impl2::{LapackScalar, UPLO};
8+
9+
pub trait Eigh<EigVal, EigVec> {
10+
fn eigh(self, UPLO) -> Result<(EigVal, EigVec)>;
11+
}
12+
13+
impl<A, S, Se> Eigh<ArrayBase<Se, Ix1>, ArrayBase<S, Ix2>> for ArrayBase<S, Ix2>
14+
where A: LapackScalar,
15+
S: DataMut<Elem = A>,
16+
Se: DataOwned<Elem = A::Real>
17+
{
18+
fn eigh(mut self, uplo: UPLO) -> Result<(ArrayBase<Se, Ix1>, ArrayBase<S, Ix2>)> {
19+
let s = A::eigh(true, self.square_layout()?, uplo, self.as_allocated_mut()?)?;
20+
Ok((ArrayBase::from_vec(s), self))
21+
}
22+
}
23+
24+
impl<'a, A, S, Se> Eigh<ArrayBase<Se, Ix1>, &'a mut ArrayBase<S, Ix2>> for &'a mut ArrayBase<S, Ix2>
25+
where A: LapackScalar,
26+
S: DataMut<Elem = A>,
27+
Se: DataOwned<Elem = A::Real>
28+
{
29+
fn eigh(mut self, uplo: UPLO) -> Result<(ArrayBase<Se, Ix1>, &'a mut ArrayBase<S, Ix2>)> {
30+
let s = A::eigh(true, self.square_layout()?, uplo, self.as_allocated_mut()?)?;
31+
Ok((ArrayBase::from_vec(s), self))
32+
}
33+
}
34+
35+
pub trait EigValsh<EigVal> {
36+
fn eigvalsh(self, UPLO) -> Result<EigVal>;
37+
}

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ pub mod qr;
5252
pub mod svd;
5353
pub mod opnorm;
5454
pub mod solve;
55+
pub mod eigh;
5556

5657
pub mod vector;
5758
pub mod matrix;

0 commit comments

Comments
 (0)