Struct sprs::TriMatBase [−][src]
Sparse matrix in the triplet format.
Sparse matrices in the triplet format use three arrays of equal sizes (accessible through the
methods row_inds
, col_inds
, data
), the first one
storing the row indices of non-zero values, the second storing the
corresponding column indices and the last array storing the corresponding
scalar value. If a non-zero location is repeated in the arrays, the
non-zero value is taken as the sum of the corresponding scalar entries.
This format is useful for iteratively building a sparse matrix, since the various non-zero entries can be specified in any order, or even partially as is common in physics with partial derivatives equations.
This format cannot be used for arithmetic operations. Arithmetic operations
are more efficient in the compressed format.
A matrix in the triplet format can be converted to the compressed format
using the methods to_csc
and to_csr
.
The TriMatBase
type is parameterized by the storage type for the row and
column indices, IStorage
, and by the storage type for the non-zero values
DStorage
. Convenient aliases are availaible to specify frequent variant:
TriMat
refers to a triplet matrix owning the storage of its indices and
and values, TriMatView
refers to a triplet matrix with slices to store
its indices and values, while TriMatViewMut
refers to a a triplet matrix
using mutable slices.
Additionaly, the type aliases TriMatI
, TriMatViewI
and
TriMatViewMutI
can be used to choose an index type different from the
default usize
.
Implementations
impl<N, I: SpIndex> TriMatBase<Vec<I, Global>, Vec<N, Global>>
[src]
pub fn new(shape: (usize, usize)) -> Self
[src]
Create a new triplet matrix of shape (nb_rows, nb_cols)
pub fn with_capacity(shape: (usize, usize), cap: usize) -> Self
[src]
Create a new triplet matrix of shape (nb_rows, nb_cols)
, and
pre-allocate cap
elements on the backing storage
pub fn from_triplets(
shape: (usize, usize),
row_inds: Vec<I>,
col_inds: Vec<I>,
data: Vec<N>
) -> Self
[src]
shape: (usize, usize),
row_inds: Vec<I>,
col_inds: Vec<I>,
data: Vec<N>
) -> Self
Create a triplet matrix from its raw components. All arrays should have the same length.
Panics
- if the arrays don’t have the same length
- if either the row or column indices are out of bounds.
pub fn add_triplet(&mut self, row: usize, col: usize, val: N)
[src]
Append a non-zero triplet to this matrix.
pub fn reserve(&mut self, cap: usize)
[src]
Reserve cap
additional non-zeros
pub fn reserve_exact(&mut self, cap: usize)
[src]
Reserve exactly cap
non-zeros
impl<N, I: SpIndex, IStorage, DStorage> TriMatBase<IStorage, DStorage> where
IStorage: Deref<Target = [I]>,
DStorage: Deref<Target = [N]>,
[src]
IStorage: Deref<Target = [I]>,
DStorage: Deref<Target = [N]>,
pub fn rows(&self) -> usize
[src]
The number of rows of the matrix
pub fn cols(&self) -> usize
[src]
The number of cols of the matrix
pub fn shape(&self) -> (usize, usize)
[src]
The shape of the matrix, as a (rows, cols)
tuple
pub fn nnz(&self) -> usize
[src]
The number of non-zero entries
pub fn row_inds(&self) -> &[I]ⓘ
[src]
The non-zero row indices
pub fn col_inds(&self) -> &[I]ⓘ
[src]
The non-zero column indices
pub fn data(&self) -> &[N]ⓘ
[src]
The non-zero values
pub fn find_locations(&self, row: usize, col: usize) -> Vec<TripletIndex>
[src]
Find all non-zero entries at the location given by row
and col
pub fn transpose_view(&self) -> TriMatViewI<'_, N, I>
[src]
Get a transposed view of this matrix
pub fn triplet_iter(&self) -> TriMatIter<Iter<'_, I>, Iter<'_, I>, Iter<'_, N>>ⓘ
[src]
Get an iterator over non-zero elements stored by this matrix
pub fn to_csc<Iptr: SpIndex>(&self) -> CsMatI<N, I, Iptr> where
N: Clone + Num,
[src]
N: Clone + Num,
Create a CSC matrix from this triplet matrix
pub fn to_csr<Iptr: SpIndex>(&self) -> CsMatI<N, I, Iptr> where
N: Clone + Num,
[src]
N: Clone + Num,
Create a CSR matrix from this triplet matrix
pub fn view(&self) -> TriMatViewI<'_, N, I>
[src]
impl<'a, N, I: SpIndex> TriMatBase<&'a [I], &'a [N]>
[src]
pub fn triplet_iter_rbr(
&self
) -> TriMatIter<Iter<'a, I>, Iter<'a, I>, Iter<'a, N>>ⓘ
[src]
&self
) -> TriMatIter<Iter<'a, I>, Iter<'a, I>, Iter<'a, N>>ⓘ
Get an iterator over non-zero elements stored by this matrix
Reborrowing version of triplet_iter()
.
impl<N, I: SpIndex, IStorage, DStorage> TriMatBase<IStorage, DStorage> where
IStorage: DerefMut<Target = [I]>,
DStorage: DerefMut<Target = [N]>,
[src]
IStorage: DerefMut<Target = [I]>,
DStorage: DerefMut<Target = [N]>,
pub fn set_triplet(
&mut self,
TripletIndex: TripletIndex,
row: usize,
col: usize,
val: N
)
[src]
&mut self,
TripletIndex: TripletIndex,
row: usize,
col: usize,
val: N
)
Replace a non-zero value at the given index.
Indices can be obtained using find_locations
.
pub fn view_mut(&mut self) -> TriMatViewMutI<'_, N, I>
[src]
Trait Implementations
impl<IStorage: Debug, DStorage: Debug> Debug for TriMatBase<IStorage, DStorage>
[src]
impl<IStorage: Hash, DStorage: Hash> Hash for TriMatBase<IStorage, DStorage>
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<'a, N, I, IS, DS> IntoIterator for &'a TriMatBase<IS, DS> where
I: 'a + SpIndex,
N: 'a,
IS: Deref<Target = [I]>,
DS: Deref<Target = [N]>,
[src]
I: 'a + SpIndex,
N: 'a,
IS: Deref<Target = [I]>,
DS: Deref<Target = [N]>,
type Item = (&'a N, (I, I))
The type of the elements being iterated over.
type IntoIter = TriMatIter<Iter<'a, I>, Iter<'a, I>, Iter<'a, N>>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<IStorage: PartialEq, DStorage: PartialEq> PartialEq<TriMatBase<IStorage, DStorage>> for TriMatBase<IStorage, DStorage>
[src]
fn eq(&self, other: &TriMatBase<IStorage, DStorage>) -> bool
[src]
fn ne(&self, other: &TriMatBase<IStorage, DStorage>) -> bool
[src]
impl<N, I, IS, DS> SparseMat for TriMatBase<IS, DS> where
I: SpIndex,
IS: Deref<Target = [I]>,
DS: Deref<Target = [N]>,
[src]
I: SpIndex,
IS: Deref<Target = [I]>,
DS: Deref<Target = [N]>,
impl<'a, N, I, IS, DS> SparseMat for &'a TriMatBase<IS, DS> where
I: 'a + SpIndex,
N: 'a,
IS: Deref<Target = [I]>,
DS: Deref<Target = [N]>,
[src]
I: 'a + SpIndex,
N: 'a,
IS: Deref<Target = [I]>,
DS: Deref<Target = [N]>,
impl<IStorage, DStorage> StructuralPartialEq for TriMatBase<IStorage, DStorage>
[src]
Auto Trait Implementations
impl<IStorage, DStorage> RefUnwindSafe for TriMatBase<IStorage, DStorage> where
DStorage: RefUnwindSafe,
IStorage: RefUnwindSafe,
DStorage: RefUnwindSafe,
IStorage: RefUnwindSafe,
impl<IStorage, DStorage> Send for TriMatBase<IStorage, DStorage> where
DStorage: Send,
IStorage: Send,
DStorage: Send,
IStorage: Send,
impl<IStorage, DStorage> Sync for TriMatBase<IStorage, DStorage> where
DStorage: Sync,
IStorage: Sync,
DStorage: Sync,
IStorage: Sync,
impl<IStorage, DStorage> Unpin for TriMatBase<IStorage, DStorage> where
DStorage: Unpin,
IStorage: Unpin,
DStorage: Unpin,
IStorage: Unpin,
impl<IStorage, DStorage> UnwindSafe for TriMatBase<IStorage, DStorage> where
DStorage: UnwindSafe,
IStorage: UnwindSafe,
DStorage: UnwindSafe,
IStorage: UnwindSafe,
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> Pointable for T
pub const ALIGN: usize
type Init = T
The type for initializers.
pub unsafe fn init(init: <T as Pointable>::Init) -> usize
pub unsafe fn deref<'a>(ptr: usize) -> &'a T
pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
pub unsafe fn drop(ptr: usize)
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
[src]
SS: SubsetOf<SP>,
pub fn to_subset(&self) -> Option<SS>
[src]
pub fn is_in_subset(&self) -> bool
[src]
pub unsafe fn to_subset_unchecked(&self) -> SS
[src]
pub fn from_subset(element: &SS) -> SP
[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>,