27 #include <type_traits>
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>;
59 #if BOOST_COMP_NVCC && BOOST_COMP_NVCC >= BOOST_VERSION_NUMBER(11, 3, 0) \
60 && BOOST_COMP_NVCC < BOOST_VERSION_NUMBER(11, 4, 0)
64 template<
typename... TArgs>
66 : m_data{std::move(arg0), static_cast<TVal>(std::forward<TArgs>(args))...}
69 1 +
sizeof...(TArgs) == TDim::value && (std::is_convertible_v<std::decay_t<TArgs>, TVal> && ...),
70 "Wrong number of arguments to Vec constructor or types are not convertible to TVal.");
75 typename = std::enable_if_t<
76 sizeof...(TArgs) == TDim::value && (std::is_convertible_v<std::decay_t<TArgs>, TVal> && ...)>>
85 #if BOOST_COMP_NVCC && BOOST_COMP_NVCC >= BOOST_VERSION_NUMBER(11, 3, 0) \
86 && BOOST_COMP_NVCC < BOOST_VERSION_NUMBER(11, 4, 0)
90 std::void_t<decltype(generator(std::integral_constant<std::size_t, 0>{}))>* ignore =
nullptr)
91 :
Vec(std::forward<F>(generator), std::make_index_sequence<TDim::value>{})
93 static_cast<void>(ignore);
96 template<
typename F, std::enable_if_t<std::is_invocable_v<F, std::
integral_constant<std::
size_t, 0>>,
int> = 0>
98 :
Vec(std::forward<F>(generator), std::make_index_sequence<TDim::value>{})
104 template<
typename F, std::size_t... Is>
106 : m_data{generator(std::integral_constant<std::size_t, Is>{})...}
128 return all(
static_cast<TVal
>(0));
135 return all(
static_cast<TVal
>(1));
150 return m_data + TDim::value;
155 return m_data + TDim::value;
170 return m_data[Dim::value - 1];
175 return m_data[Dim::value - 1];
182 template<
typename TDefer = Dim, std::enable_if_t<std::is_same_v<TDefer, Dim> && Dim::value >= 1,
int> = 0>
185 return m_data[Dim::value - 1];
188 template<
typename TDefer = Dim, std::enable_if_t<std::is_same_v<TDefer, Dim> && Dim::value >= 1,
int> = 0>
191 return m_data[Dim::value - 1];
194 template<
typename TDefer = Dim, std::enable_if_t<std::is_same_v<TDefer, Dim> && Dim::value >= 2,
int> = 0>
197 return m_data[Dim::value - 2];
200 template<
typename TDefer = Dim, std::enable_if_t<std::is_same_v<TDefer, Dim> && Dim::value >= 2,
int> = 0>
203 return m_data[Dim::value - 2];
206 template<
typename TDefer = Dim, std::enable_if_t<std::is_same_v<TDefer, Dim> && Dim::value >= 3,
int> = 0>
209 return m_data[Dim::value - 3];
212 template<
typename TDefer = Dim, std::enable_if_t<std::is_same_v<TDefer, Dim> && Dim::value >= 3,
int> = 0>
215 return m_data[Dim::value - 3];
218 template<
typename TDefer = Dim, std::enable_if_t<std::is_same_v<TDefer, Dim> && Dim::value >= 4,
int> = 0>
221 return m_data[Dim::value - 4];
224 template<
typename TDefer = Dim, std::enable_if_t<std::is_same_v<TDefer, Dim> && Dim::value >= 4,
int> = 0>
227 return m_data[Dim::value - 4];
235 template<
typename TIdx,
typename = std::enable_if_t<std::is_
integral_v<TIdx>>>
239 auto const idx =
static_cast<typename TDim::value_type
>(iIdx);
240 core::assertGreaterThan<TDim>(idx);
247 template<
typename TIdx,
typename = std::enable_if_t<std::is_
integral_v<TIdx>>>
251 auto const idx =
static_cast<typename TDim::value_type
>(iIdx);
252 core::assertGreaterThan<TDim>(idx);
257 template<
typename TFnObj, std::size_t... TIndices>
260 std::integer_sequence<std::size_t, TIndices...>)
const
266 template<
typename TFnObj, std::size_t... TIndices>
269 std::integer_sequence<std::size_t, TIndices...>,
272 return meta::foldr(f, (*
this)[TIndices]..., initial);
276 template<
typename TFnObj>
279 return foldrByIndices(f, IdxSequence());
283 template<
typename TFnObj>
284 [[nodiscard]]
ALPAKA_FN_HOST_ACC constexpr
auto foldrAll(TFnObj
const& f, TVal initial)
const
286 return foldrByIndices(f, IdxSequence(), initial);
290 #if BOOST_COMP_MSVC || defined(BOOST_COMP_MSVC_EMULATED)
291 # pragma warning(push)
292 # pragma warning(disable : 4702)
298 return foldrAll(std::multiplies<TVal>{}, TVal{1});
300 #if BOOST_COMP_MSVC || defined(BOOST_COMP_MSVC_EMULATED)
301 # pragma warning(pop)
307 return foldrAll(std::plus<TVal>{}, TVal{0});
328 return foldrAll(std::logical_and<TVal>{},
true);
335 return foldrAll(std::logical_or<TVal>{},
false);
342 return !foldrAll(std::logical_or<TVal>{},
false);
346 [[nodiscard]]
ALPAKA_FN_HOST constexpr
auto minElem() const -> typename TDim::value_type
348 return static_cast<typename TDim::value_type
>(
353 [[nodiscard]]
ALPAKA_FN_HOST constexpr
auto maxElem() const -> typename TDim::value_type
355 return static_cast<typename TDim::value_type
>(
382 #if BOOST_COMP_NVCC && BOOST_COMP_NVCC < BOOST_VERSION_NUMBER(11, 3, 0)
385 if constexpr(TDim::value > 0)
388 for(
typename TDim::value_type i = 0; i < TDim::value; ++i)
399 #if BOOST_COMP_NVCC && BOOST_COMP_NVCC < BOOST_VERSION_NUMBER(11, 3, 0)
402 if constexpr(TDim::value > 0)
405 #if BOOST_COMP_NVCC && BOOST_COMP_NVCC < BOOST_VERSION_NUMBER(11, 3, 0)
406 # pragma diag_suppress = unsigned_compare_with_zero
408 for(
typename TDim::value_type i = 0; i < TDim::value; ++i)
409 #
if BOOST_COMP_NVCC && BOOST_COMP_NVCC < BOOST_VERSION_NUMBER(11, 3, 0)
410 # pragma diag_default = unsigned_compare_with_zero
422 #if BOOST_COMP_NVCC && BOOST_COMP_NVCC < BOOST_VERSION_NUMBER(11, 3, 0)
425 if constexpr(TDim::value > 0)
428 for(
typename TDim::value_type i = 0; i < TDim::value; ++i)
437 #if BOOST_COMP_NVCC && BOOST_COMP_NVCC < BOOST_VERSION_NUMBER(11, 3, 0)
440 if constexpr(TDim::value > 0)
443 #if BOOST_COMP_NVCC && BOOST_COMP_NVCC < BOOST_VERSION_NUMBER(11, 3, 0)
444 # pragma diag_suppress = unsigned_compare_with_zero
446 for(
typename TDim::value_type i(0); i < TDim::value; ++i)
447 #
if BOOST_COMP_NVCC && BOOST_COMP_NVCC < BOOST_VERSION_NUMBER(11, 3, 0)
448 # pragma diag_default = unsigned_compare_with_zero
469 #if BOOST_COMP_NVCC && BOOST_COMP_NVCC < BOOST_VERSION_NUMBER(11, 3, 0)
472 if constexpr(TDim::value > 0)
475 for(
typename TDim::value_type i = 0; i < TDim::value; ++i)
486 #if BOOST_COMP_NVCC && BOOST_COMP_NVCC < BOOST_VERSION_NUMBER(11, 3, 0)
489 if constexpr(TDim::value > 0)
492 for(
typename TDim::value_type i = 0; i < TDim::value; ++i)
503 #if BOOST_COMP_NVCC && BOOST_COMP_NVCC < BOOST_VERSION_NUMBER(11, 3, 0)
506 if constexpr(TDim::value > 0)
509 for(
typename TDim::value_type i = 0; i < TDim::value; ++i)
520 #if BOOST_COMP_NVCC && BOOST_COMP_NVCC < BOOST_VERSION_NUMBER(11, 3, 0)
523 if constexpr(TDim::value > 0)
526 for(
typename TDim::value_type i = 0; i < TDim::value; ++i)
537 #if BOOST_COMP_NVCC && BOOST_COMP_NVCC < BOOST_VERSION_NUMBER(11, 3, 0)
540 if constexpr(TDim::value > 0)
543 for(
typename TDim::value_type i = 0; i < TDim::value; ++i)
554 #if BOOST_COMP_NVCC && BOOST_COMP_NVCC < BOOST_VERSION_NUMBER(11, 3, 0)
557 if constexpr(TDim::value > 0)
560 for(
typename TDim::value_type i = 0; i < TDim::value; ++i)
569 #if BOOST_COMP_NVCC && BOOST_COMP_NVCC < BOOST_VERSION_NUMBER(11, 3, 0)
572 if constexpr(TDim::value > 0)
575 #if BOOST_COMP_NVCC && BOOST_COMP_NVCC < BOOST_VERSION_NUMBER(11, 3, 0)
576 # pragma diag_suppress = unsigned_compare_with_zero
578 for(
typename TDim::value_type i = 0; i < TDim::value; ++i)
579 #
if BOOST_COMP_NVCC && BOOST_COMP_NVCC < BOOST_VERSION_NUMBER(11, 3, 0)
580 # pragma diag_default = unsigned_compare_with_zero
584 if(i != TDim::value - 1)
597 TVal m_data[TDim::value == 0u ? 1u : TDim::value];
600 template<
typename TFirstIndex,
typename... TRestIndices>
602 ->
Vec<
DimInt<1 +
sizeof...(TRestIndices)>, std::decay_t<TFirstIndex>>;
605 inline constexpr
bool isVec =
false;
607 template<
typename TDim,
typename TVal>
608 inline constexpr
bool isVec<Vec<TDim, TVal>> =
true;
611 template<
typename TDim,
typename TVal>
614 std::array<TVal, TDim::value> a{};
615 #if BOOST_COMP_NVCC && BOOST_COMP_NVCC < BOOST_VERSION_NUMBER(11, 3, 0)
618 if constexpr(TDim::value > 0)
621 for(
unsigned i = 0; i < TDim::value; i++)
633 typename = std::enable_if_t<(std::is_same_v<Vec<TDim, TVal>, Vecs> && ...)>>
637 #if BOOST_COMP_NVCC && BOOST_COMP_NVCC < BOOST_VERSION_NUMBER(11, 3, 0)
640 if constexpr(TDim::value > 0)
643 for(
typename TDim::value_type i = 0; i < TDim::value; ++i)
655 typename = std::enable_if_t<(std::is_same_v<Vec<TDim, TVal>, Vecs> && ...)>>
659 #if BOOST_COMP_NVCC && BOOST_COMP_NVCC < BOOST_VERSION_NUMBER(11, 3, 0)
662 if constexpr(TDim::value > 0)
665 for(
typename TDim::value_type i = 0; i < TDim::value; ++i)
674 template<
typename TDim,
typename TVal>
681 template<
typename TDim,
typename TVal>
688 template<
typename TDim,
typename TVal, std::size_t... TIndices>
694 if constexpr(std::is_same_v<std::index_sequence<TIndices...>, std::make_index_sequence<TDim::value>>)
701 sizeof...(TIndices) <= TDim::value,
702 "The sub-vector's dimensionality must be smaller than or equal to the original "
704 return {vec[TIndices]...};
710 template<
typename TValNew,
typename TDim,
typename TVal>
716 if constexpr(std::is_same_v<TValNew, TVal>)
723 #if BOOST_COMP_NVCC && BOOST_COMP_NVCC < BOOST_VERSION_NUMBER(11, 3, 0)
726 if constexpr(TDim::value > 0)
729 for(
typename TDim::value_type i = 0; i < TDim::value; ++i)
730 r[i] =
static_cast<TValNew
>(vec[i]);
739 template<
typename TDim,
typename TVal>
745 if constexpr(TDim::value <= 1)
752 for(
typename TDim::value_type i = 0; i < TDim::value; ++i)
753 r[i] = vec[TDim::value - 1u - i];
761 template<
typename TDimL,
typename TDimR,
typename TVal>
770 if constexpr(TDimL::value > 0)
772 for(
typename TDimL::value_type i = 0; i < TDimL::value; ++i)
775 if constexpr(TDimR::value > 0)
777 for(
typename TDimR::value_type i = 0; i < TDimR::value; ++i)
778 r[TDimL::value + i] = vecR[i];
786 #if defined(__clang__)
787 # pragma GCC diagnostic push
788 # pragma GCC diagnostic ignored "-Wmismatched-tags"
792 template<
typename TDim,
typename TVal>
793 struct tuple_size<
alpaka::
Vec<TDim, TVal>> : integral_constant<size_t, TDim::value>
797 template<
size_t I,
typename TDim,
typename TVal>
803 #if defined(__clang__)
804 # pragma GCC diagnostic pop
#define ALPAKA_UNREACHABLE(...)
Before CUDA 11.5 nvcc is unable to correctly identify return statements in 'if constexpr' branches....
constexpr ALPAKA_FN_HOST_ACC auto front() const -> TVal const &
ALPAKA_NO_HOST_ACC_WARNING static constexpr ALPAKA_FN_HOST_ACC auto ones() -> Vec< TDim, TVal >
One value constructor.
constexpr ALPAKA_FN_HOST_ACC auto back() const -> TVal const &
constexpr ALPAKA_FN_HOST_ACC auto begin() -> TVal *
ALPAKA_NO_HOST_ACC_WARNING static constexpr ALPAKA_FN_HOST_ACC auto all(TVal const &val) -> Vec< TDim, TVal >
Single value constructor.
Val value_type
STL-like value_type.
constexpr ALPAKA_FN_HOST_ACC auto end() -> TVal *
ALPAKA_NO_HOST_ACC_WARNING static constexpr ALPAKA_FN_HOST_ACC auto zeros() -> Vec< TDim, TVal >
Zero value constructor.
constexpr ALPAKA_FN_HOST_ACC auto end() const -> TVal const *
ALPAKA_NO_HOST_ACC_WARNING constexpr ALPAKA_FN_HOST_ACC Vec(TArgs &&... args)
Value constructor. This constructor is only available if the number of parameters matches the vector ...
constexpr ALPAKA_FN_HOST_ACC auto front() -> TVal &
constexpr ALPAKA_FN_HOST_ACC Vec()
constexpr ALPAKA_FN_HOST_ACC Vec(F &&generator)
Generator constructor. Initializes the vector with the values returned from generator(IC) in order,...
constexpr ALPAKA_FN_HOST_ACC auto back() -> TVal &
constexpr ALPAKA_FN_HOST_ACC auto begin() 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 constexpr ALPAKA_FN_HOST_ACC auto assertValueUnsigned(TArg const &arg) -> void
This method checks integral values if they are greater or equal zero. The implementation prevents war...
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.
ALPAKA_FN_HOST_ACC Complex< T > operator+(Complex< T > const &val)
Host-device arithmetic operations matching std::complex<T>.
constexpr ALPAKA_FN_HOST_ACC bool operator!=(Complex< T > const &lhs, Complex< T > const &rhs)
Inequality of two complex numbers.
ALPAKA_FN_HOST_ACC Complex< T > operator-(Complex< T > const &val)
Unary minus.
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_FN_HOST auto end(TView &view) -> Iterator< TView >
ALPAKA_FN_HOST auto begin(TView &view) -> Iterator< TView >
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_NO_HOST_ACC_WARNING constexpr ALPAKA_FN_HOST_ACC auto elementwise_max(Vec< TDim, TVal > const &p, Vecs const &... qs) -> Vec< TDim, TVal >
constexpr ALPAKA_FN_HOST_ACC auto toArray(Vec< TDim, TVal > const &v) -> std::array< TVal, TDim::value >
Converts a Vec to a std::array.
ALPAKA_NO_HOST_ACC_WARNING constexpr ALPAKA_FN_HOST_ACC auto elementwise_min(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 >>
std::integral_constant< std::size_t, N > DimInt
ALPAKA_NO_HOST_ACC_WARNING static constexpr ALPAKA_FN_HOST_ACC auto castVec(Vec< TDim, TVal > const &vec) -> Vec< TDim, TValNew >
Trait for casting a vector.
ALPAKA_NO_HOST_ACC_WARNING static constexpr ALPAKA_FN_HOST_ACC 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 constexpr ALPAKA_FN_HOST_ACC auto reverseVec(Vec< TDim, TVal > const &vec) -> Vec< TDim, TVal >
Trait for reversing a vector.
ALPAKA_NO_HOST_ACC_WARNING static constexpr ALPAKA_FN_HOST_ACC auto subVecFromIndices(Vec< TDim, TVal > const &vec) -> Vec< DimInt< sizeof...(TIndices)>, TVal >
Trait for selecting a sub-vector.