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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
use svd::types::SVDError;
use eigenvalues::types::EigenError;
use solve_linear::types::SolveError;
use least_squares::LeastSquaresError;
use factorization::qr::QRError;
use factorization::lu::LUError;
use std::ops::Sub;
use std::fmt::Debug;
use num_traits::{Float, Zero, One};
pub use lapack::{c32, c64};
#[repr(u8)]
pub enum Symmetric {
Upper = b'U',
Lower = b'L',
}
pub enum Error {
SVD(SVDError),
Eigen(EigenError),
LeastSquares(LeastSquaresError),
SolveLinear(SolveError),
QR(QRError),
LU(LUError),
}
impl From<SVDError> for Error {
fn from(e: SVDError) -> Error {
Error::SVD(e)
}
}
impl From<EigenError> for Error {
fn from(e: EigenError) -> Error {
Error::Eigen(e)
}
}
impl From<LeastSquaresError> for Error {
fn from(e: LeastSquaresError) -> Error {
Error::LeastSquares(e)
}
}
impl From<SolveError> for Error {
fn from(e: SolveError) -> Error {
Error::SolveLinear(e)
}
}
impl From<QRError> for Error {
fn from(e: QRError) -> Error {
Error::QR(e)
}
}
impl From<LUError> for Error {
fn from(e: LUError) -> Error {
Error::LU(e)
}
}
pub trait Magnitude: Copy {
fn mag(self) -> f64;
}
impl Magnitude for f32 {
fn mag(self) -> f64 {
self.abs() as f64
}
}
impl Magnitude for f64 {
fn mag(self) -> f64 {
self.abs()
}
}
impl Magnitude for c32 {
fn mag(self) -> f64 {
self.norm() as f64
}
}
impl Magnitude for c64 {
fn mag(self) -> f64 {
self.norm()
}
}
pub trait LinxalScalar: Sized + Clone + Magnitude + Debug + Zero + One + Sub<Output=Self> {}
impl<T: Sized + Clone + Magnitude + Debug + Zero + One + Sub<Output=T>> LinxalScalar for T {}
pub trait LinxalFloat: LinxalScalar + Float {}
impl<T: LinxalScalar + Float> LinxalFloat for T {}