Skip to content

Commit 9109a2f

Browse files
committed
Gather enum definitions
1 parent 08aae3b commit 9109a2f

File tree

5 files changed

+148
-147
lines changed

5 files changed

+148
-147
lines changed

lax/src/flags.rs

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
/// Upper/Lower specification for seveal usages
2+
#[derive(Debug, Clone, Copy)]
3+
#[repr(u8)]
4+
pub enum UPLO {
5+
Upper = b'U',
6+
Lower = b'L',
7+
}
8+
9+
impl UPLO {
10+
pub fn t(self) -> Self {
11+
match self {
12+
UPLO::Upper => UPLO::Lower,
13+
UPLO::Lower => UPLO::Upper,
14+
}
15+
}
16+
17+
/// To use Fortran LAPACK API in lapack-sys crate
18+
pub fn as_ptr(&self) -> *const i8 {
19+
self as *const UPLO as *const i8
20+
}
21+
}
22+
23+
#[derive(Debug, Clone, Copy)]
24+
#[repr(u8)]
25+
pub enum Transpose {
26+
No = b'N',
27+
Transpose = b'T',
28+
Hermite = b'C',
29+
}
30+
31+
impl Transpose {
32+
/// To use Fortran LAPACK API in lapack-sys crate
33+
pub fn as_ptr(&self) -> *const i8 {
34+
self as *const Transpose as *const i8
35+
}
36+
}
37+
38+
#[derive(Debug, Clone, Copy)]
39+
#[repr(u8)]
40+
pub enum NormType {
41+
One = b'O',
42+
Infinity = b'I',
43+
Frobenius = b'F',
44+
}
45+
46+
impl NormType {
47+
pub fn transpose(self) -> Self {
48+
match self {
49+
NormType::One => NormType::Infinity,
50+
NormType::Infinity => NormType::One,
51+
NormType::Frobenius => NormType::Frobenius,
52+
}
53+
}
54+
55+
/// To use Fortran LAPACK API in lapack-sys crate
56+
pub fn as_ptr(&self) -> *const i8 {
57+
self as *const NormType as *const i8
58+
}
59+
}
60+
61+
/// Flag for calculating eigenvectors or not
62+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
63+
#[repr(u8)]
64+
pub enum EigenVectorFlag {
65+
Calc = b'V',
66+
Not = b'N',
67+
}
68+
69+
impl EigenVectorFlag {
70+
pub fn is_calc(&self) -> bool {
71+
match self {
72+
EigenVectorFlag::Calc => true,
73+
EigenVectorFlag::Not => false,
74+
}
75+
}
76+
77+
pub fn then<T, F: FnOnce() -> T>(&self, f: F) -> Option<T> {
78+
if self.is_calc() {
79+
Some(f())
80+
} else {
81+
None
82+
}
83+
}
84+
85+
/// To use Fortran LAPACK API in lapack-sys crate
86+
pub fn as_ptr(&self) -> *const i8 {
87+
self as *const EigenVectorFlag as *const i8
88+
}
89+
}
90+
91+
#[repr(u8)]
92+
#[derive(Debug, Copy, Clone)]
93+
pub enum FlagSVD {
94+
All = b'A',
95+
// OverWrite = b'O',
96+
// Separately = b'S',
97+
No = b'N',
98+
}
99+
100+
impl FlagSVD {
101+
pub fn from_bool(calc_uv: bool) -> Self {
102+
if calc_uv {
103+
FlagSVD::All
104+
} else {
105+
FlagSVD::No
106+
}
107+
}
108+
109+
pub fn as_ptr(&self) -> *const i8 {
110+
self as *const FlagSVD as *const i8
111+
}
112+
}
113+
114+
/// Specifies how many of the columns of *U* and rows of *V*ᵀ are computed and returned.
115+
///
116+
/// For an input array of shape *m*×*n*, the following are computed:
117+
#[derive(Clone, Copy, Eq, PartialEq)]
118+
#[repr(u8)]
119+
pub enum UVTFlag {
120+
/// All *m* columns of *U* and all *n* rows of *V*ᵀ.
121+
Full = b'A',
122+
/// The first min(*m*,*n*) columns of *U* and the first min(*m*,*n*) rows of *V*ᵀ.
123+
Some = b'S',
124+
/// No columns of *U* or rows of *V*ᵀ.
125+
None = b'N',
126+
}
127+
128+
impl UVTFlag {
129+
pub fn as_ptr(&self) -> *const i8 {
130+
self as *const UVTFlag as *const i8
131+
}
132+
}
133+
134+
#[derive(Debug, Clone, Copy)]
135+
#[repr(u8)]
136+
pub enum Diag {
137+
Unit = b'U',
138+
NonUnit = b'N',
139+
}
140+
141+
impl Diag {
142+
pub fn as_ptr(&self) -> *const i8 {
143+
self as *const Diag as *const i8
144+
}
145+
}

lax/src/lib.rs

Lines changed: 2 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ pub mod layout;
7474
mod cholesky;
7575
mod eig;
7676
mod eigh;
77+
mod flags;
7778
mod least_squares;
7879
mod opnorm;
7980
mod qr;
@@ -88,6 +89,7 @@ mod tridiagonal;
8889
pub use self::cholesky::*;
8990
pub use self::eig::*;
9091
pub use self::eigh::*;
92+
pub use self::flags::*;
9193
pub use self::least_squares::*;
9294
pub use self::opnorm::*;
9395
pub use self::qr::*;
@@ -173,96 +175,6 @@ impl<T> VecAssumeInit for Vec<MaybeUninit<T>> {
173175
}
174176
}
175177

