pub struct RowSlice<'a> { /* private fields */ }Expand description
A borrowed view of one row’s set features.
All the read-only row operations live here, so they are written once and shared by an owned
DataRow and by a row of a DataMatrix.
Implementations§
Source§impl<'a> RowSlice<'a>
impl<'a> RowSlice<'a>
Sourcepub fn get(&self, index: usize) -> Option<f32>
pub fn get(&self, index: usize) -> Option<f32>
Value of the feature at index, or None if index is out of bounds.
Costs a binary search over the set features, unlike the other accessors here. Prefer
RowSlice::iter_nonzero when visiting a whole row.
Sourcepub fn iter(self) -> impl Iterator<Item = f32> + 'a
pub fn iter(self) -> impl Iterator<Item = f32> + 'a
Iterate over every feature value, including the zeroes.
Walks the columns in step with the set features, so it costs the column count rather than a binary search per column.
Sourcepub fn iter_nonzero(self) -> impl Iterator<Item = (usize, f32)> + 'a
pub fn iter_nonzero(self) -> impl Iterator<Item = (usize, f32)> + 'a
Iterate over the index and value of the set features only.
This is the cheap way to read a row: it visits only what is present.
Sourcepub const fn count_nonzero(&self) -> usize
pub const fn count_nonzero(&self) -> usize
Number of set features in the row.
Sourcepub fn sum(&self) -> f32
pub fn sum(&self) -> f32
Sum of the feature values, which for a presence row is the number set.
Sourcepub fn dot(&self, weights: &[f32]) -> f32
pub fn dot(&self, weights: &[f32]) -> f32
Dot product of this row with a weight vector.
Only the set features contribute, so this reads one weight per set feature. Indices
beyond the end of weights are ignored.
Sourcepub fn retain_indices(&self, keep: &[usize]) -> DataRow
pub fn retain_indices(&self, keep: &[usize]) -> DataRow
An owned row holding only the features at the given indices, renumbered to their
positions in keep.
keep must be sorted ascending. Used to drop the features a trained model found
unnecessary.
Trait Implementations§
impl<'a> Copy for RowSlice<'a>
Auto Trait Implementations§
impl<'a> Freeze for RowSlice<'a>
impl<'a> RefUnwindSafe for RowSlice<'a>
impl<'a> Send for RowSlice<'a>
impl<'a> Sync for RowSlice<'a>
impl<'a> Unpin for RowSlice<'a>
impl<'a> UnsafeUnpin for RowSlice<'a>
impl<'a> UnwindSafe for RowSlice<'a>
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> 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