pub struct Tensor { /* private fields */ }Expand description
A multi-dimensional array for neural network operations.
Tensors are the primary data structure for MNN inference, holding input and output data for models.
Implementations§
Source§impl Tensor
impl Tensor
Sourcepub unsafe fn from_ptr(ptr: *mut MNNTensor, name: Option<String>) -> Self
pub unsafe fn from_ptr(ptr: *mut MNNTensor, name: Option<String>) -> Self
Create a tensor wrapper around an existing MNN tensor pointer (public version).
§Safety
The pointer must be valid and remain valid for the lifetime of this tensor.
Sourcepub fn inner_mut(&mut self) -> *mut MNNTensor
pub fn inner_mut(&mut self) -> *mut MNNTensor
Get the mutable raw pointer to the underlying MNN tensor.
Sourcepub fn format(&self) -> DataFormat
pub fn format(&self) -> DataFormat
Get the data format of the tensor.
Sourcepub fn element_count(&self) -> i32
pub fn element_count(&self) -> i32
Get the total number of elements in the tensor.
Sourcepub fn read<T: TensorData>(&self) -> MnnResult<Vec<T>>
pub fn read<T: TensorData>(&self) -> MnnResult<Vec<T>>
Sourcepub unsafe fn as_slice_mut<T: TensorData>(&mut self) -> MnnResult<&mut [T]>
pub unsafe fn as_slice_mut<T: TensorData>(&mut self) -> MnnResult<&mut [T]>
Get a mutable reference to the tensor’s host data.
§Safety
The returned slice is valid only as long as no other operations are performed on the tensor.
Sourcepub unsafe fn as_slice<T: TensorData>(&self) -> MnnResult<&[T]>
pub unsafe fn as_slice<T: TensorData>(&self) -> MnnResult<&[T]>
Get a reference to the tensor’s host data.
§Safety
The returned slice is valid only as long as no other operations are performed on the tensor.
Sourcepub fn info(&self) -> TensorInfo
pub fn info(&self) -> TensorInfo
Get the tensor info.
Sourcepub fn copy_from_host(&mut self, host_tensor: &Tensor) -> MnnResult<()>
pub fn copy_from_host(&mut self, host_tensor: &Tensor) -> MnnResult<()>
Sourcepub fn copy_to_host(&self, host_tensor: &mut Tensor) -> MnnResult<()>
pub fn copy_to_host(&self, host_tensor: &mut Tensor) -> MnnResult<()>
Sourcepub fn create_device(
shape: &[i32],
format: DataFormat,
dtype: DataType,
) -> MnnResult<Tensor>
pub fn create_device( shape: &[i32], format: DataFormat, dtype: DataType, ) -> MnnResult<Tensor>
Sourcepub fn device_id(&self) -> u64
pub fn device_id(&self) -> u64
Get the device ID for this tensor (for GPU tensors).
§Returns
The device ID, or 0 if not a GPU tensor or unknown.