use thiserror::Error;
#[derive(Debug, Error, Clone, PartialEq)]
pub enum LetoError {
#[error("Index out of bounds: index {index:?}, shape {shape:?}")]
OutOfBounds {
index: Vec<usize>,
shape: Vec<usize>,
},
#[error("Incompatible slice: range {range:?}, shape {shape:?}")]
IncompatibleSlice {
range: (usize, usize),
shape: Vec<usize>,
},
#[error("Shape mismatch: lhs {lhs:?}, rhs {rhs:?}")]
ShapeMismatch {
lhs: Vec<usize>,
rhs: Vec<usize>,
},
#[error("Incompatible broadcast: from {from:?} to {to:?}")]
IncompatibleBroadcast {
from: Vec<usize>,
to: Vec<usize>,
},
#[error("Arithmetic overflow in layout calculations: {reason}")]
Overflow {
reason: &'static str,
},
#[error("Storage error: {reason}")]
StorageError {
reason: String,
},
#[error(
"Solver did not converge after {max_iters} iterations (residual {residual:e}, \
tolerance {tol:e})"
)]
ConvergenceError {
max_iters: usize,
residual: f64,
tol: f64,
},
#[error("Invalid input: {0}")]
InvalidInput(String),
#[error("Numerical breakdown: {0}")]
NumericalBreakdown(String),
#[error("Matrix is not positive definite: {detail}")]
NotPositiveDefinite {
detail: String,
},
}
pub type Result<T> = std::result::Result<T, LetoError>;