Struct nalgebra_sparse::pattern::SparsityPattern [−][src]
A representation of the sparsity pattern of a CSR or CSC matrix.
CSR and CSC matrices store matrices in a very similar fashion. In fact, in a certain sense, they are transposed. More precisely, when reinterpreting the three data arrays of a CSR matrix as a CSC matrix, we obtain the CSC representation of its transpose.
SparsityPattern
is an abstraction built on this observation. Whereas CSR matrices
store a matrix row-by-row, and a CSC matrix stores a matrix column-by-column, a
SparsityPattern
represents only the index data structure of a matrix lane-by-lane.
Here, a lane is a generalization of rows and columns. We further define major lanes
and minor lanes. The sparsity pattern of a CSR matrix is then obtained by interpreting
major/minor as row/column. Conversely, we obtain the sparsity pattern of a CSC matrix by
interpreting major/minor as column/row.
This allows us to use a common abstraction to talk about sparsity patterns of CSR and CSC
matrices. This is convenient, because at the abstract level, the invariants of the formats
are the same. Hence we may encode the invariants of the index data structure separately from
the scalar values of the matrix. This is especially useful in applications where the
sparsity pattern is built ahead of the matrix values, or the same sparsity pattern is re-used
between different matrices. Finally, we can use SparsityPattern
to encode adjacency
information in graphs.
Format
The format is exactly the same as for the index data structures of CSR and CSC matrices.
This means that the sparsity pattern of an m x n
sparse matrix with nnz
non-zeros,
where in this case m x n
does not mean rows x columns
, but rather majors x minors
,
is represented by the following two arrays:
major_offsets
, an array of integers with lengthm + 1
.minor_indices
, an array of integers with lengthnnz
.
The invariants and relationship between major_offsets
and minor_indices
remain the same
as for row_offsets
and col_indices
in the CSR format
specification.
Implementations
impl SparsityPattern
[src]
pub fn zeros(major_dim: usize, minor_dim: usize) -> Self
[src]
Create a sparsity pattern of the given dimensions without explicitly stored entries.
pub fn major_offsets(&self) -> &[usize]
[src]
The offsets for the major dimension.
pub fn minor_indices(&self) -> &[usize]
[src]
The indices for the minor dimension.
pub fn major_dim(&self) -> usize
[src]
The number of major lanes in the pattern.
pub fn minor_dim(&self) -> usize
[src]
The number of minor lanes in the pattern.
pub fn nnz(&self) -> usize
[src]
The number of “non-zeros”, i.e. explicitly stored entries in the pattern.
pub fn lane(&self, major_index: usize) -> &[usize]
[src]
pub fn get_lane(&self, major_index: usize) -> Option<&[usize]>
[src]
Get the lane at the given index, or None
if out of bounds.
pub fn try_from_offsets_and_indices(
major_dim: usize,
minor_dim: usize,
major_offsets: Vec<usize>,
minor_indices: Vec<usize>
) -> Result<Self, SparsityPatternFormatError>
[src]
major_dim: usize,
minor_dim: usize,
major_offsets: Vec<usize>,
minor_indices: Vec<usize>
) -> Result<Self, SparsityPatternFormatError>
Try to construct a sparsity pattern from the given dimensions, major offsets and minor indices.
Returns an error if the data does not conform to the requirements.
pub fn entries(&self) -> SparsityPatternIter<'_>ⓘNotable traits for SparsityPatternIter<'a>
impl<'a> Iterator for SparsityPatternIter<'a> type Item = (usize, usize);
[src]
Notable traits for SparsityPatternIter<'a>
impl<'a> Iterator for SparsityPatternIter<'a> type Item = (usize, usize);
An iterator over the explicitly stored “non-zero” entries (i, j).
The iteration happens in a lane-major fashion, meaning that the lane index i increases monotonically, and the minor index j increases monotonically within each lane i.
Examples
let offsets = vec![0, 2, 3, 4]; let minor_indices = vec![0, 2, 1, 0]; let pattern = SparsityPattern::try_from_offsets_and_indices(3, 4, offsets, minor_indices) .unwrap(); let entries: Vec<_> = pattern.entries().collect(); assert_eq!(entries, vec![(0, 0), (0, 2), (1, 1), (2, 0)]);
pub fn disassemble(self) -> (Vec<usize>, Vec<usize>)
[src]
Returns the raw offset and index data for the sparsity pattern.
Examples
let offsets = vec![0, 2, 3, 4]; let minor_indices = vec![0, 2, 1, 0]; let pattern = SparsityPattern::try_from_offsets_and_indices( 3, 4, offsets.clone(), minor_indices.clone()) .unwrap(); let (offsets2, minor_indices2) = pattern.disassemble(); assert_eq!(offsets2, offsets); assert_eq!(minor_indices2, minor_indices);
pub fn transpose(&self) -> Self
[src]
Computes the transpose of the sparsity pattern.
This is analogous to matrix transposition, i.e. an entry (i, j)
becomes (j, i)
in the
new pattern.
Trait Implementations
impl Clone for SparsityPattern
[src]
fn clone(&self) -> SparsityPattern
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for SparsityPattern
[src]
impl Eq for SparsityPattern
[src]
impl PartialEq<SparsityPattern> for SparsityPattern
[src]
fn eq(&self, other: &SparsityPattern) -> bool
[src]
fn ne(&self, other: &SparsityPattern) -> bool
[src]
impl StructuralEq for SparsityPattern
[src]
impl StructuralPartialEq for SparsityPattern
[src]
Auto Trait Implementations
impl RefUnwindSafe for SparsityPattern
impl Send for SparsityPattern
impl Sync for SparsityPattern
impl Unpin for SparsityPattern
impl UnwindSafe for SparsityPattern
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
SS: SubsetOf<SP>,
pub fn to_subset(&self) -> Option<SS>
pub fn is_in_subset(&self) -> bool
pub fn to_subset_unchecked(&self) -> SS
pub fn from_subset(element: &SS) -> SP
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,