Skip to main content

SpMat

Struct SpMat 

Source
pub struct SpMat<R> { /* private fields */ }
Expand description

Sparse matrix in compressed sparse column (CSC) format, backed by nalgebra_sparse::CscMatrix.

The fundamental matrix type for all differential maps in the homology pipeline. Generic over the element ring R; bounds are applied per-method.

Note: the underlying CSC may carry explicit zero entries (e.g. after an in-place subtraction). iter walks all stored triplets; iter_nz filters them.

Implementations§

Source§

impl<R> SpMat<R>

Source

pub fn try_from_csc_data( num_rows: usize, num_cols: usize, col_offsets: Vec<usize>, row_indices: Vec<usize>, values: Vec<R>, ) -> Option<Self>

Source

pub fn csc_data(&self) -> (&[usize], &[usize], &[R])

Source

pub fn disassemble(self) -> (Vec<usize>, Vec<usize>, Vec<R>)

Source

pub fn zero(shape: (usize, usize)) -> Self

Source

pub fn is_zero(&self) -> bool
where R: Zero,

Source

pub fn id(n: usize) -> Self
where R: Scalar + One,

Source

pub fn is_id(&self) -> bool
where R: Scalar + One + Zero,

Source

pub fn is_triang(&self, t: TriangularType) -> bool
where R: Zero,

Source

pub fn iter(&self) -> impl Iterator<Item = (usize, usize, &R)>

Iterates the stored (row, col, value) triplets — may include explicit zeros.

Source

pub fn iter_nz(&self) -> impl Iterator<Item = (usize, usize, &R)>
where R: Zero,

iter, filtered to non-zero values.

Source

pub fn into_dense(self) -> Mat<R>

Source

pub fn nnz(&self) -> usize

Source

pub fn density(&self) -> f64

Source

pub fn redundancy(&self) -> f64
where R: Zero,

Source

pub fn mean_weight(&self) -> f64
where R: Ring, for<'x> &'x R: RingOps<R>,

Source

pub fn block_diag<I>(blocks: I) -> SpMat<R>
where I: IntoIterator<Item = SpMat<R>>,

Source

pub fn map<F, S>(self, f: F) -> SpMat<S>
where F: Fn(R) -> S,

Source§

impl<R> SpMat<R>

Source

pub fn from_entries<T>(shape: (usize, usize), entries: T) -> Self
where T: IntoIterator<Item = (usize, usize, R)>,

Builds an SpMat of shape from (row, col, value) triplets. Zero values are skipped; duplicates at the same position are summed.

Source

pub fn from_col_vecs<I>(nrows: usize, vecs: I) -> Self
where I: IntoIterator<Item = SpVec<R>>,

Source

pub fn from_row_major<I>(shape: (usize, usize), data: I) -> Self
where I: IntoIterator<Item = R>,

Source

pub fn scalar(n: usize, a: &R) -> Self

Source

pub fn diag<I>(shape: (usize, usize), entries: I) -> Self
where I: IntoIterator<Item = R>,

Source

pub fn is_diag(&self) -> bool

Source

pub fn col_vec(&self, j: usize) -> SpVec<R>

Source

pub fn transpose(&self) -> Self

Source

pub fn extract<F>(&self, shape: (usize, usize), f: F) -> SpMat<R>
where F: Fn(usize, usize) -> Option<(usize, usize)>,

New shape-d matrix whose entry at f(i, j) (if Some) is self[(i, j)]. Entries where f returns None are dropped.

Source

pub fn permute(&self, p: &Perm, q: &Perm) -> SpMat<R>

Source

pub fn permute_rows(&self, p: &Perm) -> SpMat<R>

Source

pub fn permute_cols(&self, q: &Perm) -> SpMat<R>

Source

pub fn permute_and_split(&self, p: &Perm, q: &Perm, r: usize) -> [SpMat<R>; 4]

Applies the permutations (p, q) to self and partitions the result into four blocks at row/col r:

  paq = [[a0 | a1],   a0: r×r,     a1: r×(n-r)
         [a2 | a3]]   a2: (m-r)×r, a3: (m-r)×(n-r)
Source

pub fn submat(&self, rows: Range<usize>, cols: Range<usize>) -> SpMat<R>

Source

pub fn submat_rows(&self, rows: Range<usize>) -> SpMat<R>

