Skip to main content

TensorLike

Trait TensorLike 

Source
pub trait TensorLike:
    Send
    + Sync
    + Debug {
Show 17 methods // Required methods fn as_any(&self) -> &(dyn Any + 'static); fn shape(&self) -> &[usize]; fn dtype(&self) -> DataType; fn device(&self) -> Device; fn is_contiguous(&self) -> bool; fn view( &self, start: &[usize], end: &[usize], ) -> Result<Arc<dyn TensorLike>, FerrumError>; fn reshape( &self, shape: &[usize], ) -> Result<Arc<dyn TensorLike>, FerrumError>; fn to_cpu(&self) -> Result<Arc<dyn TensorLike>, FerrumError>; fn to_device( &self, device: &Device, ) -> Result<Arc<dyn TensorLike>, FerrumError>; fn to_dtype( &self, dtype: DataType, ) -> Result<Arc<dyn TensorLike>, FerrumError>; // Provided methods fn numel(&self) -> usize { ... } fn ndim(&self) -> usize { ... } fn is_scalar(&self) -> bool { ... } fn size_bytes(&self) -> usize { ... } fn to_vec_f32(&self) -> Result<Vec<f32>, FerrumError> { ... } fn to_vec_u32(&self) -> Result<Vec<u32>, FerrumError> { ... } fn argmax_last_dim_u32(&self) -> Result<u32, FerrumError> { ... }
}
Expand description

Core tensor trait for zero-copy, device-aware operations

Required Methods§

Source

fn as_any(&self) -> &(dyn Any + 'static)

Downcast support for backend-specific fast paths

Source

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

Get tensor shape

Source

fn dtype(&self) -> DataType

Get tensor data type

Source

fn device(&self) -> Device

Get device where tensor resides

Source

fn is_contiguous(&self) -> bool

Check if tensor is contiguous in memory

Source

fn view( &self, start: &[usize], end: &[usize], ) -> Result<Arc<dyn TensorLike>, FerrumError>

Create a view/slice of this tensor

Source

fn reshape(&self, shape: &[usize]) -> Result<Arc<dyn TensorLike>, FerrumError>

Reshape tensor to new shape (must have same number of elements)

Source

fn to_cpu(&self) -> Result<Arc<dyn TensorLike>, FerrumError>

Convert tensor to CPU device

Source

fn to_device(&self, device: &Device) -> Result<Arc<dyn TensorLike>, FerrumError>

Convert tensor to specific device

Source

fn to_dtype(&self, dtype: DataType) -> Result<Arc<dyn TensorLike>, FerrumError>

Convert tensor to specific data type

Provided Methods§

Source

fn numel(&self) -> usize

Get total number of elements

Source

fn ndim(&self) -> usize

Get number of dimensions

Source

fn is_scalar(&self) -> bool

Check if tensor is scalar (0-dimensional)

Source

fn size_bytes(&self) -> usize

Get size in bytes for this tensor

Source

fn to_vec_f32(&self) -> Result<Vec<f32>, FerrumError>

Extract tensor data as Vec (for logits sampling) This is a convenience method for backends that need to extract data

Source

fn to_vec_u32(&self) -> Result<Vec<u32>, FerrumError>

Extract tensor data as Vec (for token IDs) This is a convenience method for backends that need to extract token data

Source

fn argmax_last_dim_u32(&self) -> Result<u32, FerrumError>

Fast path: argmax over the last dimension, returning the selected token id.

Backends may override this to avoid transferring full logits to CPU.

Implementors§