Skip to main content

Tensor

Struct Tensor 

Source
pub struct Tensor<T: WithDType, B: Backend> { /* private fields */ }

Implementations§

Source§

impl<T: WithDType, B: Backend> Tensor<T, B>

Source

pub fn write_bytes<W: Write>(&self, f: &mut W) -> Result<()>

Write the tensor data to f as little-endian bytes, in row-major order.

Source§

impl<T: WithDType, B: Backend> Tensor<T, B>

Source

pub fn binary_(&self, lhs: &Self, rhs: &Self, op: BinaryOp) -> Result<()>

Source

pub fn broadcast_binary_( &self, lhs: &Self, rhs: &Self, op: BinaryOp, ) -> Result<()>

Source

pub fn inplace_add(&self, other: &Self) -> Result<()>

Source

pub fn add_(&self, lhs: &Self, rhs: &Self) -> Result<()>

Source

pub fn broadcast_add_(&self, lhs: &Self, rhs: &Self) -> Result<()>

Source

pub fn inplace_sub(&self, other: &Self) -> Result<()>

Source

pub fn sub_(&self, lhs: &Self, rhs: &Self) -> Result<()>

Source

pub fn broadcast_sub_(&self, lhs: &Self, rhs: &Self) -> Result<()>

Source

pub fn inplace_mul(&self, other: &Self) -> Result<()>

Source

pub fn mul_(&self, lhs: &Self, rhs: &Self) -> Result<()>

Source

pub fn broadcast_mul_(&self, lhs: &Self, rhs: &Self) -> Result<()>

Source

pub fn inplace_div(&self, other: &Self) -> Result<()>

Source

pub fn div_(&self, lhs: &Self, rhs: &Self) -> Result<()>

Source

pub fn broadcast_div_(&self, lhs: &Self, rhs: &Self) -> Result<()>

Source

pub fn inplace_maximum(&self, other: &Self) -> Result<()>

Source

pub fn maximum_(&self, lhs: &Self, rhs: &Self) -> Result<()>

Source

pub fn broadcast_maximum_(&self, lhs: &Self, rhs: &Self) -> Result<()>

Source

pub fn inplace_minimum(&self, other: &Self) -> Result<()>

Source

pub fn minimum_(&self, lhs: &Self, rhs: &Self) -> Result<()>

Source

pub fn broadcast_minimum_(&self, lhs: &Self, rhs: &Self) -> Result<()>

Source

pub fn to_dtype_<U: WithDType>(&self, src: &Tensor<U, B>) -> Result<()>

Source

pub fn transpose_(&self, src: &Self, dim1: usize, dim2: usize) -> Result<()>

Source

pub fn copy_(&self, src: &Self) -> Result<()>

Source

pub fn fill_(&self, value: T) -> Result<()>

Source

pub fn scale_(&self, src: &Self, m: T) -> Result<()>

Source

pub fn add_scalar_(&self, src: &Self, a: T) -> Result<()>

Source

pub fn scale_add_(&self, src: &Self, scale: T, add: T) -> Result<()>

Source§

impl<B: Backend> Tensor<f32, B>

Source

pub fn randn_(&self, mean: f32, std: f32) -> Result<()>

Source

pub fn rand_uniform_(&self, lo: f32, up: f32) -> Result<()>

Source§

impl<T: WithDTypeF, B: Backend> Tensor<T, B>

Source

pub fn unary_(&self, src: &Self, op: UnaryOp) -> Result<()>

Source

pub fn cos_(&self, src: &Self) -> Result<()>

Source

pub fn sin_(&self, src: &Self) -> Result<()>

Source

pub fn exp_(&self, src: &Self) -> Result<()>

Source

pub fn log_(&self, src: &Self) -> Result<()>

Source

pub fn neg_(&self, src: &Self) -> Result<()>

Source

pub fn gelu_erf_(&self, src: &Self) -> Result<()>

Source

pub fn elu_(&self, src: &Self, alpha: f32) -> Result<()>

Source

pub fn abs_(&self, src: &Self) -> Result<()>

Source

pub fn sqr_(&self, src: &Self) -> Result<()>

Source

pub fn sqrt_(&self, src: &Self) -> Result<()>

Source

pub fn rsqrt_(&self, src: &Self) -> Result<()>

Source

pub fn relu_(&self, src: &Self) -> Result<()>

Source

pub fn tanh_(&self, src: &Self) -> Result<()>

