This reference describes unreleased code on main; no release documents it yet.

rlmesh::Tensor

structPreviewuse rlmesh::Tensor;[source]

An immutable n-dimensional array with shared storage.

struct Tensor

The constructor copies its buffer; Clone, buffer and a contiguous reshape share storage, and copy makes a fresh one. Strides are in bytes.

PartialEq compares dtype, shape and element bytes.

from_dlpack

associated function[source]
unsafe fn from_dlpack(
    obj: NonNull<DLManagedTensorVersioned>,
) -> Result<Tensor>

Copy a versioned CPU DLPack tensor into fresh contiguous storage. On success, calls the producer’s deleter; on error, ownership stays with the caller, who may recover it with DlpackTensor::from_raw.

Safety

obj must point to a live, exclusively owned managed tensor. Its shape/stride arrays must be readable for ndim entries and all described element addresses must be readable, initialized CPU bytes for the duration of the call. The producer must not mutate them concurrently. The deleter must be valid to call once on success.

new

associated function[source]
fn new(buffer: &[u8], shape: &[usize], dtype: DType) -> Result<Tensor>

Copy buffer into a C-contiguous tensor of shape and dtype, as Tensor(buffer, shape, dtype). buffer must hold exactly size * itemsize bytes.

to_dlpack

method[source]
fn to_dlpack(&self, options: ToDlpackOptions) -> Result<DlpackTensor>

Export a DLPack 1.0 tensor, sharing read-only storage by default. A copying export owns fresh writable storage. The returned owner keeps storage and layout alive even after this tensor is destroyed.

dlpack_device

method[source]
fn dlpack_device(&self) -> (i32, i32)

The DLPack device (kDLCPU, 0).

shape

method[source]
fn shape(&self) -> &[usize]

Dimension sizes, C order.

dtype

method[source]
fn dtype(&self) -> DType

Element dtype.

ndim

method[source]
fn ndim(&self) -> usize

Number of dimensions.

size

method[source]
fn size(&self) -> usize

Number of elements.

nbytes

method[source]
fn nbytes(&self) -> usize

Size of the elements in bytes (size * itemsize).

strides

method[source]
fn strides(&self) -> Vec<usize>

Strides in bytes, one per dimension.

device

method[source]
fn device(&self) -> Device

The device the storage lives on.

buffer

method[source]
fn buffer(&self) -> &[u8]

The bytes from the first element, read-only and shared: nbytes long when contiguous, else through the last byte the strides address.

is_contiguous

method[source]
fn is_contiguous(&self) -> bool

Whether the elements are laid out C-contiguously.

reshape

method[source]
fn reshape(&self, shape: &[i64]) -> Result<Tensor>

The same elements in a new shape; one dimension may be -1. Shares storage when contiguous.

copy

method[source]
fn copy(&self) -> Tensor

A deep, contiguous copy.

tobytes

method[source]
fn tobytes(&self) -> Vec<u8>

The elements as C-ordered bytes (a copy).

Trait implementations

  • impl TensorExt for Tensor
  • impl Clone for Tensor
  • impl Display for Tensor
  • impl Debug for Tensor
  • impl PartialEq for Tensor
  • impl From<Tensor> for Value