mnn::tensor

Struct Tensor

source
pub struct Tensor<T: TensorType> { /* private fields */ }
Expand description

A generic tensor that can of host / device / owned / borrowed

Implementations§

source§

impl<H: HalideType> Tensor<Host<H>>

source

pub fn as_ref(&self) -> Tensor<Ref<'_, Host<H>>>

Get’s a reference to an owned host tensor

source§

impl<H: HalideType> Tensor<Device<H>>

source

pub fn as_ref(&self) -> Tensor<Ref<'_, Device<H>>>

Get’s a reference to an owned device tensor

source§

impl<T: TensorType> Tensor<T>
where T::H: HalideType,

source

pub unsafe fn from_ptr(tensor: *mut Tensor) -> Self

This function constructs a Tensor type from a raw pointer

§Safety

Since this constructs a Tensor from a raw pointer we have no way to guarantee that it’s a valid tensor or it’s lifetime

source

pub fn copy_from_host_tensor( &mut self, tensor: &Tensor<Host<T::H>>, ) -> Result<()>

Copies the data from a host tensor to the self tensor

source

pub fn copy_to_host_tensor(&self, tensor: &mut Tensor<Host<T::H>>) -> Result<()>

Copies the data from the self tensor to a host tensor

source

pub fn device_id(&self) -> u64

Get the device id of the tensor

source

pub fn shape(&self) -> TensorShape

Get the shape of the tensor

source

pub fn dimensions(&self) -> usize

Get the dimensions of the tensor

source

pub fn width(&self) -> u32

Get the width of the tensor

source

pub fn height(&self) -> u32

Get the height of the tensor

source

pub fn channel(&self) -> u32

Get the channel size of the tensor

source

pub fn batch(&self) -> u32

Get the batch size of the tensor

source

pub fn size(&self) -> usize

Get the size of the tensor when counted by bytes

source

pub fn element_size(&self) -> usize

Get the size of the tensor when counted by elements

source

pub fn print_shape(&self)

Print the shape of the tensor

source

pub fn print(&self)

Print the tensor

source

pub fn is_dynamic_unsized(&self) -> bool

Check if the tensor is dynamic and needs resizing

source

pub unsafe fn halide_buffer(&self) -> *const halide_buffer_t

DO not use this function directly

§Safety

This is just provided as a 1:1 compat mostly for possible later use

source

pub unsafe fn halide_buffer_mut(&self) -> *mut halide_buffer_t

Do not use this function directly

§Safety

This is just provided as a 1:1 compat mostly for possible later use

source

pub fn get_dimension_type(&self) -> DimensionType

Get the dimension type of the tensor

source

pub fn get_type(&self) -> halide_type_t

Get the data type of the tensor

source

pub fn is_type_of<H: HalideType>(&self) -> bool

Check if the tensor is of the specified data type

source

pub unsafe fn into_raw(self) -> RawTensor<'static>

§Safety

This is very unsafe do not use this unless you know what you are doing

source§

impl<T: MutableTensorType> Tensor<T>
where T::H: HalideType,

source

pub fn fill(&mut self, value: T::H)
where T::H: Copy,

Fill the tensor with the specified value

source§

impl<T: HostTensorType> Tensor<T>
where T::H: HalideType,

source

pub fn try_host(&self) -> Result<&[T::H]>

Try to map the device tensor to the host memory and get the slice

source

pub fn try_host_mut(&mut self) -> Result<&mut [T::H]>

Try to map the device tensor to the host memory and get the mutable slice

source

pub fn host(&self) -> &[T::H]

Get the host memory slice of the tensor

source

pub fn host_mut(&mut self) -> &mut [T::H]

Get the mutable host memory slice of the tensor

source§

impl<T: DeviceTensorType> Tensor<T>
where T::H: HalideType,

source

pub fn wait(&self, map_type: MapType, finish: bool)

Try to wait for the device tensor to finish processing

source

pub fn create_host_tensor_from_device( &self, copy_data: bool, ) -> Tensor<Host<T::H>>

Create a host tensor from the device tensor with same dimensions and data type and optionally copy the data from the device tensor

source§

impl<T: OwnedTensorType> Tensor<T>
where T::H: HalideType,

source

pub fn new(shape: impl AsTensorShape, dm_type: DimensionType) -> Self

Create a new tensor with the specified shape and dimension type

source§

impl<T: HostTensorType + RefTensorType> Tensor<T>
where T::H: HalideType,

source

pub fn borrowed(shape: impl AsTensorShape, input: impl AsRef<[T::H]>) -> Self

Try to create a ref tensor from any array-like type

source

pub fn borrowed_mut( shape: impl AsTensorShape, input: impl AsMut<[T::H]>, ) -> Self

Try to create a mutable ref tensor from any array-like type

Trait Implementations§

source§

impl<T: OwnedTensorType> Clone for Tensor<T>
where T::H: HalideType,

source§

fn clone(&self) -> Tensor<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: TensorType> Drop for Tensor<T>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Tensor<T>

§

impl<T> RefUnwindSafe for Tensor<T>
where T: RefUnwindSafe,

§

impl<T> !Send for Tensor<T>

§

impl<T> !Sync for Tensor<T>

§

impl<T> Unpin for Tensor<T>
where T: Unpin,

§

impl<T> UnwindSafe for Tensor<T>
where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.