lazymatrix::NormalizedColumn
LazyMatrix for Rust · 0.12.0
pub struct NormalizedColumn<'a, C, P>A borrowed column with row or ordered normalization.
The view borrows raw storage and fitted parameters without copying, fitting, gathering, or decoding. Logical entries combine raw duplicates in storage order before applying each saved stage. Borrowing takes O(1) time.
Reductions and dense updates visit every logical row, including implicit zeros, in O(nrows * stages + stored entries) time. Dense slices and sorted, unique sparse columns use constant workspace. Other storage orders and duplicates use one O(nrows) working column to coalesce raw values. The view itself and individual reads allocate nothing.
Sparse views expose their generally dense, row-dependent background through Self::implicit_value and scaled raw corrections through Self::stored_corrections. Adding those parts may differ from direct normalization through rounding or nonfinite arithmetic. Use Self::get or Self::normalize_value for direct stage-by-stage evaluation.
A view cannot outlive the operator or its fitted parameters:
use lazymatrix::{LazyMatrix, RawColumns};
fn escaped<M: RawColumns<f64>>(data: M) -> f64 {
let column = {
let op = LazyMatrix::from_row_parts(data, None, None);
op.column(0)
};
column.get(0)
}Inherent implementation
impl<'a, C, P> NormalizedColumn<'a, C, P>normalization
pub fn normalization(&self) -> &'a PBorrow the saved parameters for the complete matrix.
raw
pub fn raw(&self) -> &CBorrow the backend's raw column view.
Inherent implementation
impl<'a, F: Scalar, P: NormalizationParams<Scalar = F>> NormalizedColumn<'a, lazymatrix::SparseColumnRef<'a, F>, P>raw_sum
pub fn raw_sum(&self) -> FSum raw stored values without applying normalization.
row_indices
pub fn row_indices(&self) -> &'a [usize]Raw stored row indices in storage order, retaining duplicates.
stored_corrections
pub fn stored_corrections(&self) -> impl Iterator<Item = (usize, F)> + '_Stored corrections as (row, scaled raw value), without allocating.
Preserves storage order, duplicates, and explicit zeros. Each correction applies scales in stage order, taking O(stages) time. See the type documentation for numerical limitations.
values
pub fn values(&self) -> &'a [F]Raw stored values, including explicitly stored zeros.
Inherent implementation
impl<C, P> NormalizedColumn<'_, C, P> where P: NormalizationParams, C: RawColumn<<P as NormalizationParams>::Scalar>dot
pub fn dot<V: VectorView<<P as NormalizationParams>::Scalar> + ?Sized>(
&self,
vector: &V
) -> <P as NormalizationParams>::ScalarDot product with a vector, including transformed implicit zeros.
See the type documentation for time and workspace bounds.
Panics
Panics if vector.len() != self.len().
dot_with_sum
pub fn dot_with_sum<V: VectorView<<P as NormalizationParams>::Scalar> + ?Sized>(
&self,
vector: &V,
_vector_sum: <P as NormalizationParams>::Scalar
) -> <P as NormalizationParams>::ScalarDot product accepting a cached vector sum for LogicalColumn parity.
The sum is ignored because a scalar total cannot account for row-dependent normalization. Complexity and panics match Self::dot.
get
pub fn get(&self, row: usize) -> <P as NormalizationParams>::ScalarRead a logical entry, combining raw duplicates in storage order first.
Dense slices take O(stages) time; other raw columns take O(stored entries + stages) time. This allocates nothing and preserves stored signed zeros before normalization.
Panics
Panics if row >= self.len().
implicit_value
pub fn implicit_value(&self, row: usize) -> <P as NormalizationParams>::ScalarLogical value at a structurally absent row, in O(stages) time.
Panics
Panics if row >= self.len().
is_empty
pub fn is_empty(&self) -> boolWhether the column has no logical rows.
len
pub fn len(&self) -> usizeLogical length, including structurally absent entries.
norm_squared
pub fn norm_squared(&self) -> <P as NormalizationParams>::ScalarSum squared logical entries after applying every stage in order.
See the type documentation for time and workspace bounds.
normalize_value
pub fn normalize_value(
&self,
row: usize,
raw: <P as NormalizationParams>::Scalar
) -> <P as NormalizationParams>::ScalarApply every saved stage to a coalesced raw value in row row.
This takes O(stages) time and allocates nothing. Sum raw duplicates before calling this method.
Panics
Panics if row >= self.len().
scaled_add_to
pub fn scaled_add_to<V: VectorViewMut<<P as NormalizationParams>::Scalar> + ?Sized>(
&self,
alpha: <P as NormalizationParams>::Scalar,
destination: &mut V
)Add alpha times each logical entry to a dense destination.
Normalizes each coalesced value before multiplying by alpha. See the type documentation for time and workspace bounds.
Panics
Panics if destination.len() != self.len().
sum
pub fn sum(&self) -> <P as NormalizationParams>::ScalarSum logical entries, including transformed implicit zeros.
See the type documentation for time and workspace bounds.
weighted_dot
pub fn weighted_dot<V, W>(
&self,
vector: &V,
weights: &W
) -> <P as NormalizationParams>::Scalar where V: VectorView<<P as NormalizationParams>::Scalar> + ?Sized, W: VectorView<<P as NormalizationParams>::Scalar> + ?SizedCompute sum_i weights[i] * self[i] * vector[i] on logical entries.
See the type documentation for time and workspace bounds.
Panics
Panics unless vector.len() == weights.len() == self.len().
weighted_dot_with_sum
pub fn weighted_dot_with_sum<V, W>(
&self,
vector: &V,
weights: &W,
_weighted_vector_sum: <P as NormalizationParams>::Scalar
) -> <P as NormalizationParams>::Scalar where V: VectorView<<P as NormalizationParams>::Scalar> + ?Sized, W: VectorView<<P as NormalizationParams>::Scalar> + ?SizedWeighted dot product accepting a cached sum for LogicalColumn parity.
The cached total is ignored. Complexity and panics match Self::weighted_dot.
weighted_norm_squared
pub fn weighted_norm_squared<W: VectorView<<P as NormalizationParams>::Scalar> + ?Sized>(
&self,
weights: &W
) -> <P as NormalizationParams>::ScalarSum weights[i] * self[i]^2, including implicit zeros and signed weights.
Normalizes before squaring and visits implicit rows directly, preserving small contributions and IEEE nonfinite arithmetic. See the type documentation for time and workspace bounds.
Panics
Panics if weights.len() != self.len().
weighted_norm_squared_with_sum
pub fn weighted_norm_squared_with_sum<W: VectorView<<P as NormalizationParams>::Scalar> + ?Sized>(
&self,
weights: &W,
_weight_sum: <P as NormalizationParams>::Scalar
) -> <P as NormalizationParams>::ScalarWeighted squared norm accepting a cached total for LogicalColumn parity.
The cached total is ignored to preserve implicit-row contributions. Complexity and panics match Self::weighted_norm_squared.
Implementation of Clone
impl<C: Clone, P> Clone for NormalizedColumn<'_, C, P>clone
fn clone(&self) -> SelfImplementation of Copy
impl<C: Copy, P> Copy for NormalizedColumn<'_, C, P>Implementation of Debug
impl<'a, C: core::fmt::Debug, P: core::fmt::Debug> Debug for NormalizedColumn<'a, C, P>fmt
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::ResultImplementation of LogicalColumn
impl<C, P> LogicalColumn<<P as NormalizationParams>::Scalar> for NormalizedColumn<'_, C, P> where P: NormalizationParams, C: RawColumn<<P as NormalizationParams>::Scalar>dot
fn dot<V: VectorView<<P as NormalizationParams>::Scalar> + ?Sized>(
&self,
vector: &V
) -> <P as NormalizationParams>::Scalardot_with_sum
fn dot_with_sum<V: VectorView<<P as NormalizationParams>::Scalar> + ?Sized>(
&self,
vector: &V,
sum: <P as NormalizationParams>::Scalar
) -> <P as NormalizationParams>::Scalarget
fn get(&self, row: usize) -> <P as NormalizationParams>::Scalarlen
fn len(&self) -> usizenorm_squared
fn norm_squared(&self) -> <P as NormalizationParams>::Scalarscaled_add_to
fn scaled_add_to<V: VectorViewMut<<P as NormalizationParams>::Scalar> + ?Sized>(
&self,
alpha: <P as NormalizationParams>::Scalar,
destination: &mut V
)sum
fn sum(&self) -> <P as NormalizationParams>::Scalarweighted_dot
fn weighted_dot<V, W>(
&self,
vector: &V,
weights: &W
) -> <P as NormalizationParams>::Scalar where V: VectorView<<P as NormalizationParams>::Scalar> + ?Sized, W: VectorView<<P as NormalizationParams>::Scalar> + ?Sizedweighted_dot_with_sum
fn weighted_dot_with_sum<V, W>(
&self,
vector: &V,
weights: &W,
sum: <P as NormalizationParams>::Scalar
) -> <P as NormalizationParams>::Scalar where V: VectorView<<P as NormalizationParams>::Scalar> + ?Sized, W: VectorView<<P as NormalizationParams>::Scalar> + ?Sizedweighted_norm_squared
fn weighted_norm_squared<W: VectorView<<P as NormalizationParams>::Scalar> + ?Sized>(
&self,
weights: &W
) -> <P as NormalizationParams>::Scalarweighted_norm_squared_with_sum
fn weighted_norm_squared_with_sum<W: VectorView<<P as NormalizationParams>::Scalar> + ?Sized>(
&self,
weights: &W,
sum: <P as NormalizationParams>::Scalar
) -> <P as NormalizationParams>::ScalarImplementation of Freeze
impl<'a, C, P> Freeze for NormalizedColumn<'a, C, P> where C: Freeze, &'a P: FreezeImplementation of RefUnwindSafe
impl<'a, C, P> RefUnwindSafe for NormalizedColumn<'a, C, P> where C: RefUnwindSafe, &'a P: RefUnwindSafeImplementation of Send
impl<'a, C, P> Send for NormalizedColumn<'a, C, P> where C: Send, &'a P: SendImplementation of Sync
impl<'a, C, P> Sync for NormalizedColumn<'a, C, P> where C: Sync, &'a P: SyncImplementation of Unpin
impl<'a, C, P> Unpin for NormalizedColumn<'a, C, P> where C: Unpin, &'a P: UnpinImplementation of UnsafeUnpin
impl<'a, C, P> UnsafeUnpin for NormalizedColumn<'a, C, P> where C: UnsafeUnpin, &'a P: UnsafeUnpinImplementation of UnwindSafe
impl<'a, C, P> UnwindSafe for NormalizedColumn<'a, C, P> where C: UnwindSafe, &'a P: UnwindSafeImplementation of Any
impl<T> Any for T where T: 'static + ?SizedImplementation of Borrow
impl<T> Borrow<T> for T where T: ?SizedImplementation of BorrowMut
impl<T> BorrowMut<T> for T where T: ?SizedImplementation of ByRef
impl<T> ByRef<T> for TImplementation of CastableFrom
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT where ST: ?Sized, DT: ?SizedImplementation of CastableFrom
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT where ST: ?Sized, DT: ?SizedImplementation of CloneToUninit
impl<T> CloneToUninit for T where T: CloneImplementation of From
impl<T> From<T> for TImplementation of Imply
impl<T, U> Imply<T> for U where T: ?Sized, U: ?SizedImplementation of Into
impl<T, U> Into<U> for T where U: From<T>Implementation of IntoEither
impl<T> IntoEither for TImplementation of Pointable
impl<T> Pointable for TImplementation of Read
impl<T> Read<Exclusive, BecauseExclusive> for T where T: ?SizedImplementation of Same
impl<T> Same for TImplementation of SupersetOf
impl<SS, SP> SupersetOf<SS> for SP where SS: SubsetOf<SP>Implementation of ToOwned
impl<T> ToOwned for T where T: CloneImplementation of TryFrom
impl<T, U> TryFrom<U> for T where U: Into<T>Implementation of TryInto
impl<T, U> TryInto<U> for T where U: TryFrom<T>
