[][src]Struct mop_blocks::dr_matrix::DrMatrix

pub struct DrMatrix<DS> { /* fields omitted */ }

Dense Row Matrix

Dense matrix filled row-by-row, i.e., the tradicional matrix that is generally taught in class or used by dense linear algebra algorithms.

Tailored exclusively for storing purposes, doesn't provide any arithmetic method.

Types

  • DS: Data Storage

Implementations

impl<DS> DrMatrix<DS>[src]

pub fn constructor(&mut self) -> DrMatrixRowsConstructor<DS>[src]

pub fn clear(&mut self) where
    DS: Clear
[src]

Clears the internal data and sets the number of rows to zero.

Example

use mop_blocks::doc_tests::dr_matrix_vec;
let mut dcca = dr_matrix_vec();
dcca.clear();
assert_eq!(dcca.cols(), 5);
assert_eq!(dcca.data(), &[]);
assert_eq!(dcca.rows(), 0);

pub fn cols(&self) -> usize[src]

The number of columns.

Example

use mop_blocks::doc_tests::dr_matrix_array;
assert_eq!(dr_matrix_array().cols(), 5);

pub fn rows(&self) -> usize[src]

The number of rows.

Example

use mop_blocks::doc_tests::dr_matrix_array;
assert_eq!(dr_matrix_array().rows(), 4);

pub fn truncate(&mut self, until_row_idx: usize) where
    DS: Truncate<Input = usize>, 
[src]

Example

use mop_blocks::doc_tests::dr_matrix_vec;
let mut ddma = dr_matrix_vec();
ddma.truncate(2);
assert_eq!(ddma.cols(), 5);
assert_eq!(ddma.data(), &[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
assert_eq!(ddma.rows(), 2);

impl<DS> DrMatrix<DS> where
    DS: WithCapacity<Input = usize>, 
[src]

pub fn with_capacity(rows: usize, cols: usize) -> Self[src]

Creates a new instance with an initial rows * cols capacity.

The number of columns will be equal cols while the number of rows will be equal to zero.

Example

use mop_blocks::dr_matrix::DrMatrix;
let matrix = DrMatrix::<Vec<i32>>::with_capacity(2, 3);
assert_eq!(matrix.cols(), 3);
assert_eq!(matrix.rows(), 0);

impl<DATA, DS> DrMatrix<DS> where
    DS: AsRef<[DATA]> + Storage<Item = DATA>, 
[src]

pub fn new<IDS>(rows: usize, cols: usize, into_data: IDS) -> Result<Self> where
    IDS: Into<DS>, 
[src]

Creates a new DrMatrix from raw parameters.

Arguments

  • shape - An array containing the number of rows and columns.
  • data - The matrix data.

Example

use mop_blocks::dr_matrix::DrMatrixArray;
let _ = DrMatrixArray::new(2, 4, [1, 2, 3, 4, 5, 6, 7, 8]);

pub fn as_ref(&self) -> DrMatrixRef<DATA>[src]

Converts the inner storage to a generic immutable slice storage.

Example

use mop_blocks::{doc_tests::dr_matrix_array, dr_matrix::DrMatrixRef};
assert_eq!(
  Ok(dr_matrix_array().as_ref()),
  DrMatrixRef::new(
    4, 5,
    &[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20][..],
  )
);

pub fn data(&self) -> &[DATA][src]

Immutable slice of the internal data.

Example

use mop_blocks::doc_tests::dr_matrix_vec;
assert_eq!(
  dr_matrix_vec().data(),
  &[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
);

pub fn row(&self, row_idx: usize) -> Option<&[DATA]>[src]

Example

use mop_blocks::doc_tests::dr_matrix_array;
let ddma = dr_matrix_array();
for row_idx in 0..4 {
  let starting_row_value = row_idx * 5 + 1;
  assert_eq!(
    ddma.row(row_idx as usize),
    Some(&[
      starting_row_value,
      starting_row_value + 1,
      starting_row_value + 2,
      starting_row_value + 3,
      starting_row_value + 4
    ][..])
  );
}

pub fn row_iter(&self) -> DrMatrixRowIter<DATA>[src]

pub fn to_vec(&self) -> DrMatrixVec<DATA> where
    DATA: Clone
[src]

pub fn value(&self, row_idx: usize, col_idx: usize) -> Option<&DATA>[src]

Example

use mop_blocks::doc_tests::dr_matrix_array;
let ddma = dr_matrix_array();
for row_idx in 0..4 {
  let starting_row_value = row_idx * 5 + 1;
  for col_idx in 0..5 {
    let value = (starting_row_value + col_idx) as i32;
    assert_eq!(ddma.value(row_idx, col_idx).copied(), Some(value));
  }
}

impl<DATA, DS> DrMatrix<DS> where
    DS: AsMut<[DATA]> + Storage<Item = DATA>, 
[src]

pub fn data_mut(&mut self) -> &mut [DATA][src]

pub fn remove_row(&mut self, idx: usize) where
    DS: Truncate<Input = usize>, 
[src]

Example

use mop_blocks::doc_tests::dr_matrix_vec;
let mut ddma = dr_matrix_vec();
ddma.remove_row(2);
assert_eq!(ddma.data(), &[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 16, 17, 18, 19, 20]);
assert_eq!(ddma.rows(), 3);

pub fn row_mut(&mut self, row_idx: usize) -> Option<&mut [DATA]>[src]

pub fn row_iter_mut(&mut self) -> DrMatrixRowIterMut<DATA>[src]

pub fn swap(&mut self, a: [usize; 2], b: [usize; 2]) -> bool where
    DS: AsRef<[DATA]>, 
[src]

pub fn swap_rows(&mut self, a: usize, b: usize) -> bool[src]

Example

use mop_blocks::doc_tests::dr_matrix_array;
let mut matrix = dr_matrix_array();
let original_0_row = matrix.row(0).unwrap().to_vec();
let original_3_row = matrix.row(3).unwrap().to_vec();
matrix.swap_rows(0, 3);
assert_eq!(matrix.row(0), Some(&original_3_row[..]));
assert_eq!(matrix.row(3), Some(&original_0_row[..]));

pub fn two_rows_mut(&mut self, a: usize, b: usize) -> Option<[&mut [DATA]; 2]>[src]

pub fn value_mut(&mut self, row_idx: usize, col_idx: usize) -> Option<&mut DATA>[src]

Trait Implementations

impl<DS: Clone> Clone for DrMatrix<DS>[src]

impl<DS: Copy> Copy for DrMatrix<DS>[src]

impl<DS: Debug> Debug for DrMatrix<DS>[src]

impl<DS: Default> Default for DrMatrix<DS>[src]

impl<DS: Hash> Hash for DrMatrix<DS>[src]

impl<DS: PartialEq> PartialEq<DrMatrix<DS>> for DrMatrix<DS>[src]

impl<DS: PartialOrd> PartialOrd<DrMatrix<DS>> for DrMatrix<DS>[src]

impl<DS> StructuralPartialEq for DrMatrix<DS>[src]

Auto Trait Implementations

impl<DS> Send for DrMatrix<DS> where
    DS: Send

impl<DS> Sync for DrMatrix<DS> where
    DS: Sync

impl<DS> Unpin for DrMatrix<DS> where
    DS: Unpin

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> TraitCfg for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.