99 lines
2.5 KiB
Rust
99 lines
2.5 KiB
Rust
use thiserror::Error;
|
|
|
|
/// Errors that can occur during preprocessing operations
|
|
#[derive(Error, Debug)]
|
|
pub enum PreprocessingError {
|
|
#[error("Invalid input: {message}")]
|
|
InvalidInput { message: String },
|
|
|
|
#[error("Not fitted: transformer must be fitted before transform")]
|
|
NotFitted,
|
|
|
|
#[error("Dimension mismatch: expected {expected}, got {actual}")]
|
|
DimensionMismatch { expected: usize, actual: usize },
|
|
|
|
#[error("Invalid shape: {message}")]
|
|
InvalidShape { message: String },
|
|
|
|
#[error("Shape mismatch: expected {expected:?}, got {actual:?}")]
|
|
ShapeMismatch {
|
|
expected: Vec<usize>,
|
|
actual: Vec<usize>,
|
|
},
|
|
|
|
#[error("Empty dataset: cannot fit transformer on empty data")]
|
|
EmptyDataset,
|
|
|
|
#[error("Invalid parameter: {parameter} = {value}, {message}")]
|
|
InvalidParameter {
|
|
parameter: String,
|
|
value: String,
|
|
message: String,
|
|
},
|
|
|
|
#[error("Unsupported operation: {operation}")]
|
|
UnsupportedOperation { operation: String },
|
|
|
|
#[error("Numerical error: {message}")]
|
|
NumericalError { message: String },
|
|
|
|
#[error("Runtime error: {0}")]
|
|
Runtime(String),
|
|
|
|
#[error("Tensor error: {0}")]
|
|
Tensor(String),
|
|
|
|
#[error("Serialization error: {0}")]
|
|
Serialization(#[from] bincode::Error),
|
|
|
|
#[error("I/O error: {0}")]
|
|
IoError(String),
|
|
|
|
#[error("Invalid data: {0}")]
|
|
InvalidData(String),
|
|
}
|
|
|
|
pub type Result<T> = std::result::Result<T, PreprocessingError>;
|
|
|
|
impl From<rtx_tensor::TensorError> for PreprocessingError {
|
|
fn from(err: rtx_tensor::TensorError) -> Self {
|
|
Self::Tensor(err.to_string())
|
|
}
|
|
}
|
|
|
|
impl PreprocessingError {
|
|
pub fn invalid_input(message: impl Into<String>) -> Self {
|
|
Self::InvalidInput {
|
|
message: message.into(),
|
|
}
|
|
}
|
|
|
|
pub fn dimension_mismatch(expected: usize, actual: usize) -> Self {
|
|
Self::DimensionMismatch { expected, actual }
|
|
}
|
|
|
|
pub fn invalid_parameter(
|
|
parameter: impl Into<String>,
|
|
value: impl Into<String>,
|
|
message: impl Into<String>,
|
|
) -> Self {
|
|
Self::InvalidParameter {
|
|
parameter: parameter.into(),
|
|
value: value.into(),
|
|
message: message.into(),
|
|
}
|
|
}
|
|
|
|
pub fn unsupported_operation(operation: impl Into<String>) -> Self {
|
|
Self::UnsupportedOperation {
|
|
operation: operation.into(),
|
|
}
|
|
}
|
|
|
|
pub fn numerical_error(message: impl Into<String>) -> Self {
|
|
Self::NumericalError {
|
|
message: message.into(),
|
|
}
|
|
}
|
|
}
|