Skip to content

lazymatrix::IndexedRows ​

LazyMatrix for Rust · 0.9.0

Source

rust
pub struct IndexedRows<'a, M, F = f64>

A raw matrix restricted to strictly increasing, unique row indices.

Unlike crate::Submatrix, this selects data before normalization. Pass it to crate::LazyMatrix::new to fit on selected rows alone. Local row i maps to row_indices()[i] in the source. All columns are retained. Empty selections are allowed and follow crate::ColumnStats' empty-column rules. Invalid indices, duplicates, and descending indices panic at construction.

The wrapper owns M and borrows the index slice. Pass &matrix or a backend view to borrow storage without copying. Construction checks indices in O(k) time for k selected rows and allocates nothing. Cloning only clones M and the borrowed index slice; cloning an owned matrix can copy its storage.

Products and statistics use native source traversal. Dense scans cost O(k * ncols), CSR scans cost O(ncols + k + selected stored entries), and CSC scans cost O(k + ncols + stored entries * log(k + 1)). Sparse scans combine duplicate cells using O(k) CSC or O(ncols) CSR scratch. They never copy the design or convert its storage orientation. Reusable raw products need no additional scratch beyond traversal. Fused products with nonzero beta and centered dense fused products use O(output length) scratch. Nested raw selections allocate O(k) index mapping per scan. Statistics use O(ncols) state in addition to traversal scratch. SD uses two scans; quantiles use exact, data-dependent repeated scans, sharing scans for median and quantile range in crate::ColumnStats::normalization_stats.

RawColumns is available only if the source naturally borrows columns. Creating a filtered column allocates nothing; each traversal scans the parent column and maps selected indices by binary search. SparseRows retains the source's contiguous row slices, order, and duplicate entries. Selected CSC indices cannot be borrowed as contiguous local index slices:

rust
use lazymatrix::{IndexedRows, SparseColumns};
fn needs_slices<M: SparseColumns<f64>>() {}
fn selection<M: SparseColumns<f64>>() {
    needs_slices::<IndexedRows<'_, M>>();
}

Inherent implementation ​

Source

rust
impl<'a, M: MatrixShape, F> IndexedRows<'a, M, F>

into_source ​

rust
pub fn into_source(self) -> M

Source

Recover the source without copying.

new ​

rust
pub fn new(
    source: M,
    rows: &'a [usize]
) -> Self where F: Scalar, M: IndexedRowSource<F>

Source

Restrict raw storage to the supplied rows without reading entries.

Panics ​

Panics unless indices are strictly increasing, unique, and in bounds.

row_indices ​

rust
pub fn row_indices(&self) -> &'a [usize]

Source

Source row indices, in local row order.

source ​

rust
pub fn source(&self) -> &M

Source

Borrow the source, which may itself be a borrowed backend view.

Inherent implementation ​

Source

rust
impl<M: IndexedRowSource<F>, F: Scalar> lazymatrix::IndexedRows<'_, M, F>

Implementation of Clone ​

Source

rust
impl<'a, M: core::clone::Clone, F: core::clone::Clone> Clone for IndexedRows<'a, M, F>

clone ​

rust
fn clone(&self) -> Self

Source

Implementation of ColumnStats ​

Source

rust
impl<M: IndexedRowSource<F>, F: Scalar> ColumnStats<F> for lazymatrix::IndexedRows<'_, M, F>

col_l1 ​

rust
fn col_l1(&self) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>

Source

col_l1_centered ​

rust
fn col_l1_centered(
    &self,
    centers: &[F]
) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>

Source

col_l2 ​

rust
fn col_l2(&self) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>

Source

col_l2_centered ​

rust
fn col_l2_centered(
    &self,
    centers: &[F]
) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>

Source

col_maxabs ​

rust
fn col_maxabs(&self) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>

Source

col_maxabs_centered ​

rust
fn col_maxabs_centered(
    &self,
    centers: &[F]
) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>

Source

col_means ​

rust
fn col_means(&self) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>

Source

col_medians ​

rust
fn col_medians(&self) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>

Source

col_mins ​

rust
fn col_mins(&self) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>

Source

col_quantile_ranges ​

rust
fn col_quantile_ranges(
    &self,
    range: QuantileRange
) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>

Source

col_ranges ​

rust
fn col_ranges(&self) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>

Source

col_sds ​

rust
fn col_sds(&self, df: usize) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>

Source

normalization_stats ​

rust
fn normalization_stats(
    &self,
    spec: ColumnNormalization
) -> Result<ColumnNormalizationStats<F>, <Self as MatrixErrorType>::Error>

Source

Implementation of Copy ​

Source

rust
impl<'a, M: core::marker::Copy, F: core::marker::Copy> Copy for IndexedRows<'a, M, F>

