use core::fmt;
#[derive(Clone, PartialEq, Eq)]
pub enum LatticeError {
BufferLengthMismatch {
expected: usize,
actual: usize,
},
ZeroTileDimension,
GeometryMismatch,
ContractionMismatch {
lhs_cols: usize,
rhs_rows: usize,
},
IndexOutOfBounds {
row: usize,
col: usize,
},
}
impl fmt::Debug for LatticeError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
LatticeError::BufferLengthMismatch { expected, actual } => {
write!(
f,
"BufferLengthMismatch {{ expected: {expected}, actual: {actual} }}"
)
}
LatticeError::ZeroTileDimension => write!(f, "ZeroTileDimension"),
LatticeError::GeometryMismatch => write!(f, "GeometryMismatch"),
LatticeError::ContractionMismatch { lhs_cols, rhs_rows } => {
write!(
f,
"ContractionMismatch {{ lhs_cols: {lhs_cols}, rhs_rows: {rhs_rows} }}"
)
}
LatticeError::IndexOutOfBounds { row, col } => {
write!(f, "IndexOutOfBounds {{ row: {row}, col: {col} }}")
}
}
}
}
impl fmt::Display for LatticeError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
LatticeError::BufferLengthMismatch { expected, actual } => write!(
f,
"dense buffer length mismatch: expected {expected} elements, got {actual}"
),
LatticeError::ZeroTileDimension => {
write!(f, "tile dimensions must be non-zero")
}
LatticeError::GeometryMismatch => {
write!(f, "operands do not share the same tile geometry")
}
LatticeError::ContractionMismatch { lhs_cols, rhs_rows } => write!(
f,
"contraction mismatch: lhs has {lhs_cols} columns but rhs has {rhs_rows} rows"
),
LatticeError::IndexOutOfBounds { row, col } => {
write!(f, "index ({row}, {col}) is out of bounds")
}
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for LatticeError {}
pub type Result<T> = core::result::Result<T, LatticeError>;