Skip to content

lazymatrix::SprsCsc ​

LazyMatrix for Rust · 0.8.1

Source

rust
pub struct SprsCsc<M>

A checked CSC matrix or view that supports contiguous borrowed columns.

sprs stores CSC and CSR orientation in a runtime flag on the same type. This wrapper checks that flag once, in try_new, so column access never needs a gather or an orientation conversion. Construction and column borrowing take O(1) time and allocate nothing. The wrapper retains ownership of the supplied matrix or view and exposes no mutable access that could change its orientation.

Operators, statistics, and logical columns accept any sprs index type. Borrowing row indices as slices requires usize to match SparseColumns.

rust
use lazymatrix::{Centering, LazyMatrix, MatVec, Normalization, Scaling, SprsCsc};
use sprs::CsMat;

let x = CsMat::new_csc((3, 2), vec![0, 2, 3], vec![0, 2, 1], vec![1.0, 3.0, 2.0]);
let csc = SprsCsc::try_new(x.view()).unwrap();
let lazy = LazyMatrix::new(csc, Normalization::new(Centering::Mean, Scaling::Sd)).unwrap();
assert_eq!(lazy.matvec(&vec![1.0, -1.0]).unwrap().len(), 3);
assert_eq!(lazy.sparse_column(0).row_indices(), &[0, 2]);

A plain sprs matrix has no column-borrowing capability, since it could be CSR:

rust
use lazymatrix::SparseColumns;
fn needs_columns<M: SparseColumns<f64>>() {}
needs_columns::<sprs::CsMat<f64>>();
rust
use lazymatrix::RawColumns;
fn needs_columns<M: RawColumns<f64>>() {}
needs_columns::<sprs::CsMat<f64>>();

Indices of another width cannot provide a borrowed &[usize]:

rust
use lazymatrix::{SparseColumns, SprsCsc};
fn needs_columns<M: SparseColumns<f64>>() {}
needs_columns::<SprsCsc<sprs::CsMatI<f64, u32>>>();

Inherent implementation ​

Source

rust
impl<F, I, IP, IS, DS, Iptr> SprsCsc<sprs::CsMatBase<F, I, IP, IS, DS, Iptr>> where I: SpIndex, Iptr: SpIndex, IP: Deref<Target = [Iptr]>, IS: Deref<Target = [I]>, DS: Deref<Target = [F]>

try_new ​

rust
pub fn try_new(
    matrix: CsMatBase<F, I, IP, IS, DS, Iptr>
) -> Result<Self, CsMatBase<F, I, IP, IS, DS, Iptr>>

Source

Wrap CSC storage without copying, or return the original CSR input.

To convert CSR storage explicitly, call sprs's to_csc or into_csc before this constructor. Borrow existing data by passing matrix.view().

Inherent implementation ​

Source

rust
impl<M> SprsCsc<M>

as_inner ​

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

Source

Borrow the original matrix or view.

into_inner ​

rust
pub fn into_inner(self) -> M

Source

Recover the original matrix or view without copying.

Implementation of Clone ​

Source

rust
impl<M: core::clone::Clone> Clone for SprsCsc<M>

clone ​

rust
fn clone(&self) -> Self

Source

Implementation of ColumnStats ​

Source

rust
impl<M: ColumnStats<F>, F: Scalar> ColumnStats<F> for SprsCsc<M>

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_mins ​

rust
fn col_mins(&self) -> 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) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>

Source

normalization_stats ​

rust
fn normalization_stats(
    &self,
    spec: lazymatrix::Normalization
) -> Result<lazymatrix::NormalizationStats<F>, <Self as MatrixErrorType>::Error>

Source

Implementation of Copy ​

Source

rust
impl<M: core::marker::Copy> Copy for SprsCsc<M>

Implementation of Debug ​

Source

rust
impl<M: core::fmt::Debug> Debug for SprsCsc<M>

fmt ​

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

Source

Implementation of MatMatInto ​

Source

rust
impl<M: lazymatrix::MatMatInto<F>, F: Scalar> MatMatInto<F> for SprsCsc<M>

matmat_into ​

rust
fn matmat_into<R, O>(
    &self,
    rhs: &R,
    out: &mut O
) -> Result<(), <Self as MatrixErrorType>::Error> where R: lazymatrix::MatrixRead<F> + ?Sized, O: lazymatrix::MatrixRead<F> + lazymatrix::MatrixWrite<F> + ?Sized

Source

matmat_normalized_into ​

rust
fn matmat_normalized_into<R, O>(
    &self,
    rhs: &R,
    centers: Option<&[F]>,
    scales: Option<&[F]>,
    out: &mut O
) -> Result<(), <Self as MatrixErrorType>::Error> where R: lazymatrix::MatrixRead<F> + ?Sized, O: lazymatrix::MatrixRead<F> + lazymatrix::MatrixWrite<F> + ?Sized

Source

Implementation of MatTransposeMatInto ​

Source

rust
impl<M: lazymatrix::MatTransposeMatInto<F>, F: Scalar> MatTransposeMatInto<F> for SprsCsc<M>

