13#include <Kokkos_Macros.hpp>
15#include "detail/macros.hpp"
16#include "detail/type_seq.hpp"
17#include "detail/utils.hpp"
29template <
class... Tags>
40template <
class... Tags>
43 using type = TypeSeq<Tags...>;
49
50using DiscreteVectorElement = std::ptrdiff_t;
52template <
class QueryTag,
class... Tags>
56 return tuple.
template get<QueryTag>();
59template <
class QueryTag,
class... Tags>
62 return tuple.
template get<QueryTag>();
65template <
class QueryTag,
class... Tags>
68 DiscreteVectorElement
const& default_value)
noexcept
70 return tuple.
template get_or<QueryTag>(default_value);
73template <
class QueryTag,
class... Tags>
78 if constexpr (in_tags_v<QueryTag, detail::TypeSeq<Tags...>>) {
87template <
class... Tags>
93template <
class... Tags>
101template <
class... Tags,
class... OTags>
106 using detail::TypeSeq;
107 if constexpr (
sizeof...(Tags) >=
sizeof...(OTags)) {
108 static_assert(((type_seq_contains_v<TypeSeq<OTags>, TypeSeq<Tags...>>) && ...));
113 static_assert(((type_seq_contains_v<TypeSeq<Tags>, TypeSeq<OTags...>>) && ...));
120template <
class... Tags,
class... OTags>
125 using detail::TypeSeq;
126 if constexpr (
sizeof...(Tags) >=
sizeof...(OTags)) {
127 static_assert(((type_seq_contains_v<TypeSeq<OTags>, TypeSeq<Tags...>>) && ...));
132 static_assert(((type_seq_contains_v<TypeSeq<Tags>, TypeSeq<OTags...>>) && ...));
139template <
class Tag,
class IntegralType,
class = std::enable_if_t<std::is_integral_v<IntegralType>>>
142 IntegralType
const& rhs)
147template <
class IntegralType,
class Tag,
class = std::enable_if_t<std::is_integral_v<IntegralType>>>
149 IntegralType
const& lhs,
155template <
class Tag,
class IntegralType,
class = std::enable_if_t<std::is_integral_v<IntegralType>>>
158 IntegralType
const& rhs)
163template <
class IntegralType,
class Tag,
class = std::enable_if_t<std::is_integral_v<IntegralType>>>
165 IntegralType
const& lhs,
176 class = std::enable_if_t<std::is_integral_v<IntegralType>>>
178 IntegralType
const& lhs,
184template <
class... QueryTags,
class... Tags>
191template <
class... QueryTags,
class... Tags>
204 is_discrete_vector_v<HeadDVect> && (is_discrete_vector_v<TailDVects> && ...),
207KOKKOS_FUNCTION constexpr auto const&
take(HeadDVect
const& head, TailDVects
const&... tail)
209 DDC_IF_NVCC_THEN_PUSH_AND_SUPPRESS(implicit_return_from_non_void_function)
210 if constexpr (type_seq_contains_v<detail::TypeSeq<QueryTag>, to_type_seq_t<HeadDVect>>) {
212 (!type_seq_contains_v<detail::TypeSeq<QueryTag>, to_type_seq_t<TailDVects>> && ...),
213 "ERROR: tag redundant");
216 static_assert(
sizeof...(TailDVects) > 0,
"ERROR: tag not found");
217 return take<QueryTag>(tail...);
225class DiscreteVectorConversionOperators
234 KOKKOS_FUNCTION
constexpr operator DiscreteVectorElement
const&()
const noexcept
236 return static_cast<
DiscreteVector<Tag>
const*>(
this)->m_values[0];
239 KOKKOS_FUNCTION
constexpr operator DiscreteVectorElement&()
noexcept
247template <
class... Tags>
248KOKKOS_FUNCTION
constexpr std::array<DiscreteVectorElement,
sizeof...(Tags)>& array(
255template <
class... Tags>
256KOKKOS_FUNCTION
constexpr std::array<DiscreteVectorElement,
sizeof...(Tags)>
const& array(
265
266
267
268template <
class... Tags>
271 friend class detail::DiscreteVectorConversionOperators<
DiscreteVector<Tags...>>;
273 friend KOKKOS_FUNCTION
constexpr std::array<DiscreteVectorElement,
sizeof...(Tags)>& detail::
275 friend KOKKOS_FUNCTION
constexpr std::array<DiscreteVectorElement,
sizeof...(Tags)>
const&
276 detail::array<Tags...>(
DiscreteVector<Tags...>
const& v)
noexcept;
278 using tags_seq = detail::TypeSeq<Tags...>;
281 type_seq_is_unique_v<tags_seq>,
282 "The dimensions of a DiscreteVector must be unique");
285 std::array<DiscreteVectorElement,
sizeof...(Tags)> m_values;
288 using value_type = DiscreteVectorElement;
292 return sizeof...(Tags);
302 template <
class... DVects,
class = std::enable_if_t<(is_discrete_vector_v<DVects> && ...)>>
304 : m_values {take<Tags>(delems...).
template get<Tags>()...}
310 class = std::enable_if_t<std::is_convertible_v<IntegerType, DiscreteVectorElement>>>
312 std::array<IntegerType,
sizeof...(Tags)>
const& values)
noexcept
314 detail::convert_array_to<DiscreteVectorElement>(
316 std::make_index_sequence<
sizeof...(Tags)>()))
322 class = std::enable_if_t<(!is_discrete_vector_v<Params> && ...)>,
323 class = std::enable_if_t<(std::is_convertible_v<Params, DiscreteVectorElement> && ...)>,
324 class = std::enable_if_t<
sizeof...(Params) ==
sizeof...(Tags)>>
326 : m_values {
static_cast<DiscreteVectorElement>(params)...}
337 template <
class... OTags>
340 return ((m_values[type_seq_rank_v<Tags, tags_seq>] == rhs.
template get<Tags>()) && ...);
343#if !defined(__cpp_impl_three_way_comparison) || __cpp_impl_three_way_comparison < 201902L
345 template <
class...
OTags>
348 return !(*
this ==
rhs);
352 template <
class QueryTag>
355 static_assert(in_tags_v<QueryTag, tags_seq>,
"requested Tag absent from DiscreteVector");
356 return m_values[type_seq_rank_v<QueryTag, tags_seq>];
359 template <
class QueryTag>
362 static_assert(in_tags_v<QueryTag, tags_seq>,
"requested Tag absent from DiscreteVector");
363 return m_values[type_seq_rank_v<QueryTag, tags_seq>];
366 template <
class QueryTag>
368 DiscreteVectorElement
const& default_value)
const&
370 DDC_IF_NVCC_THEN_PUSH_AND_SUPPRESS(implicit_return_from_non_void_function)
371 if constexpr (in_tags_v<QueryTag, tags_seq>) {
372 return m_values[type_seq_rank_v<QueryTag, tags_seq>];
374 return default_value;
379 template <std::size_t N =
sizeof...(Tags)>
386 template <std::size_t N =
sizeof...(Tags),
class = std::enable_if_t<N == 1>>
393 template <std::size_t N =
sizeof...(Tags),
class = std::enable_if_t<N == 1>>
401 template <std::size_t N =
sizeof...(Tags),
class = std::enable_if_t<N == 1>>
408 template <std::size_t N =
sizeof...(Tags),
class = std::enable_if_t<N == 1>>
416 template <
class... OTags>
419 static_assert(((type_seq_contains_v<detail::TypeSeq<OTags>, tags_seq>) && ...));
420 ((m_values[type_seq_rank_v<OTags, tags_seq>] += rhs.
template get<OTags>()), ...);
426 std::size_t N =
sizeof...(Tags),
427 class = std::enable_if_t<N == 1>,
428 class = std::enable_if_t<std::is_integral_v<IntegralType>>>
435 template <
class... OTags>
438 static_assert(((type_seq_contains_v<detail::TypeSeq<OTags>, tags_seq>) && ...));
439 ((m_values[type_seq_rank_v<OTags, tags_seq>] -= rhs.
template get<OTags>()), ...);
445 std::size_t N =
sizeof...(Tags),
446 class = std::enable_if_t<N == 1>,
447 class = std::enable_if_t<std::is_integral_v<IntegralType>>>
454 template <
class... OTags>
457 static_assert(((type_seq_contains_v<detail::TypeSeq<OTags>, tags_seq>) && ...));
458 ((m_values[type_seq_rank_v<OTags, tags_seq>] *= rhs.
template get<OTags>()), ...);
468 return lhs.value() < rhs.value();
471template <
class Tag,
class IntegralType>
474 return lhs.value() < rhs;
477inline std::ostream& operator<<(std::ostream& out,
DiscreteVector<>
const&)
483template <
class Head,
class... Tags>
484std::ostream& operator<<(std::ostream& out,
DiscreteVector<Head, Tags...>
const& arr)
487 out << get<Head>(arr);
488 ((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(std::array< IntegerType, sizeof...(Tags)> const &values) noexcept
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