use std::path::PathBuf;
use tch::{Device, Kind};
pub type Result<T> = std::result::Result<T, RustTorchError>;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum RustTorchError {
#[error("invalid configuration for {field}: {reason}")]
InvalidConfiguration {
field: &'static str,
reason: String,
},
#[error("invalid dimensions for {context}: expected {expected}, got {actual}")]
InvalidDimensions {
context: String,
expected: String,
actual: String,
},
#[error("{component} does not support option `{option}` in the MVP")]
UnsupportedOption {
component: &'static str,
option: &'static str,
},
#[error("{backend} backend is unavailable: {reason}")]
BackendUnavailable {
backend: &'static str,
reason: String,
},
#[error("device mismatch in {context}: expected {expected:?}, got {actual:?}")]
DeviceMismatch {
context: String,
expected: Device,
actual: Device,
},
#[error("shape mismatch for `{name}`: expected {expected:?}, got {actual:?}")]
ShapeMismatch {
name: String,
expected: Vec<i64>,
actual: Vec<i64>,
},
#[error("dtype mismatch for `{name}`: expected {expected:?}, got {actual:?}")]
DtypeMismatch {
name: String,
expected: Kind,
actual: Kind,
},
#[error("incompatible model state; missing={missing:?}, unexpected={unexpected:?}")]
IncompatibleModelState {
missing: Vec<String>,
unexpected: Vec<String>,
},
#[error("duplicate state mapping target `{0}`")]
DuplicateMappedKey(String),
#[error("duplicate name `{0}`")]
DuplicateName(String),
#[error("missing graph input `{0}`")]
MissingGraphInput(String),
#[error("unexpected graph input `{0}`")]
UnexpectedGraphInput(String),
#[error("missing graph output `{0}`")]
MissingGraphOutput(String),
#[error("graph validation failed: {0}")]
GraphValidation(String),
#[error("unsupported graph operation: {0}")]
UnsupportedGraphOperation(String),
#[error("unsupported model file `{path}`: {reason}")]
UnsupportedModelFile {
path: PathBuf,
reason: String,
},
#[error(transparent)]
Backend(#[from] tch::TchError),
}