11 #ifndef CUBBYFLOW_MATRIX_CSR_HPP 12 #define CUBBYFLOW_MATRIX_CSR_HPP 31 template <
typename T,
typename ME>
34 MatrixCSRMatrixMul<T, ME>>
40 [[nodiscard]]
size_t GetRows()
const;
43 [[nodiscard]]
size_t GetCols()
const;
52 const size_t*
const m_rp;
53 const size_t*
const m_ci;
73 std::is_floating_point<T>::value,
74 "MatrixCSR only can be instantiated with floating point types");
84 Element(
size_t i,
size_t j,
const T& value);
118 MatrixCSR(
const std::initializer_list<std::initializer_list<T>>& lst,
119 T epsilon = std::numeric_limits<T>::epsilon());
128 template <
size_t R,
size_t C,
typename E>
130 T epsilon = std::numeric_limits<T>::epsilon());
151 void Set(
const T& s);
157 void Reserve(
size_t rows,
size_t cols,
size_t numNonZeros);
180 void Compress(
const std::initializer_list<std::initializer_list<T>>& lst,
181 T epsilon = std::numeric_limits<T>::epsilon());
190 template <
size_t R,
size_t C,
typename E>
192 T epsilon = std::numeric_limits<T>::epsilon());
195 void AddElement(
size_t i,
size_t j,
const T& value);
198 void AddElement(
const Element& element);
210 void SetElement(
size_t i,
size_t j,
const T& value);
213 void SetElement(
const Element& element);
215 [[nodiscard]]
bool IsEqual(
const MatrixCSR& other)
const;
221 double tol = std::numeric_limits<double>::epsilon())
const;
224 [[nodiscard]]
bool IsSquare()
const;
230 [[nodiscard]]
size_t GetRows()
const;
233 [[nodiscard]]
size_t GetCols()
const;
236 [[nodiscard]]
size_t NumberOfNonZeros()
const;
239 [[nodiscard]]
const T& NonZero(
size_t i)
const;
242 [[nodiscard]] T& NonZero(
size_t i);
245 [[nodiscard]]
const size_t& RowPointer(
size_t i)
const;
248 [[nodiscard]]
const size_t& ColumnIndex(
size_t i)
const;
251 [[nodiscard]] T* NonZeroData();
254 [[nodiscard]]
const T* NonZeroData()
const;
257 [[nodiscard]]
const size_t* RowPointersData()
const;
260 [[nodiscard]]
const size_t* ColumnIndicesData()
const;
299 [[nodiscard]]
MatrixCSR Add(
const T& s)
const;
305 [[nodiscard]]
MatrixCSR Sub(
const T& s)
const;
311 [[nodiscard]]
MatrixCSR Mul(
const T& s)
const;
314 template <
size_t R,
size_t C,
typename ME>
319 [[nodiscard]]
MatrixCSR Div(
const T& s)
const;
322 [[nodiscard]]
MatrixCSR RAdd(
const T& s)
const;
328 [[nodiscard]]
MatrixCSR RSub(
const T& s)
const;
334 [[nodiscard]]
MatrixCSR RMul(
const T& s)
const;
337 [[nodiscard]]
MatrixCSR RDiv(
const T& s)
const;
340 void IAdd(
const T& s);
346 void ISub(
const T& s);
352 void IMul(
const T& s);
355 template <
size_t R,
size_t C,
typename ME>
359 void IDiv(
const T& s);
362 [[nodiscard]] T
Sum()
const;
365 [[nodiscard]] T
Avg()
const;
368 [[nodiscard]] T
Min()
const;
371 [[nodiscard]] T
Max()
const;
374 [[nodiscard]] T
AbsMin()
const;
377 [[nodiscard]] T
AbsMax()
const;
381 [[nodiscard]] T
Trace()
const;
384 template <
typename U>
394 template <
size_t R,
size_t C,
typename ME>
413 template <
size_t R,
size_t C,
typename ME>
433 [[nodiscard]]
size_t HasElement(
size_t i,
size_t j)
const;
435 template <
typename Op>
ValueType AbsMin() const
Definition: MatrixExpression-Impl.hpp:141
constexpr bool IsSquare() const
Returns true if this matrix is a square matrix.
Definition: MatrixExpression-Impl.hpp:71
ValueType Sum() const
Definition: MatrixExpression-Impl.hpp:77
T operator()(size_t i, size_t j) const
Returns matrix element at (i, j).
Definition: MatrixCSR-Impl.hpp:45
Matrix expression for CSR matrix-matrix multiplication.
Definition: MatrixCSR.hpp:32
MatrixCSRMatrixMul(const MatrixCSR< T > &m1, const ME &m2)
Definition: MatrixCSR-Impl.hpp:21
constexpr std::enable_if_t< IsMatrixSizeStatic< Rows, Cols >), bool > operator==(const MatrixExpression< T, Rows, Cols, M1 > &a, const MatrixExpression< T, Rows, Cols, M2 > &b)
Definition: Matrix-Impl.hpp:1408
std::vector< size_t > IndexContainerType
Definition: MatrixCSR.hpp:91
size_t i
Definition: MatrixCSR.hpp:78
MatrixCSR< float > MatrixCSRF
Float-type CSR matrix.
Definition: MatrixCSR.hpp:445
IndexContainerType::const_iterator ConstIndexIterator
Definition: MatrixCSR.hpp:93
ValueType Min() const
Definition: MatrixExpression-Impl.hpp:99
Definition: Matrix.hpp:27
IndexContainerType::iterator IndexIterator
Definition: MatrixCSR.hpp:92
bool IsSimilar(const MatrixExpression< T, R, C, E > &m, double tol=std::numeric_limits< double >::epsilon()) const
Definition: MatrixExpression-Impl.hpp:46
void operator+=(Matrix< T, R1, C1 > &a, const MatrixExpression< T, R2, C2, M2 > &b)
Definition: Matrix-Impl.hpp:1342
Definition: pybind11Utils.hpp:20
ValueType Trace() const
Definition: MatrixExpression-Impl.hpp:183
void operator/=(Matrix< T, Rows, Cols > &a, const T &b)
Definition: Matrix-Impl.hpp:1400
ValueType AbsMax() const
Definition: MatrixExpression-Impl.hpp:162
typename NonZeroContainerType::iterator NonZeroIterator
Definition: MatrixCSR.hpp:88
Compressed Sparse Row (CSR) matrix class.
Definition: MatrixCSR.hpp:19
size_t GetCols() const
Number of columns.
Definition: MatrixCSR-Impl.hpp:39
MatrixCSR< double > MatrixCSRD
Double-type CSR matrix.
Definition: MatrixCSR.hpp:448
typename NonZeroContainerType::const_iterator ConstNonZeroIterator
Definition: MatrixCSR.hpp:89
ValueType Avg() const
Definition: MatrixExpression-Impl.hpp:93
Definition: MatrixCSR.hpp:76
void operator*=(Matrix< T, R1, C1 > &a, const MatrixExpression< T, R2, C2, M2 > &b)
Definition: Matrix-Impl.hpp:1366
Base class for matrix expression.
Definition: MatrixExpression.hpp:93
MatrixUnaryOp< U, Rows, Cols, const MatrixCSRMatrixMul< T, ME > &, TypeCast< T, U > > CastTo() const
size_t GetRows() const
Number of rows.
Definition: MatrixCSR-Impl.hpp:33
bool operator!=(const MatrixExpression< T, R1, C1, M1 > &a, const MatrixExpression< T, R2, C2, M2 > &b)
Definition: Matrix-Impl.hpp:1443
void operator-=(Matrix< T, R1, C1 > &a, const MatrixExpression< T, R2, C2, M2 > &b)
Definition: Matrix-Impl.hpp:1354
ValueType Max() const
Definition: MatrixExpression-Impl.hpp:120
T value
Definition: MatrixCSR.hpp:80
std::vector< double > NonZeroContainerType
Definition: MatrixCSR.hpp:87
size_t j
Definition: MatrixCSR.hpp:79