Skip to main content

Error

Enum Error 

Source
#[non_exhaustive]
pub enum Error {
Show 22 variants ShapeMismatch { expected: Vec<usize>, got: Vec<usize>, }, BroadcastError { lhs: Vec<usize>, rhs: Vec<usize>, }, InvalidDimension { dim: isize, ndim: usize, }, UnsupportedDType { dtype: DType, op: &'static str, }, DTypeMismatch { lhs: DType, rhs: DType, }, DeviceMismatch, OutOfMemory { size: usize, }, AllocFailed { shape: Vec<usize>, dtype: String, device: String, source: Box<Error>, }, IndexOutOfBounds { index: usize, size: usize, }, InvalidArgument { arg: &'static str, reason: String, }, NotContiguous, HostReadTypeMismatch { dtype: &'static str, dtype_bytes: usize, elem_bytes: usize, }, MissingGradient, Backend(String), BackendLimitation { backend: &'static str, operation: &'static str, reason: String, }, Msg(String), Internal(String), NotImplemented { feature: &'static str, }, FeatureRequired { dtype: DType, feature: &'static str, }, AllocatorBusy { active_allocations: usize, }, AllocatorFrozen, ArenaExhausted { requested: usize, used: usize, capacity: usize, },
}
Expand description

Errors that can occur in numr operations

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

ShapeMismatch

Shape mismatch in an operation

Fields

§expected: Vec<usize>

Expected shape

§got: Vec<usize>

Actual shape

§

BroadcastError

Shapes cannot be broadcast together

Fields

§lhs: Vec<usize>

Left-hand side shape

§rhs: Vec<usize>

Right-hand side shape

§

InvalidDimension

Invalid dimension index

Fields

§dim: isize

The invalid dimension

§ndim: usize

Number of dimensions

§

UnsupportedDType

Unsupported dtype for an operation

Fields

§dtype: DType

The unsupported dtype

§op: &'static str

The operation name

§

DTypeMismatch

DType mismatch between operands

Fields

§lhs: DType

Left-hand side dtype

§rhs: DType

Right-hand side dtype

§

DeviceMismatch

Device mismatch between operands

§

OutOfMemory

Out of memory

Fields

§size: usize

Requested size in bytes

§

AllocFailed

Tensor allocation failed, with the shape/dtype/device context

Wraps the underlying allocation error (usually Error::OutOfMemory) so the message names what was being allocated, not only a byte count.

Fields

§shape: Vec<usize>

Shape of the tensor that could not be allocated

§dtype: String

Element type short name (e.g. “bf16”, “q4_0”)

§device: String

Device name (from Device::name)

§source: Box<Error>

The underlying allocation error

§

IndexOutOfBounds

Index out of bounds

Fields

§index: usize

The invalid index

§size: usize

Size of the dimension

§

InvalidArgument

Invalid argument provided to an operation

Fields

§arg: &'static str

The argument name

§reason: String

Reason for invalidity

§

NotContiguous

Tensor is not contiguous when contiguous memory is required

§

HostReadTypeMismatch

A host read names an element type whose width differs from the dtype.

A width mismatch sizes the copy wrong, so it would read past the buffer.

Fields

§dtype: &'static str

Short name of the stored dtype

§dtype_bytes: usize

Bytes per element of the stored dtype

§elem_bytes: usize

Bytes per element of the requested host type

§

MissingGradient

Missing gradient in backward pass

§

Backend(String)

Backend-specific error

§

BackendLimitation

Backend limitation - operation valid but exceeds backend capabilities

Fields

§backend: &'static str

The backend that has the limitation

§operation: &'static str

The operation being attempted

§reason: String

Description of the limitation

§

Msg(String)

Generic message error

§

Internal(String)

Generic internal error

§

NotImplemented

Feature not yet implemented

Fields

§feature: &'static str

Description of the unimplemented feature

§

FeatureRequired

Cargo feature required but not enabled

Fields

§dtype: DType

The dtype that needs the feature

§feature: &'static str

The cargo feature name to enable

§

AllocatorBusy

Allocator cannot reset while allocations are still live

Fields

§active_allocations: usize

Number of allocations that are still live

§

AllocatorFrozen

Allocator is frozen — no new allocations permitted

§

ArenaExhausted

A CUDA graph capture arena ran out of room for an intermediate allocation.

Carries the numbers a caller needs to size a retry: the request that failed, the bytes the arena had already handed out, and the arena’s total capacity. Raised during capture_graph_into_with_arena when an intermediate allocation inside the capture overruns the pre-sized arena; the caller can recapture with a larger arena sized from used + requested.

Fields

§requested: usize

Bytes the failing allocation asked for

§used: usize

Bytes already handed out by the arena before this request

§capacity: usize

Total arena capacity in bytes

Implementations§

Source§

impl Error

Source

pub fn as_arena_exhausted(&self) -> Option<(usize, usize, usize)>

The arena-exhaustion fields, if this error is Error::ArenaExhausted or wraps one as an Error::AllocFailed source.

A CUDA graph intermediate is normally allocated through Tensor::empty/Tensor::zeros, which wraps every allocation failure in AllocFailed for shape/dtype/device context. This walks that one layer of wrapping so a caller can react to arena exhaustion without matching on message text.

Source§

impl Error

Source

pub fn shape_mismatch(expected: &[usize], got: &[usize]) -> Self

Create a shape mismatch error

Source

pub fn broadcast(lhs: &[usize], rhs: &[usize]) -> Self

Create a broadcast error

Source

pub fn unsupported_dtype(dtype: DType, op: &'static str) -> Self

Create an unsupported dtype error

Source

pub fn is_out_of_memory(&self) -> bool

Returns true when an allocation fails for lack of memory.

This holds for Error::OutOfMemory, and for Error::AllocFailed that wraps it. A caller can then name the next action, such as a smaller input, without reading the message.

Source

pub fn backend_limitation( backend: &'static str, operation: &'static str, reason: impl Into<String>, ) -> Self

Create a backend limitation error

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

Replaced by Error::source.
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

Auto Trait Implementations§

§

impl Forget for Error

§

impl Freeze for Error

§

impl Move 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> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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
Source§

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

Source§

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

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&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
Source§

impl<T> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

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

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

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

Source§

impl<T> WasmNotSendSync for T

Source§

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