Peano
Loading...
Searching...
No Matches
Vector.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
6#include "tarch/Assertions.h"
8#include "tarch/la/la.h"
9
10#include <bitset>
11#include <initializer_list>
12#include <sstream>
13#include <string>
14
15namespace tarch {
16 namespace la {
17 template <int Size, typename Scalar> struct Vector;
18
36 template <typename NewScalarType, int Size, typename Scalar>
39 );
40 } // namespace la
41} // namespace tarch
42
48template <int Size, typename Scalar>
49std::string toString(const tarch::la::Vector<Size, Scalar>& vector);
50
159template <int Size, typename Scalar> struct tarch::la::Vector {
160private:
161 Scalar _values[Size];
162
163public:
168 Vector() InlineMethod = default;
169
179 Vector(const Scalar* values) InlineMethod;
180
188 Vector(std::initializer_list<Scalar> values);
189
190 Vector(const std::bitset<Size>& values) InlineMethod;
191
195 Vector(const Scalar& initialValue);
196
209 inline Vector<Size, Scalar>& operator=(const Vector<Size, Scalar>& toAssign) {
210 #pragma unroll
211 for (int i = 0; i < Size; i++) {
212 _values[i] = toAssign._values[i];
213 }
214 return *this;
215 };
216
228 = default;
229
230//#pragma unroll
231// for (int i = 0; i < Size; i++) _values[i] = toCopy._values[i];
232// }
233
237 int size() const;
238
248 inline const Scalar& operator[](int index) const InlineMethod {
249#if defined(GPUOffloadingOff)
250 assertion3(index >= 0, index, Size, ::toString(*this));
252 index < Size,
253 index,
254 Size,
255 ::toString(*this),
256 "you may not take the indexth entry from a vector with only Size components"
257 );
258#endif
259 return _values[index];
260 }
261
267 inline Scalar& operator[](int index) InlineMethod {
268#if defined(GPUOffloadingOff)
269 assertion3(index >= 0, index, Size, ::toString(*this));
270 assertion3(index < Size, index, Size, ::toString(*this));
271#endif
272 return _values[index];
273 }
274
286 inline const Scalar& operator()(int index) const InlineMethod {
287#if defined(GPUOffloadingOff)
288 assertion3(index >= 0, index, Size, ::toString(*this));
289 assertion3(index < Size, index, Size, ::toString(*this));
290#endif
291 return _values[index];
292 }
293
299 inline Scalar& operator()(int index) InlineMethod {
300#if defined(GPUOffloadingOff)
301 assertion3(index >= 0, index, Size, ::toString(*this));
302 assertion3(index < Size, index, Size, ::toString(*this));
303#endif
304 return _values[index];
305 }
306
312 Scalar* data() { return _values; }
313
314 const Scalar* data() const { return _values; }
315};
316
317#include "tarch/la/Vector.cpph"
320#include "tarch/la/VectorSlice.h"
#define assertion4(expr, param0, param1, param2, param3)
#define assertion3(expr, param0, param1, param2)
std::string toString(const tarch::la::Vector< Size, Scalar > &vector)
Pipes the elements of a vector into a std::string and returns the string.
tarch::la::SmartPointerVector< Size, NewScalarType > convertScalar(const tarch::la::SmartPointerVector< Size, Scalar > &SmartPointerVector)
Have to include this header, as I need access to the SYCL_EXTERNAL keyword.
Definition accelerator.h:19
std::string toString(MemoryLocation value)
Simple vector class.
Definition Vector.h:159
Scalar & operator[](int index) InlineMethod
Returns ref.
Definition Vector.h:267
Scalar & operator()(int index) InlineMethod
Returns ref.
Definition Vector.h:299
const Scalar * data() const
Definition Vector.h:314
const Scalar & operator()(int index) const InlineMethod
Returns read-only ref.
Definition Vector.h:286
Scalar * data()
This routine returns a pointer to the first data element.
Definition Vector.h:312
Scalar _values[Size]
Definition Vector.h:161
const Scalar & operator[](int index) const InlineMethod
Returns read-only ref.
Definition Vector.h:248
Vector() InlineMethod=default
Clang requires the always_inline attribute, as it otherwise makes weird decisions.
Vector(const Vector< Size, Scalar > &toCopy) InlineMethod=default
Copy constructor to copy from any vector type.
int size() const
Returns the number of components of the vector.
#define InlineMethod
Generic identifier for inlined functions.
Definition tarch.h:97