Source

pub fn sigmoid_(&self, src: &Self) -> Result<()>

Source

pub fn silu_(&self, src: &Self) -> Result<()>

Source

pub fn softmax_(&self, src: &Self) -> Result<()>

Source

pub fn apply_causality_mask_(&self, offset: usize) -> Result<()>

Apply causality mask in-place. Shape: (batch * heads, seq_q, seq_kv) or (batch, heads, seq_q, seq_kv) Masks positions where key position > query position + offset (sets to -inf). offset: starting position of the first query token (for KV cache generation).

Source

pub fn rms_norm_(&self, src: &Self, alpha: &Self, eps: f32) -> Result<()>

Source

pub fn layer_norm_( &self, src: &Self, weight: &Self, bias: &Self, eps: f32, remove_mean: bool, ) -> Result<()>

Source

pub fn matmul_<L: TensorOrView<T, B>, R: TensorOrView<T, B>>( &self, lhs: &L, rhs: &R, rhs_t: bool, ) -> Result<()>

Source

pub fn rope_( &self, src: &Self, cos: &Self, sin: &Self, pos: usize, ) -> Result<()>

Source

pub fn rope_i_( &self, src: &Self, cos: &Self, sin: &Self, pos: usize, ) -> Result<()>

Source

pub fn reduce_max_(&self, src: &Self, dim: usize) -> Result<()>

Source

pub fn reduce_min_(&self, src: &Self, dim: usize) -> Result<()>

Source

pub fn reduce_argmin_<U: WithDTypeF>( dst: &Tensor<i64, B>, src: &Tensor<U, B>, dim: usize, ) -> Result<()>

Source

pub fn reduce_argmax_<U: WithDTypeF>( dst: &Tensor<i64, B>, src: &Tensor<U, B>, dim: usize, ) -> Result<()>

Source

pub fn reduce_sum_(&self, src: &Self, dim: usize) -> Result<()>

Source

pub fn conv1d_( &self, src: &Self, kernel: &Self, stride: usize, padding: usize, dilation: usize, groups: usize, ) -> Result<()>

Source

pub fn conv_transpose1d_( &self, src: &Self, kernel: &Self, stride: usize, padding: usize, output_padding: usize, groups: usize, ) -> Result<()>

Source§

impl<B: Backend> Tensor<f32, B>

Source

pub fn randn_like(&self, mean: f32, std: f32) -> Result<Self>

Source

pub fn rand_uniform_like(&self, lo: f32, up: f32) -> Result<Self>

Source

pub fn randn( &self, shape: impl Into<Shape>, mean: f32, std: f32, ) -> Result<Self>

Source

pub fn rand_uniform( &self, shape: impl Into<Shape>, lo: f32, up: f32, ) -> Result<Self>

Source§

impl<T: WithDType, B: Backend> Tensor<T, B>

Source

pub fn binary(&self, other: &Self, op: BinaryOp) -> Result<Self>

Source

pub fn broadcast_binary(&self, other: &Self, op: BinaryOp) -> Result<Self>

Source

pub fn add(&self, other: &Self) -> Result<Self>

Source

pub fn broadcast_add(&self, other: &Self) -> Result<Self>

Source

pub fn sub(&self, other: &Self) -> Result<Self>

Source

pub fn broadcast_sub(&self, other: &Self) -> Result<Self>

Source

pub fn mul(&self, other: &Self) -> Result<Self>

Source

pub fn broadcast_mul(&self, other: &Self) -> Result<Self>

Source

pub fn div(&self, other: &Self) -> Result<Self>

Source

pub fn broadcast_div(&self, other: &Self) -> Result<Self>

Source

pub fn minimum(&self, other: &Self) -> Result<Self>

Source

pub fn broadcast_minimum(&self, other: &Self) -> Result<Self>

Source

pub fn maximum(&self, other: &Self) -> Result<Self>

Source

pub fn broadcast_maximum(&self, other: &Self) -> Result<Self>

Source

pub fn transpose<D1: Dim, D2: Dim>( &self, dim1: D1, dim2: D2, ) -> Result<TensorView<T, B>>

Transpose two dimensions. Returns a TensorView (zero-copy). Call .contiguous()? on the result if you need a contiguous Tensor.

Source

pub fn copy(&self) -> Result<Self>

Source

pub fn full_like(&self, value: T) -> Result<Self>

Source