mat_transpose_mat_into ​

rust
fn mat_transpose_mat_into<R, O>(
    &self,
    rhs: &R,
    out: &mut O
) -> Result<(), <Self as MatrixErrorType>::Error> where R: lazymatrix::MatrixRead<F> + ?Sized, O: lazymatrix::MatrixRead<F> + lazymatrix::MatrixWrite<F> + ?Sized

Source

mat_transpose_mat_normalized_into ​

rust
fn mat_transpose_mat_normalized_into<R, O>(
    &self,
    rhs: &R,
    centers: Option<&[F]>,
    scales: Option<&[F]>,
    out: &mut O
) -> Result<(), <Self as MatrixErrorType>::Error> where R: lazymatrix::MatrixRead<F> + ?Sized, O: lazymatrix::MatrixRead<F> + lazymatrix::MatrixWrite<F> + ?Sized

Source

Implementation of MatTransposeVec ​

Source

rust
impl<M: MatTransposeVec<V>, V> MatTransposeVec<V> for SprsCsc<M>

mat_transpose_vec ​

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

Source

Implementation of MatTransposeVecInto ​

Source

rust
impl<M: MatTransposeVecInto<X, Y>, X, Y> MatTransposeVecInto<X, Y> for SprsCsc<M>

mat_transpose_vec_into ​

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

Source

Implementation of MatTransposeVecScaledInto ​

Source

rust
impl<M: MatTransposeVecScaledInto<X, Y, F>, X, Y, F> MatTransposeVecScaledInto<X, Y, F> for SprsCsc<M>

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

Implementation of MatVec ​

Source

rust
impl<M: MatVec<V>, V> MatVec<V> for SprsCsc<M>

matvec ​

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

Source

Implementation of MatVecInto ​

Source

rust
impl<M: MatVecInto<X, Y>, X, Y> MatVecInto<X, Y> for SprsCsc<M>

matvec_into ​

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

Source

Implementation of MatVecScaledInto ​

Source

rust
impl<M: MatVecScaledInto<X, Y, F>, X, Y, F> MatVecScaledInto<X, Y, F> for SprsCsc<M>

matvec_scaled_into ​

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

Source

Implementation of MaterializeDense ​

Source

rust
impl<M: lazymatrix::MaterializeDense<F>, F: Scalar> MaterializeDense<F> for SprsCsc<M>

materialize_normalized_into ​

rust
fn materialize_normalized_into<O: lazymatrix::MatrixWrite<F> + ?Sized>(
    &self,
    centers: Option<&[F]>,
    scales: Option<&[F]>,
    out: &mut O
) -> Result<(), <Self as MatrixErrorType>::Error>

Source

Implementation of MatrixErrorType ​

Source

rust
impl<M: lazymatrix::MatrixErrorType> MatrixErrorType for SprsCsc<M>

Error ​

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

Source

Implementation of MatrixShape ​

Source

rust
impl<M: MatrixShape> MatrixShape for SprsCsc<M>

ncols ​

rust
fn ncols(&self) -> usize

Source

nrows ​

rust
fn nrows(&self) -> usize

Source

Implementation of RawColumns ​

Source

rust
impl<F, I, IP, IS, DS, Iptr> RawColumns<F> for SprsCsc<sprs::CsMatBase<F, I, IP, IS, DS, Iptr>> where F: Scalar, I: SpIndex, Iptr: SpIndex, IP: Deref<Target = [Iptr]>, IS: Deref<Target = [I]>, DS: Deref<Target = [F]>

Column ​

rust
type Column<'a> = CsVecBase<&'a [I], &'a [F], F, I> where Self: 'a;

Source

raw_column ​

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

Source

Implementation of SparseColumns ​

Source

rust
impl<F, IP, IS, DS, Iptr> SparseColumns<F> for SprsCsc<sprs::CsMatBase<F, usize, IP, IS, DS, Iptr>> where F: Scalar, Iptr: SpIndex, IP: Deref<Target = [Iptr]>, IS: Deref<Target = [usize]>, DS: Deref<Target = [F]>

sparse_column ​

rust
fn sparse_column(&self, j: usize) -> (&[usize], &[F])

Source

Implementation of SubmatrixKernel ​

Source

rust
impl<M: lazymatrix::SubmatrixKernel<F>, F: Scalar> SubmatrixKernel<F> for SprsCsc<M>

materialize_submatrix_into ​

rust
fn materialize_submatrix_into<O: lazymatrix::MatrixWrite<F> + ?Sized>(
    &self,
    rows: std::ops::Range<usize>,
    columns: std::ops::Range<usize>,
    centers: Option<&[F]>,
    scales: Option<&[F]>,
    out: &mut O
) -> Result<(), <Self as MatrixErrorType>::Error>

Source

submatrix_matvec_into ​

