Skip to main content

TensorTrait

Trait TensorTrait 

Source
pub trait TensorTrait<T>: Send + Sync
where T: Num + Clone + Debug,
{ // Required methods fn new(shape: &[usize], name: Option<&str>) -> Result<Self> where Self: Sized; fn from_fd(fd: OwnedFd, shape: &[usize], name: Option<&str>) -> Result<Self> where Self: Sized; fn clone_fd(&self) -> Result<OwnedFd>; fn memory(&self) -> TensorMemory; fn name(&self) -> String; fn shape(&self) -> &[usize]; fn reshape(&mut self, shape: &[usize]) -> Result<()>; fn map(&self) -> Result<TensorMap<T>>; // Provided methods fn len(&self) -> usize { ... } fn is_empty(&self) -> bool { ... } fn size(&self) -> usize { ... } }

Required Methods§

Source

fn new(shape: &[usize], name: Option<&str>) -> Result<Self>
where Self: Sized,

Create a new tensor with the given shape and optional name. If no name is given, a random name will be generated.

Source

fn from_fd(fd: OwnedFd, shape: &[usize], name: Option<&str>) -> Result<Self>
where Self: Sized,

Create a new tensor using the given file descriptor, shape, and optional name. If no name is given, a random name will be generated.

On Linux: Inspects the fd to determine DMA vs SHM based on device major/minor. On other Unix (macOS): Always creates SHM tensor.

Source

fn clone_fd(&self) -> Result<OwnedFd>

Clone the file descriptor associated with this tensor.

Source

fn memory(&self) -> TensorMemory

Get the memory type of this tensor.

Source

fn name(&self) -> String

Get the name of this tensor.

Source

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

Get the shape of this tensor.

Source

fn reshape(&mut self, shape: &[usize]) -> Result<()>

Reshape this tensor to the given shape. The total number of elements must remain the same.

Source

fn map(&self) -> Result<TensorMap<T>>

Map the tensor into memory and return a TensorMap for accessing the data.

Provided Methods§

Source

fn len(&self) -> usize

Get the number of elements in this tensor.

Source

fn is_empty(&self) -> bool

Check if the tensor is empty.

Source

fn size(&self) -> usize

Get the size in bytes of this tensor.

Implementors§

Source§

impl<T> TensorTrait<T> for Tensor<T>
where T: Num + Clone + Debug + Send + Sync,

Source§

impl<T> TensorTrait<T> for DmaTensor<T>
where T: Num + Clone + Debug + Send + Sync,

Source§

impl<T> TensorTrait<T> for MemTensor<T>
where T: Num + Clone + Debug + Send + Sync,

Source§

impl<T> TensorTrait<T> for ShmTensor<T>
where T: Num + Clone + Debug + Send + Sync,