Skip to main content

GradStore

Struct GradStore 

Source
pub struct GradStore<T: FloatDType>(/* private fields */);

Implementations§

Source§

impl<T: FloatDType> GradStore<T>

Source

pub fn new() -> Self

Create a new gradient store

Source

pub fn get(&self, tensor: &Tensor<T>) -> Option<&Tensor<T>>

Get the gradient tensor associated with the given tensor

Source

pub fn get_by_index(&self, index: usize) -> Option<&Tensor<T>>

Source

pub fn remove(&mut self, tensor: &Tensor<T>) -> Option<Tensor<T>>

Remove the gradient tensor associated with the given tensor, returning it if it exists

Source

pub fn insert( &mut self, tensor: &Tensor<T>, grad: Tensor<T>, ) -> Option<Tensor<T>>

Insert a gradient tensor associated with the given tensor, returning the previous gradient tensor if it existed

Source

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

Get the gradient tensor associated with the given tensor, or, if it does not exist, insert a tensor of zeroes, with the same shape and type as the given tensors and return it

Source

pub fn get_ids(&self) -> impl Iterator<Item = &TensorId>

Get the tensor ids of the stored gradient tensors

Source

pub fn tensors(&self) -> impl Iterator<Item = &Tensor<T>>

Source

pub fn iter(&self) -> Iter<'_, TensorId, Tensor<T>>

Source

pub fn len(&self) -> usize

Trait Implementations§

Source§

impl<T: Clone + FloatDType> Clone for GradStore<T>

Source§

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

Returns a duplicate 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: Debug + FloatDType> Debug for GradStore<T>

Source§

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

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

impl<T: FloatDType> Index<&Tensor<T>> for GradStore<T>

Source§

type Output = Tensor<T>

The returned type after indexing.
Source§

fn index(&self, index: &Tensor<T>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more

Auto Trait Implementations§

§

impl<T> Freeze for GradStore<T>

§

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

§

impl<T> Send for GradStore<T>

§

impl<T> Sync for GradStore<T>

§

impl<T> Unpin for GradStore<T>

§

impl<T> UnsafeUnpin for GradStore<T>

§

impl<T> UnwindSafe for GradStore<T>
where T: RefUnwindSafe,

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.
Source§

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

Source§

fn vzip(self) -> V