1#![allow(clippy::many_single_char_names)]
13#![allow(clippy::result_large_err)]
14
15pub mod bidiagonal;
16pub mod cholesky;
17pub mod eigh;
18mod givens;
19mod householder;
20mod index;
21#[cfg(feature = "iterative")]
22pub mod lobpcg;
23pub mod norm;
24pub mod qr;
25pub mod reflection;
26pub mod svd;
27pub mod triangular;
28pub mod tridiagonal;
29
30use ndarray::{ArrayBase, Ix2, RawData, ShapeError};
31use thiserror::Error;
32
33#[derive(Debug, Error)]
34#[non_exhaustive]
35pub enum LinalgError {
36 #[error("Matrix of ({rows}, {cols}) is not square")]
38 NotSquare { rows: usize, cols: usize },
39 #[error("Expected matrix rows({rows}) >= cols({cols})")]
41 NotThin { rows: usize, cols: usize },
42 #[error("Matrix is not positive definite")]
44 NotPositiveDefinite,
45 #[error("Matrix is non-invertible")]
47 NonInvertible,
48 #[error("Matrix is empty")]
50 EmptyMatrix,
51 #[error("Matrix must have {expected} columns, not {actual}")]
53 WrongColumns { expected: usize, actual: usize },
54 #[error("Matrix must have {expected} rows, not {actual}")]
56 WrongRows { expected: usize, actual: usize },
57 #[error(transparent)]
59 Shape(#[from] ShapeError),
60}
61
62pub type Result<T> = std::result::Result<T, LinalgError>;
63
64pub(crate) fn check_square<S: RawData>(arr: &ArrayBase<S, Ix2>) -> Result<usize> {
65 let (n, m) = (arr.nrows(), arr.ncols());
66 if n != m {
67 Err(LinalgError::NotSquare { rows: n, cols: m })
68 } else {
69 Ok(n)
70 }
71}
72
73#[derive(Debug, Copy, Clone, PartialEq, Eq)]
77pub enum Order {
78 Largest,
79 Smallest,
80}