13#include <Kokkos_Macros.hpp>
15#include "ddc/detail/macros.hpp"
16#include "ddc/detail/type_seq.hpp"
28template <
class... Tags>
39template <
class... Tags>
42 using type = TypeSeq<Tags...>;
48
49using DiscreteVectorElement = std::ptrdiff_t;
51template <
class QueryTag,
class... Tags>
55 return tuple.
template get<QueryTag>();
58template <
class QueryTag,
class... Tags>
61 return tuple.
template get<QueryTag>();
64template <
class QueryTag,
class... Tags>
67 DiscreteVectorElement
const& default_value)
noexcept
69 return tuple.
template get_or<QueryTag>(default_value);
72template <
class QueryTag,
class... Tags>
77 if constexpr (in_tags_v<QueryTag, detail::TypeSeq<Tags...>>) {
86template <
class... Tags>
92template <
class... Tags>
100template <
class... Tags,
class... OTags>
105 using detail::TypeSeq;
106 if constexpr (
sizeof...(Tags) >=
sizeof...(OTags)) {
107 static_assert(((type_seq_contains_v<TypeSeq<OTags>, TypeSeq<Tags...>>) && ...));
112 static_assert(((type_seq_contains_v<TypeSeq<Tags>, TypeSeq<OTags...>>) && ...));
119template <
class... Tags,
class... OTags>
124 using detail::TypeSeq;
125 if constexpr (
sizeof...(Tags) >=
sizeof...(OTags)) {
126 static_assert(((type_seq_contains_v<TypeSeq<OTags>, TypeSeq<Tags...>>) && ...));
131 static_assert(((type_seq_contains_v<TypeSeq<Tags>, TypeSeq<OTags...>>) && ...));
138template <
class Tag,
class IntegralType,
class = std::enable_if_t<std::is_integral_v<IntegralType>>>
141 IntegralType
const& rhs)
146template <
class IntegralType,
class Tag,
class = std::enable_if_t<std::is_integral_v<IntegralType>>>
148 IntegralType
const& lhs,
154template <
class Tag,
class IntegralType,
class = std::enable_if_t<std::is_integral_v<IntegralType>>>
157 IntegralType
const& rhs)
162template <
class IntegralType,
class Tag,
class = std::enable_if_t<std::is_integral_v<IntegralType>>>
164 IntegralType
const& lhs,
175 class = std::enable_if_t<std::is_integral_v<IntegralType>>>
177 IntegralType
const& lhs,
183template <
class... QueryTags,
class... Tags>
190template <
class... QueryTags,
class... Tags>
203 is_discrete_vector_v<HeadDVect> && (is_discrete_vector_v<TailDVects> && ...),
206KOKKOS_FUNCTION constexpr auto const&
take(HeadDVect
const& head, TailDVects
const&... tail)
208 DDC_IF_NVCC_THEN_PUSH_AND_SUPPRESS(implicit_return_from_non_void_function)
209 if constexpr (type_seq_contains_v<detail::TypeSeq<QueryTag>, to_type_seq_t<HeadDVect>>) {
211 (!type_seq_contains_v<detail::TypeSeq<QueryTag>, to_type_seq_t<TailDVects>> && ...),
212 "ERROR: tag redundant");
215 static_assert(
sizeof...(TailDVects) > 0,
"ERROR: tag not found");
216 return take<QueryTag>(tail...);
224class DiscreteVectorConversionOperators
233 KOKKOS_FUNCTION
constexpr operator DiscreteVectorElement
const&()
const noexcept
235 return static_cast<
DiscreteVector<Tag>
const*>(
this)->m_values[0];
238 KOKKOS_FUNCTION
constexpr operator DiscreteVectorElement&()
noexcept
246template <
class... Tags>
247KOKKOS_FUNCTION
constexpr std::array<DiscreteVectorElement,
sizeof...(Tags)>& array(
254template <
class... Tags>
255KOKKOS_FUNCTION
constexpr std::array<DiscreteVectorElement,
sizeof...(Tags)>
const& array(
264
265
266
267template <
class... Tags>
270 friend class detail::DiscreteVectorConversionOperators<
DiscreteVector<Tags...>>;
272 friend KOKKOS_FUNCTION
constexpr std::array<DiscreteVectorElement,
sizeof...(Tags)>& detail::
274 friend KOKKOS_FUNCTION
constexpr std::array<DiscreteVectorElement,
sizeof...(Tags)>
const&
275 detail::array<Tags...>(
DiscreteVector<Tags...>
const& v)
noexcept;
277 using tags_seq = detail::TypeSeq<Tags...>;
280 std::array<DiscreteVectorElement,
sizeof...(Tags)> m_values;
283 using value_type = DiscreteVectorElement;
287 return sizeof...(Tags);
297 template <
class... DVects,
class = std::enable_if_t<(is_discrete_vector_v<DVects> && ...)>>
299 : m_values {take<Tags>(delems...).
template get<Tags>()...}
305 class = std::enable_if_t<(!is_discrete_vector_v<Params> && ...)>,
306 class = std::enable_if_t<(std::is_convertible_v<Params, DiscreteVectorElement> && ...)>,
307 class = std::enable_if_t<
sizeof...(Params) ==
sizeof...(Tags)>>
309 : m_values {
static_cast<DiscreteVectorElement>(params)...}
320 template <
class... OTags>
323 return ((m_values[type_seq_rank_v<Tags, tags_seq>] == rhs.
template get<Tags>()) && ...);
326#if !defined(__cpp_impl_three_way_comparison) || __cpp_impl_three_way_comparison < 201902L
328 template <
class...
OTags>
331 return !(*
this ==
rhs);
335 template <
class QueryTag>
338 static_assert(in_tags_v<QueryTag, tags_seq>,
"requested Tag absent from DiscreteVector");
339 return m_values[type_seq_rank_v<QueryTag, tags_seq>];
342 template <
class QueryTag>
345 static_assert(in_tags_v<QueryTag, tags_seq>,
"requested Tag absent from DiscreteVector");
346 return m_values[type_seq_rank_v<QueryTag, tags_seq>];
349 template <
class QueryTag>
351 DiscreteVectorElement
const& default_value)
const&
353 DDC_IF_NVCC_THEN_PUSH_AND_SUPPRESS(implicit_return_from_non_void_function)
354 if constexpr (in_tags_v<QueryTag, tags_seq>) {
355 return m_values[type_seq_rank_v<QueryTag, tags_seq>];
357 return default_value;
362 template <std::size_t N =
sizeof...(Tags)>
369 template <std::size_t N =
sizeof...(Tags),
class = std::enable_if_t<N == 1>>
376 template <std::size_t N =
sizeof...(Tags),
class = std::enable_if_t<N == 1>>
384 template <std::size_t N =
sizeof...(Tags),
class = std::enable_if_t<N == 1>>
391 template <std::size_t N =
sizeof...(Tags),
class = std::enable_if_t<N == 1>>
399 template <
class... OTags>
402 static_assert(((type_seq_contains_v<detail::TypeSeq<OTags>, tags_seq>) && ...));
403 ((m_values[type_seq_rank_v<OTags, tags_seq>] += rhs.
template get<OTags>()), ...);
409 std::size_t N =
sizeof...(Tags),
410 class = std::enable_if_t<N == 1>,
411 class = std::enable_if_t<std::is_integral_v<IntegralType>>>
418 template <
class... OTags>
421 static_assert(((type_seq_contains_v<detail::TypeSeq<OTags>, tags_seq>) && ...));
422 ((m_values[type_seq_rank_v<OTags, tags_seq>] -= rhs.
template get<OTags>()), ...);
428 std::size_t N =
sizeof...(Tags),
429 class = std::enable_if_t<N == 1>,
430 class = std::enable_if_t<std::is_integral_v<IntegralType>>>
437 template <
class... OTags>
440 static_assert(((type_seq_contains_v<detail::TypeSeq<OTags>, tags_seq>) && ...));
441 ((m_values[type_seq_rank_v<OTags, tags_seq>] *= rhs.
template get<OTags>()), ...);
451 return lhs.value() < rhs.value();
454template <
class Tag,
class IntegralType>
457 return lhs.value() < rhs;
460inline std::ostream& operator<<(std::ostream& out,
DiscreteVector<>
const&)
466template <
class Head,
class... Tags>
467std::ostream& operator<<(std::ostream& out,
DiscreteVector<Head, Tags...>
const& arr)
470 out << get<Head>(arr);
471 ((out <<
", " << get<Tags>(arr)), ...);
KOKKOS_FUNCTION constexpr DiscreteVector & operator--()
KOKKOS_FUNCTION constexpr DiscreteVectorElement const & get_or(DiscreteVectorElement const &default_value) const &
KOKKOS_FUNCTION constexpr std::enable_if_t< N==1, DiscreteVectorElement const & > value() const noexcept
KOKKOS_FUNCTION constexpr DiscreteVector & operator+=(IntegralType const &rhs)
KOKKOS_DEFAULTED_FUNCTION ~DiscreteVector()=default
KOKKOS_FUNCTION constexpr DiscreteVectorElement const & get() const noexcept
KOKKOS_FUNCTION constexpr DiscreteVector operator--(int)
KOKKOS_FUNCTION constexpr DiscreteVector & operator-=(DiscreteVector< OTags... > const &rhs)
KOKKOS_FUNCTION constexpr DiscreteVector & operator-=(IntegralType const &rhs)
KOKKOS_FUNCTION constexpr DiscreteVector operator++(int)
KOKKOS_FUNCTION constexpr bool operator!=(DiscreteVector< OTags... > const &rhs) const noexcept
KOKKOS_DEFAULTED_FUNCTION constexpr DiscreteVector & operator=(DiscreteVector &&other)=default
KOKKOS_FUNCTION constexpr DiscreteVector & operator++()
static KOKKOS_FUNCTION constexpr std::size_t size() noexcept
KOKKOS_DEFAULTED_FUNCTION constexpr DiscreteVector()=default
KOKKOS_DEFAULTED_FUNCTION constexpr DiscreteVector(DiscreteVector const &)=default
KOKKOS_FUNCTION constexpr DiscreteVector(DVects const &... delems) noexcept
KOKKOS_FUNCTION constexpr DiscreteVectorElement & get() noexcept
KOKKOS_FUNCTION constexpr bool operator==(DiscreteVector< OTags... > const &rhs) const noexcept
KOKKOS_FUNCTION constexpr DiscreteVector & operator*=(DiscreteVector< OTags... > const &rhs)
KOKKOS_FUNCTION constexpr DiscreteVector(Params const &... params) noexcept
KOKKOS_DEFAULTED_FUNCTION constexpr DiscreteVector(DiscreteVector &&)=default
KOKKOS_DEFAULTED_FUNCTION constexpr DiscreteVector & operator=(DiscreteVector const &other)=default
KOKKOS_FUNCTION constexpr DiscreteVector & operator+=(DiscreteVector< OTags... > const &rhs)
The top-level namespace of DDC.
KOKKOS_FUNCTION constexpr DiscreteVector< Tags... > operator+(DiscreteVector< Tags... > const &x)
Unary operators: +, -.
KOKKOS_FUNCTION constexpr auto operator*(IntegralType const &lhs, DiscreteVector< Tags... > const &rhs)
external left binary operator: *
KOKKOS_FUNCTION constexpr bool operator<(DiscreteVector< Tag > const &lhs, IntegralType const &rhs)
KOKKOS_FUNCTION constexpr DiscreteVectorElement const & get_or(DiscreteVector< Tags... > const &tuple, DiscreteVectorElement const &default_value) noexcept
KOKKOS_FUNCTION constexpr auto operator-(DiscreteVector< Tags... > const &lhs, DiscreteVector< OTags... > const &rhs)
KOKKOS_FUNCTION constexpr DiscreteVectorElement & get(DiscreteVector< Tags... > &tuple) noexcept
KOKKOS_FUNCTION constexpr DiscreteVector< Tag > operator-(DiscreteVector< Tag > const &lhs, IntegralType const &rhs)
constexpr bool is_discrete_vector_v
KOKKOS_FUNCTION constexpr DiscreteVectorElement const & get(DiscreteVector< Tags... > const &tuple) noexcept
KOKKOS_FUNCTION constexpr DiscreteVector< Tags... > operator-(DiscreteVector< Tags... > const &x)
KOKKOS_FUNCTION constexpr DiscreteVector< QueryTags... > select(DiscreteVector< Tags... > const &arr) noexcept
KOKKOS_FUNCTION constexpr DiscreteVector< Tag > operator+(IntegralType const &lhs, DiscreteVector< Tag > const &rhs)
KOKKOS_FUNCTION constexpr auto operator+(DiscreteVector< Tags... > const &lhs, DiscreteVector< OTags... > const &rhs)
Internal binary operators: +, -.
KOKKOS_FUNCTION constexpr auto const & take(HeadDVect const &head, TailDVects const &... tail)
Returns a reference towards the DiscreteVector that contains the QueryTag.
KOKKOS_FUNCTION constexpr bool operator<(DiscreteVector< Tag > const &lhs, DiscreteVector< Tag > const &rhs)
KOKKOS_FUNCTION constexpr DiscreteVector< Tag > operator-(IntegralType const &lhs, DiscreteVector< Tag > const &rhs)
KOKKOS_FUNCTION constexpr DiscreteVector< Tag > operator+(DiscreteVector< Tag > const &lhs, IntegralType const &rhs)
KOKKOS_FUNCTION constexpr DiscreteVector< QueryTag > select_or(DiscreteVector< Tags... > const &arr, DiscreteVector< QueryTag > const &default_value) noexcept
KOKKOS_FUNCTION constexpr DiscreteVector< QueryTags... > select(DiscreteVector< Tags... > &&arr) noexcept