pub struct CsrGradient { /* private fields */ }Expand description
Sparse gradient for a 2-D embedding table, stored in compressed sparse row (CSR) form.
Invariants (checked by CsrGradient::validate):
row_offsets.len() == shape.0 + 1,row_offsets[0] == 0, monotonically non-decreasing, androw_offsets[shape.0] == col_indices.len().col_indices.len() == values.len().- within every row the column indices are strictly ascending and
< shape.1.
Implementations§
Source§impl CsrGradient
impl CsrGradient
Sourcepub fn new(
row_offsets: Vec<usize>,
col_indices: Vec<usize>,
values: Vec<f64>,
shape: (usize, usize),
) -> Result<Self, GpuOptimError>
pub fn new( row_offsets: Vec<usize>, col_indices: Vec<usize>, values: Vec<f64>, shape: (usize, usize), ) -> Result<Self, GpuOptimError>
Build a CSR gradient and validate it.
§Errors
Returns GpuOptimError::InvalidState / GpuOptimError::DimensionMismatch
when any structural invariant is violated.
Sourcepub fn empty(shape: (usize, usize)) -> Self
pub fn empty(shape: (usize, usize)) -> Self
Create an empty (all-zero) CSR gradient of the given shape.
Sourcepub fn validate(&self) -> Result<(), GpuOptimError>
pub fn validate(&self) -> Result<(), GpuOptimError>
Validate all CSR structural invariants.
§Errors
See the type-level documentation for the checked invariants.
Sourcepub fn row(&self, r: usize) -> Result<(&[usize], &[f64]), GpuOptimError>
pub fn row(&self, r: usize) -> Result<(&[usize], &[f64]), GpuOptimError>
Column indices and values stored for row r.
§Errors
Returns GpuOptimError::DimensionMismatch when r is out of range.
Sourcepub fn iter(&self) -> impl Iterator<Item = (usize, usize, f64)> + '_
pub fn iter(&self) -> impl Iterator<Item = (usize, usize, f64)> + '_
Iterate over (row, col, value) triplets in row-major (and within a row,
column-ascending) order.
Sourcepub fn to_coo(&self) -> CooGradient
pub fn to_coo(&self) -> CooGradient
Convert to a flattened 1-D CooGradient using linear indices
row * cols + col over a rows * cols view. The resulting indices are
globally ascending, so the COO gradient is already canonical.
Sourcepub fn from_coo(
coo: &CooGradient,
shape: (usize, usize),
) -> Result<Self, GpuOptimError>
pub fn from_coo( coo: &CooGradient, shape: (usize, usize), ) -> Result<Self, GpuOptimError>
Build a CSR gradient from a flattened 1-D CooGradient of dimension
shape.0 * shape.1, decoding each linear index into (row, col).
§Errors
Returns GpuOptimError::DimensionMismatch when coo.dim() does not
equal shape.0 * shape.1, or GpuOptimError::InvalidState when the
table would have zero columns while carrying entries.
Trait Implementations§
Source§impl Clone for CsrGradient
impl Clone for CsrGradient
Source§fn clone(&self) -> CsrGradient
fn clone(&self) -> CsrGradient
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 CsrGradient
impl Debug for CsrGradient
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 CsrGradient
impl PartialEq for CsrGradient
impl StructuralPartialEq for CsrGradient
Auto Trait Implementations§
impl Freeze for CsrGradient
impl RefUnwindSafe for CsrGradient
impl Send for CsrGradient
impl Sync for CsrGradient
impl Unpin for CsrGradient
impl UnsafeUnpin for CsrGradient
impl UnwindSafe for CsrGradient
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