Implementation of Debug ​

Source

rust
impl<'a, M: core::fmt::Debug, F: core::fmt::Debug> Debug for IndexedRows<'a, M, F>

fmt ​

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

Source

Implementation of IndexedRowSource ​

Source

rust
impl<M: IndexedRowSource<F>, F: Scalar> IndexedRowSource<F> for IndexedRows<'_, M, F>

IS_DENSE ​

rust
const IS_DENSE: bool = M::IS_DENSE;

Source

for_each_indexed_entry ​

rust
fn for_each_indexed_entry(
    &self,
    rows: &[usize],
    visit: impl FnMut(usize, usize, F)
) -> Result<(), <Self as MatrixErrorType>::Error>

Source

Implementation of MatTransposeVec ​

Source

rust
impl<M: IndexedRowSource<F>, F: Scalar, V> MatTransposeVec<V> for IndexedRows<'_, M, F> where V: VectorOwned<F, Owned = V> + VectorViewMut<F>

mat_transpose_vec ​

rust
fn mat_transpose_vec(
    &self,
    x: &V
) -> Result<V, <Self as MatrixErrorType>::Error>

Source

mat_transpose_vec_normalized ​

rust
fn mat_transpose_vec_normalized<N: Scalar>(
    &self,
    x: &V,
    centers: Option<&[N]>,
    scales: Option<&[N]>
) -> Result<V, <Self as MatrixErrorType>::Error> where V: lazymatrix::SumEntries<N> + lazymatrix::ScaledSubSlice<N> + lazymatrix::ElemDivAssign<N>

Source

Implementation of MatTransposeVecInto ​

Source

rust
impl<M: IndexedRowSource<F>, F: Scalar, X: VectorView<F>, Y: VectorViewMut<F>> MatTransposeVecInto<X, Y> for IndexedRows<'_, M, F>

mat_transpose_vec_into ​

rust
fn mat_transpose_vec_into(
    &self,
    x: &X,
    out: &mut Y
) -> Result<(), <Self as MatrixErrorType>::Error>

Source

mat_transpose_vec_normalized_into ​

rust
fn mat_transpose_vec_normalized_into<N: Scalar>(
    &self,
    x: &X,
    centers: Option<&[N]>,
    scales: Option<&[N]>,
    out: &mut Y
) -> Result<(), <Self as MatrixErrorType>::Error> where X: lazymatrix::SumEntries<N>, Y: lazymatrix::ScaledSubSlice<N> + lazymatrix::ElemDivAssign<N>

Source

Implementation of MatTransposeVecScaledInto ​

Source

rust
impl<M: IndexedRowSource<F>, F: Scalar, X: VectorView<F>, Y: VectorViewMut<F>> MatTransposeVecScaledInto<X, Y, F> for IndexedRows<'_, M, F>

mat_transpose_vec_scaled_into ​

rust
fn mat_transpose_vec_scaled_into(
    &self,
    alpha: F,
    x: &X,
    beta: F,
    out: &mut Y
) -> Result<(), <Self as MatrixErrorType>::Error>

Source

try_mat_transpose_vec_scaled_normalized_into ​

rust
fn try_mat_transpose_vec_scaled_normalized_into(
    &self,
    alpha: F,
    x: &X,
    beta: F,
    centers: Option<&[F]>,
    scales: Option<&[F]>,
    out: &mut Y
) -> Option<Result<(), <Self as MatrixErrorType>::Error>>

Source

Implementation of MatVec ​

Source

rust
impl<M: IndexedRowSource<F>, F: Scalar, V> MatVec<V> for IndexedRows<'_, M, F> where V: VectorOwned<F, Owned = V> + VectorViewMut<F>

matvec ​

rust
fn matvec(&self, x: &V) -> Result<V, <Self as MatrixErrorType>::Error>

Source

matvec_normalized ​

rust
fn matvec_normalized<N: Scalar>(
    &self,
    x: &V,
    centers: Option<&[N]>,
    scales: Option<&[N]>
) -> Result<V, <Self as MatrixErrorType>::Error> where V: Clone + lazymatrix::ElemDivAssign<N> + lazymatrix::DotSlice<N> + lazymatrix::SubScalarAssign<N>

Source

Implementation of MatVecInto ​

Source

rust
impl<M: IndexedRowSource<F>, F: Scalar, X: VectorView<F>, Y: VectorViewMut<F>> MatVecInto<X, Y> for IndexedRows<'_, M, F>

matvec_into ​

rust
fn matvec_into(
    &self,
    x: &X,
    out: &mut Y
) -> Result<(), <Self as MatrixErrorType>::Error>

Source

matvec_normalized_into ​

