Skip to main content

SparseRunningStatistics

Struct SparseRunningStatistics 

Source
pub struct SparseRunningStatistics<T>
where T: Float,
{ /* private fields */ }
Expand description

Running statistics that accepts sparse column input but stores sufficient statistics in dense vectors.

This is more efficient than RunningStatistics<Ix1> when the input data is sparse and has many rows, as it avoids materializing dense matrices during reads.

Implementations§

Source§

impl<T> SparseRunningStatistics<T>
where T: Float + AddAssign + Sum + Zero,

Source

pub fn new(nrows: usize) -> Self

Create a new SparseRunningStatistics object

§Arguments
  • nrows - Number of rows (features)
Source

pub fn add_sparse_column(&mut self, row_indices: &[usize], values: &[T])

Add a sparse column (row indices + values) to the running statistics. The column advances ncols_processed by one.

Source

pub fn nrows(&self) -> usize

Source

pub fn ncols_processed(&self) -> usize

Source

pub fn to_vecs(&self) -> (Vec<T>, Vec<T>, Vec<T>, Vec<T>)

Convert to owned vectors (npos, sum, mean, std)

Source

pub fn add_csc(&mut self, csc: &CscMatrix<T>)

Add columns from a CscMatrix

§Arguments
  • csc - Sparse matrix in CSC format
Source

pub fn add_dense_column(&mut self, values: &[T])

Add a dense column directly. Skips zero / non-finite entries so npos stays equivalent to what add_sparse_column would produce — useful when an upstream coarsening step yields a dense [D, n] intermediate we don’t want to re-sparsify.

Loop is structured for autovectorization: hoists the running-sum and running-square accumulations through zip_eq over independent &mut slices (no aliasing), and uses a branchless 1/0 mask for the npos increment so the compiler can emit cmov / vmaskmovps instead of a control-flow branch per element.

Source

pub fn add_dense_column_scaled(&mut self, values: &[T], scale: T)

Self::add_dense_column with every value scaled by scale on the way in. Folding the multiply into the accumulation loop touches each element once, where scale-into-a-buffer-then-add would write and re-read the whole column.

Source

pub fn add_dense_columns(&mut self, dense: &DMatrix<T>)
where T: Scalar,

Add every column of a dense [D, n] matrix in column-major order. Calls add_dense_column per column so the inner loop stays vectorizable; the per-column overhead is negligible (one += 1 for ncols_processed) compared to the per-element accumulation work.

Source

pub fn merge(&mut self, other: &Self)

Combine another SparseRunningStatistics into this one. Used to reduce per-thread accumulators back to a single result without holding a global lock during the streaming pass.

Source§

impl<T> SparseRunningStatistics<T>

Source

pub fn save(&self, filename: &str, names: &[Box<str>], sep: &str) -> Result<()>

Save the statistics to a file (parquet if filename ends with .parquet, otherwise a separator-delimited text file).

Source

pub fn to_f32_vecs(&self) -> (Vec<f32>, Vec<f32>, Vec<f32>, Vec<f32>)

Get statistics as vectors (nnz, tot, mu, sig) converted to f32

Source

pub fn to_string_vec( &self, names: &[Box<str>], sep: &str, ) -> Result<Vec<Box<str>>>

Convert statistics to string vectors for output

Trait Implementations§

Source§

impl<T> Clone for SparseRunningStatistics<T>
where T: Float + Clone,

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<T> RunningStatOps<T> for SparseRunningStatistics<T>
where T: Float + AddAssign + Sum + Zero,

Source§

fn count_positives(&self) -> Vec<T>

Count of positive (non-zero) values per row

Source§

fn sum(&self) -> Vec<T>

Sum per row

Source§

fn mean(&self) -> Vec<T>

Mean per row Uses ncols_processed as the denominator (implicit zeros count)

Source§

fn variance(&self) -> Vec<T>

Variance per row

Source§

fn std(&self) -> Vec<T>

Standard deviation per row

Source§

type Output = Vec<T>

Source§

fn clear(&mut self)

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> ErasedDestructor for T
where T: 'static,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V