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§
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<Arc<dyn TensorLike>, FerrumError>
fn view( &self, start: &[usize], end: &[usize], ) -> Result<Arc<dyn TensorLike>, FerrumError>
Create a view/slice of this tensor
Sourcefn reshape(&self, shape: &[usize]) -> Result<Arc<dyn TensorLike>, FerrumError>
fn reshape(&self, shape: &[usize]) -> Result<Arc<dyn TensorLike>, FerrumError>
Reshape tensor to new shape (must have same number of elements)
Sourcefn to_cpu(&self) -> Result<Arc<dyn TensorLike>, FerrumError>
fn to_cpu(&self) -> Result<Arc<dyn TensorLike>, FerrumError>
Convert tensor to CPU device
Sourcefn to_device(&self, device: &Device) -> Result<Arc<dyn TensorLike>, FerrumError>
fn to_device(&self, device: &Device) -> Result<Arc<dyn TensorLike>, FerrumError>
Convert tensor to specific device
Sourcefn to_dtype(&self, dtype: DataType) -> Result<Arc<dyn TensorLike>, FerrumError>
fn to_dtype(&self, dtype: DataType) -> Result<Arc<dyn TensorLike>, FerrumError>
Convert tensor to specific data type
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>, FerrumError>
fn to_vec_f32(&self) -> Result<Vec<f32>, FerrumError>
Extract tensor data as Vec
Sourcefn to_vec_u32(&self) -> Result<Vec<u32>, FerrumError>
fn to_vec_u32(&self) -> Result<Vec<u32>, FerrumError>
Extract tensor data as Vec
Sourcefn argmax_last_dim_u32(&self) -> Result<u32, FerrumError>
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.