OpenLB 1.8.1
Loading...
Searching...
No Matches
olb::Matrix< T, ROWS, COLS > Class Template Reference

Matrix with a defined number of ROWS and columns (COLS) More...

#include <matrix.h>

+ Collaboration diagram for olb::Matrix< T, ROWS, COLS >:

Public Member Functions

constexpr Matrix ()
 
constexpr Matrix (const T data[ROWS][COLS])
 
template<unsigned V_SIZE>
constexpr Matrix (const Vector< T, V_SIZE > &vector)
 Create matrix from olb::Vector.
 
constexpr Matrix (const Matrix< T, ROWS, COLS > &matrix)
 
constexpr Matrix & operator= (const Matrix &matrix)
 
constexpr Matrix (Matrix &&matrix)
 
constexpr Matrix & operator= (Matrix &&matrix)
 
constexpr T * data ()
 
constexpr const T * data () const
 
constexpr Vector< T, COLS > & operator[] (const unsigned row)
 
constexpr const Vector< T, COLS > & operator[] (const unsigned row) const
 
template<unsigned C>
constexpr Matrix operator* (const Matrix< T, COLS, C > &matrix) const
 
constexpr Vector< T, COLS > operator* (const Vector< T, COLS > &vector) const
 
constexpr Matrix< T, COLS, ROWS > transpose () const
 

Static Public Attributes

static constexpr unsigned rows = ROWS
 number of rows
 
static constexpr unsigned cols = COLS
 number of columns
 

Friends

std::ostream & operator<< (std::ostream &os, const Matrix &matrix)
 

Detailed Description

template<typename T, unsigned ROWS, unsigned COLS>
class olb::Matrix< T, ROWS, COLS >

Matrix with a defined number of ROWS and columns (COLS)

Definition at line 33 of file matrix.h.

Constructor & Destructor Documentation

◆ Matrix() [1/5]

template<typename T , unsigned ROWS, unsigned COLS>
olb::Matrix< T, ROWS, COLS >::Matrix ( )
inlineconstexpr

Definition at line 43 of file matrix.h.

43{};

◆ Matrix() [2/5]

template<typename T , unsigned ROWS, unsigned COLS>
olb::Matrix< T, ROWS, COLS >::Matrix ( const T data[ROWS][COLS])
inlineconstexpr

Definition at line 44 of file matrix.h.

45 {
46 for (unsigned m = 0; m < ROWS; ++m) {
47 for (unsigned n = 0; n < COLS; ++n) {
48 _data[m][n] = data[m][n];
49 }
50 }
51 }
constexpr T * data()
Definition matrix.h:82
constexpr T m(unsigned iPop, unsigned jPop, tag::MRT)
Definition mrt.h:386

References olb::Matrix< T, ROWS, COLS >::data().

+ Here is the call graph for this function:

◆ Matrix() [3/5]

template<typename T , unsigned ROWS, unsigned COLS>
template<unsigned V_SIZE>
olb::Matrix< T, ROWS, COLS >::Matrix ( const Vector< T, V_SIZE > & vector)
inlineconstexpr

Create matrix from olb::Vector.

Definition at line 55 of file matrix.h.

56 {
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];
62 }
63 }
64 }

◆ Matrix() [4/5]

template<typename T , unsigned ROWS, unsigned COLS>
olb::Matrix< T, ROWS, COLS >::Matrix ( const Matrix< T, ROWS, COLS > & matrix)
inlineconstexpr

Definition at line 66 of file matrix.h.

67 {
68 _data = matrix._data;
69 }

◆ Matrix() [5/5]

template<typename T , unsigned ROWS, unsigned COLS>
olb::Matrix< T, ROWS, COLS >::Matrix ( Matrix< T, ROWS, COLS > && matrix)
inlineconstexpr

Definition at line 75 of file matrix.h.

75{ _data = std::move(matrix._data); }

Member Function Documentation

◆ data() [1/2]

template<typename T , unsigned ROWS, unsigned COLS>
T * olb::Matrix< T, ROWS, COLS >::data ( )
inlineconstexpr

Definition at line 82 of file matrix.h.

82{ return _data.data(); }

References olb::Vector< T, Size >::data().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ data() [2/2]

template<typename T , unsigned ROWS, unsigned COLS>
const T * olb::Matrix< T, ROWS, COLS >::data ( ) const
inlineconstexpr

Definition at line 83 of file matrix.h.

83{ return _data.data(); }

References olb::Vector< T, Size >::data().

