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, actual: Vec, }, #[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 = std::result::Result; impl From for PreprocessingError { fn from(err: rtx_tensor::TensorError) -> Self { Self::Tensor(err.to_string()) } } impl PreprocessingError { pub fn invalid_input(message: impl Into) -> 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, value: impl Into, message: impl Into, ) -> Self { Self::InvalidParameter { parameter: parameter.into(), value: value.into(), message: message.into(), } } pub fn unsupported_operation(operation: impl Into) -> Self { Self::UnsupportedOperation { operation: operation.into(), } } pub fn numerical_error(message: impl Into) -> Self { Self::NumericalError { message: message.into(), } } }