pub fn scale(&self, m: T) -> Result<Self>

Source

pub fn add_scalar(&self, a: T) -> Result<Self>

Source

pub fn scale_add(&self, scale: T, add: T) -> Result<Self>

Source

pub fn to<U: WithDType>(&self) -> Result<Tensor<U, B>>

Cast tensor to a different dtype.

Source

pub fn flatten_all(&self) -> Result<Self>

Flatten all dimensions into a single dimension.

Source

pub fn flatten<D: Dim>(&self, start_dim: D, end_dim: D) -> Result<Self>

Flatten dimensions from start to end (inclusive) into a single dimension.

Source

pub fn zeros_like(&self) -> Result<Self>

Create a tensor of zeros with the same shape.

Source

pub fn t(&self) -> Result<TensorView<T, B>>

Transpose (swap last two dimensions). Returns a TensorView (zero-copy). Call .contiguous()? on the result if you need a contiguous Tensor.

Source

pub fn unsqueeze<D: Dim>(&self, dim: D) -> Result<Self>

Unsqueeze: add a dimension of size 1 at the given position.

Source§

impl<T: WithDTypeF, B: Backend> Tensor<T, B>

Source

pub fn cos(&self) -> Result<Self>

Source

pub fn sin(&self) -> Result<Self>

Source

pub fn silu(&self) -> Result<Self>

Source

pub fn softmax(&self) -> Result<Self>

Source

pub fn apply_causality_mask(&self, offset: usize) -> Result<Self>

Apply causality mask and return a new tensor. Shape: (batch * heads, seq_q, seq_kv) or (batch, heads, seq_q, seq_kv) Masks positions where key position > query position + offset (sets to -inf). offset: starting position of the first query token (for KV cache generation).

Source

pub fn rms_norm(&self, alpha: &Self, eps: f32) -> Result<Self>

Source

pub fn layer_norm(&self, weight: &Self, bias: &Self, eps: f32) -> Result<Self>

Source

pub fn layer_norm_rm( &self, weight: &Self, bias: &Self, eps: f32, remove_mean: bool, ) -> Result<Self>

Source

pub fn rope(&self, cos: &Self, sin: &Self, pos: usize) -> Result<Self>

Source

pub fn sdpa_decode( &self, k: &TensorView<T, B>, v: &TensorView<T, B>, mask: Option<&Self>, scale: f32, ) -> Result<Self>

Scaled-dot-product attention for a single query position (autoregressive decode).

self is the query, shape (b, 1, h, d). k and v are the accumulated keys and values, shape (b, kv, h, d) — the layout an attention cache is written in, so callers need no transposes. Returns (b, 1, h * d), ready for the output projection.

mask, when given, holds additive terms per key position (0 to keep it, -inf to drop it), applied to every head. It is either kv values, shared by the whole batch, or one row of kv values per batch entry, shaped (b, kv) or (b, 1, 1, kv) — which is how a batch of sequences padded to a common length hides each one’s padding. The per-row form spells kv out even when it is 1, so (b, 1) rather than (b,). A mask per head is not supported on either path, and neither is a rank-3 per-row mask: against the (b, h, 1, kv) scores a rank-3 mask’s first dimension is the head, so (b, 1, kv) is the same shape as the per-head (h, 1, kv) whenever b == h.

Backends advertising Backend::FUSED_SDPA_DECODE run this as one pass; otherwise it is composed from transpose/matmul/softmax, which is what the caller would have written by hand.

Source

pub fn rope_i(&self, cos: &Self, sin: &Self, pos: usize) -> Result<Self>

Source

pub fn conv1d( &self, kernel: &Self, bias: Option<&Self>, stride: usize, padding: usize, dilation: usize, groups: usize, ) -> Result<Self>

1D convolution. Input: (batch, in_channels, length) Kernel: (out_channels, in_channels/groups, kernel_size) Output: (batch, out_channels, out_length)

The kernel is treated as a model parameter: on the CPU, the gemm keeps it packed between calls. Do not write it in place once it has been used.

Source

pub fn conv_transpose1d( &self, kernel: &Self, bias: Option<&Self>, stride: usize, padding: usize, output_padding: usize, groups: usize, ) -> Result<Self>

1D transposed convolution. Input: (batch, in_channels, length) Kernel: (in_channels, out_channels/groups, kernel_size) Output: (batch, out_channels, out_length)

