#![allow(clippy::many_single_char_names)]
#![allow(clippy::result_large_err)]
pub mod bidiagonal;
pub mod cholesky;
pub mod eigh;
mod givens;
mod householder;
mod index;
#[cfg(feature = "iterative")]
pub mod lobpcg;
pub mod norm;
pub mod qr;
pub mod reflection;
pub mod svd;
pub mod triangular;
pub mod tridiagonal;
use ndarray::{ArrayBase, Ix2, RawData, ShapeError};
use thiserror::Error;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum LinalgError {
#[error("Matrix of ({rows}, {cols}) is not square")]
NotSquare { rows: usize, cols: usize },
#[error("Expected matrix rows({rows}) >= cols({cols})")]
NotThin { rows: usize, cols: usize },
#[error("Matrix is not positive definite")]
NotPositiveDefinite,
#[error("Matrix is non-invertible")]
NonInvertible,
#[error("Matrix is empty")]
EmptyMatrix,
#[error("Matrix must have {expected} columns, not {actual}")]
WrongColumns { expected: usize, actual: usize },
#[error("Matrix must have {expected} rows, not {actual}")]
WrongRows { expected: usize, actual: usize },
#[error(transparent)]
Shape(#[from] ShapeError),
}
pub type Result<T> = std::result::Result<T, LinalgError>;
pub(crate) fn check_square<S: RawData>(arr: &ArrayBase<S, Ix2>) -> Result<usize> {
let (n, m) = (arr.nrows(), arr.ncols());
if n != m {
Err(LinalgError::NotSquare { rows: n, cols: m })
} else {
Ok(n)
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum Order {
Largest,
Smallest,
}