25
25
#include " pmacc/math/Vector.hpp"
26
26
#include " pmacc/types.hpp"
27
27
28
+ #include < alpaka/core/Common.hpp>
29
+
28
30
#include < type_traits>
29
31
30
32
namespace pmacc
@@ -65,19 +67,15 @@ namespace pmacc
65
67
{
66
68
}
67
69
68
- constexpr DataSpace (DataSpace const &) = default;
69
-
70
- HDINLINE constexpr DataSpace& operator =(DataSpace const &) = default ;
71
-
72
70
/* * constructor.
73
71
*
74
72
* Sets size of all dimensions from alpaka.
73
+ * Reverses (permutes) the order of the dimensions.
75
74
*/
76
75
template <typename T_MemberType>
77
- HDINLINE explicit DataSpace (alpaka::Vec<::alpaka::DimInt<T_dim>, T_MemberType> const & value)
76
+ HDINLINE explicit constexpr DataSpace (alpaka::Vec<::alpaka::DimInt<T_dim>, T_MemberType> const & value)
77
+ : BaseType(makeReversedArgs(value, std::make_index_sequence<T_dim>{}))
78
78
{
79
- for (uint32_t i = 0u ; i < T_dim; i++)
80
- (*this )[T_dim - 1 - i] = value[i];
81
79
}
82
80
83
81
/* * Constructor for N-dimensional DataSpace.
@@ -86,7 +84,8 @@ namespace pmacc
86
84
*
87
85
* @param args size of each dimension, x,y,z,...
88
86
*/
89
- template <typename ... T_Args, typename = std::enable_if_t <(std::is_convertible_v<T_Args, int > && ...)>>
87
+ template <std::convertible_to<int >... T_Args>
88
+ requires (sizeof ...(T_Args) == T_dim)
90
89
constexpr DataSpace (T_Args&&... args) : BaseType(std::forward<T_Args>(args)...)
91
90
{
92
91
static_assert (sizeof ...(T_Args) == T_dim, " Number of arguments must be equal to the DataSpace dimension." );
@@ -96,12 +95,9 @@ namespace pmacc
96
95
{
97
96
}
98
97
99
- HDINLINE DataSpace (math::Size_t<T_dim> const & vec)
98
+ // constructor to convert from size_t vector to int dataspace
99
+ HDINLINE constexpr DataSpace (math::Size_t<T_dim> const & vec) : BaseType(vec)
100
100
{
101
- for (uint32_t i = 0 ; i < T_dim; ++i)
102
- {
103
- (*this )[i] = vec[i];
104
- }
105
101
}
106
102
107
103
/* *
@@ -110,14 +106,10 @@ namespace pmacc
110
106
* @param value value which is setfor all dimensions
111
107
* @return the new DataSpace
112
108
*/
113
- HDINLINE static DataSpace<T_dim> create (int value = 1 )
109
+ HDINLINE static constexpr DataSpace<T_dim> create (int value = 1 ) noexcept
114
110
{
115
- DataSpace<T_dim> tmp;
116
- for (uint32_t i = 0 ; i < T_dim; ++i)
117
- {
118
- tmp[i] = value;
119
- }
120
- return tmp;
111
+ return [value]<std::size_t ... Is>(std::index_sequence<Is...>)
112
+ { return DataSpace<T_dim>((static_cast <void >(Is), value)...); }(std::make_index_sequence<T_dim>{});
121
113
}
122
114
123
115
/* *
@@ -136,22 +128,25 @@ namespace pmacc
136
128
* @param other DataSpace to compare with
137
129
* @return true if one dimension is greater, false otherwise
138
130
*/
139
- HINLINE bool isOneDimensionGreaterThan (MemSpace<T_dim> const & other) const
131
+ HINLINE constexpr bool isOneDimensionGreaterThan (MemSpace<T_dim> const & other) const
140
132
{
141
- for (uint32_t i = 0 ; i < T_dim; ++i)
142
- {
143
- if ((*this )[i] > other[i])
144
- return true ;
145
- }
146
- return false ;
133
+ return [this , other]<std::size_t ... Is>(std::index_sequence<Is...>)
134
+ { return (((*this )[Is] > other[Is]) || ...); }(std::make_index_sequence<T_dim>{});
147
135
}
148
136
149
137
HDINLINE operator math::Size_t<T_dim>() const
150
138
{
151
- math::Size_t<T_dim> result;
152
- for (uint32_t i = 0 ; i < T_dim; i++)
153
- result[i] = static_cast <size_t >((*this )[i]);
154
- return result;
139
+ return [this ]<std::size_t ... Is>(std::index_sequence<Is...>) -> math::Size_t<T_dim>
140
+ { return {static_cast <std::size_t >((*this )[Is])...}; }(std::make_index_sequence<T_dim>{});
141
+ }
142
+
143
+ private:
144
+ template <typename T_MemberType, std::size_t ... Is>
145
+ static constexpr ALPAKA_FN_INLINE BaseType makeReversedArgs (
146
+ alpaka::Vec<::alpaka::DimInt<T_dim>, T_MemberType> const & value,
147
+ std::index_sequence<Is...>) noexcept
148
+ {
149
+ return {static_cast <int >(value[T_dim - 1 - Is])...};
155
150
}
156
151
};
157
152
0 commit comments