Source

pub fn submat_cols(&self, cols: Range<usize>) -> SpMat<R>

Source

pub fn block_split(self, point: (usize, usize)) -> [SpMat<R>; 4]

Source

pub fn h_split(self, k: usize) -> [SpMat<R>; 2]

Source

pub fn v_split(self, k: usize) -> [SpMat<R>; 2]

Source

pub fn block_combine(blocks: [SpMat<R>; 4]) -> SpMat<R>

Source

pub fn h_stack(left: Self, right: Self) -> Self

Source

pub fn v_stack(top: Self, bot: Self) -> Self

Source

pub fn extend_by_zero(&mut self, add_rows: usize, add_cols: usize)

Source

pub fn row_perm_mat(p: &Perm) -> Self
where R: One,

Source

pub fn col_perm_mat(p: &Perm) -> Self
where R: One,

Trait Implementations§

Source§

impl<R> Add for SpMat<R>

Source§

type Output = SpMat<R>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: SpMat<R>) -> Self::Output

Performs the + operation. Read more
Source§

impl<R> Add<&SpMat<R>> for &SpMat<R>

Source§

type Output = SpMat<R>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &SpMat<R>) -> Self::Output

Performs the + operation. Read more
Source§

impl<R> Add<&SpMat<R>> for SpMat<R>

Source§

type Output = SpMat<R>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &SpMat<R>) -> Self::Output

Performs the + operation. Read more
Source§

impl<R> Add<SpMat<R>> for &SpMat<R>

Source§

type Output = SpMat<R>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: SpMat<R>) -> Self::Output

Performs the + operation. Read more
Source§

impl<R> AddAssign for SpMat<R>

Source§

fn add_assign(&mut self, rhs: SpMat<R>)

Performs the += operation. Read more
Source§

impl<R> AddAssign<&SpMat<R>> for SpMat<R>

Source§

fn add_assign(&mut self, rhs: &SpMat<R>)

Performs the += operation. Read more
Source§

impl<R: Clone> Clone for SpMat<R>

Source§

fn clone(&self) -> SpMat<R>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<R> Debug for SpMat<R>
where R: Display + Debug,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<R> Default for SpMat<R>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<R> Display for SpMat<R>
where R: Display + Debug,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<R: Eq + Zero> Eq for SpMat<R>

Source§

impl<R> From<CscMatrix<R>> for SpMat<R>

Source§

fn from(inner: CscMatrix<R>) -> Self

Converts to this type from the input type.
Source§

impl<R> From<Mat<R>> for SpMat<R>
where R: Scalar + Zero,

Source§

fn from(value: Mat<R>) -> Self

Converts to this type from the input type.
Source§

impl<R> From<SpMat<R>> for Mat<R>

Source§

fn from(value: SpMat<R>) -> Self

Converts to this type from the input type.
Source§

impl<R> From<SpMat<R>> for SpPluq<R>
where R: Ring, for<'x> &'x R: RingOps<R>,

Converts a into the trivial PLUQ whose Schur complement is a itself

Source§

fn from(a: SpMat<R>) -> Self

Converts to this type from the input type.
Source§

impl<R> From<SpVec<R>> for SpMat<R>

Source§

fn from(vec: SpVec<R>) -> Self

Converts to this type from the input type.
Source§

impl<R> MatTrait for SpMat<R>

Source§

fn shape(&self) -> (usize, usize)

Source§

fn n_rows(&self) -> usize

Source§

fn n_cols(&self) -> usize

Source§

fn is_square(&self) -> bool

Source§

impl<R> Mul for SpMat<R>

Source§

type Output = SpMat<R>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: SpMat<R>) -> Self::Output

Performs the * operation. Read more
Source§

impl<R> Mul<&SpMat<R>> for &SpMat<R>

Source§

type Output = SpMat<R>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &SpMat<R>) -> Self::Output

Performs the * operation. Read more
Source§

impl<R> Mul<&SpMat<R>> for SpMat<R>

Source§

type Output = SpMat<R>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &SpMat<R>) -> Self::Output

Performs the * operation. Read more
Source§

impl<R> Mul<&SpVec<R>> for SpMat<R>
where R: Ring, for<'x> &'x R: RingOps<R>,

Source§

type Output = SpVec<R>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &SpVec<R>) -> Self::Output

