pub trait TensorLike:
Send
+ Sync
+ Debug {
Show 17 methods
// Required methods
fn as_any(&self) -> &dyn Any;
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<TensorRef>;
fn reshape(&self, shape: &[usize]) -> Result<TensorRef>;
fn to_cpu(&self) -> Result<TensorRef>;
fn to_device(&self, device: &Device) -> Result<TensorRef>;
fn to_dtype(&self, dtype: DataType) -> Result<TensorRef>;
// 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>> { ... }
fn to_vec_u32(&self) -> Result<Vec<u32>> { ... }
fn argmax_last_dim_u32(&self) -> Result<u32> { ... }
}Expand description
Core tensor trait for zero-copy, device-aware operations
Required Methods§
Sourcefn is_contiguous(&self) -> bool
fn is_contiguous(&self) -> bool
Check if tensor is contiguous in memory
Sourcefn view(&self, start: &[usize], end: &[usize]) -> Result<TensorRef>
fn view(&self, start: &[usize], end: &[usize]) -> Result<TensorRef>
Create a view/slice of this tensor
Provided Methods§
Sourcefn size_bytes(&self) -> usize
fn size_bytes(&self) -> usize
Get size in bytes for this tensor
Sourcefn to_vec_f32(&self) -> Result<Vec<f32>>
fn to_vec_f32(&self) -> Result<Vec<f32>>
Extract tensor data as Vec
Sourcefn to_vec_u32(&self) -> Result<Vec<u32>>
fn to_vec_u32(&self) -> Result<Vec<u32>>
Extract tensor data as Vec
Sourcefn argmax_last_dim_u32(&self) -> Result<u32>
fn argmax_last_dim_u32(&self) -> Result<u32>
Fast path: argmax over the last dimension, returning the selected token id.
Backends may override this to avoid transferring full logits to CPU.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".