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);
74template <
class... Tags>
80template <
class... Tags>
88template <
class... Tags,
class... OTags>
93 using detail::TypeSeq;
94 if constexpr (
sizeof...(Tags) >=
sizeof...(OTags)) {
95 static_assert(((type_seq_contains_v<TypeSeq<OTags>, TypeSeq<Tags...>>) && ...));
100 static_assert(((type_seq_contains_v<TypeSeq<Tags>, TypeSeq<OTags...>>) && ...));
107template <
class... Tags,
class... OTags>
112 using detail::TypeSeq;
113 if constexpr (
sizeof...(Tags) >=
sizeof...(OTags)) {
114 static_assert(((type_seq_contains_v<TypeSeq<OTags>, TypeSeq<Tags...>>) && ...));
119 static_assert(((type_seq_contains_v<TypeSeq<Tags>, TypeSeq<OTags...>>) && ...));
126template <
class Tag,
class IntegralType,
class = std::enable_if_t<std::is_integral_v<IntegralType>>>
129 IntegralType
const& rhs)
134template <
class IntegralType,
class Tag,
class = std::enable_if_t<std::is_integral_v<IntegralType>>>
136 IntegralType
const& lhs,
142template <
class Tag,
class IntegralType,
class = std::enable_if_t<std::is_integral_v<IntegralType>>>
145 IntegralType
const& rhs)
150template <
class IntegralType,
class Tag,
class = std::enable_if_t<std::is_integral_v<IntegralType>>>
152 IntegralType
const& lhs,
163 class = std::enable_if_t<std::is_integral_v<IntegralType>>>
165 IntegralType
const& lhs,
171template <
class... QueryTags,
class... Tags>
178template <
class... QueryTags,
class... Tags>
191 is_discrete_vector_v<HeadDVect> && (is_discrete_vector_v<TailDVects> && ...),
194KOKKOS_FUNCTION constexpr auto const&
take(HeadDVect
const& head, TailDVects
const&... tail)
196 DDC_IF_NVCC_THEN_PUSH_AND_SUPPRESS(implicit_return_from_non_void_function)
197 if constexpr (type_seq_contains_v<detail::TypeSeq<QueryTag>, to_type_seq_t<HeadDVect>>) {
199 (!type_seq_contains_v<detail::TypeSeq<QueryTag>, to_type_seq_t<TailDVects>> && ...),
200 "ERROR: tag redundant");
203 static_assert(
sizeof...(TailDVects) > 0,
"ERROR: tag not found");
204 return take<QueryTag>(tail...);
212class DiscreteVectorConversionOperators
221 KOKKOS_FUNCTION
constexpr operator DiscreteVectorElement
const&()
const noexcept
223 return static_cast<
DiscreteVector<Tag>
const*>(
this)->m_values[0];
226 KOKKOS_FUNCTION
constexpr operator DiscreteVectorElement&()
noexcept
234template <
class... Tags>
235KOKKOS_FUNCTION
constexpr std::array<DiscreteVectorElement,
sizeof...(Tags)>& array(
242template <
class... Tags>
243KOKKOS_FUNCTION
constexpr std::array<DiscreteVectorElement,
sizeof...(Tags)>
const& array(
252
253
254
255template <
class... Tags>
258 friend class detail::DiscreteVectorConversionOperators<
DiscreteVector<Tags...>>;
260 friend KOKKOS_FUNCTION
constexpr std::array<DiscreteVectorElement,
sizeof...(Tags)>& detail::
262 friend KOKKOS_FUNCTION
constexpr std::array<DiscreteVectorElement,
sizeof...(Tags)>
const&
263 detail::array<Tags...>(
DiscreteVector<Tags...>
const& v)
noexcept;
265 using tags_seq = detail::TypeSeq<Tags...>;
268 std::array<DiscreteVectorElement,
sizeof...(Tags)> m_values;
273 return sizeof...(Tags);
283 template <
class... DVects,
class = std::enable_if_t<(is_discrete_vector_v<DVects> && ...)>>
285 : m_values {take<Tags>(delems...).
template get<Tags>()...}
291 class = std::enable_if_t<(!is_discrete_vector_v<Params> && ...)>,
292 class = std::enable_if_t<(std::is_convertible_v<Params, DiscreteVectorElement> && ...)>,
293 class = std::enable_if_t<
sizeof...(Params) ==
sizeof...(Tags)>>
295 : m_values {
static_cast<DiscreteVectorElement>(params)...}
306 template <
class... OTags>
309 return ((m_values[type_seq_rank_v<Tags, tags_seq>] == rhs.
template get<Tags>()) && ...);
312#if !defined(__cpp_impl_three_way_comparison) || __cpp_impl_three_way_comparison < 201902L
314 template <
class...
OTags>
317 return !(*
this ==
rhs);
321 template <
class QueryTag>
324 static_assert(in_tags_v<QueryTag, tags_seq>,
"requested Tag absent from DiscreteVector");
325 return m_values[type_seq_rank_v<QueryTag, tags_seq>];
328 template <
class QueryTag>
331 static_assert(in_tags_v<QueryTag, tags_seq>,
"requested Tag absent from DiscreteVector");
332 return m_values[type_seq_rank_v<QueryTag, tags_seq>];
335 template <
class QueryTag>
337 DiscreteVectorElement
const& default_value)
const&
339 DDC_IF_NVCC_THEN_PUSH_AND_SUPPRESS(implicit_return_from_non_void_function)
340 if constexpr (in_tags_v<QueryTag, tags_seq>) {
341 return m_values[type_seq_rank_v<QueryTag, tags_seq>];
343 return default_value;
348 template <std::size_t N =
sizeof...(Tags)>
355 template <std::size_t N =
sizeof...(Tags),
class = std::enable_if_t<N == 1>>
362 template <std::size_t N =
sizeof...(Tags),
class = std::enable_if_t<N == 1>>
370 template <std::size_t N =
sizeof...(Tags),
class = std::enable_if_t<N == 1>>
377 template <std::size_t N =
sizeof...(Tags),
class = std::enable_if_t<N == 1>>
385 template <
class... OTags>
388 static_assert(((type_seq_contains_v<detail::TypeSeq<OTags>, tags_seq>) && ...));
389 ((m_values[type_seq_rank_v<OTags, tags_seq>] += rhs.
template get<OTags>()), ...);
395 std::size_t N =
sizeof...(Tags),
396 class = std::enable_if_t<N == 1>,
397 class = std::enable_if_t<std::is_integral_v<IntegralType>>>
404 template <
class... OTags>
407 static_assert(((type_seq_contains_v<detail::TypeSeq<OTags>, tags_seq>) && ...));
408 ((m_values[type_seq_rank_v<OTags, tags_seq>] -= rhs.
template get<OTags>()), ...);
414 std::size_t N =
sizeof...(Tags),
415 class = std::enable_if_t<N == 1>,
416 class = std::enable_if_t<std::is_integral_v<IntegralType>>>
423 template <
class... OTags>
426 static_assert(((type_seq_contains_v<detail::TypeSeq<OTags>, tags_seq>) && ...));
427 ((m_values[type_seq_rank_v<OTags, tags_seq>] *= rhs.
template get<OTags>()), ...);
437 return lhs.value() < rhs.value();
440template <
class Tag,
class IntegralType>
443 return lhs.value() < rhs;
446inline std::ostream& operator<<(std::ostream& out,
DiscreteVector<>
const&)
452template <
class Head,
class... Tags>
453std::ostream& operator<<(std::ostream& out,
DiscreteVector<Head, Tags...>
const& arr)
456 out << get<Head>(arr);
457 ((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< QueryTags... > select(DiscreteVector< Tags... > &&arr) noexcept