Skip to main content

TensorMetadata

Trait TensorMetadata 

pub trait TensorMetadata:
    Clone
    + Send
    + Sync
    + Debug {
    type Device: DeviceOps;

    // Required methods
    fn dtype(&self) -> DType;
    fn shape(&self) -> Shape;
    fn device(&self) -> Self::Device;
    fn can_mut(&self) -> bool;

    // Provided methods
    fn rank(&self) -> usize { ... }
    fn scheme(&self) -> QuantScheme { ... }
}
Expand description

Tensor metadata trait for tensor primitive.

Required Associated Types§

type Device: DeviceOps

The device type associated with the tensor.

Required Methods§

fn dtype(&self) -> DType

Get the dtype of the tensor.

fn shape(&self) -> Shape

Get the shape of the tensor.

fn device(&self) -> Self::Device

Get the device associated with the tensor.

fn can_mut(&self) -> bool

Whether the tensor’s buffer can be mutated in place — i.e. this handle uniquely owns it, so an in-place op (slice_assign, an inplace kernel) writes the existing allocation instead of copying it first.

Backends that track buffer ownership (cubecl, fusion, tch) answer precisely; a backend that can’t must return a conservative false — the buffer may be aliased, so an in-place write can’t be assumed safe.

Provided Methods§

fn rank(&self) -> usize

Get the number of dimensions of the tensor.

fn scheme(&self) -> QuantScheme

Get the quantization scheme for a quantized float tensor.

§Panics

Panics if the tensor is not quantized.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§