OpenLB 1.7
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Friends | List of all members
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 (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 Matrixoperator= (const Matrix &matrix)
 
constexpr Matrix (Matrix &&matrix)
 
constexpr Matrixoperator= (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 31 of file matrix.h.

Constructor & Destructor Documentation

◆ Matrix() [1/5]

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

Definition at line 41 of file matrix.h.

41{};

◆ Matrix() [2/5]

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

Definition at line 42 of file matrix.h.

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

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>
constexpr olb::Matrix< T, ROWS, COLS >::Matrix ( const Vector< T, V_SIZE > & vector)
inlineconstexpr

Create matrix from olb::Vector.

Definition at line 53 of file matrix.h.

54 {
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];
60 }
61 }
62 }

◆ Matrix() [4/5]

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

Definition at line 64 of file matrix.h.

65 {
66 _data = matrix._data;
67 }

◆ Matrix() [5/5]

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

Definition at line 73 of file matrix.h.

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

Member Function Documentation

◆ data() [1/2]

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

Definition at line 80 of file matrix.h.

80{ return _data.data(); }

References olb::Vector< T, D >::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>
constexpr const T * olb::Matrix< T, ROWS, COLS >::data ( ) const
inlineconstexpr

Definition at line 81 of file matrix.h.

81{ return _data.data(); }

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

+ Here is the call graph for this function:

◆ operator*() [1/2]

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

Definition at line 101 of file matrix.h.

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

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>
constexpr Vector< T, COLS > olb::Matrix< T, ROWS, COLS >::operator* ( const Vector< T, COLS > & vector) const
inlineconstexpr

Definition at line 116 of file matrix.h.

117 {
118 Vector<T, COLS> result;
119 for (unsigned row = 0; row < ROWS; ++row) {
120 result[row] = _data[row] * vector;
121 }
122 return result;
123 }

◆ operator=() [1/2]

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

Definition at line 68 of file matrix.h.

69 {
70 _data = matrix._data;
71 return *this;
72 }

◆ operator=() [2/2]

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

Definition at line 74 of file matrix.h.

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

◆ operator[]() [1/2]

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

Definition at line 83 of file matrix.h.

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

◆ operator[]() [2/2]

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

Definition at line 87 of file matrix.h.

88 {
89 return _data[row];
90 }

◆ transpose()

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

Definition at line 125 of file matrix.h.

126 {
127 Matrix<T,COLS,ROWS> result;
128 for (unsigned m = 0; m < ROWS; ++m) {
129 for (unsigned n = 0; n < COLS; ++n) {
130 result[n][m] = ((*this)[m][n]);
131 }
132 }
133 return result;
134 }
+ 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 92 of file matrix.h.

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

Member Data Documentation

◆ cols

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

number of columns

Definition at line 39 of file matrix.h.

◆ rows

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

number of rows

Definition at line 37 of file matrix.h.


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