pub struct CooGradient { /* private fields */ }Expand description
Sparse gradient for a 1-D dense parameter / embedding-row view, stored as a coordinate list (COO).
The representation is kept canonical: indices is strictly ascending, so the
entries are sorted and free of duplicates, and every index is < dim.
Implementations§
Source§impl CooGradient
impl CooGradient
Sourcepub fn new(
indices: Vec<usize>,
values: Vec<f64>,
dim: usize,
) -> Result<Self, GpuOptimError>
pub fn new( indices: Vec<usize>, values: Vec<f64>, dim: usize, ) -> Result<Self, GpuOptimError>
Build a canonical COO gradient from already sorted, unique indices.
§Errors
Returns GpuOptimError::InvalidState when indices and values have
mismatched lengths or when indices is not strictly ascending, and
GpuOptimError::DimensionMismatch when any index is >= dim.
Sourcepub fn new_unsorted(
indices: Vec<usize>,
values: Vec<f64>,
dim: usize,
) -> Result<Self, GpuOptimError>
pub fn new_unsorted( indices: Vec<usize>, values: Vec<f64>, dim: usize, ) -> Result<Self, GpuOptimError>
Build a COO gradient from arbitrary (possibly unsorted, possibly duplicated) coordinate/value pairs.
Duplicate indices are accumulated (their gradient values are summed), which matches the semantics of looking up the same embedding row multiple times within one mini-batch. The result is canonicalized to strictly ascending indices.
§Errors
Returns an error when lengths mismatch or when any index is >= dim.
Sourcepub fn validate(&self) -> Result<(), GpuOptimError>
pub fn validate(&self) -> Result<(), GpuOptimError>
Validate the structural invariants: matching lengths, strictly ascending indices and in-bounds indices.
§Errors
See CooGradient::new.
Sourcepub fn values(&self) -> &[f64]
pub fn values(&self) -> &[f64]
Gradient values (parallel to CooGradient::indices).
Trait Implementations§
Source§impl Clone for CooGradient
impl Clone for CooGradient
Source§fn clone(&self) -> CooGradient
fn clone(&self) -> CooGradient
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CooGradient
impl Debug for CooGradient
Source§impl From<&CsrGradient> for CooGradient
impl From<&CsrGradient> for CooGradient
Source§fn from(csr: &CsrGradient) -> Self
fn from(csr: &CsrGradient) -> Self
Source§impl PartialEq for CooGradient
impl PartialEq for CooGradient
impl StructuralPartialEq for CooGradient
Auto Trait Implementations§
impl Freeze for CooGradient
impl RefUnwindSafe for CooGradient
impl Send for CooGradient
impl Sync for CooGradient
impl Unpin for CooGradient
impl UnsafeUnpin for CooGradient
impl UnwindSafe for CooGradient
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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