pub struct DataMatrix { /* private fields */ }Expand description
Many rows over the same set of feature columns, stored in a handful of large blocks.
Each row’s indices are contiguous within one block. Rows are addressed logically and reordered by permuting a small table of row descriptors, so shuffling between epochs moves twelve bytes per row rather than the indices themselves.
Implementations§
Source§impl DataMatrix
impl DataMatrix
Sourcepub fn count_nonzero(&self) -> usize
pub fn count_nonzero(&self) -> usize
Total set features across every row.
Sourcepub fn allocated_bytes(&self) -> usize
pub fn allocated_bytes(&self) -> usize
Bytes of storage currently allocated for indices and row descriptors.
Sourcepub fn iter(&self) -> impl Iterator<Item = RowSlice<'_>> + '_
pub fn iter(&self) -> impl Iterator<Item = RowSlice<'_>> + '_
Iterate over the rows in logical order.
Sourcepub fn row_builder(&mut self) -> Result<RowBuilder<'_>>
pub fn row_builder(&mut self) -> Result<RowBuilder<'_>>
Start a new row. Call RowBuilder::finish to record it.
§Errors
Returns an error if the matrix already holds u32::MAX rows.
Sourcepub fn push_row(&mut self, row: RowSlice<'_>) -> Result<()>
pub fn push_row(&mut self, row: RowSlice<'_>) -> Result<()>
Append a copy of row.
§Errors
Returns an error if row spans a different number of columns, or if the matrix is
full.
Sourcepub fn permute(&mut self, permutation: &[usize]) -> Result<()>
pub fn permute(&mut self, permutation: &[usize]) -> Result<()>
Reorder the rows so that logical row i becomes what was logical row permutation[i].
Only the row descriptors move; no indices are copied.
§Errors
Returns an error if permutation isn’t the same length as the matrix.
Sourcepub fn split_off(&mut self, at: usize) -> Result<Self>
pub fn split_off(&mut self, at: usize) -> Result<Self>
Split off the logical rows from at onwards into a new matrix.
The rows are copied, because after a shuffle the logical tail is scattered across the blocks. The original keeps its blocks allocated, so this does not hand memory back.
§Errors
Returns an error if at is beyond the end, or if copying a row fails.
Sourcepub fn retain_indices(&mut self, keep: &[usize]) -> Result<()>
pub fn retain_indices(&mut self, keep: &[usize]) -> Result<()>
Rebuild every row to hold only the features at the given indices, renumbered.
keep must be sorted ascending. Builds a fresh matrix, so peak memory is the old rows
plus the new, narrower ones.
§Errors
Returns an error if the rebuilt matrix cannot accept a row, which cannot happen if it already holds them.
Sourcepub fn column_sums(&self) -> Vec<f32>
pub fn column_sums(&self) -> Vec<f32>
Sum each feature column across every row.
A single pass over the rows, touching only their set features.
Trait Implementations§
Source§impl Clone for DataMatrix
impl Clone for DataMatrix
Source§impl Debug for DataMatrix
impl Debug for DataMatrix
Source§impl Default for DataMatrix
impl Default for DataMatrix
Source§impl<'de> Deserialize<'de> for DataMatrix
impl<'de> Deserialize<'de> for DataMatrix
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.
Source§impl PartialEq for DataMatrix
impl PartialEq for DataMatrix
Auto Trait Implementations§
impl Freeze for DataMatrix
impl RefUnwindSafe for DataMatrix
impl Send for DataMatrix
impl Sync for DataMatrix
impl Unpin for DataMatrix
impl UnsafeUnpin for DataMatrix
impl UnwindSafe for DataMatrix
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