lazymatrix::Submatrix
LazyMatrix for Rust · 0.8.1
pub struct Submatrix<'a, M, F = f64>A borrowed restriction of an already normalized matrix to contiguous ranges.
Construction and nested selection take O(1) time, allocate nothing, and borrow the original data and fitted parameters. Selecting rows never refits normalization. All entry indices exposed by this view are local.
Dense products visit only selected entries. Sparse products scan stored entries in selected outer rows or columns, filtering the other axis. They use O(selected rows + selected columns) workspace, never a dense design copy. Column filtering scans the parent column; row filtering scans the parent row.
This is a logical operator, not a contiguous sparse storage capability. Filtered sparse views expose iterators instead of rebased index slices.
use lazymatrix::{LazyMatrix, SparseColumns, Submatrix};
fn needs_slices<M: SparseColumns<f64>>() {}
fn restricted_columns<M: SparseColumns<f64>>(_: &LazyMatrix<M>) {
needs_slices::<Submatrix<'_, M>>();
}use lazymatrix::{LazyMatrix, SparseRows, Submatrix};
fn needs_slices<M: SparseRows<f64>>() {}
fn restricted_rows<M: SparseRows<f64>>(_: &LazyMatrix<M>) {
needs_slices::<Submatrix<'_, M>>();
}Inherent implementation
impl<'a, M: MatrixShape, F: Scalar> Submatrix<'a, M, F>centers
pub fn centers(&self) -> Option<&'a [F]>Borrow the selected columns' original centers.
column
pub fn column(
&self,
j: usize
) -> LazyColumn<FilteredRawColumn<<M as RawColumns>::Column<'_>>, F> where M: RawColumns<F>Borrow a logical column, filtering and rebasing its stored row indices.
Filtering takes O(parent stored entries) per traversal and allocates nothing. The parent must provide natural column borrowing.
Panics
Panics if j >= self.ncols().
ncols
pub fn ncols(&self) -> usizeNumber of selected columns.
nrows
pub fn nrows(&self) -> usizeNumber of selected rows.
row
pub fn row(&self, i: usize) -> SubmatrixRow<'_, F> where M: SparseRows<F>Borrow a filtered normalized sparse row without copying its entries.
Stored-entry iteration takes O(parent stored row entries), preserves order and duplicates, and rebases column indices to the selection.
Panics
Panics if i >= self.nrows().
scales
pub fn scales(&self) -> Option<&'a [F]>Borrow the selected columns' original scales.
sparse_column
pub fn sparse_column(
&self,
j: usize
) -> SubmatrixSparseColumn<'_, F> where M: SparseColumns<F>Borrow a filtered sparse column with locally indexed entry iterators.
Panics
Panics if j >= self.ncols().
submatrix
pub fn submatrix(&self, rows: Range<usize>, columns: Range<usize>) -> SelfSelect a rectangle using coordinates relative to this view.
Panics
Panics on reversed or out-of-bounds ranges.
Inherent implementation
impl<M: SubmatrixKernel<F>, F: Scalar> Submatrix<'_, M, F>to_eager
pub fn to_eager<D: MatrixOwned<F>>(
&self
) -> Result<EagerMatrix<D, F>, <M as MatrixErrorType>::Error>Explicitly allocate and materialize this rectangle in a dense backend.
Requires O(selected rows * selected columns) output storage. Only the selected fitted parameters are cloned; no statistics are recomputed. Returns the source error on failure.
to_eager_into
pub fn to_eager_into<'b, D: MatrixWrite<F> + ?Sized>(
&self,
out: &'b mut D
) -> Result<EagerMatrix<&'b mut D, F>, <M as MatrixErrorType>::Error>Overwrite dense output and return an eager operator borrowing it.
Fitted metadata is cloned, and kernels may allocate one working row or column. Output may be partial on a source error.
Panics
Panics before writing if the output shape differs from this rectangle.
Implementation of Clone
impl<M, F> Clone for Submatrix<'_, M, F>clone
fn clone(&self) -> SelfImplementation of Columns
impl<M: RawColumns<F>, F: Scalar> Columns<F> for Submatrix<'_, M, F>Column
type Column<'b> = LazyColumn<FilteredRawColumn<<M as RawColumns<F>>::Column<'b>>, F> where Self: 'b;column
fn column(&self, j: usize) -> <Self as Columns>::Column<'_>Implementation of Debug
impl<'a, M: core::fmt::Debug, F: core::fmt::Debug> Debug for Submatrix<'a, M, F>fmt
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::ResultImplementation of MatTransposeVec
impl<M, V, F> MatTransposeVec<V> for Submatrix<'_, M, F> where M: SubmatrixKernel<F>, F: Scalar, V: VectorOwned<F, Owned = V> + VectorViewMut<F>mat_transpose_vec
fn mat_transpose_vec(
&self,
x: &V
) -> Result<V, <Self as MatrixErrorType>::Error>Implementation of MatTransposeVecInto
impl<M, X, Y, F> MatTransposeVecInto<X, Y> for Submatrix<'_, M, F> where M: SubmatrixKernel<F>, F: Scalar, X: VectorView<F>, Y: VectorViewMut<F>mat_transpose_vec_into
fn mat_transpose_vec_into(
&self,
x: &X,
out: &mut Y
) -> Result<(), <Self as MatrixErrorType>::Error>Implementation of MatTransposeVecScaledInto
impl<M, X, Y, F> MatTransposeVecScaledInto<X, Y, F> for Submatrix<'_, M, F> where M: SubmatrixKernel<F>, F: Scalar, X: VectorView<F>, Y: VectorViewMut<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>Implementation of MatVec
impl<M, V, F> MatVec<V> for Submatrix<'_, M, F> where M: SubmatrixKernel<F>, F: Scalar, V: VectorOwned<F, Owned = V> + VectorViewMut<F>matvec
fn matvec(&self, x: &V) -> Result<V, <Self as MatrixErrorType>::Error>Implementation of MatVecInto
impl<M, X, Y, F> MatVecInto<X, Y> for Submatrix<'_, M, F> where M: SubmatrixKernel<F>, F: Scalar, X: VectorView<F>, Y: VectorViewMut<F>matvec_into
fn matvec_into(
&self,
x: &X,
out: &mut Y
) -> Result<(), <Self as MatrixErrorType>::Error>Implementation of MatVecScaledInto
impl<M, X, Y, F> MatVecScaledInto<X, Y, F> for Submatrix<'_, M, F> where M: SubmatrixKernel<F>, F: Scalar, X: VectorView<F>, Y: VectorViewMut<F>matvec_scaled_into
fn matvec_scaled_into(
&self,
alpha: F,
x: &X,
beta: F,
out: &mut Y
) -> Result<(), <Self as MatrixErrorType>::Error>Implementation of MatrixErrorType
impl<M: MatrixErrorType, F> MatrixErrorType for Submatrix<'_, M, F>Error
type Error = <M as MatrixErrorType>::Error;Implementation of MatrixShape
impl<M, F> MatrixShape for Submatrix<'_, M, F>ncols
fn ncols(&self) -> usizenrows
fn nrows(&self) -> usizeImplementation of Freeze
impl<'a, M, F> Freeze for Submatrix<'a, M, F> where &'a LazyMatrix<M, F>: FreezeImplementation of RefUnwindSafe
impl<'a, M, F> RefUnwindSafe for Submatrix<'a, M, F> where &'a LazyMatrix<M, F>: RefUnwindSafeImplementation of Send
impl<'a, M, F> Send for Submatrix<'a, M, F> where &'a LazyMatrix<M, F>: SendImplementation of Sync
impl<'a, M, F> Sync for Submatrix<'a, M, F> where &'a LazyMatrix<M, F>: SyncImplementation of Unpin
impl<'a, M, F> Unpin for Submatrix<'a, M, F> where &'a LazyMatrix<M, F>: UnpinImplementation of UnsafeUnpin
impl<'a, M, F> UnsafeUnpin for Submatrix<'a, M, F> where &'a LazyMatrix<M, F>: UnsafeUnpinImplementation of UnwindSafe
impl<'a, M, F> UnwindSafe for Submatrix<'a, M, F> where &'a LazyMatrix<M, 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>