The kernel is treated as a model parameter: on the CPU, the gemm keeps it packed between calls. Do not write it in place once it has been used.

Source

pub fn sqr(&self) -> Result<Self>

Element-wise square.

Source

pub fn sqrt(&self) -> Result<Self>

Element-wise square root.

Source

pub fn rsqrt(&self) -> Result<Self>

Element-wise reciprocal square root.

Source

pub fn abs(&self) -> Result<Self>

Element-wise absolute value.

Source

pub fn neg(&self) -> Result<Self>

Element-wise negation.

Source

pub fn log(&self) -> Result<Self>

Element-wise log.

Source

pub fn exp(&self) -> Result<Self>

Element-wise exponential.

Source

pub fn sum_keepdim(&self, dims: impl Into<Vec<usize>>) -> Result<Self>

Sum along dimensions, keeping the dimensions (with size 1).

Source

pub fn max<D: Dim>(&self, dim: D) -> Result<Self>

Maximum value along dimension.

Source

pub fn min<D: Dim>(&self, dim: D) -> Result<Self>

Minimum value along dimension.

Source

pub fn argmin<D: Dim>(&self, dim: D) -> Result<Tensor<i64, B>>

Argmin along dimension. Returns i64 indices.

Source

pub fn argmax<D: Dim>(&self, dim: D) -> Result<Tensor<i64, B>>

Argmax along dimension. Returns i64 indices.

Source

pub fn gelu_erf(&self) -> Result<Self>

GELU activation with erf.

Source

pub fn elu(&self, alpha: f32) -> Result<Self>

ELU activation.

Source

pub fn relu(&self) -> Result<Self>

ReLU activation.

Source

pub fn tanh(&self) -> Result<Self>

Tanh activation.

Source

pub fn sigmoid(&self) -> Result<Self>

Sigmoid activation.

Source

pub fn expand(&self, shape: impl Into<Shape>) -> Result<TensorView<T, B>>

Expand tensor to a new shape (broadcasting).

Source

pub fn pad_with_zeros<D: Dim>( &self, dim: D, left: usize, right: usize, ) -> Result<Self>

Pad with zeros along a dimension.

Source

pub fn pad_with_same<D: Dim>( &self, dim: D, left: usize, right: usize, ) -> Result<Self>

Pad by replicating boundary values.

Source

pub fn matmul_t<R: TensorOrView<T, B>>(&self, rhs: &R) -> Result<Self>

Source

pub fn matmul<R: TensorOrView<T, B>>(&self, rhs: &R) -> Result<Self>

Source§

impl<T: WithDType, B: Backend> Tensor<T, B>

Source

pub fn save_safetensors(&self, name: &str, path: impl AsRef<Path>) -> Result<()>

Save this tensor to a safetensors file with the given name.

Source§

impl<T: WithDType, B: Backend> Tensor<T, B>

Source

pub fn dims0(&self) -> Result<()>

Source§

impl<T: WithDType, B: Backend> Tensor<T, B>

Source

pub fn dims1(&self) -> Result<usize>

Source§

impl<T: WithDType, B: Backend> Tensor<T, B>

Source

pub fn dims2(&self) -> Result<(usize, usize)>

Source§

impl<T: WithDType, B: Backend> Tensor<T, B>

Source

pub fn dims3(&self) -> Result<(usize, usize, usize)>

Source§

impl<T: WithDType, B: Backend> Tensor<T, B>

Source

pub fn dims4(&self) -> Result<(usize, usize, usize, usize)>

Source§

impl<T: WithDType, B: Backend> Tensor<T, B>

Source

pub fn dims5(&self) -> Result<(usize, usize, usize, usize, usize)>

Source§

impl<T: WithDType, B: Backend> Tensor<T, B>

Source

pub fn dtype(&self) -> DType

Source

pub fn shape(&self) -> &Shape

Source

pub fn elem_count(&self) -> usize

Source

pub fn rank(&self) -> usize

Source

pub fn dims(&self) -> &[usize]

Source

pub fn dim(&self, index: impl Dim) -> Result<usize>

Source

pub fn device(&self) -> &B

Source

pub fn storage(&self) -> Result<RwLockReadGuard<'_, B::Storage<T>>>

Borrow the underlying storage immutably. Returns an error if the storage is currently mutably borrowed.

Source

pub fn storage_mut(&self) -> Result<RwLockWriteGuard<'_, B::Storage<T>>>

