Skip to main content

SparseCow

Enum SparseCow 

Source
pub enum SparseCow<'a, T, F, Arch>
where T: Send + Sync, F: CowFormat, Arch: SimdArch,
{ Borrowed(SparseView<'a, T, F, Arch>), Owned(<F as CowFormat>::Owned<T>), }
Expand description

Clone-on-Write sparse matrix, generic over the storage format F.

Borrowed wraps a zero-copy SparseView; Owned holds heap-backed storage. Reads never allocate; SparseCow::to_owned promotes exactly once.

§Examples

use hermes_simd_core::{Csr, CsrData, Validated};
use hermes_simd_core::sparse::{SparseCow, SparseSpMv};
use hermes_simd_intrinsics::Scalar;

let values = [1.0_f64, 2.0, 3.0];
let col_indices = [0, 2, 1];
let row_ptr = [0, 2, 3];
let data = CsrData::new(&values, &col_indices, &row_ptr, 2, 3);
let matrix = SparseCow::<f64, Validated<Csr>, Scalar>::try_borrowed(data).unwrap();

let x = [10.0, 20.0, 30.0];
let mut y = [0.0; 2];
matrix.spmv(&x, &mut y);

assert_eq!(matrix.nrows(), 2);
assert_eq!(matrix.ncols(), 3);
assert!(matrix.is_borrowed());
assert_eq!(y, [70.0, 60.0]);

Variants§

§

Borrowed(SparseView<'a, T, F, Arch>)

Zero-copy borrowed view.

§

Owned(<F as CowFormat>::Owned<T>)

Owned heap-backed storage.

Implementations§

Source§

impl<'a, T, F, Arch> SparseCow<'a, T, F, Arch>
where T: Send + Sync, F: CowFormat, Arch: SimdArch,

Source

pub fn borrowed( data: <F as SparseFormat>::Storage<'a, T>, ) -> SparseCow<'a, T, F, Arch>

Wrap borrowed view storage (zero allocation).

Source

pub fn owned(storage: <F as CowFormat>::Owned<T>) -> SparseCow<'a, T, F, Arch>

Wrap owned storage (already heap-allocated).

Source

pub fn nrows(&self) -> usize

Number of rows.

Source

pub fn ncols(&self) -> usize

Number of columns.

Source

pub fn is_borrowed(&self) -> bool

Returns true if this holds a borrowed view (no heap allocation).

Source

pub fn is_owned(&self) -> bool

Returns true if this holds heap-owned data.

Source

pub fn to_owned(&mut self)
where T: Clone,

Promote to owned, cloning from the borrowed view if needed.

Idempotent: an already-owned container is left untouched.

Source§

impl<'a, T, F, Arch> SparseCow<'a, T, Validated<F>, Arch>
where T: Send + Sync, F: CowFormat, Arch: SimdArch, <F as SparseFormat>::Storage<'a, T>: SparseValidate,

Source

pub fn try_borrowed( data: <F as SparseFormat>::Storage<'a, T>, ) -> Result<SparseCow<'a, T, Validated<F>, Arch>, SimdError>

Validate borrowed storage and wrap it in a zero-copy sparse Cow.

§Errors

Returns the format-specific validation error if data is malformed.

Source§

impl<'a, T, Arch> SparseCow<'a, T, Csr, Arch>
where T: Send + Sync + Clone, Arch: SimdArch,

Source

pub fn from_slices( values: &[T], col_indices: &[i32], row_ptr: &[i32], nrows: usize, ncols: usize, ) -> SparseCow<'a, T, Csr, Arch>

Build an owned CSR Cow from slices.

Source§

impl<'a, T, Arch> SparseCow<'a, T, Validated<Csr>, Arch>
where T: Send + Sync + Clone, Arch: SimdArch,

Source

pub fn from_slices( values: &[T], col_indices: &[i32], row_ptr: &[i32], nrows: usize, ncols: usize, ) -> Result<SparseCow<'a, T, Validated<Csr>, Arch>, SimdError>

Build an owned validated CSR Cow from slices.

§Errors

Returns the CSR validation error if the sparse structure is malformed.

Source§

impl<'a, T, const C: usize, Arch> SparseCow<'a, T, SellP<C>, Arch>
where T: Send + Sync + Clone, Arch: SimdArch,

Source

pub fn from_slices( values: &[T], col_indices: &[i32], slice_ptr: &[i32], slice_col_count: &[i32], nrows: usize, ncols: usize, ) -> SparseCow<'a, T, SellP<C>, Arch>

Build an owned SELL-p Cow from slices.

Source§

impl<'a, T, const C: usize, Arch> SparseCow<'a, T, Validated<SellP<C>>, Arch>
where T: Send + Sync + Clone, Arch: SimdArch,

Source

pub fn from_slices( values: &[T], col_indices: &[i32], slice_ptr: &[i32], slice_col_count: &[i32], nrows: usize, ncols: usize, ) -> Result<SparseCow<'a, T, Validated<SellP<C>>, Arch>, SimdError>

Build an owned validated SELL-p Cow from slices.

§Errors

Returns the SELL-p validation error if the sparse structure is malformed.

Source§

impl<'a, T, const BM: usize, const BN: usize, Arch> SparseCow<'a, T, BlockedCoo<BM, BN>, Arch>
where T: Send + Sync + Clone, Arch: SimdArch,

Source

pub fn from_slices( blocks: &[T], block_row: &[i32], block_col: &[i32], nblocks: usize, nrows: usize, ncols: usize, ) -> SparseCow<'a, T, BlockedCoo<BM, BN>, Arch>

Build an owned Blocked-COO Cow from slices.

Source§

impl<'a, T, const BM: usize, const BN: usize, Arch> SparseCow<'a, T, Validated<BlockedCoo<BM, BN>>, Arch>
where T: Send + Sync + Clone, Arch: SimdArch,

Source

pub fn from_slices( blocks: &[T], block_row: &[i32], block_col: &[i32], nblocks: usize, nrows: usize, ncols: usize, ) -> Result<SparseCow<'a, T, Validated<BlockedCoo<BM, BN>>, Arch>, SimdError>

Build an owned validated Blocked-COO Cow from slices.

§Errors

Returns the Blocked-COO validation error if the sparse structure is malformed.

Source§

impl<'a, T, Arch> SparseCow<'a, T, DenseWithMask, Arch>
where T: Send + Sync + Clone, Arch: SimdArch,

Source

pub fn from_slices( values: &[T], mask: &[bool], nrows: usize, ncols: usize, ) -> SparseCow<'a, T, DenseWithMask, Arch>

Build an owned DenseWithMask Cow from slices.

Trait Implementations§

Source§

impl<'a, T, F, Arch> SparseOps<T> for SparseCow<'a, T, F, Arch>
where T: NumericElement, F: CowFormat, Arch: SimdArch, SparseView<'b, T, F, Arch>: for<'b> SparseOps<T>,

Source§

fn sum_values(&self) -> T

Compute the sum of all elements stored in the sparse matrix.
Source§

fn elementwise_mul_dense(&self, dense: &[T], out_values: &mut [T])

Elementwise multiply the sparse matrix values by corresponding entries in a dense matrix, writing the results to out_values.
Source§

impl<'a, T, F, Arch> SparseSpMv<T> for SparseCow<'a, T, F, Arch>
where T: NumericElement, F: CowFormat, Arch: SimdArch, SparseView<'b, T, F, Arch>: for<'b> SparseSpMv<T>,

Source§

fn spmv(&self, x: &[T], y: &mut [T])

Perform matrix-vector multiplication: y += A * x. Read more
Source§

impl<'a, T, F, Arch> SparseValidate for SparseCow<'a, T, F, Arch>
where T: Send + Sync, F: CowFormat, Arch: SimdArch, <F as SparseFormat>::Storage<'b, T>: for<'b> SparseValidate, <F as CowFormat>::Owned<T>: SparseValidate,

Source§

fn validate(&self) -> Result<(), SimdError>

Validate structural correctness and bounds checks.

Auto Trait Implementations§

§

impl<'a, T, F, Arch> Freeze for SparseCow<'a, T, F, Arch>
where <F as CowFormat>::Owned<T>: Freeze, <F as SparseFormat>::Storage<'a, T>: Freeze,

§

impl<'a, T, F, Arch> RefUnwindSafe for SparseCow<'a, T, F, Arch>
where <F as CowFormat>::Owned<T>: RefUnwindSafe, <F as SparseFormat>::Storage<'a, T>: RefUnwindSafe, Arch: RefUnwindSafe,

§

impl<'a, T, F, Arch> Send for SparseCow<'a, T, F, Arch>
where <F as SparseFormat>::Storage<'a, T>: Send,

§

impl<'a, T, F, Arch> Sync for SparseCow<'a, T, F, Arch>
where <F as SparseFormat>::Storage<'a, T>: Sync,

§

impl<'a, T, F, Arch> Unpin for SparseCow<'a, T, F, Arch>
where <F as CowFormat>::Owned<T>: Unpin, <F as SparseFormat>::Storage<'a, T>: Unpin, Arch: Unpin,

§

impl<'a, T, F, Arch> UnsafeUnpin for SparseCow<'a, T, F, Arch>
where <F as CowFormat>::Owned<T>: UnsafeUnpin, <F as SparseFormat>::Storage<'a, T>: UnsafeUnpin,

§

impl<'a, T, F, Arch> UnwindSafe for SparseCow<'a, T, F, Arch>
where <F as CowFormat>::Owned<T>: UnwindSafe, <F as SparseFormat>::Storage<'a, T>: UnwindSafe, Arch: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<F, W, T, D> Deserialize<With<T, W>, D> for F
where W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

Source§

fn deserialize( &self, deserializer: &mut D, ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The type for metadata in pointers and references to Self.
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

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

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.