Skip to main content

Error

Enum Error 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Validation

A shared tensor validation fact discovered by an einsum operation.

Fields

§op: &'static str

Public operation name.

§source: ValidationError

Machine-readable validation payload.

§

InvalidSubscripts

Einsum notation is malformed or cannot be parsed.

Fields

§message: String

Human-readable parser detail.

§

Planning

No valid contraction plan could be constructed for the supplied expression or optimizer configuration.

Fields

§source: PlanningError

Typed planning-domain cause.

§

Numerical

A numerical contraction or backend accumulation failed to converge.

Fields

§message: String

Human-readable numerical detail.

§

Tensor(Error)

A concrete tensor/backend operation failed.

§

Runtime(Error)

Graph construction or extension execution failed in the runtime.

Implementations§

Source§

impl Error

Source

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 { .. }));
Source

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 { .. }));
Source

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 { .. }));
Source

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(_)));
Source

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 { .. }));
Source

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 { .. }));
Source

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 { .. }));
Source

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 { .. }
    }
));
Source

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 { .. }));
Source

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),
);
Source

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 Debug for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Error

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for Error

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Error> for Error

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> ByRef<T> for T

§

fn by_ref(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

§

impl<T> MaybeSend for T
where T: Send,

§

impl<T> MaybeSendSync for T
where T: Send + Sync,

§

impl<T> MaybeSync for T
where T: Sync,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,