#[derive(Debug, PartialEq)]
pub enum IError {
IncompatibleSizeError((usize, usize), usize),
IncompatibleShape((usize, usize), (usize, usize)),
OutOfBoundary(usize, usize),
DividedByZero,
SingularMatrix,
NoSolution((usize, usize), usize),
Message(String),
}
pub type IResult<T> = std::result::Result<T, IError>;
impl std::error::Error for IError {}
impl std::fmt::Display for IError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
IError::IncompatibleSizeError((required_row, required_col), real) => write!(
f,
"incompatible size while require ({:?} x {:?}) but the real size is {:?}",
required_row, required_col, real
),
IError::IncompatibleShape(required, real) => {
write!(
f,
"incompatible shape while require {:?} but the real shape is {:?}",
required, real
)
}
IError::OutOfBoundary(row, col) => {
write!(f, "out of boundary at ({:?}, {:?})", row, col)
}
IError::DividedByZero => write!(f, "can not divide by zero"),
IError::SingularMatrix => write!(f, "matrix is strange which determinant is zero"),
IError::NoSolution((row, col), rank) => {
write!(
f,
"linear equation {:?}x{:?} with rank {:?} has no solution",
row, col, rank
)
}
IError::Message(msg) => write!(f, "{:?}", msg),
}
}
}