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>
37 tarch::la::Vector<Size, NewScalarType> convertScalar(
38 const tarch::la::Vector<Size, Scalar>& vector
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
170 Vector(const Scalar* values) InlineMethod;
171
179 Vector(std::initializer_list<Scalar> values);
180
181 Vector(const std::bitset<Size>& values) InlineMethod;
182
186 Vector(const Scalar& initialValue);
187
200 inline Vector<Size, Scalar>& operator=(const Vector<Size, Scalar>& toAssign) {
201 #pragma unroll
202 for (int i = 0; i < Size; i++) {
203 _values[i] = toAssign._values[i];
204 }
205 return *this;
206 };
207
219 = default;
220
221//#pragma unroll
222// for (int i = 0; i < Size; i++) _values[i] = toCopy._values[i];
223// }
224
228 int size() const;
229
239 inline const Scalar& operator[](int index) const InlineMethod {
240#if defined(GPUOffloadingOff)
241 assertion3(index >= 0, index, Size, ::toString(*this));
243 index < Size,
244 index,
245 Size,
246 ::toString(*this),
247 "you may not take the indexth entry from a vector with only Size components"
248 );
249#endif
250 return _values[index];
251 }
252
258 inline Scalar& operator[](int index) InlineMethod {
259#if defined(GPUOffloadingOff)
260 assertion3(index >= 0, index, Size, ::toString(*this));
261 assertion3(index < Size, index, Size, ::toString(*this));
262#endif
263 return _values[index];
264 }
265
277 inline const Scalar& operator()(int index) const InlineMethod {
278#if defined(GPUOffloadingOff)
279 assertion3(index >= 0, index, Size, ::toString(*this));
280 assertion3(index < Size, index, Size, ::toString(*this));
281#endif
282 return _values[index];
283 }
284
290 inline Scalar& operator()(int index) InlineMethod {
291#if defined(GPUOffloadingOff)
292 assertion3(index >= 0, index, Size, ::toString(*this));
293 assertion3(index < Size, index, Size, ::toString(*this));
294#endif
295 return _values[index];
296 }
297
303 Scalar* data() { return _values; }
304
305 const Scalar* data() const { return _values; }
306};
307
308#include "tarch/la/Vector.cpph"
311#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.
Definition Vector.cpph:48
STL namespace.
My collection of tiny vector operations.
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:258
int size() const
Returns the number of components of the vector.
Definition Vector.cpph:43
Scalar & operator()(int index) InlineMethod
Returns ref.
Definition Vector.h:290
const Scalar * data() const
Definition Vector.h:305
const Scalar & operator()(int index) const InlineMethod
Returns read-only ref.
Definition Vector.h:277
Scalar * data()
This routine returns a pointer to the first data element.
Definition Vector.h:303
const Scalar & operator[](int index) const InlineMethod
Returns read-only ref.
Definition Vector.h:239
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.
#define InlineMethod
Generic identifier for inlined functions.
Definition tarch.h:66