Go to the documentation of this file.
7 #ifndef INCLUDE_JET_MATRIX_CSR_H_
8 #define INCLUDE_JET_MATRIX_CSR_H_
30 template <
typename T,
typename VE>
59 template <
typename T,
typename ME>
81 const size_t*
const _rp;
82 const size_t*
const _ci;
99 std::is_floating_point<T>::value,
100 "MatrixCsr only can be instantiated with floating point types");
145 MatrixCsr(
const std::initializer_list<std::initializer_list<T>>& lst,
146 T epsilon = std::numeric_limits<T>::epsilon());
155 template <
typename E>
157 T epsilon = std::numeric_limits<T>::epsilon());
200 void compress(
const std::initializer_list<std::initializer_list<T>>& lst,
201 T epsilon = std::numeric_limits<T>::epsilon());
210 template <
typename E>
212 T epsilon = std::numeric_limits<T>::epsilon());
241 double tol = std::numeric_limits<double>::epsilon())
const;
336 template <
typename VE>
340 template <
typename ME>
384 template <
typename ME>
415 template <
typename U>
427 template <
typename E>
452 template <
typename ME>
480 size_t hasElement(
size_t i,
size_t j)
const;
482 template <
typename Op>
494 #include "detail/matrix_csr-inl.h"
496 #endif // INCLUDE_JET_MATRIX_CSR_H_
IndexContainerType::iterator IndexIterator
Definition: matrix_csr.h:117
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.
void addElement(const Element &element)
Adds non-zero element.
bool isSquare() const
Returns true if this matrix is a square matrix.
MatrixCsr()
Constructs an empty matrix.
MatrixCsr sub(const T &s) const
Returns this matrix - input scalar.
Matrix expression for CSR matrix-matrix multiplication.
Definition: matrix_csr.h:61
Base class for vector expression.
Definition: vector_expression.h:25
static MatrixCsr< T > makeIdentity(size_t m)
void setElement(const Element &element)
Sets non-zero element.
MatrixCsr & operator+=(const T &s)
Addition assignment with input scalar.
MatrixCsr(MatrixCsr &&other)
Move constructor.
NonZeroIterator nonZeroBegin()
Returns the begin iterator of the non-zero elements.
Definition: matrix_csr.h:102
const size_t *const columnIndicesData() const
Returns constant pointer of the column indices data.
MatrixCsr rdiv(const T &s) const
Returns input matrix / this scalar.
size_t i
Definition: matrix_csr.h:103
MatrixCsrMatrixMul(const MatrixCsr< T > &m1, const ME &m2)
MatrixCsr mul(const T &s) const
Returns this matrix * input scalar.
MatrixCsr & operator+=(const MatrixCsr &m)
Addition assignment with input matrix (element-wise).
MatrixCsr & operator*=(const T &s)
Multiplication assignment with input scalar.
void imul(const T &s)
Multiplies input scalar to this matrix.
NonZeroContainerType::const_iterator ConstNonZeroIterator
Definition: matrix_csr.h:114
MatrixCsr rmul(const T &s) const
Returns input scalar * this matrix.
T operator()(size_t i, size_t j) const
Returns matrix element at (i, j).
MatrixCsr & operator=(const E &m)
Compresses input (dense) matrix expression into a sparse matrix.
void clear()
Clears the matrix and make it zero-dimensional.
const T *const nonZeroData() const
Returns constant pointer of the non-zero elements data.
MatrixCsr add(const MatrixCsr &m) const
Returns this matrix + input matrix (element-wise).
T & nonZero(size_t i)
Returns i-th non-zero element.
void addRow(const NonZeroContainerType &nonZeros, const IndexContainerType &columnIndices)
Vector expression for CSR matrix-vector multiplication.
Definition: matrix_csr.h:32
MatrixCsr radd(const MatrixCsr &m) const
Returns input matrix + this matrix (element-wise).
size_t j
Definition: matrix_csr.h:104
const size_t *const rowPointersData() const
Returns constant pointer of the row pointers data.
void addElement(size_t i, size_t j, const T &value)
Adds non-zero element to (i, j).
Compressed Sparse Row (CSR) matrix class.
Definition: matrix_csr.h:19
Element(size_t i, size_t j, const T &value)
IndexIterator columnIndicesEnd()
Returns the end iterator of the column indices.
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.
T * nonZeroData()
Returns pointer of the non-zero elements data.
bool operator!=(const MatrixCsr &m) const
Returns true if is not equal to m.
MatrixCsr rsub(const MatrixCsr &m) const
Returns input matrix - this matrix (element-wise).
ConstIndexIterator rowPointersEnd() const
Returns the end const iterator of the row pointers.
T value
Definition: matrix_csr.h:105
Definition: advection_solver2.h:18
Size2 size() const
Returns the size of this matrix.
size_t numberOfNonZeros() const
Returns the number of non-zero elements.
MatrixCsr & operator-=(const MatrixCsr &m)
Subtraction assignment with input matrix (element-wise).
MatrixCsrMatrixMul< T, ME > mul(const MatrixExpression< T, ME > &m) const
Returns this matrix * input matrix.
MatrixCsr & operator*=(const MatrixExpression< T, ME > &m)
Multiplication assignment with input matrix.
void isub(const MatrixCsr &m)
Subtracts input matrix from this matrix (element-wise).
MatrixCsr(const MatrixExpression< T, E > &other, T epsilon=std::numeric_limits< T >::epsilon())
Compresses input (dense) matrix expression into a sparse matrix.
IndexIterator columnIndicesBegin()
Returns the begin iterator of the column indices.
T min() const
Returns minimum among all elements.
Base class for matrix expression.
Definition: matrix_expression.h:26
MatrixCsr(const MatrixCsr &other)
Copy constructor.
ConstNonZeroIterator nonZeroEnd() const
Returns the end const iterator of the non-zero elements.
void isub(const T &s)
Subtracts input scalar from this matrix.
IndexContainerType::const_iterator ConstIndexIterator
Definition: matrix_csr.h:118
MatrixCsr & operator=(const MatrixCsr &other)
Copies to this matrix.
void compress(const MatrixExpression< T, E > &other, T epsilon=std::numeric_limits< T >::epsilon())
Compresses input (dense) matrix expression into a sparse matrix.
std::vector< T > NonZeroContainerType
Definition: matrix_csr.h:112
bool isEqual(const MatrixCsr &other) const
std::vector< size_t > IndexContainerType
Definition: matrix_csr.h:116
void iadd(const MatrixCsr &m)
Adds input matrix to this matrix (element-wise).
void setElement(size_t i, size_t j, const T &value)
Sets non-zero element to (i, j).
T absmax() const
Returns absolute maximum among all elements.
size_t rows() const
Number of rows.
MatrixCsr radd(const T &s) const
Returns input scalar + this matrix.
ConstIndexIterator columnIndicesEnd() const
Returns the end const iterator of the column indices.
NonZeroContainerType::iterator NonZeroIterator
Definition: matrix_csr.h:113
MatrixCsrVectorMul(const MatrixCsrVectorMul &)
T max() const
Returns maximum among all elements.
MatrixCsr & operator-=(const T &s)
Subtraction assignment with input scalar.
ConstNonZeroIterator nonZeroBegin() const
Returns the begin const iterator of the non-zero elements.
MatrixCsr< float > MatrixCsrF
Float-type CSR matrix.
Definition: matrix_csr.h:487
size_t rows() const
Returns number of rows of this matrix.
Size2 size() const
Size of the matrix.
2-D size class.
Definition: size2.h:19
size_t cols() const
Number of columns.
MatrixCsr rsub(const T &s) const
Returns input scalar - this matrix.
MatrixCsrVectorMul(const MatrixCsr< T > &m, const VE &v)
void set(const MatrixCsr &other)
Copy from given sparse matrix.
void imul(const MatrixExpression< T, ME > &m)
Multiplies input matrix to this matrix.
MatrixCsr div(const T &s) const
Returns this matrix / input scalar.
MatrixCsr< double > MatrixCsrD
Double-type CSR matrix.
Definition: matrix_csr.h:490
IndexIterator rowPointersEnd()
Returns the end iterator of the row pointers.
T avg() const
Returns average of all elements.
MatrixCsr add(const T &s) const
Returns this matrix + input scalar.
bool isSimilar(const MatrixCsr &other, double tol=std::numeric_limits< double >::epsilon()) const
ConstIndexIterator rowPointersBegin() const
Returns the begin const iterator of the row pointers.
T absmin() const
Returns absolute minimum among all elements.
const size_t & columnIndex(size_t i) const
Returns i-th column index.
const size_t & rowPointer(size_t i) const
Returns i-th row pointer.
const T & nonZero(size_t i) const
Returns i-th non-zero element.
bool operator==(const MatrixCsr &m) const
Returns true if is equal to m.
void reserve(size_t rows, size_t cols, size_t numNonZeros)
Reserves memory space of this matrix.
T operator[](size_t i) const
Returns vector element at i.
MatrixCsr sub(const MatrixCsr &m) const
Returns this matrix - input matrix (element-wise).
MatrixCsrVectorMul< T, VE > mul(const VectorExpression< T, VE > &v) const
Returns this matrix * input vector.
IndexIterator rowPointersBegin()
Returns the begin iterator of the row pointers.
ConstIndexIterator columnIndicesBegin() const
Returns the begin const iterator of the column indices.
NonZeroIterator nonZeroEnd()
Returns the end iterator of the non-zero elements.
MatrixCsr & operator=(MatrixCsr &&other)
Moves to this matrix.
void iadd(const T &s)
Adds input scalar to this matrix.
void set(const T &s)
Sets whole matrix with input scalar.
void idiv(const T &s)
Divides this matrix with input scalar.
size_t cols() const
Returns number of columns of this matrix.
MatrixCsr & operator/=(const T &s)
Division assignment with input scalar.
size_t size() const
Size of the vector.
T sum() const
Returns sum of all elements.
MatrixCsr< U > castTo() const
Type-casts to different value-typed matrix.
T operator()(size_t i, size_t j) const
Returns (i,j) element.