pub struct DataRow { /* private fields */ }Expand description
One row of features, owning its storage.
A DataMatrix is the right choice for many rows; this is for the one-off cases, such as
featurizing a single file for inference.
Implementations§
Source§impl DataRow
impl DataRow
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.
Sourcepub fn set(&mut self, index: usize, value: f32) -> Result<()>
pub fn set(&mut self, index: usize, value: f32) -> Result<()>
Set the feature at index.
Idempotent, and accepts the columns in any order — it inserts so as to keep the indices
sorted, which costs a move of the tail. Prefer RowAccumulator when setting many.
§Errors
Returns an error if index is out of bounds, or if value is neither zero nor one. A
row records which features are present, so it cannot hold another value.
Sourcepub fn iter(&self) -> impl Iterator<Item = f32> + '_
pub fn iter(&self) -> impl Iterator<Item = f32> + '_
Iterate over every feature value, including the zeroes.
Sourcepub fn iter_nonzero(&self) -> impl Iterator<Item = (usize, f32)> + '_
pub fn iter_nonzero(&self) -> impl Iterator<Item = (usize, f32)> + '_
Iterate over the index and value of the set features only.
Sourcepub const fn count_nonzero(&self) -> usize
pub const fn count_nonzero(&self) -> usize
Number of set features in the row.
Sourcepub fn retain_indices(&self, keep: &[usize]) -> Self
pub fn retain_indices(&self, keep: &[usize]) -> Self
A new row holding only the features at the given indices, renumbered.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for DataRow
impl<'de> Deserialize<'de> for DataRow
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Source§impl FromIterator<DataRow> for DataMatrix
Collect owned rows into a matrix.
impl FromIterator<DataRow> for DataMatrix
Collect owned rows into a matrix.
Rows spanning a different number of columns are skipped rather than silently corrupting the matrix; the parsers check widths explicitly instead of relying on this.
impl StructuralPartialEq for DataRow
Auto Trait Implementations§
impl Freeze for DataRow
impl RefUnwindSafe for DataRow
impl Send for DataRow
impl Sync for DataRow
impl Unpin for DataRow
impl UnsafeUnpin for DataRow
impl UnwindSafe for DataRow
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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