use std::time::Duration;
use crate::types::Algorithm;
#[derive(Debug, thiserror::Error)]
pub enum SolverError {
#[error(
"solver did not converge after {iterations} iterations (residual={residual:.2e}, tol={tolerance:.2e})"
)]
NonConvergence {
iterations: usize,
residual: f64,
tolerance: f64,
},
#[error("numerical instability at iteration {iteration}: {detail}")]
NumericalInstability {
iteration: usize,
detail: String,
},
#[error("compute budget exhausted: {reason}")]
BudgetExhausted {
reason: String,
elapsed: Duration,
},
#[error("invalid input: {0}")]
InvalidInput(#[from] ValidationError),
#[error(
"spectral radius {spectral_radius:.4} exceeds limit {limit:.4} for algorithm {algorithm}"
)]
SpectralRadiusExceeded {
spectral_radius: f64,
limit: f64,
algorithm: Algorithm,
},
#[error("backend error: {0}")]
BackendError(String),
}
#[derive(Debug, thiserror::Error)]
pub enum ValidationError {
#[error("dimension mismatch: {0}")]
DimensionMismatch(String),
#[error("non-finite value detected: {0}")]
NonFiniteValue(String),
#[error("column index {index} out of bounds for {cols} columns (row {row})")]
IndexOutOfBounds {
index: u32,
row: usize,
cols: usize,
},
#[error("row_ptrs is not monotonically non-decreasing at position {position}")]
NonMonotonicRowPtrs {
position: usize,
},
#[error("parameter out of range: {name} = {value} (expected {expected})")]
ParameterOutOfRange {
name: String,
value: String,
expected: String,
},
#[error("matrix size {rows}x{cols} exceeds maximum supported {max_dim}x{max_dim}")]
MatrixTooLarge {
rows: usize,
cols: usize,
max_dim: usize,
},
}