-
Notifications
You must be signed in to change notification settings - Fork 65
/
flags.rs
145 lines (127 loc) · 3.04 KB
/
flags.rs
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/// Upper/Lower specification for seveal usages
#[derive(Debug, Clone, Copy)]
#[repr(u8)]
pub enum UPLO {
Upper = b'U',
Lower = b'L',
}
impl UPLO {
pub fn t(self) -> Self {
match self {
UPLO::Upper => UPLO::Lower,
UPLO::Lower => UPLO::Upper,
}
}
/// To use Fortran LAPACK API in lapack-sys crate
pub fn as_ptr(&self) -> *const i8 {
self as *const UPLO as *const i8
}
}
#[derive(Debug, Clone, Copy)]
#[repr(u8)]
pub enum Transpose {
No = b'N',
Transpose = b'T',
Hermite = b'C',
}
impl Transpose {
/// To use Fortran LAPACK API in lapack-sys crate
pub fn as_ptr(&self) -> *const i8 {
self as *const Transpose as *const i8
}
}
#[derive(Debug, Clone, Copy)]
#[repr(u8)]
pub enum NormType {
One = b'O',
Infinity = b'I',
Frobenius = b'F',
}
impl NormType {
pub fn transpose(self) -> Self {
match self {
NormType::One => NormType::Infinity,
NormType::Infinity => NormType::One,
NormType::Frobenius => NormType::Frobenius,
}
}
/// To use Fortran LAPACK API in lapack-sys crate
pub fn as_ptr(&self) -> *const i8 {
self as *const NormType as *const i8
}
}
/// Flag for calculating eigenvectors or not
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum EigenVectorFlag {
Calc = b'V',
Not = b'N',
}
impl EigenVectorFlag {
pub fn is_calc(&self) -> bool {
match self {
EigenVectorFlag::Calc => true,
EigenVectorFlag::Not => false,
}
}
pub fn then<T, F: FnOnce() -> T>(&self, f: F) -> Option<T> {
if self.is_calc() {
Some(f())
} else {
None
}
}
/// To use Fortran LAPACK API in lapack-sys crate
pub fn as_ptr(&self) -> *const i8 {
self as *const EigenVectorFlag as *const i8
}
}
#[repr(u8)]
#[derive(Debug, Copy, Clone)]
pub enum FlagSVD {
All = b'A',
// OverWrite = b'O',
// Separately = b'S',
No = b'N',
}
impl FlagSVD {
pub fn from_bool(calc_uv: bool) -> Self {
if calc_uv {
FlagSVD::All
} else {
FlagSVD::No
}
}
pub fn as_ptr(&self) -> *const i8 {
self as *const FlagSVD as *const i8
}
}
/// Specifies how many of the columns of *U* and rows of *V*ᵀ are computed and returned.
///
/// For an input array of shape *m*×*n*, the following are computed:
#[derive(Clone, Copy, Eq, PartialEq)]
#[repr(u8)]
pub enum UVTFlag {
/// All *m* columns of *U* and all *n* rows of *V*ᵀ.
Full = b'A',
/// The first min(*m*,*n*) columns of *U* and the first min(*m*,*n*) rows of *V*ᵀ.
Some = b'S',
/// No columns of *U* or rows of *V*ᵀ.
None = b'N',
}
impl UVTFlag {
pub fn as_ptr(&self) -> *const i8 {
self as *const UVTFlag as *const i8
}
}
#[derive(Debug, Clone, Copy)]
#[repr(u8)]
pub enum Diag {
Unit = b'U',
NonUnit = b'N',
}
impl Diag {
pub fn as_ptr(&self) -> *const i8 {
self as *const Diag as *const i8
}
}