rust
fn submatrix_matvec_into<X: lazymatrix::VectorView<F> + ?Sized, Y: lazymatrix::VectorViewMut<F> + ?Sized>(
    &self,
    rows: std::ops::Range<usize>,
    columns: std::ops::Range<usize>,
    centers: Option<&[F]>,
    scales: Option<&[F]>,
    alpha: F,
    x: &X,
    beta: F,
    out: &mut Y
) -> Result<(), <Self as MatrixErrorType>::Error>

Source

submatrix_transpose_into ​

rust
fn submatrix_transpose_into<X: lazymatrix::VectorView<F> + ?Sized, Y: lazymatrix::VectorViewMut<F> + ?Sized>(
    &self,
    rows: std::ops::Range<usize>,
    columns: std::ops::Range<usize>,
    centers: Option<&[F]>,
    scales: Option<&[F]>,
    alpha: F,
    x: &X,
    beta: F,
    out: &mut Y
) -> Result<(), <Self as MatrixErrorType>::Error>

Source

Implementation of WeightedColumnSumsInto ​

Source

rust
impl<F, IP, IS, DS, Iptr> WeightedColumnSumsInto<F> for lazymatrix::SprsCsc<sprs::CsMatBase<F, usize, IP, IS, DS, Iptr>> where F: Scalar, Iptr: SpIndex, IP: Deref<Target = [Iptr]>, IS: Deref<Target = [usize]>, DS: Deref<Target = [F]>

weighted_column_sums_into ​

rust
fn weighted_column_sums_into<W, O>(
    &self,
    weights: &W,
    out: &mut O
) -> Result<(), <Self as MatrixErrorType>::Error> where W: VectorView<F> + ?Sized, O: VectorViewMut<F> + ?Sized

Source

Implementation of WeightedColumnSumsKernel ​

Source

rust
impl<F, IP, IS, DS, Iptr> WeightedColumnSumsKernel<F> for lazymatrix::SprsCsc<sprs::CsMatBase<F, usize, IP, IS, DS, Iptr>> where F: Scalar, Iptr: SpIndex, IP: Deref<Target = [Iptr]>, IS: Deref<Target = [usize]>, DS: Deref<Target = [F]>

weighted_column_sums_normalized_into ​

rust
fn weighted_column_sums_normalized_into<W, O>(
    &self,
    weights: &W,
    centers: Option<&[F]>,
    scales: Option<&[F]>,
    out: &mut O
) -> Result<(), <Self as MatrixErrorType>::Error> where W: VectorView<F> + ?Sized, O: VectorViewMut<F> + ?Sized

Source

Implementation of WeightedGramInto ​

Source

rust
impl<F, IP, IS, DS, Iptr> WeightedGramInto<F> for lazymatrix::SprsCsc<sprs::CsMatBase<F, usize, IP, IS, DS, Iptr>> where F: Scalar, Iptr: SpIndex, IP: Deref<Target = [Iptr]>, IS: Deref<Target = [usize]>, DS: Deref<Target = [F]>

weighted_gram_into ​

rust
fn weighted_gram_into<W, O>(
    &self,
    weights: &W,
    out: &mut O
) -> Result<(), <Self as MatrixErrorType>::Error> where W: VectorView<F> + ?Sized, O: MatrixWrite<F> + ?Sized

Source

Implementation of WeightedGramKernel ​

Source

rust
impl<F, IP, IS, DS, Iptr> WeightedGramKernel<F> for lazymatrix::SprsCsc<sprs::CsMatBase<F, usize, IP, IS, DS, Iptr>> where F: Scalar, Iptr: SpIndex, IP: Deref<Target = [Iptr]>, IS: Deref<Target = [usize]>, DS: Deref<Target = [F]>

weighted_gram_normalized_into ​

rust
fn weighted_gram_normalized_into<W, O>(
    &self,
    weights: &W,
    centers: Option<&[F]>,
    scales: Option<&[F]>,
    out: &mut O
) -> Result<(), <Self as MatrixErrorType>::Error> where W: VectorView<F> + ?Sized, O: MatrixWrite<F> + ?Sized

Source

Implementation of Freeze ​

rust
impl<M> Freeze for SprsCsc<M> where M: Freeze

Implementation of RefUnwindSafe ​

rust
impl<M> RefUnwindSafe for SprsCsc<M> where M: RefUnwindSafe

Implementation of Send ​

rust
impl<M> Send for SprsCsc<M> where M: Send

Implementation of Sync ​

rust
impl<M> Sync for SprsCsc<M> where M: Sync

Implementation of Unpin ​

rust
impl<M> Unpin for SprsCsc<M> where M: Unpin

Implementation of UnsafeUnpin ​

rust
impl<M> UnsafeUnpin for SprsCsc<M> where M: UnsafeUnpin

Implementation of UnwindSafe ​

rust
impl<M> UnwindSafe for SprsCsc<M> where M: 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 MatMat ​

Source

rust
impl<M, F> MatMat<F> for M where M: MatMatInto<F> + ?Sized, F: Scalar

Implementation of MatTransposeMat ​

Source

rust
impl<M, F> MatTransposeMat<F> for M where M: MatTransposeMatInto<F> + ?Sized, F: Scalar

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.