rust
fn matvec_normalized_into<N: Scalar>(
    &self,
    x: &X,
    centers: Option<&[N]>,
    scales: Option<&[N]>,
    out: &mut Y
) -> Result<(), <Self as MatrixErrorType>::Error> where X: Clone + lazymatrix::ElemDivAssign<N> + lazymatrix::DotSlice<N>, Y: lazymatrix::SubScalarAssign<N>

Source

Implementation of MatVecScaledInto ​

Source

rust
impl<M: IndexedRowSource<F>, F: Scalar, X: VectorView<F>, Y: VectorViewMut<F>> MatVecScaledInto<X, Y, F> for IndexedRows<'_, M, F>

matvec_scaled_into ​

rust
fn matvec_scaled_into(
    &self,
    alpha: F,
    x: &X,
    beta: F,
    out: &mut Y
) -> Result<(), <Self as MatrixErrorType>::Error>

Source

try_matvec_scaled_normalized_into ​

rust
fn try_matvec_scaled_normalized_into(
    &self,
    alpha: F,
    x: &X,
    beta: F,
    centers: Option<&[F]>,
    scales: Option<&[F]>,
    out: &mut Y
) -> Option<Result<(), <Self as MatrixErrorType>::Error>>

Source

Implementation of MatrixErrorType ​

Source

rust
impl<M: MatrixErrorType, F> MatrixErrorType for IndexedRows<'_, M, F>

Error ​

rust
type Error = <M as MatrixErrorType>::Error;

Source

Implementation of MatrixShape ​

Source

rust
impl<M: MatrixShape, F> MatrixShape for IndexedRows<'_, M, F>

ncols ​

rust
fn ncols(&self) -> usize

Source

nrows ​

rust
fn nrows(&self) -> usize

Source

Implementation of RawColumns ​

Source

rust
impl<M: RawColumns<F>, F: Scalar> RawColumns<F> for IndexedRows<'_, M, F>

Column ​

rust
type Column<'b> = IndexedRawColumn<'b, <M as RawColumns<F>>::Column<'b>> where Self: 'b;

Source

raw_column ​

rust
fn raw_column(&self, j: usize) -> <Self as RawColumns>::Column<'_>

Source

Implementation of SparseRows ​

Source

rust
impl<M: SparseRows<F>, F: Scalar> SparseRows<F> for IndexedRows<'_, M, F>

sparse_row ​

rust
fn sparse_row(&self, i: usize) -> (&[usize], &[F])

Source

Implementation of Freeze ​

rust
impl<'a, M, F> Freeze for IndexedRows<'a, M, F> where M: Freeze, PhantomData<F>: Freeze

Implementation of RefUnwindSafe ​

rust
impl<'a, M, F> RefUnwindSafe for IndexedRows<'a, M, F> where M: RefUnwindSafe, PhantomData<F>: RefUnwindSafe

Implementation of Send ​

rust
impl<'a, M, F> Send for IndexedRows<'a, M, F> where M: Send, PhantomData<F>: Send

Implementation of Sync ​

rust
impl<'a, M, F> Sync for IndexedRows<'a, M, F> where M: Sync, PhantomData<F>: Sync

Implementation of Unpin ​

rust
impl<'a, M, F> Unpin for IndexedRows<'a, M, F> where M: Unpin, PhantomData<F>: Unpin

Implementation of UnsafeUnpin ​

rust
impl<'a, M, F> UnsafeUnpin for IndexedRows<'a, M, F> where M: UnsafeUnpin, PhantomData<F>: UnsafeUnpin

Implementation of UnwindSafe ​

rust
impl<'a, M, F> UnwindSafe for IndexedRows<'a, M, F> where M: UnwindSafe, PhantomData<F>: UnwindSafe

Implementation of Any ​

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

Implementation of Borrow ​

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

Implementation of BorrowMut ​

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

Implementation of ByRef ​

rust
impl<T> ByRef<T> for T

Implementation of CastableFrom ​

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

Implementation of CastableFrom ​

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

Implementation of CloneToUninit ​

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

Implementation of From ​

rust
impl<T> From<T> for T

Implementation of Imply ​

rust
impl<T, U> Imply<T> for U where T: ?Sized, U: ?Sized

Implementation of Into ​

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

Implementation of IntoEither ​

rust
impl<T> IntoEither for T

Implementation of Pointable ​

rust
impl<T> Pointable for T

Implementation of Read ​

rust
impl<T> Read<Exclusive, BecauseExclusive> for T where T: ?Sized

Implementation of Same ​

rust
impl<T> Same for T

Implementation of SupersetOf ​

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

Implementation of ToOwned ​

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

Implementation of TryFrom ​

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

Implementation of TryInto ​

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

Released under the MIT and Apache 2.0 licenses.