pub enum Error {
ShapeMismatch {
expected: Shape,
got: Shape,
},
RankMismatch {
expected: usize,
got: usize,
},
DTypeMismatch {
expected: DType,
got: DType,
},
DimOutOfRange {
dim: usize,
rank: usize,
},
NarrowOutOfBounds {
dim: usize,
start: usize,
len: usize,
dim_size: usize,
},
NotAScalar {
shape: Shape,
},
ElementCountMismatch {
shape: Shape,
expected: usize,
got: usize,
},
MatmulShapeMismatch {
m: usize,
k1: usize,
k2: usize,
n: usize,
},
ReshapeElementMismatch {
src: usize,
dst: usize,
dst_shape: Shape,
},
Msg(String),
}Expand description
All errors that can occur within Shrew.
This enum captures every failure mode: shape mismatches, dtype mismatches, device mismatches, out-of-bounds indexing, and backend-specific errors. Using a single error type across the library simplifies error propagation.
Variants§
ShapeMismatch
Shape mismatch between two tensors (e.g., trying to add [2,3] + [4,5]).
RankMismatch
Operation requires a specific rank (number of dimensions).
DTypeMismatch
DType mismatch between tensors in a binary operation.
DimOutOfRange
Dimension index out of range for the tensor’s rank.
NarrowOutOfBounds
Narrow/slice operation out of bounds.
NotAScalar
Tried to access a scalar from a non-scalar tensor.
ElementCountMismatch
Element count mismatch when creating from a vec.
MatmulShapeMismatch
Matrix multiplication dimension mismatch.
ReshapeElementMismatch
Cannot reshape because element counts differ.
Msg(String)
Generic message for cases not covered above.