30template <
typename T,
unsigned ROWS,
unsigned COLS>
37 static constexpr unsigned rows = ROWS;
39 static constexpr unsigned cols = COLS;
44 for (
unsigned m = 0; m < ROWS; ++m) {
45 for (
unsigned n = 0; n < COLS; ++n) {
46 _data[m][n] =
data[m][n];
52 template <
unsigned V_SIZE>
55 static_assert(V_SIZE == ROWS * COLS,
56 "ERROR: Vector size must correspond to matrix size.");
57 for (
unsigned m = 0; m < ROWS; ++m) {
58 for (
unsigned n = 0; n < COLS; ++n) {
59 _data[m][n] = vector[m * COLS + n];
73 constexpr Matrix(
Matrix&& matrix) { _data = std::move(matrix._data); }
76 _data = std::move(matrix._data);
81 constexpr const T*
data()
const {
return _data.
data(); }
94 for (
unsigned row = 0; row < matrix.
rows; ++row) {
95 os << matrix[row] <<
'\n';
100 template <
unsigned C>
104 for (
unsigned i = 0; i < ROWS; ++i) {
105 for (
unsigned j = 0; j < C; ++j) {
107 for (
unsigned k = 0; k < ROWS; ++k) {
108 result[i][j] += this->
operator[](i)[k] * matrix[k][j];
119 for (
unsigned row = 0; row < ROWS; ++row) {
120 result[row] = _data[row] * vector;
128 for (
unsigned m = 0; m < ROWS; ++m) {
129 for (
unsigned n = 0; n < COLS; ++n) {
130 result[n][m] = ((*this)[m][n]);
Matrix with a defined number of ROWS and columns (COLS)
static constexpr unsigned rows
number of rows
friend std::ostream & operator<<(std::ostream &os, const Matrix &matrix)
constexpr Matrix< T, COLS, ROWS > transpose() const
constexpr Vector< T, COLS > & operator[](const unsigned row)
constexpr const T * data() const
constexpr Matrix & operator=(Matrix &&matrix)
constexpr Matrix(T data[ROWS][COLS])
constexpr Matrix(const Vector< T, V_SIZE > &vector)
Create matrix from olb::Vector.
static constexpr unsigned cols
number of columns
constexpr Matrix(Matrix &&matrix)
constexpr Matrix operator*(const Matrix< T, COLS, C > &matrix) const
constexpr const Vector< T, COLS > & operator[](const unsigned row) const
constexpr Vector< T, COLS > operator*(const Vector< T, COLS > &vector) const
constexpr Matrix(const Matrix< T, ROWS, COLS > &matrix)
constexpr Matrix & operator=(const Matrix &matrix)
constexpr const T * data() const any_platform
Top level namespace for all of OpenLB.