Borrow the underlying storage mutably. Returns an error if the storage is currently borrowed (mutably or immutably).

Source

pub fn zeros(shape: impl Into<Shape>, device: &B) -> Result<Self>

Source

pub fn to_vec(&self) -> Result<Vec<T>>

Source

pub fn to_scalar(&self) -> Result<T>

Source

pub fn to_vec1(&self) -> Result<Vec<T>>

Source

pub fn to_vec2(&self) -> Result<Vec<Vec<T>>>

Source

pub fn to_vec3(&self) -> Result<Vec<Vec<Vec<T>>>>

Source

pub fn full(value: T, shape: impl Into<Shape>, device: &B) -> Result<Self>

Source

pub fn broadcast_as<S: Into<Shape>>(&self, shape: S) -> Result<TensorView<T, B>>

Source

pub fn reshape(&self, shape: impl ShapeWithOneHole) -> Result<Self>

Reshape the tensor to a new shape with the same number of elements. This operation shares the underlying data (no copy).

Source

pub fn squeeze(&self, dim: impl Dim) -> Result<Self>

Source

pub fn narrow( &self, dim: impl Dim, range: impl RangeBounds<usize>, ) -> Result<TensorView<T, B>>

Extract a slice of the tensor along a given dimension. Returns a TensorView (zero-copy). Call .contiguous()? on the result if you need a contiguous Tensor.

Source

pub unsafe fn alloc_uninit(shape: impl Into<Shape>, dev: &B) -> Result<Self>

§Safety

The returned tensor’s data is uninitialized.

Source

pub fn index_select( &self, indices: &Tensor<i64, B>, dim: impl Dim, ) -> Result<Self>

Source

pub fn from_vec<S: ShapeWithOneHole>( data: Vec<T>, shape: S, dev: &B, ) -> Result<Self>

Source

pub fn cat(tensors: &[&Self], dim: impl Dim) -> Result<Self>

Concatenate tensors along a given dimension.

Source

pub fn stack(tensors: &[&Self], dim: impl Dim) -> Result<Self>

Stack tensors along a new dimension. All tensors must have the same shape. The new dimension is inserted at position dim.

Source

pub fn downcast(&self) -> Result<TypedTensor<B>>

Source

pub fn slice_set(&self, src: &Self, dim: impl Dim, offset: usize) -> Result<()>

Set the values on self using values from src. The copy starts at the specified offset for the target dimension dim on self.

self and src must have the same shape except on dimension dim where the self size has to be greater than or equal to offset plus the src size.

Note that this modifies self in place.

Source

pub fn slice_assign<D: Dim>( &self, src: &Self, dim: D, offset: usize, ) -> Result<()>

Source

pub fn scatter<D: Dim>( &self, indexes: &Tensor<i64, B>, source: &Self, dim: D, ) -> Result<Self>

Source

pub fn scatter_set<D: Dim>( &self, indexes: &Tensor<i64, B>, source: &Self, dim: D, ) -> Result<()>

Source

pub fn apply<M: Module>(&self, m: &M) -> Result<Self>

Trait Implementations§

Source§

impl<T: WithDType, B: Backend> Clone for Tensor<T, B>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: WithDType, B: Backend> Debug for Tensor<T, B>

Source§

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

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

impl<T: WithDType, B: Backend> Display for Tensor<T, B>

Source§

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

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

impl<'a, B: Backend> From<&'a Tensor<f32, B>> for FloatOrTensor<'a, B>

Source§

