#[non_exhaustive]pub enum Error {
Validation {
op: &'static str,
source: ValidationError,
},
InvalidSubscripts {
message: String,
},
Planning {
source: PlanningError,
},
Numerical {
message: String,
},
Tensor(Error),
Runtime(Error),
}Expand description
Errors produced while parsing, planning, lowering, or executing einsum expressions.
§Examples
use tenferro_einsum::Error;
use tenferro_tensor::{ErrorKind, ShapeMismatch, ShapeVec, ValidationKind};
let err = Error::validation(
"einsum",
ShapeMismatch::ExpectedActual {
expected: ShapeVec::from_vec(vec![2, 3]),
actual: ShapeVec::from_vec(vec![2, 4]),
}
.into(),
);
assert_eq!(err.kind(), ErrorKind::Validation(ValidationKind::ShapeMismatch));Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Validation
A shared tensor validation fact discovered by an einsum operation.
Fields
source: ValidationErrorMachine-readable validation payload.
InvalidSubscripts
Einsum notation is malformed or cannot be parsed.
Planning
No valid contraction plan could be constructed for the supplied expression or optimizer configuration.
Fields
source: PlanningErrorTyped planning-domain cause.
Numerical
A numerical contraction or backend accumulation failed to converge.
Tensor(Error)
A concrete tensor/backend operation failed.
Runtime(Error)
Graph construction or extension execution failed in the runtime.
Implementations§
Source§impl Error
impl Error
Sourcepub fn validation(op: &'static str, source: ValidationError) -> Self
pub fn validation(op: &'static str, source: ValidationError) -> Self
Construct a shared validation error.
§Examples
use tenferro_einsum::Error;
use tenferro_tensor::ValidationError;
let error = Error::validation("einsum", ValidationError::RankMismatch {
expected: 2,
actual: 1,
});
assert!(matches!(error, Error::Validation { .. }));Sourcepub fn invalid_argument(
op: &'static str,
argument: &'static str,
message: impl Into<String>,
) -> Self
pub fn invalid_argument( op: &'static str, argument: &'static str, message: impl Into<String>, ) -> Self
Construct an invalid-argument validation error.
§Examples
use tenferro_einsum::Error;
let error = Error::invalid_argument("einsum", "inputs", "at least one input is required");
assert!(matches!(error, Error::Validation { .. }));Sourcepub fn shape_mismatch(
op: &'static str,
expected: impl Into<Vec<usize>>,
actual: impl Into<Vec<usize>>,
) -> Self
pub fn shape_mismatch( op: &'static str, expected: impl Into<Vec<usize>>, actual: impl Into<Vec<usize>>, ) -> Self
Construct a shape-mismatch validation error.
§Examples
use tenferro_einsum::Error;
let error = Error::shape_mismatch("einsum", [2, 3], [2, 4]);
assert!(matches!(error, Error::Validation { .. }));Sourcepub fn dtype_mismatch(op: &'static str, expected: DType, actual: DType) -> Self
pub fn dtype_mismatch(op: &'static str, expected: DType, actual: DType) -> Self
Construct a dtype-mismatch validation error.
§Examples
use tenferro_einsum::Error;
use tenferro_tensor::DType;
let error = Error::dtype_mismatch("einsum", DType::F32, DType::F64);
assert!(matches!(error, Error::Tensor(_)));Sourcepub fn rank_mismatch(op: &'static str, expected: usize, actual: usize) -> Self
pub fn rank_mismatch(op: &'static str, expected: usize, actual: usize) -> Self
Construct a rank-mismatch validation error.
§Examples
use tenferro_einsum::Error;
let error = Error::rank_mismatch("einsum", 2, 1);
assert!(matches!(error, Error::Validation { .. }));Sourcepub fn invalid_subscripts(message: impl Into<String>) -> Self
pub fn invalid_subscripts(message: impl Into<String>) -> Self
Construct an invalid-notation error.
§Examples
use tenferro_einsum::Error;
let error = Error::invalid_subscripts("missing `->`");
assert!(matches!(error, Error::InvalidSubscripts { .. }));Sourcepub fn planning(message: impl Into<String>) -> Self
pub fn planning(message: impl Into<String>) -> Self
Construct a planning failure.
§Examples
use tenferro_einsum::Error;
let error = Error::planning("no contraction path");
assert!(matches!(error, Error::Planning { .. }));Sourcepub fn planning_runtime_state(message: impl Into<String>) -> Self
pub fn planning_runtime_state(message: impl Into<String>) -> Self
Construct a planning failure caused by unavailable planner state.
§Examples
use tenferro_einsum::{Error, PlanningError};
use tenferro_tensor::ErrorKind;
let error = Error::planning_runtime_state("planner lock is poisoned");
assert_eq!(error.kind(), ErrorKind::RuntimeState);
assert!(matches!(
error,
Error::Planning {
source: PlanningError::RuntimeState { .. }
}
));Sourcepub fn numerical(message: impl Into<String>) -> Self
pub fn numerical(message: impl Into<String>) -> Self
Construct a numerical failure.
§Examples
use tenferro_einsum::Error;
let error = Error::numerical("contraction did not converge");
assert!(matches!(error, Error::Numerical { .. }));Sourcepub fn kind(&self) -> ErrorKind
pub fn kind(&self) -> ErrorKind
Return the stable coarse classification of this einsum failure.
§Examples
use tenferro_einsum::Error;
use tenferro_tensor::{ErrorKind, ValidationKind};
assert_eq!(
Error::invalid_subscripts("bad").kind(),
ErrorKind::Validation(ValidationKind::InvalidArgument),
);Sourcepub fn into_tensor_error(self, op: &'static str) -> Error
pub fn into_tensor_error(self, op: &'static str) -> Error
Promote this error to the tensor error used by a type-erased extension boundary without formatting away its typed source.
Shared validation is promoted directly. All crate-local and nested errors remain a boxed source under the einsum extension family.
§Examples
use std::error::Error as _;
use tenferro_einsum::Error;
use tenferro_tensor::{Error as TensorError, ErrorKind, ValidationKind};
let tensor_error = Error::planning("no valid contraction path")
.into_tensor_error("einsum_extension");
assert_eq!(
tensor_error.kind(),
ErrorKind::Validation(ValidationKind::InvalidArgument)
);
assert!(matches!(tensor_error, TensorError::Extension { .. }));
assert!(tensor_error.source().is_some());Trait Implementations§
Source§impl Error for Error
impl Error for Error
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Auto Trait Implementations§
impl Freeze for Error
impl !RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnsafeUnpin for Error
impl !UnwindSafe for Error
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more