1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use crate::error::*;
use crate::layout::*;
use crate::types::*;
use ndarray::*;
pub trait Eig {
type EigVal;
type EigVec;
fn eig(&self) -> Result<(Self::EigVal, Self::EigVec)>;
}
impl<A, S> Eig for ArrayBase<S, Ix2>
where
A: Scalar + Lapack,
S: Data<Elem = A>,
{
type EigVal = Array1<A::Complex>;
type EigVec = Array2<A::Complex>;
fn eig(&self) -> Result<(Self::EigVal, Self::EigVec)> {
let mut a = self.to_owned();
let layout = a.square_layout()?;
let (s, t) = A::eig(true, layout, a.as_allocated_mut()?)?;
let n = layout.len() as usize;
Ok((
ArrayBase::from(s),
Array2::from_shape_vec((n, n).f(), t).unwrap(),
))
}
}
pub trait EigVals {
type EigVal;
fn eigvals(&self) -> Result<Self::EigVal>;
}
impl<A, S> EigVals for ArrayBase<S, Ix2>
where
A: Scalar + Lapack,
S: Data<Elem = A>,
{
type EigVal = Array1<A::Complex>;
fn eigvals(&self) -> Result<Self::EigVal> {
let mut a = self.to_owned();
let (s, _) = A::eig(false, a.square_layout()?, a.as_allocated_mut()?)?;
Ok(ArrayBase::from(s))
}
}