Peano
Loading...
Searching...
No Matches
ShallowMatrix.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 ShallowMatrix;
10 }
11}
12
13
15
17
18#include <string>
19
20
21
28template<int Rows, int Cols, typename Scalar>
30 private:
34 Scalar* _values;
35
36 public:
40 ShallowMatrix(Scalar* values);
41
46
51
55 int rows() const;
56
60 int cols() const;
61
65 int size() const;
66
72 inline Scalar & operator() (
73 int rowIndex,
74 int colIndex
75 )
76 #ifdef UseManualInlining
77 __attribute__((always_inline))
78 #endif
79 {
80 assertion5( rowIndex >= 0, Rows, Cols, rowIndex, colIndex, toString() );
81 assertion5( colIndex >= 0, Rows, Cols, rowIndex, colIndex, toString() );
82 assertion5( rowIndex < Rows, Rows, Cols, rowIndex, colIndex, toString() );
83 assertion5( colIndex < Cols, Rows, Cols, rowIndex, colIndex, toString() );
84 return _values[rowIndex * Cols + colIndex];
85 }
86
90 inline const Scalar & operator() (
91 int rowIndex,
92 int colIndex
93 ) const
94 #ifdef UseManualInlining
95 __attribute__((always_inline))
96 #endif
97 {
98 assertion5( rowIndex >= 0, Rows, Cols, rowIndex, colIndex, toString() );
99 assertion5( colIndex >= 0, Rows, Cols, rowIndex, colIndex, toString() );
100 assertion5( rowIndex < Rows, Rows, Cols, rowIndex, colIndex, toString() );
101 assertion5( colIndex < Cols, Rows, Cols, rowIndex, colIndex, toString() );
102 return _values[rowIndex * Cols + colIndex];
103 }
104
105 std::string toString() const;
106
107 std::string toPrettyString(int numberOfDigits=4) const;
108
115 template <typename NewScalarType>
117
121 Scalar* data() {
122 return _values;
123 }
124
125 const Scalar * data() const {
126 return _values;
127 }
128};
129
130
131
132#include "tarch/la/ShallowMatrix.cpph"
133
#define assertion5(expr, param0, param1, param2, param3, param4)
Static (i.e.
Definition Matrix.h:42
Shallow matrix wrapping an existing array.
int size() const
Returns the number of total elements in the matrix.
std::string toString() const
tarch::la::Matrix< Rows, Cols, NewScalarType > convertScalar() const
Convert the scalar type.
Scalar * _values
Values of the matrix components.
const Scalar * data() const
Scalar & operator()(int rowIndex, int colIndex)
Returns element at given row and column index (from 0..size-1).
ShallowMatrix(const ShallowMatrix &copy)
Shallow copy.
ShallowMatrix & operator=(const ShallowMatrix &copy)
Shallow copy.
int rows() const
Returns the number of rows in the matrix.
Scalar * data()
Return pointer back to original data.
std::string toPrettyString(int numberOfDigits=4) const
int cols() const
Returns the number of columns in the matrix.
ShallowMatrix(Scalar *values)
Constructs a non-initialized matrix.
Have to include this header, as I need access to the SYCL_EXTERNAL keyword.
Definition accelerator.h:19