use crate::device::Device;
use crate::dtype::DType;
use crate::shape::Shape;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error("shape mismatch: expected {expected:?}, got {got:?} in {op}")]
ShapeMismatch {
expected: Shape,
got: Shape,
op: &'static str,
},
#[error("cannot broadcast {lhs:?} with {rhs:?}")]
BroadcastIncompatible {
lhs: Shape,
rhs: Shape,
},
#[error("dtype mismatch: expected {expected:?}, got {got:?} in {op}")]
DTypeMismatch {
expected: DType,
got: DType,
op: &'static str,
},
#[error("dtype {dtype:?} is not supported by {op}")]
UnsupportedDType {
dtype: DType,
op: &'static str,
},
#[error("device mismatch: {lhs:?} vs {rhs:?} in {op}")]
DeviceMismatch {
lhs: Device,
rhs: Device,
op: &'static str,
},
#[error("index {index:?} out of bounds for shape {shape:?}")]
IndexOutOfBounds {
index: Vec<usize>,
shape: Shape,
},
#[error("rank mismatch: index of rank {index_rank} against shape of rank {shape_rank}")]
RankMismatch {
index_rank: usize,
shape_rank: usize,
},
#[error("no backend available for device {device:?}")]
BackendUnavailable {
device: Device,
},
#[error("invalid argument to {op}: {detail}")]
InvalidArgument {
op: &'static str,
detail: String,
},
#[error("backend failure in {op}: {detail}")]
Backend {
op: &'static str,
detail: String,
},
#[error("io failure in {op}: {detail}")]
Io {
op: &'static str,
detail: String,
},
#[error("{op} is not implemented for {detail}")]
NotImplemented {
op: &'static str,
detail: String,
},
}
pub type Result<T> = std::result::Result<T, Error>;