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