pub struct SparseSign {
pub rows: usize,
pub cols: usize,
pub sparsity: usize,
/* private fields */
}Expand description
Sparse sign random matrix: each column has exactly s non-zeros, each ±1.
This provides an efficient O(s·n) matrix-vector product compared to O(m·n) for dense random matrices. Typically s = O(log(m)) suffices for good embedding properties.
Fields§
§rows: usizeNumber of rows (sketch dimension)
cols: usizeNumber of columns (original dimension)
sparsity: usizeSparsity: number of non-zeros per column
Implementations§
Source§impl SparseSign
impl SparseSign
Sourcepub fn new(
rows: usize,
cols: usize,
sparsity: Option<usize>,
seed: Option<u64>,
) -> LinalgResult<Self>
pub fn new( rows: usize, cols: usize, sparsity: Option<usize>, seed: Option<u64>, ) -> LinalgResult<Self>
Construct a sparse sign matrix with given dimensions and sparsity.
§Arguments
rows- Sketch dimension (number of rows)cols- Input dimension (number of columns)sparsity- Non-zeros per column (default: max(1, ceil(log2(rows))))seed- Optional RNG seed for reproducibility
Sourcepub fn apply(&self, x: &ArrayView1<'_, f64>) -> LinalgResult<Array1<f64>>
pub fn apply(&self, x: &ArrayView1<'_, f64>) -> LinalgResult<Array1<f64>>
Apply the sparse sign matrix: y = S * x, result is rows-vector.
§Arguments
x- Input vector of lengthself.cols
Sourcepub fn apply_matrix(&self, a: &ArrayView2<'_, f64>) -> LinalgResult<Array2<f64>>
pub fn apply_matrix(&self, a: &ArrayView2<'_, f64>) -> LinalgResult<Array2<f64>>
Apply S to each column of matrix A (result: rows × n).
Computes S * A for a cols × n matrix A.
Sourcepub fn apply_transpose(
&self,
x: &ArrayView1<'_, f64>,
) -> LinalgResult<Array1<f64>>
pub fn apply_transpose( &self, x: &ArrayView1<'_, f64>, ) -> LinalgResult<Array1<f64>>
Apply S^T (transpose): y = S^T * x, result is cols-vector.
Trait Implementations§
Source§impl Clone for SparseSign
impl Clone for SparseSign
Source§fn clone(&self) -> SparseSign
fn clone(&self) -> SparseSign
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for SparseSign
impl RefUnwindSafe for SparseSign
impl Send for SparseSign
impl Sync for SparseSign
impl Unpin for SparseSign
impl UnsafeUnpin for SparseSign
impl UnwindSafe for SparseSign
Blanket Implementations§
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more