use thiserror::Error;
#[derive(Error, Debug, Clone, PartialEq)]
pub enum SvdLibError {
#[error("invalid argument: {0}")]
InvalidArgument(String),
#[error("shape mismatch: {0}")]
ShapeMismatch(String),
#[error("{stage}: no convergence after {iterations} iterations")]
NoConvergence {
stage: &'static str,
iterations: usize,
},
#[error("{stage}: {message}")]
Failed {
stage: &'static str,
message: String,
},
#[error("dense {factorization} failed: {message}")]
DenseFactorization {
factorization: &'static str,
message: String,
},
#[error("ndarray shape error: {0}")]
Shape(String),
}
impl From<ndarray::ShapeError> for SvdLibError {
fn from(e: ndarray::ShapeError) -> Self {
SvdLibError::Shape(e.to_string())
}
}
impl SvdLibError {
pub(crate) fn invalid(msg: impl Into<String>) -> Self {
SvdLibError::InvalidArgument(msg.into())
}
pub(crate) fn failed(stage: &'static str, msg: impl Into<String>) -> Self {
SvdLibError::Failed {
stage,
message: msg.into(),
}
}
pub(crate) fn shape(msg: impl Into<String>) -> Self {
SvdLibError::ShapeMismatch(msg.into())
}
}
pub type Result<T> = std::result::Result<T, SvdLibError>;