32 template<
typename TDim,
typename TVal>
36 template<
typename TDim,
typename TVal>
40 static_assert(TDim::value >= 0u,
"Invalid dimensionality");
49 using IdxSequence = std::make_integer_sequence<std::size_t, TDim::value>;
61 typename = std::enable_if_t<
62 sizeof...(TArgs) == TDim::value && (std::is_convertible_v<std::decay_t<TArgs>, TVal> && ...)>>
70 template<
typename F, std::enable_if_t<std::is_invocable_v<F, std::
integral_constant<std::
size_t, 0>>,
int> = 0>
72 :
Vec(
std::forward<F>(generator),
std::make_index_sequence<TDim::value>{})
77 template<
typename F, std::size_t... Is>
79 : m_data{generator(
std::integral_constant<
std::size_t, Is>{})...}
101 return all(
static_cast<TVal
>(0));
108 return all(
static_cast<TVal
>(1));
123 return m_data + TDim::value;
128 return m_data + TDim::value;
143 return m_data[Dim::value - 1];
148 return m_data[Dim::value - 1];
155 template<
typename TDefer = Dim, std::enable_if_t<std::is_same_v<TDefer, Dim> && Dim::value >= 1,
int> = 0>
158 return m_data[Dim::value - 1];
161 template<
typename TDefer = Dim, std::enable_if_t<std::is_same_v<TDefer, Dim> && Dim::value >= 1,
int> = 0>
164 return m_data[Dim::value - 1];
167 template<
typename TDefer = Dim, std::enable_if_t<std::is_same_v<TDefer, Dim> && Dim::value >= 2,
int> = 0>
170 return m_data[Dim::value - 2];
173 template<
typename TDefer = Dim, std::enable_if_t<std::is_same_v<TDefer, Dim> && Dim::value >= 2,
int> = 0>
176 return m_data[Dim::value - 2];
179 template<
typename TDefer = Dim, std::enable_if_t<std::is_same_v<TDefer, Dim> && Dim::value >= 3,
int> = 0>
182 return m_data[Dim::value - 3];
185 template<
typename TDefer = Dim, std::enable_if_t<std::is_same_v<TDefer, Dim> && Dim::value >= 3,
int> = 0>
188 return m_data[Dim::value - 3];
191 template<
typename TDefer = Dim, std::enable_if_t<std::is_same_v<TDefer, Dim> && Dim::value >= 4,
int> = 0>
194 return m_data[Dim::value - 4];
197 template<
typename TDefer = Dim, std::enable_if_t<std::is_same_v<TDefer, Dim> && Dim::value >= 4,
int> = 0>
200 return m_data[Dim::value - 4];
208 template<
typename TIdx,
typename = std::enable_if_t<std::is_
integral_v<TIdx>>>
212 auto const idx =
static_cast<typename TDim::value_type
>(iIdx);
220 template<
typename TIdx,
typename = std::enable_if_t<std::is_
integral_v<TIdx>>>
224 auto const idx =
static_cast<typename TDim::value_type
>(iIdx);
230 template<
typename TFnObj, std::size_t... TIndices>
233 std::integer_sequence<std::size_t, TIndices...>)
const
239 template<
typename TFnObj, std::size_t... TIndices>
242 std::integer_sequence<std::size_t, TIndices...>,
245 return meta::foldr(f, (*
this)[TIndices]..., initial);
249 template<
typename TFnObj>
252 return foldrByIndices(f, IdxSequence());
256 template<
typename TFnObj>
257 [[nodiscard]]
ALPAKA_FN_HOST_ACC constexpr auto foldrAll(TFnObj
const& f, TVal initial)
const
259 return foldrByIndices(f, IdxSequence(), initial);
263#if BOOST_COMP_MSVC || defined(BOOST_COMP_MSVC_EMULATED)
264# pragma warning(push)
265# pragma warning(disable : 4702)
271 return foldrAll(std::multiplies<TVal>{}, TVal{1});
273#if BOOST_COMP_MSVC || defined(BOOST_COMP_MSVC_EMULATED)
280 return foldrAll(std::plus<TVal>{}, TVal{0});
287 return foldrAll(meta::min<TVal>{}, std::numeric_limits<TVal>::max());
294 return foldrAll(meta::max<TVal>{}, std::numeric_limits<TVal>::min());
301 return foldrAll(std::logical_and<TVal>{},
true);
308 return foldrAll(std::logical_or<TVal>{},
false);
315 return !foldrAll(std::logical_or<TVal>{},
false);
319 [[nodiscard]]
ALPAKA_FN_HOST constexpr auto minElem() const -> typename TDim::value_type
321 return static_cast<typename TDim::value_type
>(
322 std::distance(std::begin(m_data), std::min_element(std::begin(m_data), std::end(m_data))));
326 [[nodiscard]]
ALPAKA_FN_HOST constexpr auto maxElem() const -> typename TDim::value_type
328 return static_cast<typename TDim::value_type
>(
329 std::distance(std::begin(m_data), std::max_element(std::begin(m_data), std::end(m_data))));
355 if constexpr(TDim::value > 0)
357 for(
typename TDim::value_type i = 0; i < TDim::value; ++i)
368 if constexpr(TDim::value > 0)
370 for(
typename TDim::value_type i = 0; i < TDim::value; ++i)
381 if constexpr(TDim::value > 0)
383 for(
typename TDim::value_type i = 0; i < TDim::value; ++i)
392 if constexpr(TDim::value > 0)
394 for(
typename TDim::value_type i(0); i < TDim::value; ++i)
411 ALPAKA_FN_HOST_ACC friend constexpr auto operator<(Vec
const& p, Vec
const& q) -> Vec<TDim, bool>
414 if constexpr(TDim::value > 0)
416 for(
typename TDim::value_type i = 0; i < TDim::value; ++i)
424 ALPAKA_FN_HOST_ACC friend constexpr auto operator<=(Vec
const& p, Vec
const& q) -> Vec<TDim, bool>
427 if constexpr(TDim::value > 0)
429 for(
typename TDim::value_type i = 0; i < TDim::value; ++i)
437 ALPAKA_FN_HOST_ACC friend constexpr auto operator>(Vec
const& p, Vec
const& q) -> Vec<TDim, bool>
440 if constexpr(TDim::value > 0)
442 for(
typename TDim::value_type i = 0; i < TDim::value; ++i)
450 ALPAKA_FN_HOST_ACC friend constexpr auto operator>=(Vec
const& p, Vec
const& q) -> Vec<TDim, bool>
453 if constexpr(TDim::value > 0)
455 for(
typename TDim::value_type i = 0; i < TDim::value; ++i)
463 ALPAKA_FN_HOST_ACC friend constexpr auto operator&&(Vec
const& p, Vec
const& q) -> Vec<TDim, bool>
466 if constexpr(TDim::value > 0)
468 for(
typename TDim::value_type i = 0; i < TDim::value; ++i)
476 ALPAKA_FN_HOST_ACC friend constexpr auto operator||(Vec
const& p, Vec
const& q) -> Vec<TDim, bool>
479 if constexpr(TDim::value > 0)
481 for(
typename TDim::value_type i = 0; i < TDim::value; ++i)
490 if constexpr(TDim::value > 0)
492 for(
typename TDim::value_type i = 0; i < TDim::value; ++i)
495 if(i != TDim::value - 1)
508 TVal m_data[TDim::value == 0u ? 1u : TDim::value];
511 template<
typename TFirstIndex,
typename... TRestIndices>
513 ->
Vec<
DimInt<1 +
sizeof...(TRestIndices)>, std::decay_t<TFirstIndex>>;
516 inline constexpr bool isVec =
false;
518 template<
typename TDim,
typename TVal>
519 inline constexpr bool isVec<Vec<TDim, TVal>> =
true;
522 template<
typename TDim,
typename TVal>
525 std::array<TVal, TDim::value> a{};
526 if constexpr(TDim::value > 0)
528 for(
unsigned i = 0; i < TDim::value; i++)
540 typename = std::enable_if_t<(std::is_same_v<Vec<TDim, TVal>, Vecs> && ...)>>
544 if constexpr(TDim::value > 0)
546 for(
typename TDim::value_type i = 0; i < TDim::value; ++i)
547 r[i] = std::min({p[i], qs[i]...});
558 typename = std::enable_if_t<(std::is_same_v<Vec<TDim, TVal>, Vecs> && ...)>>
562 if constexpr(TDim::value > 0)
564 for(
typename TDim::value_type i = 0; i < TDim::value; ++i)
565 r[i] = std::max({p[i], qs[i]...});
573 template<
typename TDim,
typename TVal>
580 template<
typename TDim,
typename TVal>
587 template<
typename TDim,
typename TVal, std::size_t... TIndices>
593 if constexpr(std::is_same_v<std::index_sequence<TIndices...>, std::make_index_sequence<TDim::value>>)
600 sizeof...(TIndices) <= TDim::value,
601 "The sub-vector's dimensionality must be smaller than or equal to the original "
603 return {vec[TIndices]...};
609 template<
typename TValNew,
typename TDim,
typename TVal>
615 if constexpr(std::is_same_v<TValNew, TVal>)
622 if constexpr(TDim::value > 0)
624 for(
typename TDim::value_type i = 0; i < TDim::value; ++i)
625 r[i] =
static_cast<TValNew
>(vec[i]);
634 template<
typename TDim,
typename TVal>
640 if constexpr(TDim::value <= 1)
647 for(
typename TDim::value_type i = 0; i < TDim::value; ++i)
648 r[i] = vec[TDim::value - 1u - i];
656 template<
typename TDimL,
typename TDimR,
typename TVal>
665 if constexpr(TDimL::value > 0)
667 for(
typename TDimL::value_type i = 0; i < TDimL::value; ++i)
670 if constexpr(TDimR::value > 0)
672 for(
typename TDimR::value_type i = 0; i < TDimR::value; ++i)
673 r[TDimL::value + i] = vecR[i];
681#if defined(__clang__)
682# pragma GCC diagnostic push
683# pragma GCC diagnostic ignored "-Wmismatched-tags"
687 template<
typename TDim,
typename TVal>
688 struct tuple_size<
alpaka::Vec<TDim, TVal>> : integral_constant<size_t, TDim::value>
692 template<
size_t I,
typename TDim,
typename TVal>
693 struct tuple_element<I,
alpaka::Vec<TDim, TVal>>
698#if defined(__clang__)
699# pragma GCC diagnostic pop
#define ALPAKA_UNREACHABLE(...)
Before CUDA 11.5 nvcc is unable to correctly identify return statements in 'if constexpr' branches....
ALPAKA_FN_HOST_ACC constexpr auto begin() -> TVal *
ALPAKA_NO_HOST_ACC_WARNING static ALPAKA_FN_HOST_ACC constexpr auto ones() -> Vec< TDim, TVal >
One value constructor.
ALPAKA_FN_HOST_ACC constexpr auto begin() const -> TVal const *
ALPAKA_FN_HOST_ACC constexpr auto front() -> TVal &
ALPAKA_FN_HOST_ACC constexpr Vec()
Val value_type
STL-like value_type.
ALPAKA_FN_HOST_ACC constexpr Vec(F &&generator)
Generator constructor. Initializes the vector with the values returned from generator(IC) in order,...
ALPAKA_NO_HOST_ACC_WARNING static ALPAKA_FN_HOST_ACC constexpr auto zeros() -> Vec< TDim, TVal >
Zero value constructor.
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC constexpr Vec(TArgs &&... args)
Value constructor. This constructor is only available if the number of parameters matches the vector ...
ALPAKA_NO_HOST_ACC_WARNING static ALPAKA_FN_HOST_ACC constexpr auto all(TVal const &val) -> Vec< TDim, TVal >
Single value constructor.
ALPAKA_FN_HOST_ACC constexpr auto front() const -> TVal const &
ALPAKA_FN_HOST_ACC constexpr auto end() const -> TVal const *
ALPAKA_FN_HOST_ACC constexpr auto end() -> TVal *
ALPAKA_FN_HOST_ACC constexpr auto back() -> TVal &
ALPAKA_FN_HOST_ACC constexpr auto back() const -> TVal const &
#define ALPAKA_FN_HOST_ACC
#define ALPAKA_NO_HOST_ACC_WARNING
Disable nvcc warning: 'calling a host function from host device function.' Usage: ALPAKA_NO_HOST_ACC_...
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC constexpr auto assertValueUnsigned(TArg const &arg) -> void
This method checks integral values if they are greater or equal zero. The implementation prevents war...
auto clipCast(V const &val) -> T
ALPAKA_FN_HOST_ACC Complex< T > operator+(Complex< T > const &val)
Host-device arithmetic operations matching std::complex<T>.
ALPAKA_FN_HOST_ACC Complex< T > operator-(Complex< T > const &val)
Unary minus.
constexpr ALPAKA_FN_HOST_ACC bool operator==(Complex< T > const &lhs, Complex< T > const &rhs)
Equality of two complex numbers.
std::basic_ostream< TChar, TTraits > & operator<<(std::basic_ostream< TChar, TTraits > &os, Complex< T > const &x)
Host-only output of a complex number.
ALPAKA_FN_HOST_ACC Complex< T > operator*(Complex< T > const &lhs, Complex< T > const &rhs)
Muptiplication of two complex numbers.
constexpr ALPAKA_FN_HOST_ACC bool operator!=(Complex< T > const &lhs, Complex< T > const &rhs)
Inequality of two complex numbers.
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto max(T const &max_ctx, Tx const &x, Ty const &y)
Returns the larger of two arguments. NaNs are treated as missing data (between a NaN and a numeric va...
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto min(T const &min_ctx, Tx const &x, Ty const &y)
Returns the smaller of two arguments. NaNs are treated as missing data (between a NaN and a numeric v...
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_ACC auto all(TWarp const &warp, std::int32_t predicate) -> std::int32_t
Evaluates predicate for all active threads of the warp and returns non-zero if and only if predicate ...
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_ACC auto any(TWarp const &warp, std::int32_t predicate) -> std::int32_t
Evaluates predicate for all active threads of the warp and returns non-zero if and only if predicate ...
The alpaka accelerator library.
ALPAKA_FN_HOST_ACC constexpr auto toArray(Vec< TDim, TVal > const &v) -> std::array< TVal, TDim::value >
Converts a Vec to a std::array.
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC constexpr auto elementwise_min(Vec< TDim, TVal > const &p, Vecs const &... qs) -> Vec< TDim, TVal >
std::integral_constant< std::size_t, N > DimInt
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC constexpr auto elementwise_max(Vec< TDim, TVal > const &p, Vecs const &... qs) -> Vec< TDim, TVal >
ALPAKA_FN_HOST_ACC Vec(TFirstIndex &&, TRestIndices &&...) -> Vec< DimInt< 1+sizeof...(TRestIndices)>, std::decay_t< TFirstIndex > >
ALPAKA_NO_HOST_ACC_WARNING static ALPAKA_FN_HOST_ACC constexpr auto castVec(Vec< TDim, TVal > const &vec) -> Vec< TDim, TValNew >
Trait for casting a vector.
ALPAKA_NO_HOST_ACC_WARNING static ALPAKA_FN_HOST_ACC constexpr auto concatVec(Vec< TDimL, TVal > const &vecL, Vec< TDimR, TVal > const &vecR) -> Vec< DimInt< TDimL::value+TDimR::value >, TVal >
Trait for concatenating two vectors.
The dimension getter type trait.
ALPAKA_NO_HOST_ACC_WARNING static ALPAKA_FN_HOST_ACC constexpr auto reverseVec(Vec< TDim, TVal > const &vec) -> Vec< TDim, TVal >
Trait for reversing a vector.
ALPAKA_NO_HOST_ACC_WARNING static ALPAKA_FN_HOST_ACC constexpr auto subVecFromIndices(Vec< TDim, TVal > const &vec) -> Vec< DimInt< sizeof...(TIndices)>, TVal >
Trait for selecting a sub-vector.