pub struct CsrMatrix<DS, US> { /* private fields */ }Expand description
This structure can hold differents mixed types of indexed storages.
Implementations§
Source§impl<DS, US> CsrMatrix<DS, US>
impl<DS, US> CsrMatrix<DS, US>
Sourcepub fn new(shape: [usize; 2], data: DS, indcs: US, ptrs: US) -> Self
pub fn new(shape: [usize; 2], data: DS, indcs: US, ptrs: US) -> Self
Creates a new CsrMatrix from raw parameters.
§Arguments
shape- An array containing the number of rows and columns.data- The matrix data.indcs- Each column index of its corresponding data.ptrs- The length of each row.
§Examples
use mop_structs::matrix::csr_matrix::CsrMatrixArray;
let _ = CsrMatrixArray::new([2, 4], [1, 2, 3], [0, 1, 2], [0, 3, 3]);§Assertions
- The length of
datamust be equal the length ofindcs.
use mop_structs::matrix::csr_matrix::CsrMatrixRef;
let _ = CsrMatrixRef::new([2, 4], &[1, 2, 3], &[], &[0, 3, 3]);- The length of
datais greater than the number of rows times the number of columns.
use mop_structs::matrix::csr_matrix::CsrMatrixRef;
let _ = CsrMatrixRef::new(
[2, 4], &[1, 2, 3, 4, 5, 6, 7, 8, 9], &[0, 1, 2, 3, 0, 1, 2, 3, 0], &[0, 4, 8]
);- The length of
ptrsmust be equal the number of rows plus 1.
use mop_structs::matrix::csr_matrix::CsrMatrixRef;
let _ = CsrMatrixRef::new([2, 4], &[1, 2, 3], &[0, 1, 2], &[0, 3, 3, 3, 3]);- Column indices must be less than the number of columns.
use mop_structs::matrix::csr_matrix::CsrMatrixRef;
let _ = CsrMatrixRef::new([2, 4], &[1, 2, 3], &[0, 1, 9], &[0, 3, 3]);- Column indices of a row must be unique.
use mop_structs::matrix::csr_matrix::CsrMatrixRef;
let _ = CsrMatrixRef::new([2, 4], &[1, 2, 3], &[0, 0, 0], &[0, 3, 3]);- Rows length must end with the nnz.
use mop_structs::matrix::csr_matrix::CsrMatrixRef;
let _ = CsrMatrixRef::new([2, 4], &[1, 2, 3], &[0, 1, 2], &[0, 3, 9]);- Rows length must be in ascending order.
use mop_structs::matrix::csr_matrix::CsrMatrixRef;
let _ = CsrMatrixRef::new([3, 4], &[1, 2, 3, 4], &[0, 0, 0, 1], &[0, 1, 0, 4]);Sourcepub unsafe fn new_unchecked(
shape: [usize; 2],
data: DS,
indcs: US,
ptrs: US,
) -> Self
pub unsafe fn new_unchecked( shape: [usize; 2], data: DS, indcs: US, ptrs: US, ) -> Self
A faster and unsafe version of new.
Sourcepub fn as_ref(&self) -> CsrMatrixRef<'_, DS::Item>
pub fn as_ref(&self) -> CsrMatrixRef<'_, DS::Item>
Converts the inner storage to a generic immutable slice storage.
§Examples
use mop_structs::{
doc_tests::csr_matrix_array,
matrix::csr_matrix::CsrMatrixRef
};
assert_eq!(
csr_matrix_array().as_ref(),
CsrMatrixRef::new(
[4, 5],
&[1, 2, 3, 4, 5],
&[0, 2, 1, 3, 4],
&[0, 2, 4, 4, 5]
)
);Sourcepub fn data(&self) -> &[DS::Item]
pub fn data(&self) -> &[DS::Item]
Returns an immutable reference to the data elements.
§Examples
use mop_structs::doc_tests::csr_matrix_array;
let a = csr_matrix_array();
assert_eq!(a.data(), &[1, 2, 3, 4, 5]);Sourcepub fn indcs(&self) -> &[usize]
pub fn indcs(&self) -> &[usize]
Returns an immutable reference to the column indices of the data elements.
§Examples
use mop_structs::doc_tests::csr_matrix_array;
let a = csr_matrix_array();
assert_eq!(a.indcs(), &[0, 2, 1, 3, 4]);Sourcepub fn nnz(&self) -> usize
pub fn nnz(&self) -> usize
Returns the Number of NonZero elements.
§Examples
use mop_structs::doc_tests::csr_matrix_array;
assert_eq!(csr_matrix_array().nnz(), 5);Sourcepub fn ptrs(&self) -> &[usize]
pub fn ptrs(&self) -> &[usize]
Returns an immutable reference to the rows length.
§Examples
use mop_structs::doc_tests::csr_matrix_array;
let a = csr_matrix_array();
assert_eq!(a.ptrs(), &[0, 2, 4, 4, 5]);Sourcepub fn row(&self, row_idx: usize) -> CssSlice<'_, DS::Item>
pub fn row(&self, row_idx: usize) -> CssSlice<'_, DS::Item>
Returns an immutable reference to the row at the row_idx row.
§Examples
use mop_structs::{
doc_tests::csr_matrix_array,
vec::css::CssSlice
};
assert_eq!(
csr_matrix_array().row(0),
CssSlice::new(5, &[1, 2], &[0, 2])
);§Assertions
row_idxmust be less than the number of rows.
use mop_structs::doc_tests::csr_matrix_array;
let _ = csr_matrix_array().row(10);Sourcepub fn row_iter(&self) -> CsrMatrixRowIter<'_, DS::Item> ⓘ
pub fn row_iter(&self) -> CsrMatrixRowIter<'_, DS::Item> ⓘ
An iterator that returns immutable references of all rows.
§Examples
use mop_structs::{
doc_tests::csr_matrix_array,
vec::css::CssSlice
};
let mut a = csr_matrix_array();
let mut li = a.row_iter();
li.next();
assert_eq!(li.next(), Some(CssSlice::new(5, &[3, 4], &[1, 3])));
li.next();
li.next();
assert_eq!(li.next(), None);Sourcepub fn row_par_iter(
&self,
) -> ParallelIteratorWrapper<CsrMatrixRowIter<'_, DS::Item>>
pub fn row_par_iter( &self, ) -> ParallelIteratorWrapper<CsrMatrixRowIter<'_, DS::Item>>
An parallel iterator that returns immutable references of all rows.
§Examples
use mop_structs::{
doc_tests::csr_matrix_array,
prelude::*
};
let a = csr_matrix_array();
a.row_par_iter().enumerate().for_each(|(idx, x)| assert_eq!(x, a.row(idx)));Sourcepub fn value(&self, row_idx: usize, col_idx: usize) -> Option<&DS::Item>
pub fn value(&self, row_idx: usize, col_idx: usize) -> Option<&DS::Item>
If any, returns an immutable reference to the element at the row_idx row and
col_idx column.
§Examples
use mop_structs::doc_tests::csr_matrix_array;
let a = csr_matrix_array();
assert_eq!(a.value(0, 0), Some(&1));
assert_eq!(a.value(1, 0), None);§Assertions
row_idxmust be less than the number of rows andcol_idxmust be less than the number of columns.
use mop_structs::doc_tests::csr_matrix_array;
let _ = csr_matrix_array().value(10, 10);Source§impl<DS, US> CsrMatrix<DS, US>
impl<DS, US> CsrMatrix<DS, US>
Sourcepub fn data_mut(&mut self) -> &mut [DS::Item]
pub fn data_mut(&mut self) -> &mut [DS::Item]
Returns an mutable reference to the data elements.
§Examples
use mop_structs::doc_tests::csr_matrix_array;
let mut a = csr_matrix_array();
assert_eq!(a.data_mut(), &mut [1, 2, 3, 4, 5]);Sourcepub fn parts_with_data_mut(&mut self) -> (&mut [DS::Item], &[usize], &[usize])
pub fn parts_with_data_mut(&mut self) -> (&mut [DS::Item], &[usize], &[usize])
In a single borrow of Self, returns borrows for the most imporant inner
parts (&mut data, &indices and &pointers).
Sourcepub fn row_mut(&mut self, row_idx: usize) -> CssSliceMut<'_, DS::Item>
pub fn row_mut(&mut self, row_idx: usize) -> CssSliceMut<'_, DS::Item>
Returns an mutable reference to the row at the row_idx position.
§Examples
use mop_structs::{
doc_tests::csr_matrix_array,
vec::css::CssSliceMut
};
assert_eq!(
csr_matrix_array().row_mut(1),
CssSliceMut::new(5, &mut [3, 4], &[1, 3])
);§Assertions
row_idxmust be less than the number of rows.
use mop_structs::doc_tests::csr_matrix_array;
let _ = csr_matrix_array().row_mut(10);Sourcepub fn row_iter_mut(&mut self) -> CsrMatrixRowIterMut<'_, DS::Item> ⓘ
pub fn row_iter_mut(&mut self) -> CsrMatrixRowIterMut<'_, DS::Item> ⓘ
An iterator that returns mutable references of all rows.
§Examples
use mop_structs::{
doc_tests::csr_matrix_array,
vec::css::CssSliceMut
};
let mut a = csr_matrix_array();
let mut li = a.row_iter_mut();
li.next();
assert_eq!(li.next(), Some(CssSliceMut::new(5, &mut [3, 4], &[1, 3])));
li.next();
li.next();
assert_eq!(li.next(), None);Sourcepub fn row_par_iter_mut(
&mut self,
) -> ParallelIteratorWrapper<CsrMatrixRowIterMut<'_, DS::Item>>
pub fn row_par_iter_mut( &mut self, ) -> ParallelIteratorWrapper<CsrMatrixRowIterMut<'_, DS::Item>>
An parallel iterator that returns mutable references of all rows.
§Examples
use mop_structs::{
doc_tests::csr_matrix_array,
prelude::*
};
let mut a = csr_matrix_array();
a.row_par_iter_mut().for_each(|mut a| a.data_mut().iter_mut().for_each(|b| *b += 2));
assert_eq!(a.data(), &[3, 4, 5, 6, 7]);pub fn split_at_mut( &mut self, row_idx: usize, ) -> (CssSliceMut<'_, DS::Item>, CssSliceMut<'_, DS::Item>)
Sourcepub fn value_mut(
&mut self,
row_idx: usize,
col_idx: usize,
) -> Option<&mut DS::Item>
pub fn value_mut( &mut self, row_idx: usize, col_idx: usize, ) -> Option<&mut DS::Item>
If any, returns an mutable reference to the element at the row_idx row and
col_idx column.
§Examples
use mop_structs::doc_tests::csr_matrix_array;
let mut a = csr_matrix_array();
assert_eq!(a.value_mut(0, 0), Some(&mut 1));
assert_eq!(a.value_mut(1, 0), None);§Assertions
row_idxmust be less than the number of rows andcol_idxmust be less than the number of columns.
use mop_structs::doc_tests::csr_matrix_array;
let _ = csr_matrix_array().value_mut(10, 10);Sourcepub fn swap(&mut self, a: [usize; 2], b: [usize; 2])
pub fn swap(&mut self, a: [usize; 2], b: [usize; 2])
Swaps two elements of two distinct coordinates.
§Examples
use mop_structs::doc_tests::csr_matrix_array;
let mut a = csr_matrix_array();
a.swap([0, 0], [3, 4]);
assert_eq!(a.data(), &[5, 2, 3, 4, 1]);§Assertions
arow must be less than the number of rows andacolumn must be less than the number of columns.
use mop_structs::doc_tests::csr_matrix_array;
let _ = csr_matrix_array().swap([10, 10], [0, 0]);brow must be less than the number of rows andbcolumn must be less than the number of columns.
use mop_structs::doc_tests::csr_matrix_array;
let _ = csr_matrix_array().swap([0, 0], [10, 10]);aorbcoordinates must point to existing elements.
use mop_structs::doc_tests::csr_matrix_array;
let _ = csr_matrix_array().swap([1, 1], [2, 2]);Source§impl<DS, US> CsrMatrix<DS, US>
impl<DS, US> CsrMatrix<DS, US>
Sourcepub fn rows_capacity(&self) -> usize
pub fn rows_capacity(&self) -> usize
Returns the current rows capacity.
§Examples
use mop_structs::doc_tests::csr_matrix_vec_array;
assert_eq!(csr_matrix_vec_array().rows_capacity(), 4);Source§impl<DS, US> CsrMatrix<DS, US>
impl<DS, US> CsrMatrix<DS, US>
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Removes all values and sets the number of rows to zero but doesn’t modify the number of columns.
Note that this method has no effect on the allocated capacity.
§Examples
use mop_structs::{
doc_tests::csr_matrix_vec_array,
matrix::csr_matrix::CsrMatrixRef,
prelude::*
};
let mut a = csr_matrix_vec_array();
a.clear();
assert_eq!(a.as_ref(), CsrMatrixRef::new(
[0, a.cols()],
&[],
&[],
&[0]
));pub fn extend(&mut self, other: &Self)
Sourcepub fn row_constructor(&mut self) -> CsrMatrixRowConstructor<'_, DS, US>
pub fn row_constructor(&mut self) -> CsrMatrixRowConstructor<'_, DS, US>
See CsrMatrixRowConstructor for more information.
pub fn truncate(&mut self, until_row_idx: usize)
Trait Implementations§
Source§impl<'de, DS, US> Deserialize<'de> for CsrMatrix<DS, US>where
DS: Deserialize<'de>,
US: Deserialize<'de>,
impl<'de, DS, US> Deserialize<'de> for CsrMatrix<DS, US>where
DS: Deserialize<'de>,
US: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<DS, US> Matrix for CsrMatrix<DS, US>
impl<DS, US> Matrix for CsrMatrix<DS, US>
Source§impl<DS: PartialOrd, US: PartialOrd> PartialOrd for CsrMatrix<DS, US>
impl<DS: PartialOrd, US: PartialOrd> PartialOrd for CsrMatrix<DS, US>
impl<DS: Copy, US: Copy> Copy for CsrMatrix<DS, US>
impl<DS, US> StructuralPartialEq for CsrMatrix<DS, US>
Auto Trait Implementations§
impl<DS, US> Freeze for CsrMatrix<DS, US>
impl<DS, US> RefUnwindSafe for CsrMatrix<DS, US>where
DS: RefUnwindSafe,
US: RefUnwindSafe,
impl<DS, US> Send for CsrMatrix<DS, US>
impl<DS, US> Sync for CsrMatrix<DS, US>
impl<DS, US> Unpin for CsrMatrix<DS, US>
impl<DS, US> UnwindSafe for CsrMatrix<DS, US>where
DS: UnwindSafe,
US: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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>
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