use std::fmt;
#[derive(Debug)]
#[non_exhaustive]
pub enum MattenMlprepError {
DynamicTensor,
ExpectedMatrix {
shape: Vec<usize>,
},
InvalidRatio(f64),
EmptySplit {
rows: usize,
train_ratio: f64,
},
ZeroVariance {
column: usize,
},
Matten(matten::MattenError),
}
impl fmt::Display for MattenMlprepError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
MattenMlprepError::DynamicTensor => write!(
f,
"matten-mlprep error: dynamic tensors are not supported; call \
try_numeric() to convert to a numeric tensor first"
),
MattenMlprepError::ExpectedMatrix { shape } => write!(
f,
"matten-mlprep error: expected a rank-2 tensor (rows = samples, \
columns = features), got shape {shape:?}"
),
MattenMlprepError::InvalidRatio(r) => write!(
f,
"matten-mlprep error: train_ratio must be a finite value in (0.0, 1.0), got {r}"
),
MattenMlprepError::EmptySplit { rows, train_ratio } => write!(
f,
"matten-mlprep error: a split of {rows} row(s) at ratio {train_ratio} \
leaves the train set empty; use a larger ratio or more rows"
),
MattenMlprepError::ZeroVariance { column } => write!(
f,
"matten-mlprep error: column {column} has zero variance/range and \
cannot be scaled; drop or handle the constant column first"
),
MattenMlprepError::Matten(e) => {
write!(f, "matten-mlprep error: matten rejected the result: {e}")
}
}
}
}
impl std::error::Error for MattenMlprepError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
MattenMlprepError::Matten(e) => Some(e),
_ => None,
}
}
}