CsrMatrix

Struct CsrMatrix 

Source
pub struct CsrMatrix<DS, US> { /* private fields */ }
Expand description

This structure can hold differents mixed types of indexed storages.

Implementations§

Source§

impl<T> CsrMatrix<Vec<T>, Vec<usize>>

Source

pub fn new_rnd<F, R>(shape: [usize; 2], nnz: usize, rng: &mut R, cb: F) -> Self
where F: FnMut(&mut R, [usize; 2]) -> T, R: Rng,

Source

pub fn with_vec_capacity(shape: [usize; 2], nnz: usize) -> Self

Source§

impl<DA, UA> CsrMatrix<VecArray<DA>, VecArray<UA>>
where DA: Array, UA: Array<Item = usize>,

Source

pub fn new_rnd<F, R>(shape: [usize; 2], nnz: usize, rng: &mut R, cb: F) -> Self
where F: FnMut(&mut R, [usize; 2]) -> DA::Item, R: Rng,

Source

pub fn with_vec_array(cols: usize) -> Self

Source§

impl<DS, US> CsrMatrix<DS, US>
where DS: StDenseStoRef, US: StDenseStoRef<Item = usize>,

Source

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 data must be equal the length of indcs.
use mop_structs::matrix::csr_matrix::CsrMatrixRef;
let _ = CsrMatrixRef::new([2, 4], &[1, 2, 3], &[], &[0, 3, 3]);
  • The length of data is 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 ptrs must 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]);
Source

pub unsafe fn new_unchecked( shape: [usize; 2], data: DS, indcs: US, ptrs: US, ) -> Self

A faster and unsafe version of new.

Source

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]
    )
);
Source

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]);
Source

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]);
Source

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);
Source

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]);
Source

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_idx must be less than the number of rows.
use mop_structs::doc_tests::csr_matrix_array;
let _ = csr_matrix_array().row(10);
Source

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);
Source

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)));
Source

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_idx must be less than the number of rows and col_idx must 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>
where DS: StDenseStoMut, US: StDenseStoRef<Item = usize>,

Source

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]);
Source

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).

Source

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_idx must be less than the number of rows.
use mop_structs::doc_tests::csr_matrix_array;
let _ = csr_matrix_array().row_mut(10);
Source

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);
Source

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]);
Source

pub fn split_at_mut( &mut self, row_idx: usize, ) -> (CssSliceMut<'_, DS::Item>, CssSliceMut<'_, DS::Item>)

Source

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_idx must be less than the number of rows and col_idx must be less than the number of columns.
use mop_structs::doc_tests::csr_matrix_array;
let _ = csr_matrix_array().value_mut(10, 10);
Source

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
  • a row must be less than the number of rows and a column 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]);
  • b row must be less than the number of rows and b column 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]);
  • a or b coordinates 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>
where DS: DynDenseStoRef, US: DynDenseStoRef<Item = usize>,

Source

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>
where DS: DynDenseStoMut, US: DynDenseStoMut<Item = usize>,

Source

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]
));
Source

pub fn extend(&mut self, other: &Self)
where DS::Item: Copy, US::Item: Copy,

Source

pub fn row_constructor(&mut self) -> CsrMatrixRowConstructor<'_, DS, US>

See CsrMatrixRowConstructor for more information.

Source

pub fn truncate(&mut self, until_row_idx: usize)

Trait Implementations§

Source§

impl<DS: Clone, US: Clone> Clone for CsrMatrix<DS, US>

Source§

fn clone(&self) -> CsrMatrix<DS, US>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<DS: Debug, US: Debug> Debug for CsrMatrix<DS, US>

Source§

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

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

impl<DS: Default, US: Default> Default for CsrMatrix<DS, US>

Source§

fn default() -> CsrMatrix<DS, US>

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

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>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<DS: Hash, US: Hash> Hash for CsrMatrix<DS, US>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<DS, US> Matrix for CsrMatrix<DS, US>

Source§

fn cols(&self) -> usize

The number of columns.

§Examples
use mop_structs::{doc_tests::csr_matrix_array, prelude::*};
assert_eq!(csr_matrix_array().cols(), 5);
Source§

fn rows(&self) -> usize

The number of rows.

§Examples
use mop_structs::{doc_tests::csr_matrix_array, prelude::*};
assert_eq!(csr_matrix_array().rows(), 4);
Source§

impl<DS: PartialEq, US: PartialEq> PartialEq for CsrMatrix<DS, US>

Source§

fn eq(&self, other: &CsrMatrix<DS, US>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<DS: PartialOrd, US: PartialOrd> PartialOrd for CsrMatrix<DS, US>

Source§

fn partial_cmp(&self, other: &CsrMatrix<DS, US>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<DS, US> Serialize for CsrMatrix<DS, US>
where DS: Serialize, US: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<DS: Copy, US: Copy> Copy for CsrMatrix<DS, US>

Source§

impl<DS, US> StructuralPartialEq for CsrMatrix<DS, US>

Auto Trait Implementations§

§

impl<DS, US> Freeze for CsrMatrix<DS, US>
where DS: Freeze, US: Freeze,

§

impl<DS, US> RefUnwindSafe for CsrMatrix<DS, US>

§

impl<DS, US> Send for CsrMatrix<DS, US>
where DS: Send, US: Send,

§

impl<DS, US> Sync for CsrMatrix<DS, US>
where DS: Sync, US: Sync,

§

impl<DS, US> Unpin for CsrMatrix<DS, US>
where DS: Unpin, US: Unpin,

§

impl<DS, US> UnwindSafe for CsrMatrix<DS, US>
where DS: UnwindSafe, US: 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> 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> 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> 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, 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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,