Peano
Loading...
Searching...
No Matches
Matrix.h
Go to the documentation of this file.
1// This file is part of the Peano project. For conditions of distribution and
2// use, please see the copyright notice at www.peano-framework.org
3#pragma once
4
5
6namespace tarch {
7 namespace la {
8 template<int Rows, int Cols, typename Scalar>
9 class Matrix;
10
19 template<int Rows, int Cols, typename Scalar>
21 }
22}
23
24
29
31
32
33#include <string>
34#include <initializer_list>
35
36
37
41template<int Rows, int Cols, typename Scalar>
43 private:
47 Scalar _values[Rows*Cols];
48
52 friend Matrix<Rows,Cols,Scalar> buildMatrix<Rows,Cols,Scalar>(const Scalar* values);
53
54 public:
58 Matrix();
62 Matrix( const Scalar& value);
63 Matrix( std::initializer_list<Scalar> values );
64
68 int rows() const;
69
73 int cols() const;
74
78 int size() const;
79
85 inline Scalar & operator() (
86 int rowIndex,
87 int colIndex
88 )
89 #ifdef UseManualInlining
90 __attribute__((always_inline))
91 #endif
92 {
93 assertion5( rowIndex >= 0, Rows, Cols, rowIndex, colIndex, toString() );
94 assertion5( colIndex >= 0, Rows, Cols, rowIndex, colIndex, toString() );
95 assertion5( rowIndex < Rows, Rows, Cols, rowIndex, colIndex, toString() );
96 assertion5( colIndex < Cols, Rows, Cols, rowIndex, colIndex, toString() );
97 return _values[rowIndex * Cols + colIndex];
98 }
99
103 inline const Scalar & operator() (
104 int rowIndex,
105 int colIndex
106 ) const
107 #ifdef UseManualInlining
108 __attribute__((always_inline))
109 #endif
110 {
111 assertion5( rowIndex >= 0, Rows, Cols, rowIndex, colIndex, toString() );
112 assertion5( colIndex >= 0, Rows, Cols, rowIndex, colIndex, toString() );
113 assertion5( rowIndex < Rows, Rows, Cols, rowIndex, colIndex, toString() );
114 assertion5( colIndex < Cols, Rows, Cols, rowIndex, colIndex, toString() );
115 return _values[rowIndex * Cols + colIndex];
116 }
117
118 std::string toString() const;
119
120 std::string toPrettyString(int numberOfDigits=4) const;
121
122 template <typename NewScalarType>
124
130 Scalar* data() {
131 return _values;
132 }
133
134 const Scalar * data() const {
135 return _values;
136 }
137};
138
139
140
141#include "tarch/la/Matrix.cpph"
142
#define assertion5(expr, param0, param1, param2, param3, param4)
int __attribute__((optimize("O0"))) toolbox
Static (i.e.
Definition Matrix.h:42
std::string toString() const
Definition Matrix.cpph:64
std::string toPrettyString(int numberOfDigits=4) const
Definition Matrix.cpph:86
Scalar _values[Rows *Cols]
Values of the matrix components.
Definition Matrix.h:47
int cols() const
Returns the number of columns in the matrix.
Definition Matrix.cpph:52
Matrix()
Constructs a non-initialized matrix.
Definition Matrix.cpph:21
Scalar & operator()(int rowIndex, int colIndex)
Returns element at given row and column index (from 0..size-1).
Definition Matrix.h:85
int size() const
Returns the number of total elements in the matrix.
Definition Matrix.cpph:58
tarch::la::Matrix< Rows, Cols, NewScalarType > convertScalar() const
Definition Matrix.cpph:113
const Scalar * data() const
Definition Matrix.h:134
int rows() const
Returns the number of rows in the matrix.
Definition Matrix.cpph:46
Scalar * data()
This routine returns a pointer to the first data element.
Definition Matrix.h:130
Matrix< Rows, Cols, Scalar > buildMatrix(const Scalar *values)
Deep copy builder function.
Have to include this header, as I need access to the SYCL_EXTERNAL keyword.
Definition accelerator.h:19