[−][src]Struct mop_structs::matrix::csr_matrix::CsrMatrix
This structure can hold differents mixed types of indexed storages.
Methods
impl<DS, US> CsrMatrix<DS, US> where
DS: StDenseStoRef,
US: StDenseStoRef<Item = usize>, [src]
DS: StDenseStoRef,
US: StDenseStoRef<Item = usize>,
pub fn new(shape: [usize; 2], data: DS, indcs: US, ptrs: US) -> Self[src]
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]);
pub unsafe fn new_unchecked(
shape: [usize; 2],
data: DS,
indcs: US,
ptrs: US
) -> Self[src]
shape: [usize; 2],
data: DS,
indcs: US,
ptrs: US
) -> Self
A faster and unsafe version of new.
pub fn as_ref(&self) -> CsrMatrixRef<DS::Item>[src]
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] ) );
pub fn data(&self) -> &[DS::Item][src]
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]);
pub fn indcs(&self) -> &[usize][src]
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]);
pub fn nnz(&self) -> usize[src]
Returns the Number of NonZero elements.
Examples
use mop_structs::doc_tests::csr_matrix_array; assert_eq!(csr_matrix_array().nnz(), 5);
pub fn ptrs(&self) -> &[usize][src]
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]);
pub fn row(&self, row_idx: usize) -> CssSlice<DS::Item>[src]
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);
ⓘImportant traits for CsrMatrixRowIter<'a, T>pub fn row_iter(&self) -> CsrMatrixRowIter<DS::Item>[src]
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);
pub fn row_par_iter(
&self
) -> ParallelIteratorWrapper<CsrMatrixRowIter<DS::Item>>[src]
&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)));
pub fn value(&self, row_idx: usize, col_idx: usize) -> Option<&DS::Item>[src]
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);
impl<DS, US> CsrMatrix<DS, US> where
DS: StDenseStoMut,
US: StDenseStoRef<Item = usize>, [src]
DS: StDenseStoMut,
US: StDenseStoRef<Item = usize>,
pub fn data_mut(&mut self) -> &mut [DS::Item][src]
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]);
pub fn parts_with_data_mut(&mut self) -> (&mut [DS::Item], &[usize], &[usize])[src]
In a single borrow of Self, returns borrows for the most imporant inner
parts (&mut data, &indices and &pointers).
pub fn row_mut(&mut self, row_idx: usize) -> CssSliceMut<DS::Item>[src]
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);
ⓘImportant traits for CsrMatrixRowIterMut<'a, T>pub fn row_iter_mut(&mut self) -> CsrMatrixRowIterMut<DS::Item>[src]
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);
pub fn row_par_iter_mut(
&mut self
) -> ParallelIteratorWrapper<CsrMatrixRowIterMut<DS::Item>>[src]
&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>)[src]
&mut self,
row_idx: usize
) -> (CssSliceMut<DS::Item>, CssSliceMut<DS::Item>)
pub fn value_mut(
&mut self,
row_idx: usize,
col_idx: usize
) -> Option<&mut DS::Item>[src]
&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);
pub fn swap(&mut self, a: [usize; 2], b: [usize; 2])[src]
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]);
impl<DS, US> CsrMatrix<DS, US> where
DS: DynDenseStoRef,
US: DynDenseStoRef<Item = usize>, [src]
DS: DynDenseStoRef,
US: DynDenseStoRef<Item = usize>,
pub fn rows_capacity(&self) -> usize[src]
Returns the current rows capacity.
Examples
use mop_structs::doc_tests::csr_matrix_vec_array; assert_eq!(csr_matrix_vec_array().rows_capacity(), 4);
impl<DS, US> CsrMatrix<DS, US> where
DS: DynDenseStoMut,
US: DynDenseStoMut<Item = usize>, [src]
DS: DynDenseStoMut,
US: DynDenseStoMut<Item = usize>,
pub fn clear(&mut self)[src]
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) where
DS::Item: Copy,
US::Item: Copy, [src]
DS::Item: Copy,
US::Item: Copy,
pub fn row_constructor(&mut self) -> CsrMatrixRowConstructor<DS, US>[src]
See CsrMatrixRowConstructor for more information.
pub fn truncate(&mut self, until_row_idx: usize)[src]
Trait Implementations
impl<DS, US> Matrix for CsrMatrix<DS, US>[src]
fn cols(&self) -> usize[src]
The number of columns.
Examples
use mop_structs::{doc_tests::csr_matrix_array, prelude::*}; assert_eq!(csr_matrix_array().cols(), 5);
fn rows(&self) -> usize[src]
The number of rows.
Examples
use mop_structs::{doc_tests::csr_matrix_array, prelude::*}; assert_eq!(csr_matrix_array().rows(), 4);
impl<DS: PartialOrd, US: PartialOrd> PartialOrd<CsrMatrix<DS, US>> for CsrMatrix<DS, US>[src]
fn partial_cmp(&self, other: &CsrMatrix<DS, US>) -> Option<Ordering>[src]
fn lt(&self, other: &CsrMatrix<DS, US>) -> bool[src]
fn le(&self, other: &CsrMatrix<DS, US>) -> bool[src]
fn gt(&self, other: &CsrMatrix<DS, US>) -> bool[src]
fn ge(&self, other: &CsrMatrix<DS, US>) -> bool[src]
impl<DS: Copy, US: Copy> Copy for CsrMatrix<DS, US>[src]
impl<DS: Clone, US: Clone> Clone for CsrMatrix<DS, US>[src]
fn clone(&self) -> CsrMatrix<DS, US>[src]
fn clone_from(&mut self, source: &Self)1.0.0[src]
Performs copy-assignment from source. Read more
impl<DS: PartialEq, US: PartialEq> PartialEq<CsrMatrix<DS, US>> for CsrMatrix<DS, US>[src]
fn eq(&self, other: &CsrMatrix<DS, US>) -> bool[src]
fn ne(&self, other: &CsrMatrix<DS, US>) -> bool[src]
impl<DS: Default, US: Default> Default for CsrMatrix<DS, US>[src]
impl<DS: Hash, US: Hash> Hash for CsrMatrix<DS, US>[src]
fn hash<__HDSUS: Hasher>(&self, state: &mut __HDSUS)[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher, 1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher]. Read more
impl<DS: Debug, US: Debug> Debug for CsrMatrix<DS, US>[src]
impl<DS, US> Serialize for CsrMatrix<DS, US> where
DS: Serialize,
US: Serialize, [src]
DS: Serialize,
US: Serialize,
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer, [src]
__S: Serializer,
impl<'de, DS, US> Deserialize<'de> for CsrMatrix<DS, US> where
DS: Deserialize<'de>,
US: Deserialize<'de>, [src]
DS: Deserialize<'de>,
US: Deserialize<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>, [src]
__D: Deserializer<'de>,
Auto Trait Implementations
impl<DS, US> Send for CsrMatrix<DS, US> where
DS: Send,
US: Send,
DS: Send,
US: Send,
impl<DS, US> Sync for CsrMatrix<DS, US> where
DS: Sync,
US: Sync,
DS: Sync,
US: Sync,
Blanket Implementations
impl<T> From for T[src]
impl<T, U> Into for T where
U: From<T>, [src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
impl<T, U> TryFrom for T where
U: Into<T>, [src]
U: Into<T>,
type Error = !
try_from)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T> Borrow for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T, U> TryInto for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
impl<T> DeserializeOwned for T where
T: Deserialize<'de>, [src]
T: Deserialize<'de>,