Jet
v1.3.3
|
Compressed Sparse Row (CSR) matrix class. More...
#include <jet/matrix_csr.h>
Classes | |
struct | Element |
Public Types | |
typedef std::vector< T > | NonZeroContainerType |
typedef NonZeroContainerType::iterator | NonZeroIterator |
typedef NonZeroContainerType::const_iterator | ConstNonZeroIterator |
typedef std::vector< size_t > | IndexContainerType |
typedef IndexContainerType::iterator | IndexIterator |
typedef IndexContainerType::const_iterator | ConstIndexIterator |
Public Member Functions | |
MatrixCsr () | |
Constructs an empty matrix. More... | |
MatrixCsr (const std::initializer_list< std::initializer_list< T >> &lst, T epsilon=std::numeric_limits< T >::epsilon()) | |
Compresses given initializer list lst into a sparse matrix. More... | |
template<typename E > | |
MatrixCsr (const MatrixExpression< T, E > &other, T epsilon=std::numeric_limits< T >::epsilon()) | |
Compresses input (dense) matrix expression into a sparse matrix. More... | |
MatrixCsr (const MatrixCsr &other) | |
Copy constructor. More... | |
MatrixCsr (MatrixCsr &&other) | |
Move constructor. More... | |
void | clear () |
Clears the matrix and make it zero-dimensional. More... | |
void | set (const T &s) |
Sets whole matrix with input scalar. More... | |
void | set (const MatrixCsr &other) |
Copy from given sparse matrix. More... | |
void | reserve (size_t rows, size_t cols, size_t numNonZeros) |
Reserves memory space of this matrix. More... | |
void | compress (const std::initializer_list< std::initializer_list< T >> &lst, T epsilon=std::numeric_limits< T >::epsilon()) |
Compresses given initializer list lst into a sparse matrix. More... | |
template<typename E > | |
void | compress (const MatrixExpression< T, E > &other, T epsilon=std::numeric_limits< T >::epsilon()) |
Compresses input (dense) matrix expression into a sparse matrix. More... | |
void | addElement (size_t i, size_t j, const T &value) |
Adds non-zero element to (i, j). More... | |
void | addElement (const Element &element) |
Adds non-zero element. More... | |
void | addRow (const NonZeroContainerType &nonZeros, const IndexContainerType &columnIndices) |
void | setElement (size_t i, size_t j, const T &value) |
Sets non-zero element to (i, j). More... | |
void | setElement (const Element &element) |
Sets non-zero element. More... | |
bool | isEqual (const MatrixCsr &other) const |
bool | isSimilar (const MatrixCsr &other, double tol=std::numeric_limits< double >::epsilon()) const |
bool | isSquare () const |
Returns true if this matrix is a square matrix. More... | |
Size2 | size () const |
Returns the size of this matrix. More... | |
size_t | rows () const |
Returns number of rows of this matrix. More... | |
size_t | cols () const |
Returns number of columns of this matrix. More... | |
size_t | numberOfNonZeros () const |
Returns the number of non-zero elements. More... | |
const T & | nonZero (size_t i) const |
Returns i-th non-zero element. More... | |
T & | nonZero (size_t i) |
Returns i-th non-zero element. More... | |
const size_t & | rowPointer (size_t i) const |
Returns i-th row pointer. More... | |
const size_t & | columnIndex (size_t i) const |
Returns i-th column index. More... | |
T * | nonZeroData () |
Returns pointer of the non-zero elements data. More... | |
const T *const | nonZeroData () const |
Returns constant pointer of the non-zero elements data. More... | |
const size_t *const | rowPointersData () const |
Returns constant pointer of the row pointers data. More... | |
const size_t *const | columnIndicesData () const |
Returns constant pointer of the column indices data. More... | |
NonZeroIterator | nonZeroBegin () |
Returns the begin iterator of the non-zero elements. More... | |
ConstNonZeroIterator | nonZeroBegin () const |
Returns the begin const iterator of the non-zero elements. More... | |
NonZeroIterator | nonZeroEnd () |
Returns the end iterator of the non-zero elements. More... | |
ConstNonZeroIterator | nonZeroEnd () const |
Returns the end const iterator of the non-zero elements. More... | |
IndexIterator | rowPointersBegin () |
Returns the begin iterator of the row pointers. More... | |
ConstIndexIterator | rowPointersBegin () const |
Returns the begin const iterator of the row pointers. More... | |
IndexIterator | rowPointersEnd () |
Returns the end iterator of the row pointers. More... | |
ConstIndexIterator | rowPointersEnd () const |
Returns the end const iterator of the row pointers. More... | |
IndexIterator | columnIndicesBegin () |
Returns the begin iterator of the column indices. More... | |
ConstIndexIterator | columnIndicesBegin () const |
Returns the begin const iterator of the column indices. More... | |
IndexIterator | columnIndicesEnd () |
Returns the end iterator of the column indices. More... | |
ConstIndexIterator | columnIndicesEnd () const |
Returns the end const iterator of the column indices. More... | |
MatrixCsr | add (const T &s) const |
Returns this matrix + input scalar. More... | |
MatrixCsr | add (const MatrixCsr &m) const |
Returns this matrix + input matrix (element-wise). More... | |
MatrixCsr | sub (const T &s) const |
Returns this matrix - input scalar. More... | |
MatrixCsr | sub (const MatrixCsr &m) const |
Returns this matrix - input matrix (element-wise). More... | |
MatrixCsr | mul (const T &s) const |
Returns this matrix * input scalar. More... | |
template<typename VE > | |
MatrixCsrVectorMul< T, VE > | mul (const VectorExpression< T, VE > &v) const |
Returns this matrix * input vector. More... | |
template<typename ME > | |
MatrixCsrMatrixMul< T, ME > | mul (const MatrixExpression< T, ME > &m) const |
Returns this matrix * input matrix. More... | |
MatrixCsr | div (const T &s) const |
Returns this matrix / input scalar. More... | |
MatrixCsr | radd (const T &s) const |
Returns input scalar + this matrix. More... | |
MatrixCsr | radd (const MatrixCsr &m) const |
Returns input matrix + this matrix (element-wise). More... | |
MatrixCsr | rsub (const T &s) const |
Returns input scalar - this matrix. More... | |
MatrixCsr | rsub (const MatrixCsr &m) const |
Returns input matrix - this matrix (element-wise). More... | |
MatrixCsr | rmul (const T &s) const |
Returns input scalar * this matrix. More... | |
MatrixCsr | rdiv (const T &s) const |
Returns input matrix / this scalar. More... | |
void | iadd (const T &s) |
Adds input scalar to this matrix. More... | |
void | iadd (const MatrixCsr &m) |
Adds input matrix to this matrix (element-wise). More... | |
void | isub (const T &s) |
Subtracts input scalar from this matrix. More... | |
void | isub (const MatrixCsr &m) |
Subtracts input matrix from this matrix (element-wise). More... | |
void | imul (const T &s) |
Multiplies input scalar to this matrix. More... | |
template<typename ME > | |
void | imul (const MatrixExpression< T, ME > &m) |
Multiplies input matrix to this matrix. More... | |
void | idiv (const T &s) |
Divides this matrix with input scalar. More... | |
T | sum () const |
Returns sum of all elements. More... | |
T | avg () const |
Returns average of all elements. More... | |
T | min () const |
Returns minimum among all elements. More... | |
T | max () const |
Returns maximum among all elements. More... | |
T | absmin () const |
Returns absolute minimum among all elements. More... | |
T | absmax () const |
Returns absolute maximum among all elements. More... | |
T | trace () const |
template<typename U > | |
MatrixCsr< U > | castTo () const |
Type-casts to different value-typed matrix. More... | |
template<typename E > | |
MatrixCsr & | operator= (const E &m) |
Compresses input (dense) matrix expression into a sparse matrix. More... | |
MatrixCsr & | operator= (const MatrixCsr &other) |
Copies to this matrix. More... | |
MatrixCsr & | operator= (MatrixCsr &&other) |
Moves to this matrix. More... | |
MatrixCsr & | operator+= (const T &s) |
Addition assignment with input scalar. More... | |
MatrixCsr & | operator+= (const MatrixCsr &m) |
Addition assignment with input matrix (element-wise). More... | |
MatrixCsr & | operator-= (const T &s) |
Subtraction assignment with input scalar. More... | |
MatrixCsr & | operator-= (const MatrixCsr &m) |
Subtraction assignment with input matrix (element-wise). More... | |
MatrixCsr & | operator*= (const T &s) |
Multiplication assignment with input scalar. More... | |
template<typename ME > | |
MatrixCsr & | operator*= (const MatrixExpression< T, ME > &m) |
Multiplication assignment with input matrix. More... | |
MatrixCsr & | operator/= (const T &s) |
Division assignment with input scalar. More... | |
T | operator() (size_t i, size_t j) const |
Returns (i,j) element. More... | |
bool | operator== (const MatrixCsr &m) const |
Returns true if is equal to m. More... | |
bool | operator!= (const MatrixCsr &m) const |
Returns true if is not equal to m. More... | |
Static Public Member Functions | |
static MatrixCsr< T > | makeIdentity (size_t m) |
Compressed Sparse Row (CSR) matrix class.
This class defines Compressed Sparse Row (CSR) matrix using arrays of non-zero elements, row pointers, and column indices.
T | Type of the element. |
typedef IndexContainerType::const_iterator jet::MatrixCsr< T >::ConstIndexIterator |
typedef NonZeroContainerType::const_iterator jet::MatrixCsr< T >::ConstNonZeroIterator |
typedef std::vector<size_t> jet::MatrixCsr< T >::IndexContainerType |
typedef IndexContainerType::iterator jet::MatrixCsr< T >::IndexIterator |
typedef std::vector<T> jet::MatrixCsr< T >::NonZeroContainerType |
typedef NonZeroContainerType::iterator jet::MatrixCsr< T >::NonZeroIterator |
jet::MatrixCsr< T >::MatrixCsr | ( | ) |
Constructs an empty matrix.
jet::MatrixCsr< T >::MatrixCsr | ( | const std::initializer_list< std::initializer_list< T >> & | lst, |
T | epsilon = std::numeric_limits< T >::epsilon() |
||
) |
Compresses given initializer list lst
into a sparse matrix.
This constructor will build a matrix with given initializer list lst
such as
Note the initializer has 4x3 structure which will create 4x3 matrix. During the process, zero elements (less than epsilon
) will not be stored.
lst | Initializer list that should be copy to the new matrix. |
jet::MatrixCsr< T >::MatrixCsr | ( | const MatrixExpression< T, E > & | other, |
T | epsilon = std::numeric_limits< T >::epsilon() |
||
) |
Compresses input (dense) matrix expression into a sparse matrix.
This function sets this sparse matrix with dense input matrix. During the process, zero elements (less than epsilon
) will not be stored.
jet::MatrixCsr< T >::MatrixCsr | ( | const MatrixCsr< T > & | other | ) |
Copy constructor.
jet::MatrixCsr< T >::MatrixCsr | ( | MatrixCsr< T > && | other | ) |
Move constructor.
T jet::MatrixCsr< T >::absmax | ( | ) | const |
Returns absolute maximum among all elements.
T jet::MatrixCsr< T >::absmin | ( | ) | const |
Returns absolute minimum among all elements.
MatrixCsr jet::MatrixCsr< T >::add | ( | const MatrixCsr< T > & | m | ) | const |
Returns this matrix + input matrix (element-wise).
MatrixCsr jet::MatrixCsr< T >::add | ( | const T & | s | ) | const |
Returns this matrix + input scalar.
void jet::MatrixCsr< T >::addElement | ( | const Element & | element | ) |
Adds non-zero element.
void jet::MatrixCsr< T >::addElement | ( | size_t | i, |
size_t | j, | ||
const T & | value | ||
) |
Adds non-zero element to (i, j).
void jet::MatrixCsr< T >::addRow | ( | const NonZeroContainerType & | nonZeros, |
const IndexContainerType & | columnIndices | ||
) |
T jet::MatrixCsr< T >::avg | ( | ) | const |
Returns average of all elements.
Type-casts to different value-typed matrix.
void jet::MatrixCsr< T >::clear | ( | ) |
Clears the matrix and make it zero-dimensional.
size_t jet::MatrixCsr< T >::cols | ( | ) | const |
Returns number of columns of this matrix.
const size_t& jet::MatrixCsr< T >::columnIndex | ( | size_t | i | ) | const |
Returns i-th column index.
IndexIterator jet::MatrixCsr< T >::columnIndicesBegin | ( | ) |
Returns the begin iterator of the column indices.
ConstIndexIterator jet::MatrixCsr< T >::columnIndicesBegin | ( | ) | const |
Returns the begin const iterator of the column indices.
const size_t* const jet::MatrixCsr< T >::columnIndicesData | ( | ) | const |
Returns constant pointer of the column indices data.
IndexIterator jet::MatrixCsr< T >::columnIndicesEnd | ( | ) |
Returns the end iterator of the column indices.
ConstIndexIterator jet::MatrixCsr< T >::columnIndicesEnd | ( | ) | const |
Returns the end const iterator of the column indices.
void jet::MatrixCsr< T >::compress | ( | const MatrixExpression< T, E > & | other, |
T | epsilon = std::numeric_limits< T >::epsilon() |
||
) |
Compresses input (dense) matrix expression into a sparse matrix.
This function sets this sparse matrix with dense input matrix. During the process, zero elements (less than epsilon
) will not be stored.
void jet::MatrixCsr< T >::compress | ( | const std::initializer_list< std::initializer_list< T >> & | lst, |
T | epsilon = std::numeric_limits< T >::epsilon() |
||
) |
Compresses given initializer list lst
into a sparse matrix.
This function will fill the matrix with given initializer list lst
such as
Note the initializer has 4x3 structure which will resize to 4x3 matrix. During the process, zero elements (less than epsilon
) will not be stored.
lst | Initializer list that should be copy to the new matrix. |
MatrixCsr jet::MatrixCsr< T >::div | ( | const T & | s | ) | const |
Returns this matrix / input scalar.
void jet::MatrixCsr< T >::iadd | ( | const MatrixCsr< T > & | m | ) |
Adds input matrix to this matrix (element-wise).
void jet::MatrixCsr< T >::iadd | ( | const T & | s | ) |
Adds input scalar to this matrix.
void jet::MatrixCsr< T >::idiv | ( | const T & | s | ) |
Divides this matrix with input scalar.
void jet::MatrixCsr< T >::imul | ( | const MatrixExpression< T, ME > & | m | ) |
Multiplies input matrix to this matrix.
void jet::MatrixCsr< T >::imul | ( | const T & | s | ) |
Multiplies input scalar to this matrix.
bool jet::MatrixCsr< T >::isEqual | ( | const MatrixCsr< T > & | other | ) | const |
bool jet::MatrixCsr< T >::isSimilar | ( | const MatrixCsr< T > & | other, |
double | tol = std::numeric_limits< double >::epsilon() |
||
) | const |
Returns true if this matrix is similar to the input matrix within the given tolerance.
bool jet::MatrixCsr< T >::isSquare | ( | ) | const |
Returns true if this matrix is a square matrix.
void jet::MatrixCsr< T >::isub | ( | const MatrixCsr< T > & | m | ) |
Subtracts input matrix from this matrix (element-wise).
void jet::MatrixCsr< T >::isub | ( | const T & | s | ) |
Subtracts input scalar from this matrix.
|
static |
Makes a m x m matrix with all diagonal elements to 1, and other elements to 0.
T jet::MatrixCsr< T >::max | ( | ) | const |
Returns maximum among all elements.
T jet::MatrixCsr< T >::min | ( | ) | const |
Returns minimum among all elements.
MatrixCsrMatrixMul<T, ME> jet::MatrixCsr< T >::mul | ( | const MatrixExpression< T, ME > & | m | ) | const |
Returns this matrix * input matrix.
MatrixCsr jet::MatrixCsr< T >::mul | ( | const T & | s | ) | const |
Returns this matrix * input scalar.
MatrixCsrVectorMul<T, VE> jet::MatrixCsr< T >::mul | ( | const VectorExpression< T, VE > & | v | ) | const |
Returns this matrix * input vector.
T& jet::MatrixCsr< T >::nonZero | ( | size_t | i | ) |
Returns i-th non-zero element.
const T& jet::MatrixCsr< T >::nonZero | ( | size_t | i | ) | const |
Returns i-th non-zero element.
NonZeroIterator jet::MatrixCsr< T >::nonZeroBegin | ( | ) |
Returns the begin iterator of the non-zero elements.
ConstNonZeroIterator jet::MatrixCsr< T >::nonZeroBegin | ( | ) | const |
Returns the begin const iterator of the non-zero elements.
T* jet::MatrixCsr< T >::nonZeroData | ( | ) |
Returns pointer of the non-zero elements data.
const T* const jet::MatrixCsr< T >::nonZeroData | ( | ) | const |
Returns constant pointer of the non-zero elements data.
NonZeroIterator jet::MatrixCsr< T >::nonZeroEnd | ( | ) |
Returns the end iterator of the non-zero elements.
ConstNonZeroIterator jet::MatrixCsr< T >::nonZeroEnd | ( | ) | const |
Returns the end const iterator of the non-zero elements.
size_t jet::MatrixCsr< T >::numberOfNonZeros | ( | ) | const |
Returns the number of non-zero elements.
bool jet::MatrixCsr< T >::operator!= | ( | const MatrixCsr< T > & | m | ) | const |
Returns true if is not equal to m.
T jet::MatrixCsr< T >::operator() | ( | size_t | i, |
size_t | j | ||
) | const |
Returns (i,j) element.
MatrixCsr& jet::MatrixCsr< T >::operator*= | ( | const MatrixExpression< T, ME > & | m | ) |
Multiplication assignment with input matrix.
MatrixCsr& jet::MatrixCsr< T >::operator*= | ( | const T & | s | ) |
Multiplication assignment with input scalar.
MatrixCsr& jet::MatrixCsr< T >::operator+= | ( | const MatrixCsr< T > & | m | ) |
Addition assignment with input matrix (element-wise).
MatrixCsr& jet::MatrixCsr< T >::operator+= | ( | const T & | s | ) |
Addition assignment with input scalar.
MatrixCsr& jet::MatrixCsr< T >::operator-= | ( | const MatrixCsr< T > & | m | ) |
Subtraction assignment with input matrix (element-wise).
MatrixCsr& jet::MatrixCsr< T >::operator-= | ( | const T & | s | ) |
Subtraction assignment with input scalar.
MatrixCsr& jet::MatrixCsr< T >::operator/= | ( | const T & | s | ) |
Division assignment with input scalar.
MatrixCsr& jet::MatrixCsr< T >::operator= | ( | const E & | m | ) |
Compresses input (dense) matrix expression into a sparse matrix.
This function sets this sparse matrix with dense input matrix. During the process, zero elements (less than epsilon
) will not be stored.
MatrixCsr& jet::MatrixCsr< T >::operator= | ( | const MatrixCsr< T > & | other | ) |
Copies to this matrix.
MatrixCsr& jet::MatrixCsr< T >::operator= | ( | MatrixCsr< T > && | other | ) |
Moves to this matrix.
bool jet::MatrixCsr< T >::operator== | ( | const MatrixCsr< T > & | m | ) | const |
Returns true if is equal to m.
MatrixCsr jet::MatrixCsr< T >::radd | ( | const MatrixCsr< T > & | m | ) | const |
Returns input matrix + this matrix (element-wise).
MatrixCsr jet::MatrixCsr< T >::radd | ( | const T & | s | ) | const |
Returns input scalar + this matrix.
MatrixCsr jet::MatrixCsr< T >::rdiv | ( | const T & | s | ) | const |
Returns input matrix / this scalar.
void jet::MatrixCsr< T >::reserve | ( | size_t | rows, |
size_t | cols, | ||
size_t | numNonZeros | ||
) |
Reserves memory space of this matrix.
MatrixCsr jet::MatrixCsr< T >::rmul | ( | const T & | s | ) | const |
Returns input scalar * this matrix.
const size_t& jet::MatrixCsr< T >::rowPointer | ( | size_t | i | ) | const |
Returns i-th row pointer.
IndexIterator jet::MatrixCsr< T >::rowPointersBegin | ( | ) |
Returns the begin iterator of the row pointers.
ConstIndexIterator jet::MatrixCsr< T >::rowPointersBegin | ( | ) | const |
Returns the begin const iterator of the row pointers.
const size_t* const jet::MatrixCsr< T >::rowPointersData | ( | ) | const |
Returns constant pointer of the row pointers data.
IndexIterator jet::MatrixCsr< T >::rowPointersEnd | ( | ) |
Returns the end iterator of the row pointers.
ConstIndexIterator jet::MatrixCsr< T >::rowPointersEnd | ( | ) | const |
Returns the end const iterator of the row pointers.
size_t jet::MatrixCsr< T >::rows | ( | ) | const |
Returns number of rows of this matrix.
MatrixCsr jet::MatrixCsr< T >::rsub | ( | const MatrixCsr< T > & | m | ) | const |
Returns input matrix - this matrix (element-wise).
MatrixCsr jet::MatrixCsr< T >::rsub | ( | const T & | s | ) | const |
Returns input scalar - this matrix.
void jet::MatrixCsr< T >::set | ( | const MatrixCsr< T > & | other | ) |
Copy from given sparse matrix.
void jet::MatrixCsr< T >::set | ( | const T & | s | ) |
Sets whole matrix with input scalar.
void jet::MatrixCsr< T >::setElement | ( | const Element & | element | ) |
Sets non-zero element.
void jet::MatrixCsr< T >::setElement | ( | size_t | i, |
size_t | j, | ||
const T & | value | ||
) |
Sets non-zero element to (i, j).
Size2 jet::MatrixCsr< T >::size | ( | ) | const |
Returns the size of this matrix.
MatrixCsr jet::MatrixCsr< T >::sub | ( | const MatrixCsr< T > & | m | ) | const |
Returns this matrix - input matrix (element-wise).
MatrixCsr jet::MatrixCsr< T >::sub | ( | const T & | s | ) | const |
Returns this matrix - input scalar.
T jet::MatrixCsr< T >::sum | ( | ) | const |
Returns sum of all elements.
T jet::MatrixCsr< T >::trace | ( | ) | const |
Returns sum of all diagonal elements.