Branch data Line data Source code
1 : : //
2 : : // Class NDRegion
3 : : // NDRegion is a simple container of N PRegion objects. It is templated
4 : : // on the type of data (T) and the number of PRegions (Dim).
5 : : //
6 : : #include <iostream>
7 : :
8 : : namespace ippl {
9 : : template <typename T, unsigned Dim>
10 : : template <class... Args>
11 : 96 : KOKKOS_FUNCTION NDRegion<T, Dim>::NDRegion(const Args&... args)
12 [ + - ]: 96 : : NDRegion({args...}) {
13 : : static_assert(Dim == sizeof...(args), "Wrong number of arguments.");
14 : 96 : }
15 : :
16 : : template <typename T, unsigned Dim>
17 [ + + ]: 432 : KOKKOS_FUNCTION NDRegion<T, Dim>::NDRegion(std::initializer_list<PRegion<T>> regions) {
18 : 96 : unsigned int i = 0;
19 [ + + ]: 432 : for (auto& r : regions) {
20 : 336 : regions_m[i] = r;
21 : 336 : ++i;
22 : : }
23 : 96 : }
24 : :
25 : : template <typename T, unsigned Dim>
26 [ + + ]: 54 : KOKKOS_INLINE_FUNCTION NDRegion<T, Dim>::NDRegion(const NDRegion<T, Dim>& nr) {
27 [ + + ]: 54 : for (unsigned int i = 0; i < Dim; i++) {
28 : 42 : regions_m[i] = nr.regions_m[i];
29 : : }
30 : 12 : }
31 : :
32 : : template <typename T, unsigned Dim>
33 : 264 : KOKKOS_INLINE_FUNCTION NDRegion<T, Dim>& NDRegion<T, Dim>::operator=(
34 : : const NDRegion<T, Dim>& nr) {
35 [ + + ]: 1188 : for (unsigned int i = 0; i < Dim; i++) {
36 : 924 : regions_m[i] = nr.regions_m[i];
37 : : }
38 : 264 : return *this;
39 : : }
40 : :
41 : : template <typename T, unsigned Dim>
42 : 1386 : KOKKOS_INLINE_FUNCTION const PRegion<T>& NDRegion<T, Dim>::operator[](unsigned d) const {
43 : 1386 : return regions_m[d];
44 : : }
45 : :
46 : : template <typename T, unsigned Dim>
47 : 11340 : KOKKOS_INLINE_FUNCTION PRegion<T>& NDRegion<T, Dim>::operator[](unsigned d) {
48 : 11340 : return regions_m[d];
49 : : }
50 : :
51 : : template <typename T, unsigned Dim>
52 : : KOKKOS_INLINE_FUNCTION NDRegion<T, Dim>& NDRegion<T, Dim>::operator+=(const T t) {
53 : : for (unsigned int i = 0; i < Dim; i++) {
54 : : regions_m[i] += t;
55 : : }
56 : : return *this;
57 : : }
58 : :
59 : : template <typename T, unsigned Dim>
60 : : KOKKOS_INLINE_FUNCTION NDRegion<T, Dim>& NDRegion<T, Dim>::operator-=(const T t) {
61 : : for (unsigned int i = 0; i < Dim; i++) {
62 : : regions_m[i] -= t;
63 : : }
64 : : return *this;
65 : : }
66 : :
67 : : template <typename T, unsigned Dim>
68 : : KOKKOS_INLINE_FUNCTION NDRegion<T, Dim>& NDRegion<T, Dim>::operator*=(const T t) {
69 : : for (unsigned int i = 0; i < Dim; i++) {
70 : : regions_m[i] *= t;
71 : : }
72 : : return *this;
73 : : }
74 : :
75 : : template <typename T, unsigned Dim>
76 : : KOKKOS_INLINE_FUNCTION NDRegion<T, Dim>& NDRegion<T, Dim>::operator/=(const T t) {
77 : : if (t != 0) {
78 : : for (unsigned int i = 0; i < Dim; i++) {
79 : : regions_m[i] /= t;
80 : : }
81 : : }
82 : : return *this;
83 : : }
84 : :
85 : : template <typename T, unsigned Dim>
86 : : KOKKOS_INLINE_FUNCTION bool NDRegion<T, Dim>::empty() const {
87 : : bool isEmpty = true;
88 : : for (unsigned int i = 0; i < Dim; i++) {
89 : : isEmpty &= regions_m[i].empty();
90 : : }
91 : : return isEmpty;
92 : : }
93 : :
94 : : template <typename T, unsigned Dim>
95 : 0 : inline std::ostream& operator<<(std::ostream& out, const NDRegion<T, Dim>& idx) {
96 : 0 : out << '{';
97 [ # # ]: 0 : for (unsigned d = 0; d < Dim; ++d) {
98 [ # # ]: 0 : out << idx[d] << ((d == Dim - 1) ? '}' : ',');
99 : : }
100 : 0 : return out;
101 : : }
102 : : } // namespace ippl
|