32template <
typename T,
unsigned ROWS,
unsigned COLS>
39 static constexpr unsigned rows = ROWS;
41 static constexpr unsigned cols = COLS;
46 for (
unsigned m = 0; m < ROWS; ++m) {
47 for (
unsigned n = 0; n < COLS; ++n) {
48 _data[m][n] =
data[m][n];
54 template <
unsigned V_SIZE>
57 static_assert(V_SIZE == ROWS * COLS,
58 "ERROR: Vector size must correspond to matrix size.");
59 for (
unsigned m = 0; m < ROWS; ++m) {
60 for (
unsigned n = 0; n < COLS; ++n) {
61 _data[m][n] = vector[m * COLS + n];
75 constexpr Matrix(
Matrix&& matrix) { _data = std::move(matrix._data); }
78 _data = std::move(matrix._data);
83 constexpr const T*
data()
const {
return _data.
data(); }
96 for (
unsigned row = 0; row < matrix.
rows; ++row) {
97 os << matrix[row] <<
'\n';
102 template <
unsigned C>
106 for (
unsigned i = 0; i < ROWS; ++i) {
107 for (
unsigned j = 0; j < C; ++j) {
109 for (
unsigned k = 0; k < ROWS; ++k) {
110 result[i][j] += this->
operator[](i)[k] * matrix[k][j];
121 for (
unsigned row = 0; row < ROWS; ++row) {
122 result[row] = _data[row] * vector;
130 for (
unsigned m = 0; m < ROWS; ++m) {
131 for (
unsigned n = 0; n < COLS; ++n) {
132 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(const 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
auto solveLinearSystem(const Matrix< T, 2, 2 > &a, const Vector< T, 2 > &rhs)
Solve a * x = rhs.
constexpr auto determinant(const Matrix< T, 2, 2 > &m)
Top level namespace for all of OpenLB.