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>
impl<T> BandMat<T>
pub fn new(n: usize, m: usize, sub: u32, sup: u32) -> BandMat<T>
pub fn rows(&self) -> usize
pub fn cols(&self) -> usize
sourcepub unsafe fn set_rows(&mut self, n: usize)
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
sourcepub unsafe fn set_cols(&mut self, n: usize)
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
pub unsafe fn set_sub_diagonals(&mut self, n: u32)
pub unsafe fn set_sup_diagonals(&mut self, n: u32)
pub unsafe fn push(&mut self, val: T)
source§impl<T: Copy> BandMat<T>
impl<T: Copy> BandMat<T>
sourcepub fn from_matrix(
mat: Mat<T>,
sub_diagonals: u32,
sup_diagonals: u32
) -> BandMat<T>
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>
impl<T: Copy + Default> BandMat<T>
sourcepub fn to_matrix(bandmat: Self) -> Mat<T>
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.