ExclusiveTensor

Struct ExclusiveTensor 

Source
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>
where E: Element, D: Dimension + IntoTorchShape,

Source

pub fn zeros<Sh: IntoDimension<Dim = D>>(shape: Sh) -> Self

Create a zero-initialized tensor.

Source

pub fn ones<Sh: IntoDimension<Dim = D>>(shape: Sh) -> Self

Create a one-initialized tensor.

Source§

impl<E, D: Dimension> ExclusiveTensor<E, D>

Source

pub fn into_tensor(self) -> Tensor

Convert into the inner tensor.

Source§

impl<E> ExclusiveTensor<E, IxDyn>
where E: Element,

Source

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>
where E: Element, D: Dimension,

Source

pub fn as_slice(&self) -> &[E]

View the tensor data as a slice.

Source

pub fn as_slice_mut(&mut self) -> &mut [E]

View the tensor data as a mutable slice.

Source

pub fn array_view(&self) -> ArrayView<'_, E, D>

View as an n-dimensional array.

Source

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>
where D: Dimension + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, E, D> From<&'a ExclusiveTensor<E, D>> for ArrayView<'a, E, D>
where E: Element, D: Dimension,

Source§

fn from(exclusive: &'a ExclusiveTensor<E, D>) -> Self

Converts to this type from the input type.
Source§

impl<E, D: Dimension> From<ExclusiveTensor<E, D>> for Tensor

Source§

fn from(exclusive: ExclusiveTensor<E, D>) -> Self

Converts to this type from the input type.
Source§

impl<A: Element> NumArray1D for ExclusiveTensor<A, Ix1>

Source§

type Elem = A

Source§

fn zeros(size: usize) -> Self

Create a new instance of the given size with all elements initialized to zero.
Source§

fn ones(size: usize) -> Self

Create a new instance of the given size with all elements initialized to one.
Source§

fn as_slice(&self) -> &[Self::Elem]

View as a slice.
Source§

fn as_slice_mut(&mut self) -> &mut [Self::Elem]

View as a mutable slice.
Source§

impl<A: Element> NumArray2D for ExclusiveTensor<A, Ix2>

Source§

type Elem = A

Source§

fn zeros(size: (usize, usize)) -> Self

Create a new instance of the given size with all elements initialized to zero.
Source§

fn ones(size: (usize, usize)) -> Self

Create a new instance of the given size with all elements initialized to one.
Source§

fn view(&self) -> ArrayView<'_, Self::Elem, Ix2>

View as a two-dimensional ArrayView.
Source§

fn view_mut(&mut self) -> ArrayViewMut<'_, Self::Elem, Ix2>

Mutable view as a two-dimensional ArrayViewMut.

Auto Trait Implementations§

§

impl<E, D> Freeze for ExclusiveTensor<E, D>
where D: Freeze,

§

impl<E, D> RefUnwindSafe for ExclusiveTensor<E, D>

§

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>
where D: Unpin, E: Unpin,

§

impl<E, D> UnwindSafe for ExclusiveTensor<E, D>
where D: UnwindSafe, E: 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> AsAny for T
where T: Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert into an Any trait reference.
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> BuildFromArray1D for T
where T: NumArray1D,

Source§

type Array = T

Source§

impl<T> BuildFromArray2D for T
where T: NumArray2D,

Source§

type Array = T

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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> Wrap for T

Source§

fn wrap<W>(self, wrapper: W) -> Wrapped<Self, W>

Wrap in the given wrapper.