fn from(value: &'a Tensor<f32, B>) -> Self

Converts to this type from the input type.
Source§

impl<T: WithDType, B: Backend> From<&Tensor<T, B>> for TensorView<T, B>

Source§

fn from(inner: &Tensor<T, B>) -> Self

Converts to this type from the input type.
Source§

impl<T: WithDTypeF, B: Backend> From<Tensor<T, B>> for StreamTensor<T, B>

Source§

fn from(t: Tensor<T, B>) -> Self

Converts to this type from the input type.
Source§

impl<T: WithDTypeF, B: Backend> From<Tensor<T, B>> for StreamTensor<T, B>

Source§

fn from(t: Tensor<T, B>) -> Self

Converts to this type from the input type.
Source§

impl<T: WithDType, B: Backend> From<Tensor<T, B>> for TensorView<T, B>

Source§

fn from(inner: Tensor<T, B>) -> Self

Converts to this type from the input type.
Source§

impl<T: WithDType, B: Backend> TensorOrView<T, B> for Tensor<T, B>

Source§

fn shape(&self) -> &Shape

Source§

fn storage_and_offset( &self, ) -> Result<(RwLockReadGuard<'_, B::Storage<T>>, usize)>

Source§

fn strides(&self) -> Cow<'_, [usize]>

Source§

fn device(&self) -> &B

Source§

fn rank(&self) -> usize

Source§

fn dims(&self) -> &[usize]

Source§

impl<T: WithDType, B: Backend> TryFrom<&Tensor<T, B>> for Vec<T>

Source§

type Error = Error

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

fn try_from(tensor: &Tensor<T, B>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<T: WithDType, B: Backend> TryFrom<&Tensor<T, B>> for Vec<Vec<T>>

Source§

type Error = Error

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

fn try_from(tensor: &Tensor<T, B>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<T: WithDType, B: Backend> TryFrom<&Tensor<T, B>> for Vec<Vec<Vec<T>>>

Source§

type Error = Error

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

fn try_from(tensor: &Tensor<T, B>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<B: Backend> TryFrom<&Tensor<bf16, B>> for bf16

Source§

type Error = Error

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

fn try_from(tensor: &Tensor<bf16, B>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<B: Backend> TryFrom<&Tensor<f16, B>> for f16

Source§

type Error = Error

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

fn try_from(tensor: &Tensor<f16, B>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<B: Backend> TryFrom<&Tensor<f32, B>> for f32

Source§

type Error = Error

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

fn try_from(tensor: &Tensor<f32, B>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<B: Backend> TryFrom<&Tensor<i64, B>> for i64

Source§

type Error = Error

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

fn try_from(tensor: &Tensor<i64, B>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<B: Backend> TryFrom<&Tensor<u8, B>> for u8

Source§

type Error = Error

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

fn try_from(tensor: &Tensor<u8, B>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<T: WithDType, B: Backend> TryFrom<Tensor<T, B>> for Vec<T>

Source§

type Error = Error

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

fn try_from(tensor: Tensor<T, B>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<T: WithDType, B: Backend> TryFrom<Tensor<T, B>> for Vec<Vec<T>>

Source§

type Error = Error

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

fn try_from(tensor: Tensor<T, B>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<T: WithDType, B: Backend> TryFrom<Tensor<T, B>> for Vec<Vec<Vec<T>>>

Source§

type Error = Error

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

fn try_from(tensor: Tensor<T, B>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<B: Backend> TryFrom<Tensor<bf16, B>> for bf16

Source§

type Error = Error

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

fn try_from(tensor: Tensor<bf16, B>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<B: Backend> TryFrom<Tensor<f16, B>> for f16

Source§

type Error = Error

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

fn try_from(tensor: Tensor<f16, B>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<B: Backend> TryFrom<Tensor<f32, B>> for f32

Source§

type Error = Error

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

fn try_from(tensor: Tensor<f32, B>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<B: Backend> TryFrom<Tensor<i64, B>> for i64

Source§

type Error = Error

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

fn try_from(tensor: Tensor<i64, B>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<B: Backend> TryFrom<Tensor<u8, B>> for u8

Source§

type Error = Error

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

fn try_from(tensor: Tensor<u8, B>) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<T, B> Forget for Tensor<T, B>

§

impl<T, B> Freeze for Tensor<T, B>
where Arc<RwLock<<B as Backend>::Storage<T>>>: Freeze, B: Freeze, PhantomData<T>: Freeze,

§

impl<T, B> Move for Tensor<T, B>

§

impl<T, B> RefUnwindSafe for Tensor<T, B>

§

impl<T, B> Send for Tensor<T, B>
where Arc<RwLock<<B as Backend>::Storage<T>>>: Send, PhantomData<T>: Send,

§

impl<T, B> Sync for Tensor<T, B>
where Arc<RwLock<<B as Backend>::Storage<T>>>: Sync, PhantomData<T>: Sync,

§

impl<T, B> Unpin for Tensor<T, B>
where B: Unpin, Arc<RwLock<<B as Backend>::Storage<T>>>: Unpin, PhantomData<T>: Unpin,

§

impl<T, B> UnsafeUnpin for Tensor<T, B>

§

impl<T, B> UnwindSafe for Tensor<T, B>

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

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> 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> ThreadSafe for T
where T: Send + Sync + ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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 = !

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more