pub enum Tensor<T>{
Dma(DmaTensor<T>),
Shm(ShmTensor<T>),
Mem(MemTensor<T>),
}Variants§
Implementations§
Source§impl<T> Tensor<T>
impl<T> Tensor<T>
Sourcepub fn new(
shape: &[usize],
memory: Option<TensorMemory>,
name: Option<&str>,
) -> Result<Self>
pub fn new( shape: &[usize], memory: Option<TensorMemory>, name: Option<&str>, ) -> Result<Self>
Create a new tensor with the given shape, memory type, and optional name. If no name is given, a random name will be generated. If no memory type is given, the best available memory type will be chosen based on the platform and environment variables.
On Linux platforms, the order of preference is: Dma -> Shm -> Mem. On other Unix platforms (macOS), the order is: Shm -> Mem. On non-Unix platforms, only Mem is available.
§Environment Variables
EDGEFIRST_TENSOR_FORCE_MEM: If set to a non-zero and non-false value, forces the use of regular system memory allocation (TensorMemory::Mem) regardless of platform capabilities.
§Example
use edgefirst_tensor::{Error, Tensor, TensorMemory, TensorTrait};
let tensor = Tensor::<f32>::new(&[2, 3, 4], Some(TensorMemory::Mem), Some("test_tensor"))?;
assert_eq!(tensor.memory(), TensorMemory::Mem);
assert_eq!(tensor.name(), "test_tensor");Trait Implementations§
Source§impl<T> TensorTrait<T> for Tensor<T>
impl<T> TensorTrait<T> for Tensor<T>
Source§fn from_fd(fd: OwnedFd, shape: &[usize], name: Option<&str>) -> Result<Self>
fn from_fd(fd: OwnedFd, shape: &[usize], name: Option<&str>) -> Result<Self>
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 file descriptor to determine the appropriate tensor type (Dma or Shm) based on the device major and minor numbers. On other Unix (macOS): Always creates SHM tensor.
Source§fn new(shape: &[usize], name: Option<&str>) -> Result<Self>
fn new(shape: &[usize], name: Option<&str>) -> Result<Self>
Create a new tensor with the given shape and optional name. If no name
is given, a random name will be generated.
Source§fn memory(&self) -> TensorMemory
fn memory(&self) -> TensorMemory
Get the memory type of this tensor.
Source§fn reshape(&mut self, shape: &[usize]) -> Result<()>
fn reshape(&mut self, shape: &[usize]) -> Result<()>
Reshape this tensor to the given shape. The total number of elements
must remain the same.
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more