|
| 1 | +//! Linear Algebra eXtension (LAX) |
| 2 | +//! =============================== |
| 3 | +//! |
| 4 | +//! ndarray-free safe Rust wrapper for LAPACK FFI |
| 5 | +//! |
| 6 | +//! Linear equation, Inverse matrix, Condition number |
| 7 | +//! -------------------------------------------------- |
| 8 | +//! |
| 9 | +//! As the property of $A$, several types of triangular factorization are used: |
| 10 | +//! |
| 11 | +//! - LU-decomposition for general matrix |
| 12 | +//! - $PA = LU$, where $L$ is lower matrix, $U$ is upper matrix, and $P$ is permutation matrix |
| 13 | +//! - Bunch-Kaufman diagonal pivoting method for nonpositive-definite Hermitian matrix |
| 14 | +//! - $A = U D U^\dagger$, where $U$ is upper matrix, |
| 15 | +//! $D$ is Hermitian and block diagonal with 1-by-1 and 2-by-2 diagonal blocks. |
| 16 | +//! |
| 17 | +//! | matrix type | Triangler factorization (TRF) | Solve (TRS) | Inverse matrix (TRI) | Reciprocal condition number (CON) | |
| 18 | +//! |:--------------------------------|:------------------------------|:------------|:---------------------|:----------------------------------| |
| 19 | +//! | General (GE) | [lu] | [solve] | [inv] | [rcond] | |
| 20 | +//! | Symmetric (SY) / Hermitian (HE) | [bk] | [solveh] | [invh] | - | |
| 21 | +//! |
| 22 | +//! [lu]: solve/trait.Solve_.html#tymethod.lu |
| 23 | +//! [solve]: solve/trait.Solve_.html#tymethod.solve |
| 24 | +//! [inv]: solve/trait.Solve_.html#tymethod.inv |
| 25 | +//! [rcond]: solve/trait.Solve_.html#tymethod.rcond |
| 26 | +//! |
| 27 | +//! [bk]: solveh/trait.Solveh_.html#tymethod.bk |
| 28 | +//! [solveh]: solveh/trait.Solveh_.html#tymethod.solveh |
| 29 | +//! [invh]: solveh/trait.Solveh_.html#tymethod.invh |
| 30 | +//! |
| 31 | +//! Eigenvalue Problem |
| 32 | +//! ------------------- |
| 33 | +//! |
| 34 | +//! Solve eigenvalue problem for a matrix $A$ |
| 35 | +//! |
| 36 | +//! $$ Av_i = \lambda_i v_i $$ |
| 37 | +//! |
| 38 | +//! or generalized eigenvalue problem |
| 39 | +//! |
| 40 | +//! $$ Av_i = \lambda_i B v_i $$ |
| 41 | +//! |
| 42 | +//! | matrix type | Eigenvalue (EV) | Generalized Eigenvalue Problem (EG) | |
| 43 | +//! |:--------------------------------|:----------------|:------------------------------------| |
| 44 | +//! | General (GE) |[eig] | - | |
| 45 | +//! | Symmetric (SY) / Hermitian (HE) |[eigh] |[eigh_generalized] | |
| 46 | +//! |
| 47 | +//! [eig]: eig/trait.Eig_.html#tymethod.eig |
| 48 | +//! [eigh]: eigh/trait.Eigh_.html#tymethod.eigh |
| 49 | +//! [eigh_generalized]: eigh/trait.Eigh_.html#tymethod.eigh_generalized |
| 50 | +//! |
| 51 | +//! Singular Value Decomposition (SVD), Least square problem |
| 52 | +//! ---------------------------------------------------------- |
| 53 | +//! |
| 54 | +//! | matrix type | Singular Value Decomposition (SVD) | SVD with divided-and-conquer (SDD) | Least square problem (LSD) | |
| 55 | +//! |:-------------|:-----------------------------------|:-----------------------------------|:---------------------------| |
| 56 | +//! | General (GE) | [svd] | [svddc] | [least_squares] | |
| 57 | +//! |
| 58 | +//! [svd]: svd/trait.SVD_.html#tymethod.svd |
| 59 | +//! [svddc]: svddck/trait.SVDDC_.html#tymethod.svddc |
| 60 | +//! [least_squares]: least_squares/trait.LeastSquaresSvdDivideConquer_.html#tymethod.least_squares |
| 61 | +
|
| 62 | +extern crate blas_src; |
| 63 | +extern crate lapack_src; |
| 64 | + |
| 65 | +pub mod cholesky; |
| 66 | +pub mod eig; |
| 67 | +pub mod eigh; |
| 68 | +pub mod error; |
| 69 | +pub mod layout; |
| 70 | +pub mod least_squares; |
| 71 | +pub mod opnorm; |
| 72 | +pub mod qr; |
| 73 | +pub mod solve; |
| 74 | +pub mod solveh; |
| 75 | +pub mod svd; |
| 76 | +pub mod svddc; |
| 77 | +pub mod triangular; |
| 78 | +pub mod tridiagonal; |
| 79 | + |
| 80 | +pub use self::cholesky::*; |
| 81 | +pub use self::eig::*; |
| 82 | +pub use self::eigh::*; |
| 83 | +pub use self::least_squares::*; |
| 84 | +pub use self::opnorm::*; |
| 85 | +pub use self::qr::*; |
| 86 | +pub use self::solve::*; |
| 87 | +pub use self::solveh::*; |
| 88 | +pub use self::svd::*; |
| 89 | +pub use self::svddc::*; |
| 90 | +pub use self::triangular::*; |
| 91 | +pub use self::tridiagonal::*; |
| 92 | + |
| 93 | +use cauchy::*; |
| 94 | + |
| 95 | +pub type Pivot = Vec<i32>; |
| 96 | + |
| 97 | +/// Trait for primitive types which implements LAPACK subroutines |
| 98 | +pub trait Lapack: |
| 99 | + OperatorNorm_ |
| 100 | + + QR_ |
| 101 | + + SVD_ |
| 102 | + + SVDDC_ |
| 103 | + + Solve_ |
| 104 | + + Solveh_ |
| 105 | + + Cholesky_ |
| 106 | + + Eig_ |
| 107 | + + Eigh_ |
| 108 | + + Triangular_ |
| 109 | + + Tridiagonal_ |
| 110 | +{ |
| 111 | +} |
| 112 | + |
| 113 | +impl Lapack for f32 {} |
| 114 | +impl Lapack for f64 {} |
| 115 | +impl Lapack for c32 {} |
| 116 | +impl Lapack for c64 {} |
| 117 | + |
| 118 | +/// Upper/Lower specification for seveal usages |
| 119 | +#[derive(Debug, Clone, Copy)] |
| 120 | +#[repr(u8)] |
| 121 | +pub enum UPLO { |
| 122 | + Upper = b'U', |
| 123 | + Lower = b'L', |
| 124 | +} |
| 125 | + |
| 126 | +#[derive(Debug, Clone, Copy)] |
| 127 | +#[repr(u8)] |
| 128 | +pub enum Transpose { |
| 129 | + No = b'N', |
| 130 | + Transpose = b'T', |
| 131 | + Hermite = b'C', |
| 132 | +} |
| 133 | + |
| 134 | +#[derive(Debug, Clone, Copy)] |
| 135 | +#[repr(u8)] |
| 136 | +pub enum NormType { |
| 137 | + One = b'O', |
| 138 | + Infinity = b'I', |
| 139 | + Frobenius = b'F', |
| 140 | +} |
| 141 | + |
| 142 | +impl NormType { |
| 143 | + pub(crate) fn transpose(self) -> Self { |
| 144 | + match self { |
| 145 | + NormType::One => NormType::Infinity, |
| 146 | + NormType::Infinity => NormType::One, |
| 147 | + NormType::Frobenius => NormType::Frobenius, |
| 148 | + } |
| 149 | + } |
| 150 | +} |
0 commit comments