Struct rust_blas::math::bandmat::BandMat

source ·
pub struct BandMat<T> { /* private fields */ }
Expand description

Banded Matrix A banded matrix is a matrix where only the diagonal, a number of super-diagonals and a number of sub-diagonals are non-zero. https://en.wikipedia.org/wiki/Band_matrix

Implementations§

source§

impl<T> BandMat<T>

source

pub fn new(n: usize, m: usize, sub: u32, sup: u32) -> BandMat<T>

source

pub fn rows(&self) -> usize

source

pub fn cols(&self) -> usize

source

pub unsafe fn set_rows(&mut self, n: usize)

Set Rows Manually

§Safety

No guarantees are made about rows x columns being equivalent to data length after this operation

source

pub unsafe fn set_cols(&mut self, n: usize)

Set Columns Manually

§Safety

No guarantees are made about rows x columns being equivalent to data length after this operation

source

pub unsafe fn set_sub_diagonals(&mut self, n: u32)

source

pub unsafe fn set_sup_diagonals(&mut self, n: u32)

source

pub unsafe fn push(&mut self, val: T)

source§

impl<T: Copy> BandMat<T>

source

pub fn from_matrix( mat: Mat<T>, sub_diagonals: u32, sup_diagonals: u32 ) -> BandMat<T>

Converts a Mat into a BandMat.

The idea is to compress the the band matrix by compressing it to a form that is as legible as possible but without many of the extraneous zeros. You can read more about the process here: Wikipedia and Official BLAS Docs, but the best demonstration is probably by example.

Say you have a matrix:

let m =
[
  0.5, 2.0, 0.0, 0.0,
  1.0, 0.5, 2.0, 0.0,
  0.0, 1.0, 0.5, 2.0,
  0.0, 0.0, 1.0, 0.5,
];

This method will transform it into:

let x = 0.0;
let m =
[
  x,   0.5, 2.0,
  1.0, 0.5, 2.0,
  1.0, 0.5, 2.0,
  1.0, 0.5,   x,
];

The x’s represent the values that will not be read by the blas operation, and therefore can remain unchanged. Notice that the dimensions of the new matrix are (rows, LDA), where LDA = <sub diagonals> + <sup diagonals> + 1. This matrix will be stored in the original memory of the matrix that is consumed by this method.

For details about how the conversion actually happens, consult the code comments.

§Panics

Panics if the size of the vector representing the input matrix is too small, that is rows * LDA > rows * cols. In this case there is not enough space to perform a safe conversion to the Band Storage format.

source§

impl<T: Copy + Default> BandMat<T>

source

pub fn to_matrix(bandmat: Self) -> Mat<T>

Converts a BandMat back into a Mat.

This method creates a Mat instance by reversing the steps from the from_matrix method. It will also fill in all the values that are “zero” to the default value of T.

For more information about the implementation, please consult the code comments.

§Panics

Panics if the values of rows * cols doesn’t correspond to the length of the data vector.

source§

impl<T: Clone> BandMat<T>

source

pub fn fill(value: T, n: usize, m: usize) -> BandMat<T>

Trait Implementations§

source§

impl<T> BandMatrix<T> for BandMat<T>

source§

fn sub_diagonals(&self) -> u32

source§

fn sup_diagonals(&self) -> u32

source§

fn as_matrix(&self) -> &dyn Matrix<T>

source§

impl<T: Debug> Debug for BandMat<T>

source§

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

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

impl<T: Display> Display for BandMat<T>

source§

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

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

impl<'a, T> From<&'a dyn BandMatrix<T>> for BandMat<T>
where T: Copy,

source§

fn from(a: &dyn BandMatrix<T>) -> BandMat<T>

Converts to this type from the input type.
source§

impl<T> Index<usize> for BandMat<T>

§

type Output = [T]

The returned type after indexing.
source§

fn index(&self, index: usize) -> &[T]

Performs the indexing (container[index]) operation. Read more
source§

impl<T> Matrix<T> for BandMat<T>

source§

fn lead_dim(&self) -> u32

The leading dimension of the matrix. Defaults to cols for RowMajor order and ‘rows’ for ColMajor order.
source§

fn rows(&self) -> u32

Returns the number of rows.
source§

fn cols(&self) -> u32

Returns the number of columns.
source§

fn as_ptr(&self) -> *const T

An unsafe pointer to a contiguous block of memory.
source§

fn as_mut_ptr(&mut self) -> *mut T

An unsafe pointer to a contiguous block of memory.
source§

fn order(&self) -> Order

The order of the matrix. Defaults to RowMajor.
source§

impl<T: PartialEq> PartialEq for BandMat<T>

source§

fn eq(&self, other: &BandMat<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T> StructuralPartialEq for BandMat<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for BandMat<T>
where T: RefUnwindSafe,

§

impl<T> Send for BandMat<T>
where T: Send,

§

impl<T> Sync for BandMat<T>
where T: Sync,

§

impl<T> Unpin for BandMat<T>
where T: Unpin,

§

impl<T> UnwindSafe for BandMat<T>
where T: 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> 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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.