Skip to main content

DataMatrix

Struct DataMatrix 

Source
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

Source

pub fn new(row_len: usize) -> Self

An empty matrix whose rows span row_len feature columns.

Source

pub fn len(&self) -> usize

Number of rows.

Source

pub fn is_empty(&self) -> bool

Whether the matrix has no rows.

Source

pub const fn row_len(&self) -> usize

Number of feature columns.

Source

pub fn blocks(&self) -> usize

Number of storage blocks allocated.

Source

pub fn count_nonzero(&self) -> usize

Total set features across every row.

Source

pub fn allocated_bytes(&self) -> usize

Bytes of storage currently allocated for indices and row descriptors.

Source

pub fn row(&self, index: usize) -> Option<RowSlice<'_>>

Borrow the logical row at index.

Source

pub fn iter(&self) -> impl Iterator<Item = RowSlice<'_>> + '_

Iterate over the rows in logical order.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DataMatrix

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DataMatrix

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for DataMatrix

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

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§

fn from_iter<I: IntoIterator<Item = DataRow>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl PartialEq for DataMatrix

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for DataMatrix

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.