lazymatrix::IndexedRows
LazyMatrix for Rust · 0.9.0
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:
use lazymatrix::{IndexedRows, SparseColumns};
fn needs_slices<M: SparseColumns<f64>>() {}
fn selection<M: SparseColumns<f64>>() {
needs_slices::<IndexedRows<'_, M>>();
}Inherent implementation
impl<'a, M: MatrixShape, F> IndexedRows<'a, M, F>into_source
pub fn into_source(self) -> MRecover the source without copying.
new
pub fn new(
source: M,
rows: &'a [usize]
) -> Self where F: Scalar, M: IndexedRowSource<F>Restrict raw storage to the supplied rows without reading entries.
Panics
Panics unless indices are strictly increasing, unique, and in bounds.
row_indices
pub fn row_indices(&self) -> &'a [usize]Source row indices, in local row order.
source
pub fn source(&self) -> &MBorrow the source, which may itself be a borrowed backend view.
Inherent implementation
impl<M: IndexedRowSource<F>, F: Scalar> lazymatrix::IndexedRows<'_, M, F>Implementation of Clone
impl<'a, M: core::clone::Clone, F: core::clone::Clone> Clone for IndexedRows<'a, M, F>clone
fn clone(&self) -> SelfImplementation of ColumnStats
impl<M: IndexedRowSource<F>, F: Scalar> ColumnStats<F> for lazymatrix::IndexedRows<'_, M, F>col_l1
fn col_l1(&self) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>col_l1_centered
fn col_l1_centered(
&self,
centers: &[F]
) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>col_l2
fn col_l2(&self) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>col_l2_centered
fn col_l2_centered(
&self,
centers: &[F]
) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>col_maxabs
fn col_maxabs(&self) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>col_maxabs_centered
fn col_maxabs_centered(
&self,
centers: &[F]
) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>col_means
fn col_means(&self) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>col_medians
fn col_medians(&self) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>col_mins
fn col_mins(&self) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>col_quantile_ranges
fn col_quantile_ranges(
&self,
range: QuantileRange
) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>col_ranges
fn col_ranges(&self) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>col_sds
fn col_sds(&self, df: usize) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>normalization_stats
fn normalization_stats(
&self,
spec: ColumnNormalization
) -> Result<ColumnNormalizationStats<F>, <Self as MatrixErrorType>::Error>Implementation of Copy
impl<'a, M: core::marker::Copy, F: core::marker::Copy> Copy for IndexedRows<'a, M, F>Implementation of Debug
impl<'a, M: core::fmt::Debug, F: core::fmt::Debug> Debug for IndexedRows<'a, M, F>fmt
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::ResultImplementation of IndexedRowSource
impl<M: IndexedRowSource<F>, F: Scalar> IndexedRowSource<F> for IndexedRows<'_, M, F>IS_DENSE
const IS_DENSE: bool = M::IS_DENSE;for_each_indexed_entry
fn for_each_indexed_entry(
&self,
rows: &[usize],
visit: impl FnMut(usize, usize, F)
) -> Result<(), <Self as MatrixErrorType>::Error>Implementation of MatTransposeVec
impl<M: IndexedRowSource<F>, F: Scalar, V> MatTransposeVec<V> for IndexedRows<'_, M, F> where V: VectorOwned<F, Owned = V> + VectorViewMut<F>mat_transpose_vec
fn mat_transpose_vec(
&self,
x: &V
) -> Result<V, <Self as MatrixErrorType>::Error>mat_transpose_vec_normalized
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>Implementation of MatTransposeVecInto
impl<M: IndexedRowSource<F>, F: Scalar, X: VectorView<F>, Y: VectorViewMut<F>> MatTransposeVecInto<X, Y> for IndexedRows<'_, M, F>mat_transpose_vec_into
fn mat_transpose_vec_into(
&self,
x: &X,
out: &mut Y
) -> Result<(), <Self as MatrixErrorType>::Error>mat_transpose_vec_normalized_into
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>Implementation of MatTransposeVecScaledInto
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
fn mat_transpose_vec_scaled_into(
&self,
alpha: F,
x: &X,
beta: F,
out: &mut Y
) -> Result<(), <Self as MatrixErrorType>::Error>try_mat_transpose_vec_scaled_normalized_into
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>>Implementation of MatVec
impl<M: IndexedRowSource<F>, F: Scalar, V> MatVec<V> for IndexedRows<'_, M, F> where V: VectorOwned<F, Owned = V> + VectorViewMut<F>matvec
fn matvec(&self, x: &V) -> Result<V, <Self as MatrixErrorType>::Error>matvec_normalized
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>Implementation of MatVecInto
impl<M: IndexedRowSource<F>, F: Scalar, X: VectorView<F>, Y: VectorViewMut<F>> MatVecInto<X, Y> for IndexedRows<'_, M, F>matvec_into
fn matvec_into(
&self,
x: &X,
out: &mut Y
) -> Result<(), <Self as MatrixErrorType>::Error>matvec_normalized_into
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>Implementation of MatVecScaledInto
impl<M: IndexedRowSource<F>, F: Scalar, X: VectorView<F>, Y: VectorViewMut<F>> MatVecScaledInto<X, Y, F> for IndexedRows<'_, M, F>matvec_scaled_into
fn matvec_scaled_into(
&self,
alpha: F,
x: &X,
beta: F,
out: &mut Y
) -> Result<(), <Self as MatrixErrorType>::Error>try_matvec_scaled_normalized_into
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>>Implementation of MatrixErrorType
impl<M: MatrixErrorType, F> MatrixErrorType for IndexedRows<'_, M, F>Error
type Error = <M as MatrixErrorType>::Error;Implementation of MatrixShape
impl<M: MatrixShape, F> MatrixShape for IndexedRows<'_, M, F>ncols
fn ncols(&self) -> usizenrows
fn nrows(&self) -> usizeImplementation of RawColumns
impl<M: RawColumns<F>, F: Scalar> RawColumns<F> for IndexedRows<'_, M, F>Column
type Column<'b> = IndexedRawColumn<'b, <M as RawColumns<F>>::Column<'b>> where Self: 'b;raw_column
fn raw_column(&self, j: usize) -> <Self as RawColumns>::Column<'_>Implementation of SparseRows
impl<M: SparseRows<F>, F: Scalar> SparseRows<F> for IndexedRows<'_, M, F>sparse_row
fn sparse_row(&self, i: usize) -> (&[usize], &[F])Implementation of Freeze
impl<'a, M, F> Freeze for IndexedRows<'a, M, F> where M: Freeze, PhantomData<F>: FreezeImplementation of RefUnwindSafe
impl<'a, M, F> RefUnwindSafe for IndexedRows<'a, M, F> where M: RefUnwindSafe, PhantomData<F>: RefUnwindSafeImplementation of Send
impl<'a, M, F> Send for IndexedRows<'a, M, F> where M: Send, PhantomData<F>: SendImplementation of Sync
impl<'a, M, F> Sync for IndexedRows<'a, M, F> where M: Sync, PhantomData<F>: SyncImplementation of Unpin
impl<'a, M, F> Unpin for IndexedRows<'a, M, F> where M: Unpin, PhantomData<F>: UnpinImplementation of UnsafeUnpin
impl<'a, M, F> UnsafeUnpin for IndexedRows<'a, M, F> where M: UnsafeUnpin, PhantomData<F>: UnsafeUnpinImplementation of UnwindSafe
impl<'a, M, F> UnwindSafe for IndexedRows<'a, M, F> where M: UnwindSafe, PhantomData<F>: 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>
