pub enum SparseCow<'a, T: Send + Sync, F: CowFormat, Arch: SimdArch> {
Borrowed(SparseView<'a, T, F, Arch>),
Owned(F::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::Owned<T>)
Owned heap-backed storage.
Implementations§
Source§impl<'a, T: Send + Sync, F: CowFormat, Arch: SimdArch> SparseCow<'a, T, F, Arch>
impl<'a, T: Send + Sync, F: CowFormat, Arch: SimdArch> SparseCow<'a, T, F, Arch>
Sourcepub fn is_borrowed(&self) -> bool
pub fn is_borrowed(&self) -> bool
Returns true if this holds a borrowed view (no heap allocation).
Source§impl<'a, T: Send + Sync, F: CowFormat, Arch: SimdArch> SparseCow<'a, T, Validated<F>, Arch>where
F::Storage<'a, T>: SparseValidate,
impl<'a, T: Send + Sync, F: CowFormat, Arch: SimdArch> SparseCow<'a, T, Validated<F>, Arch>where
F::Storage<'a, T>: SparseValidate,
Source§impl<'a, T: Send + Sync + Clone, const C: usize, Arch: SimdArch> SparseCow<'a, T, SellP<C>, Arch>
impl<'a, T: Send + Sync + Clone, const C: usize, Arch: SimdArch> SparseCow<'a, T, SellP<C>, Arch>
Source§impl<'a, T: Send + Sync + Clone, const C: usize, Arch: SimdArch> SparseCow<'a, T, Validated<SellP<C>>, Arch>
impl<'a, T: Send + Sync + Clone, const C: usize, Arch: SimdArch> SparseCow<'a, T, Validated<SellP<C>>, Arch>
Source§impl<'a, T: Send + Sync + Clone, const BM: usize, const BN: usize, Arch: SimdArch> SparseCow<'a, T, BlockedCoo<BM, BN>, Arch>
impl<'a, T: Send + Sync + Clone, const BM: usize, const BN: usize, Arch: SimdArch> SparseCow<'a, T, BlockedCoo<BM, BN>, Arch>
Trait Implementations§
Source§impl<'a, T, F, Arch> SparseOps<T> for SparseCow<'a, T, F, Arch>
impl<'a, T, F, Arch> SparseOps<T> for SparseCow<'a, T, F, Arch>
Source§fn sum_values(&self) -> T
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])
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>
impl<'a, T, F, Arch> SparseSpMv<T> for SparseCow<'a, T, F, Arch>
Auto Trait Implementations§
impl<'a, T, F, Arch> Freeze for SparseCow<'a, T, F, Arch>
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>
impl<'a, T, F, Arch> Sync for SparseCow<'a, T, F, Arch>
impl<'a, T, F, Arch> Unpin for SparseCow<'a, T, F, Arch>
impl<'a, T, F, Arch> UnsafeUnpin for SparseCow<'a, T, F, Arch>
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> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Returns the layout of the type.
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Returns whether the given value has been niched. Read more
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
Writes data to
out indicating that a T is niched.