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
5#include "tarch/la/la.h"
6#include "tarch/Assertions.h"
9
10#include <string>
11#include <bitset>
12#include <sstream>
13#include <initializer_list>
14
15namespace tarch {
16 namespace la {
17 template <int Size, typename Scalar>
18 struct Vector;
19
36 template <typename NewScalarType, int Size, typename Scalar>
38 }
39}
40
46template<int Size, typename Scalar>
47std::string toString( const tarch::la::Vector<Size,Scalar>& vector );
48
149template <int Size, typename Scalar>
151 private:
152 Scalar _values[Size];
153
154 public:
158 Vector() InlineMethod = default;
159
160 Vector( const Scalar* values ) InlineMethod;
161
169 Vector( std::initializer_list<Scalar> values );
170
171 Vector( const std::bitset<Size>& values ) InlineMethod;
172
176 Vector(const Scalar& initialValue);
177
186 inline Vector<Size,Scalar>& operator= (const Vector<Size,Scalar>& toAssign) InlineMethod;
187
196 Vector(const Vector<Size,Scalar>& toCopy);
197
201 int size() const;
202
212 inline const Scalar& operator[] (int index) const InlineMethod {
213#if defined(GPUOffloadingOff)
214 assertion3 ( index >= 0, index, Size, ::toString(*this) );
215 assertion4 ( index < Size, index, Size, ::toString(*this), "you may not take the indexth entry from a vector with only Size components" );
216#endif
217 return _values[index];
218 }
219
225 inline Scalar& operator[] (int index) InlineMethod {
226#if defined(GPUOffloadingOff)
227 assertion3 ( index >= 0, index, Size, ::toString(*this) );
228 assertion3 ( index < Size, index, Size, ::toString(*this) );
229#endif
230 return _values[index];
231 }
232
244 inline const Scalar& operator() (int index) const InlineMethod {
245#if defined(GPUOffloadingOff)
246 assertion3 ( index >= 0, index, Size, ::toString(*this) );
247 assertion3 ( index < Size, index, Size, ::toString(*this) );
248#endif
249 return _values[index];
250 }
251
257 inline Scalar& operator() (int index) InlineMethod {
258#if defined(GPUOffloadingOff)
259 assertion3 ( index >= 0, index, Size, ::toString(*this) );
260 assertion3 ( index < Size, index, Size, ::toString(*this) );
261#endif
262 return _values[index];
263 }
264
270 Scalar* data() {
271 return _values;
272 }
273
274 const Scalar * data() const {
275 return _values;
276 }
277};
278
279#include "tarch/la/Vector.cpph"
283#include "tarch/la/VectorSlice.h"
284
#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:80
Definition vec.h:7
STL namespace.
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:150
int size() const
Returns the number of components of the vector.
Definition Vector.cpph:75
const Scalar * data() const
Definition Vector.h:274
const Scalar & operator()(int index) const InlineMethod
Returns read-only ref.
Definition Vector.h:244
Scalar * data()
This routine returns a pointer to the first data element.
Definition Vector.h:270
Scalar _values[Size]
Definition Vector.h:152
const Scalar & operator[](int index) const InlineMethod
Returns read-only ref.
Definition Vector.h:212
Vector() InlineMethod=default
Clang requires the always_inline attribute, as it otherwise makes weird decisions.
#define InlineMethod
Generic identifier for inlined functions.
Definition tarch.h:66