#[non_exhaustive]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum SolverError {
DimensionMismatch {
lhs: u32,
rhs: u32,
},
InvalidDimension,
InvalidInput,
NonFiniteInput,
UnsupportedProblemStructure,
SingularMatrix,
IllConditioned,
NumericalDomain,
Overflow,
WorkspaceTooSmall,
Cancelled,
BackendUnavailable,
InternalInvariantViolation,
}
const _: () = assert!(core::mem::size_of::<SolverError>() <= 16);
impl SolverError {
#[inline]
#[must_use]
pub const fn is_input_error(self) -> bool {
matches!(
self,
Self::DimensionMismatch { .. }
| Self::InvalidDimension
| Self::InvalidInput
| Self::NonFiniteInput
)
}
#[inline]
#[must_use]
pub const fn is_numerical_error(self) -> bool {
matches!(
self,
Self::SingularMatrix | Self::IllConditioned | Self::NumericalDomain | Self::Overflow
)
}
#[inline]
#[must_use]
pub const fn is_resource_error(self) -> bool {
matches!(
self,
Self::WorkspaceTooSmall | Self::Cancelled | Self::BackendUnavailable
)
}
}
#[inline]
#[must_use]
pub const fn error_code_to_str(err: SolverError) -> &'static str {
match err {
SolverError::DimensionMismatch { .. } => "dimension_mismatch",
SolverError::InvalidDimension => "invalid_dimension",
SolverError::InvalidInput => "invalid_input",
SolverError::NonFiniteInput => "non_finite_input",
SolverError::UnsupportedProblemStructure => "unsupported_problem_structure",
SolverError::SingularMatrix => "singular_matrix",
SolverError::IllConditioned => "ill_conditioned",
SolverError::NumericalDomain => "numerical_domain",
SolverError::Overflow => "overflow",
SolverError::WorkspaceTooSmall => "workspace_too_small",
SolverError::Cancelled => "cancelled",
SolverError::BackendUnavailable => "backend_unavailable",
SolverError::InternalInvariantViolation => "internal_invariant_violation",
}
}
#[cfg(test)]
mod tests;