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;
271 using value_type = DiscreteVectorElement;
275 return sizeof...(Tags);
285 template <
class... DVects,
class = std::enable_if_t<(is_discrete_vector_v<DVects> && ...)>>
287 : m_values {take<Tags>(delems...).
template get<Tags>()...}
293 class = std::enable_if_t<(!is_discrete_vector_v<Params> && ...)>,
294 class = std::enable_if_t<(std::is_convertible_v<Params, DiscreteVectorElement> && ...)>,
295 class = std::enable_if_t<
sizeof...(Params) ==
sizeof...(Tags)>>
297 : m_values {
static_cast<DiscreteVectorElement>(params)...}
308 template <
class... OTags>
311 return ((m_values[type_seq_rank_v<Tags, tags_seq>] == rhs.
template get<Tags>()) && ...);
314#if !defined(__cpp_impl_three_way_comparison) || __cpp_impl_three_way_comparison < 201902L
316 template <
class...
OTags>
319 return !(*
this ==
rhs);
323 template <
class QueryTag>
326 static_assert(in_tags_v<QueryTag, tags_seq>,
"requested Tag absent from DiscreteVector");
327 return m_values[type_seq_rank_v<QueryTag, tags_seq>];
330 template <
class QueryTag>
333 static_assert(in_tags_v<QueryTag, tags_seq>,
"requested Tag absent from DiscreteVector");
334 return m_values[type_seq_rank_v<QueryTag, tags_seq>];
337 template <
class QueryTag>
339 DiscreteVectorElement
const& default_value)
const&
341 DDC_IF_NVCC_THEN_PUSH_AND_SUPPRESS(implicit_return_from_non_void_function)
342 if constexpr (in_tags_v<QueryTag, tags_seq>) {
343 return m_values[type_seq_rank_v<QueryTag, tags_seq>];
345 return default_value;
350 template <std::size_t N =
sizeof...(Tags)>
357 template <std::size_t N =
sizeof...(Tags),
class = std::enable_if_t<N == 1>>
364 template <std::size_t N =
sizeof...(Tags),
class = std::enable_if_t<N == 1>>
372 template <std::size_t N =
sizeof...(Tags),
class = std::enable_if_t<N == 1>>
379 template <std::size_t N =
sizeof...(Tags),
class = std::enable_if_t<N == 1>>
387 template <
class... OTags>
390 static_assert(((type_seq_contains_v<detail::TypeSeq<OTags>, tags_seq>) && ...));
391 ((m_values[type_seq_rank_v<OTags, tags_seq>] += rhs.
template get<OTags>()), ...);
397 std::size_t N =
sizeof...(Tags),
398 class = std::enable_if_t<N == 1>,
399 class = std::enable_if_t<std::is_integral_v<IntegralType>>>
406 template <
class... OTags>
409 static_assert(((type_seq_contains_v<detail::TypeSeq<OTags>, tags_seq>) && ...));
410 ((m_values[type_seq_rank_v<OTags, tags_seq>] -= rhs.
template get<OTags>()), ...);
416 std::size_t N =
sizeof...(Tags),
417 class = std::enable_if_t<N == 1>,
418 class = std::enable_if_t<std::is_integral_v<IntegralType>>>
425 template <
class... OTags>
428 static_assert(((type_seq_contains_v<detail::TypeSeq<OTags>, tags_seq>) && ...));
429 ((m_values[type_seq_rank_v<OTags, tags_seq>] *= rhs.
template get<OTags>()), ...);
439 return lhs.value() < rhs.value();
442template <
class Tag,
class IntegralType>
445 return lhs.value() < rhs;
448inline std::ostream& operator<<(std::ostream& out,
DiscreteVector<>
const&)
454template <
class Head,
class... Tags>
455std::ostream& operator<<(std::ostream& out,
DiscreteVector<Head, Tags...>
const& arr)
458 out << get<Head>(arr);
459 ((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