|
| 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 | +} |
0 commit comments