+ Here is the call graph for this function:

◆ operator*() [1/2]

template<typename T , unsigned ROWS, unsigned COLS>
template<unsigned C>
Matrix olb::Matrix< T, ROWS, COLS >::operator* ( const Matrix< T, COLS, C > & matrix) const
inlineconstexpr

Definition at line 103 of file matrix.h.

104 {
105 Matrix<T,ROWS,C> result;
106 for (unsigned i = 0; i < ROWS; ++i) {
107 for (unsigned j = 0; j < C; ++j) {
108 result[i][j] = 0;
109 for (unsigned k = 0; k < ROWS; ++k) {
110 result[i][j] += this->operator[](i)[k] * matrix[k][j];
111 }
112 }
113 }
114 return result;
115 }
constexpr Vector< T, COLS > & operator[](const unsigned row)
Definition matrix.h:85
constexpr Matrix()
Definition matrix.h:43

References olb::Matrix< T, ROWS, COLS >::operator[]().

+ Here is the call graph for this function:

◆ operator*() [2/2]

template<typename T , unsigned ROWS, unsigned COLS>
Vector< T, COLS > olb::Matrix< T, ROWS, COLS >::operator* ( const Vector< T, COLS > & vector) const
inlineconstexpr

Definition at line 118 of file matrix.h.

119 {
120 Vector<T, COLS> result;
121 for (unsigned row = 0; row < ROWS; ++row) {
122 result[row] = _data[row] * vector;
123 }
124 return result;
125 }
Vector(T &&t, Ts &&... ts) -> Vector< std::remove_cvref_t< T >, 1+sizeof...(Ts)>

◆ operator=() [1/2]

template<typename T , unsigned ROWS, unsigned COLS>
Matrix & olb::Matrix< T, ROWS, COLS >::operator= ( const Matrix< T, ROWS, COLS > & matrix)
inlineconstexpr

Definition at line 70 of file matrix.h.

71 {
72 _data = matrix._data;
73 return *this;
74 }

◆ operator=() [2/2]

template<typename T , unsigned ROWS, unsigned COLS>
Matrix & olb::Matrix< T, ROWS, COLS >::operator= ( Matrix< T, ROWS, COLS > && matrix)
inlineconstexpr

Definition at line 76 of file matrix.h.

77 {
78 _data = std::move(matrix._data);
79 return *this;
80 }

◆ operator[]() [1/2]

template<typename T , unsigned ROWS, unsigned COLS>
Vector< T, COLS > & olb::Matrix< T, ROWS, COLS >::operator[] ( const unsigned row)
inlineconstexpr

Definition at line 85 of file matrix.h.

86 {
87 return _data[row];
88 };
+ Here is the caller graph for this function:

◆ operator[]() [2/2]

template<typename T , unsigned ROWS, unsigned COLS>
const Vector< T, COLS > & olb::Matrix< T, ROWS, COLS >::operator[] ( const unsigned row) const
inlineconstexpr

Definition at line 89 of file matrix.h.

90 {
91 return _data[row];
92 }

◆ transpose()

template<typename T , unsigned ROWS, unsigned COLS>
Matrix< T, COLS, ROWS > olb::Matrix< T, ROWS, COLS >::transpose ( ) const
inlineconstexpr

Definition at line 127 of file matrix.h.

128 {
129 Matrix<T,COLS,ROWS> result;
130 for (unsigned m = 0; m < ROWS; ++m) {
131 for (unsigned n = 0; n < COLS; ++n) {
132 result[n][m] = ((*this)[m][n]);
133 }
134 }
135 return result;
136 }
+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ operator<<

template<typename T , unsigned ROWS, unsigned COLS>
std::ostream & operator<< ( std::ostream & os,
const Matrix< T, ROWS, COLS > & matrix )
friend

Definition at line 94 of file matrix.h.

95 {
96 for (unsigned row = 0; row < matrix.rows; ++row) {
97 os << matrix[row] << '\n';
98 }
99 return os;
100 }

Member Data Documentation

◆ cols

template<typename T , unsigned ROWS, unsigned COLS>
unsigned olb::Matrix< T, ROWS, COLS >::cols = COLS
staticconstexpr

number of columns

Definition at line 41 of file matrix.h.

◆ rows

template<typename T , unsigned ROWS, unsigned COLS>
unsigned olb::Matrix< T, ROWS, COLS >::rows = ROWS
staticconstexpr

number of rows

Definition at line 39 of file matrix.h.


The documentation for this class was generated from the following file: