use std::fmt;
#[derive(Debug)]
#[non_exhaustive]
pub enum MattenNdarrayError {
DynamicTensor,
ZeroSizedAxis(Vec<usize>),
NdarrayShape(ndarray::ShapeError),
Matten(matten::MattenError),
}
impl fmt::Display for MattenNdarrayError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
MattenNdarrayError::DynamicTensor => write!(
f,
"matten-ndarray error: dynamic tensors cannot be converted; call \
try_numeric() to convert to a numeric tensor first"
),
MattenNdarrayError::ZeroSizedAxis(shape) => write!(
f,
"matten-ndarray error: ndarray shape {shape:?} contains a zero-length \
axis, which matten does not support"
),
MattenNdarrayError::NdarrayShape(e) => {
write!(
f,
"matten-ndarray error: ndarray could not build the array: {e}"
)
}
MattenNdarrayError::Matten(e) => {
write!(
f,
"matten-ndarray error: matten rejected the conversion: {e}"
)
}
}
}
}
impl std::error::Error for MattenNdarrayError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
MattenNdarrayError::NdarrayShape(e) => Some(e),
MattenNdarrayError::Matten(e) => Some(e),
_ => None,
}
}
}