176-
/// Upper/Lower specification for seveal usages
177-
#[derive(Debug, Clone, Copy)]
178-
#[repr(u8)]
179-
pub enum UPLO {
180-
Upper = b'U',
181-
Lower = b'L',
182-
}
183-
184-
impl UPLO {
185-
pub fn t(self) -> Self {
186-
match self {
187-
UPLO::Upper => UPLO::Lower,
188-
UPLO::Lower => UPLO::Upper,
189-
}
190-
}
191-
192-
/// To use Fortran LAPACK API in lapack-sys crate
193-
pub fn as_ptr(&self) -> *const i8 {
194-
self as *const UPLO as *const i8
195-
}
196-
}
197-
198-
#[derive(Debug, Clone, Copy)]
199-
#[repr(u8)]
200-
pub enum Transpose {
201-
No = b'N',
202-
Transpose = b'T',
203-
Hermite = b'C',
204-
}
205-
206-
impl Transpose {
207-
/// To use Fortran LAPACK API in lapack-sys crate
208-
pub fn as_ptr(&self) -> *const i8 {
209-
self as *const Transpose as *const i8
210-
}
211-
}
212-
213-
#[derive(Debug, Clone, Copy)]
214-
#[repr(u8)]
215-
pub enum NormType {
216-
One = b'O',
217-
Infinity = b'I',
218-
Frobenius = b'F',
219-
}
220-
221-
impl NormType {
222-
pub fn transpose(self) -> Self {
223-
match self {
224-
NormType::One => NormType::Infinity,
225-
NormType::Infinity => NormType::One,
226-
NormType::Frobenius => NormType::Frobenius,
227-
}
228-
}
229-
230-
/// To use Fortran LAPACK API in lapack-sys crate
231-
pub fn as_ptr(&self) -> *const i8 {
232-
self as *const NormType as *const i8
233-
}
234-
}
235-
236-
/// Flag for calculating eigenvectors or not
237-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
238-
#[repr(u8)]
239-
pub enum EigenVectorFlag {
240-
Calc = b'V',
241-
Not = b'N',
242-
}
243-
244-
impl EigenVectorFlag {
245-
pub fn is_calc(&self) -> bool {
246-
match self {
247-
EigenVectorFlag::Calc => true,
248-
EigenVectorFlag::Not => false,
249-
}
250-
}
251-
252-
pub fn then<T, F: FnOnce() -> T>(&self, f: F) -> Option<T> {
253-
if self.is_calc() {
254-
Some(f())
255-
} else {
256-
None
257-
}
258-
}
259-
260-
/// To use Fortran LAPACK API in lapack-sys crate
261-
pub fn as_ptr(&self) -> *const i8 {
262-
self as *const EigenVectorFlag as *const i8
263-
}
264-
}
265-
266178
/// Create a vector without initialization
267179
///
268180
/// Safety

lax/src/svd.rs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,9 @@
11
//! Singular-value decomposition
22
3-
use crate::{error::*, layout::MatrixLayout, *};
3+
use super::{error::*, layout::*, *};
44
use cauchy::*;
55
use num_traits::{ToPrimitive, Zero};
66

7-
#[repr(u8)]
8-
#[derive(Debug, Copy, Clone)]
9-
enum FlagSVD {
10-
All = b'A',
11-
// OverWrite = b'O',
12-
// Separately = b'S',
13-
No = b'N',
14-
}
15-
16-
impl FlagSVD {
17-
fn from_bool(calc_uv: bool) -> Self {
18-
if calc_uv {
19-
FlagSVD::All
20-
} else {
21-
FlagSVD::No
22-
}
23-
}
24-
25-
fn as_ptr(&self) -> *const i8 {
26-
self as *const FlagSVD as *const i8
27-
}
28-
}
29-
307
/// Result of SVD
318
pub struct SVDOutput<A: Scalar> {
329
/// diagonal values

lax/src/svddc.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,6 @@ use crate::{error::*, layout::MatrixLayout, *};
22
use cauchy::*;
33
use num_traits::{ToPrimitive, Zero};
44

5-
/// Specifies how many of the columns of *U* and rows of *V*ᵀ are computed and returned.
6-
///
7-
/// For an input array of shape *m*×*n*, the following are computed:
8-
#[derive(Clone, Copy, Eq, PartialEq)]
9-
#[repr(u8)]
10-
pub enum UVTFlag {
11-
/// All *m* columns of *U* and all *n* rows of *V*ᵀ.
12-
Full = b'A',
13-
/// The first min(*m*,*n*) columns of *U* and the first min(*m*,*n*) rows of *V*ᵀ.
14-
Some = b'S',
15-
/// No columns of *U* or rows of *V*ᵀ.
16-
None = b'N',
17-
}
18-
19-
impl UVTFlag {
20-
fn as_ptr(&self) -> *const i8 {
21-
self as *const UVTFlag as *const i8
22-
}
23-
}
24-
255
pub trait SVDDC_: Scalar {
266
fn svddc(l: MatrixLayout, jobz: UVTFlag, a: &mut [Self]) -> Result<SVDOutput<Self>>;
277
}

lax/src/triangular.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,6 @@
33
use crate::{error::*, layout::*, *};
44
use cauchy::*;
55

6-
#[derive(Debug, Clone, Copy)]
7-
#[repr(u8)]
8-
pub enum Diag {
9-
Unit = b'U',
10-
NonUnit = b'N',
11-
}
12-
13-
impl Diag {
14-
fn as_ptr(&self) -> *const i8 {
15-
self as *const Diag as *const i8
16-
}
17-
}
18-
196
/// Wraps `*trtri` and `*trtrs`
207
pub trait Triangular_: Scalar {
218
fn solve_triangular(

0 commit comments

Comments
 (0)