pub struct ExclusiveTensor<E, D>where
D: Dimension,{ /* private fields */ }Expand description
An exclusive owner of a Tensor and its data.
Given an ordinary Tensor, it is impossible to reason about the lifetime of the data at
Tensor::data_ptr. Copies created by Tensor::shallow_clone share the same underlying
tensor object and can cause the data memory to be moved or reallocated at any time (for
example, by calling Tensor::resize_]).
To avoid this issue, ExclusiveTensor manages the creation of the tensor such that it has
exclusive access to the underlying data. An ExclusiveTensor can never provide &Tensor
references to the managed tensor.
The managed tensor always lives on the CPU device.
Implementations§
Source§impl<E, D> ExclusiveTensor<E, D>
impl<E, D> ExclusiveTensor<E, D>
Sourcepub fn zeros<Sh: IntoDimension<Dim = D>>(shape: Sh) -> Self
pub fn zeros<Sh: IntoDimension<Dim = D>>(shape: Sh) -> Self
Create a zero-initialized tensor.
Sourcepub fn ones<Sh: IntoDimension<Dim = D>>(shape: Sh) -> Self
pub fn ones<Sh: IntoDimension<Dim = D>>(shape: Sh) -> Self
Create a one-initialized tensor.
Source§impl<E, D: Dimension> ExclusiveTensor<E, D>
impl<E, D: Dimension> ExclusiveTensor<E, D>
Sourcepub fn into_tensor(self) -> Tensor
pub fn into_tensor(self) -> Tensor
Convert into the inner tensor.
Source§impl<E> ExclusiveTensor<E, IxDyn>where
E: Element,
impl<E> ExclusiveTensor<E, IxDyn>where
E: Element,
Sourcepub fn try_copy_from(tensor: &Tensor) -> Result<Self, ExclusiveTensorError>
pub fn try_copy_from(tensor: &Tensor) -> Result<Self, ExclusiveTensorError>
Try to create a dynamic-shape tensor by deep copying from a Tensor.
The tensor dtype must match the element type E.
Source§impl<E, D> ExclusiveTensor<E, D>
impl<E, D> ExclusiveTensor<E, D>
Sourcepub fn as_slice_mut(&mut self) -> &mut [E]
pub fn as_slice_mut(&mut self) -> &mut [E]
View the tensor data as a mutable slice.
Sourcepub fn array_view(&self) -> ArrayView<'_, E, D>
pub fn array_view(&self) -> ArrayView<'_, E, D>
View as an n-dimensional array.
Sourcepub fn array_view_mut(&mut self) -> ArrayViewMut<'_, E, D>
pub fn array_view_mut(&mut self) -> ArrayViewMut<'_, E, D>
View as a mutable n-dimensional array.
Trait Implementations§
Source§impl<E: Debug, D> Debug for ExclusiveTensor<E, D>
impl<E: Debug, D> Debug for ExclusiveTensor<E, D>
Source§impl<'a, E, D> From<&'a ExclusiveTensor<E, D>> for ArrayView<'a, E, D>
impl<'a, E, D> From<&'a ExclusiveTensor<E, D>> for ArrayView<'a, E, D>
Source§fn from(exclusive: &'a ExclusiveTensor<E, D>) -> Self
fn from(exclusive: &'a ExclusiveTensor<E, D>) -> Self
Source§impl<E, D: Dimension> From<ExclusiveTensor<E, D>> for Tensor
impl<E, D: Dimension> From<ExclusiveTensor<E, D>> for Tensor
Source§fn from(exclusive: ExclusiveTensor<E, D>) -> Self
fn from(exclusive: ExclusiveTensor<E, D>) -> Self
Source§impl<A: Element> NumArray1D for ExclusiveTensor<A, Ix1>
impl<A: Element> NumArray1D for ExclusiveTensor<A, Ix1>
type Elem = A
Source§fn zeros(size: usize) -> Self
fn zeros(size: usize) -> Self
Source§fn ones(size: usize) -> Self
fn ones(size: usize) -> Self
Source§fn as_slice_mut(&mut self) -> &mut [Self::Elem]
fn as_slice_mut(&mut self) -> &mut [Self::Elem]
Source§impl<A: Element> NumArray2D for ExclusiveTensor<A, Ix2>
impl<A: Element> NumArray2D for ExclusiveTensor<A, Ix2>
type Elem = A
Source§fn zeros(size: (usize, usize)) -> Self
fn zeros(size: (usize, usize)) -> Self
Source§fn ones(size: (usize, usize)) -> Self
fn ones(size: (usize, usize)) -> Self
Source§fn view_mut(&mut self) -> ArrayViewMut<'_, Self::Elem, Ix2>
fn view_mut(&mut self) -> ArrayViewMut<'_, Self::Elem, Ix2>
ArrayViewMut.Auto Trait Implementations§
impl<E, D> Freeze for ExclusiveTensor<E, D>where
D: Freeze,
impl<E, D> RefUnwindSafe for ExclusiveTensor<E, D>where
D: RefUnwindSafe,
E: RefUnwindSafe,
impl<E, D> Send for ExclusiveTensor<E, D>where
E: Send,
impl<E, D> !Sync for ExclusiveTensor<E, D>
impl<E, D> Unpin for ExclusiveTensor<E, D>
impl<E, D> UnwindSafe for ExclusiveTensor<E, D>where
D: UnwindSafe,
E: 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
Source§impl<T> BuildFromArray1D for Twhere
T: NumArray1D,
impl<T> BuildFromArray1D for Twhere
T: NumArray1D,
Source§impl<T> BuildFromArray2D for Twhere
T: NumArray2D,
impl<T> BuildFromArray2D for Twhere
T: NumArray2D,
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>
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>
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