Performs the * operation. Read more
Source§

impl<R> Mul<&SpVec<R>> for &SpMat<R>
where R: Ring, for<'x> &'x R: RingOps<R>,

Source§

type Output = SpVec<R>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &SpVec<R>) -> Self::Output

Performs the * operation. Read more
Source§

impl<R> Mul<SpMat<R>> for &SpMat<R>

Source§

type Output = SpMat<R>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: SpMat<R>) -> Self::Output

Performs the * operation. Read more
Source§

impl<R> Mul<SpVec<R>> for SpMat<R>
where R: Ring, for<'x> &'x R: RingOps<R>,

Source§

type Output = SpVec<R>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: SpVec<R>) -> Self::Output

Performs the * operation. Read more
Source§

impl<R> Mul<SpVec<R>> for &SpMat<R>
where R: Ring, for<'x> &'x R: RingOps<R>,

Source§

type Output = SpVec<R>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: SpVec<R>) -> Self::Output

Performs the * operation. Read more
Source§

impl<R> MulAssign for SpMat<R>

Source§

fn mul_assign(&mut self, rhs: SpMat<R>)

Performs the *= operation. Read more
Source§

impl<R> MulAssign<&SpMat<R>> for SpMat<R>

Source§

fn mul_assign(&mut self, rhs: &SpMat<R>)

Performs the *= operation. Read more
Source§

impl<R> Neg for SpMat<R>
where R: Scalar + Neg<Output = R>,

Source§

type Output = SpMat<R>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<R> Neg for &SpMat<R>
where R: Scalar + Neg<Output = R>,

Source§

type Output = SpMat<R>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<R: PartialEq + Zero> PartialEq for SpMat<R>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<R> Sub for SpMat<R>

Source§

type Output = SpMat<R>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: SpMat<R>) -> Self::Output

Performs the - operation. Read more
Source§

impl<R> Sub<&SpMat<R>> for &SpMat<R>

Source§

type Output = SpMat<R>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &SpMat<R>) -> Self::Output

Performs the - operation. Read more
Source§

impl<R> Sub<&SpMat<R>> for SpMat<R>

Source§

type Output = SpMat<R>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &SpMat<R>) -> Self::Output

Performs the - operation. Read more
Source§

impl<R> Sub<SpMat<R>> for &SpMat<R>

Source§

type Output = SpMat<R>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: SpMat<R>) -> Self::Output

Performs the - operation. Read more
Source§

impl<R> SubAssign for SpMat<R>

Source§

fn sub_assign(&mut self, rhs: SpMat<R>)

Performs the -= operation. Read more
Source§

impl<R> SubAssign<&SpMat<R>> for SpMat<R>

Source§

fn sub_assign(&mut self, rhs: &SpMat<R>)

Performs the -= operation. Read more

Auto Trait Implementations§

§

impl<R> Freeze for SpMat<R>

§

impl<R> RefUnwindSafe for SpMat<R>
where R: RefUnwindSafe,

§

impl<R> Send for SpMat<R>
where R: Send,

§

impl<R> Sync for SpMat<R>
where R: Sync,

§

impl<R> Unpin for SpMat<R>
where R: Unpin,

§

impl<R> UnsafeUnpin for SpMat<R>

§

impl<R> UnwindSafe for SpMat<R>
where R: 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> 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<T> CloneAnd for T
where T: Clone,

Source§

fn clone_and<F>(&self, f: F) -> Self
where F: FnOnce(&mut Self),

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T, Right> ClosedAdd<Right> for T
where T: Add<Right, Output = T> + AddAssign<Right>,

Source§

impl<T, Right> ClosedAddAssign<Right> for T
where T: ClosedAdd<Right> + AddAssign<Right>,

Source§

impl<T, Right> ClosedMul<Right> for T
where T: Mul<Right, Output = T> + MulAssign<Right>,

Source§

impl<T, Right> ClosedMulAssign<Right> for T
where T: ClosedMul<Right> + MulAssign<Right>,

Source§

impl<T> ClosedNeg for T
where T: Neg<Output = T>,

Source§

impl<T, Right> ClosedSub<Right> for T
where T: Sub<Right, Output = T> + SubAssign<Right>,

Source§

impl<T, Right> ClosedSubAssign<Right> for T
where T: ClosedSub<Right> + SubAssign<Right>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.