13#include <Kokkos_Macros.hpp>
15#include "ddc/detail/type_seq.hpp"
16#include "ddc/discrete_element.hpp"
17#include "ddc/discrete_vector.hpp"
24template <
class... DDims>
32template <
class... Tags>
43template <
class... Tags>
46 using type = TypeSeq<Tags...>;
51template <
class... DDims>
58 using discrete_element_type = DiscreteElement<DDims...>;
63 DiscreteElement<DDims...> m_element_begin;
65 DiscreteElement<DDims...> m_element_end;
70 return sizeof...(DDims);
76 template <
class... DDoms,
class = std::enable_if_t<(is_discrete_domain_v<DDoms> && ...)>>
78 : m_element_begin(domains.front()...)
79 , m_element_end((domains.front() + domains.extents())...)
84
85
86
88 discrete_element_type
const& element_begin,
89 discrete_vector_type
const& size)
90 : m_element_begin(element_begin)
91 , m_element_end(element_begin + size)
105 template <
class... ODims>
108 if (
empty() && other.empty()) {
111 return m_element_begin == other.m_element_begin && m_element_end == other.m_element_end;
114#if !defined(__cpp_impl_three_way_comparison) || __cpp_impl_three_way_comparison < 201902L
116 template <
class...
ODims>
119 return !(*
this ==
other);
125 return (1UL * ... * (uid<DDims>(m_element_end) - uid<DDims>(m_element_begin)));
130 return discrete_vector_type((uid<DDims>(m_element_end) - uid<DDims>(m_element_begin))...);
133 template <
class QueryDDim>
137 uid<QueryDDim>(m_element_end) - uid<QueryDDim>(m_element_begin));
142 return m_element_begin;
147 return discrete_element_type((uid<DDims>(m_element_end) - 1)...);
171 discrete_vector_type n1,
172 discrete_vector_type n2)
const
177 template <
class... ODDims>
180 assert(((uid<ODDims>(m_element_begin) <= uid<ODDims>(odomain.m_element_begin)) && ...));
181 assert(((uid<ODDims>(m_element_end) >= uid<ODDims>(odomain.m_element_end)) && ...));
185 DiscreteElement<DDims...>(
186 (uid_or<DDims>(odomain.m_element_begin, uid<DDims>(m_element_begin)))...),
187 DiscreteVector<DDims...>((get_or<DDims>(oextents, get<DDims>(myextents)))...));
201 std::size_t N =
sizeof...(DDims),
202 class DDim0 = std::enable_if_t<N == 1, std::tuple_element_t<0, std::tuple<DDims...>>>>
209 std::size_t N =
sizeof...(DDims),
210 class DDim0 = std::enable_if_t<N == 1, std::tuple_element_t<0, std::tuple<DDims...>>>>
217 std::size_t N =
sizeof...(DDims),
218 class DDim0 = std::enable_if_t<N == 1, std::tuple_element_t<0, std::tuple<DDims...>>>>
225 std::size_t N =
sizeof...(DDims),
226 class DDim0 = std::enable_if_t<N == 1, std::tuple_element_t<0, std::tuple<DDims...>>>>
233 std::size_t N =
sizeof...(DDims),
234 class = std::enable_if_t<N == 1, std::tuple_element_t<0, std::tuple<DDims...>>>>
241 std::size_t N =
sizeof...(DDims),
242 class = std::enable_if_t<N == 1, std::tuple_element_t<0, std::tuple<DDims...>>>>
256 using discrete_element_type = DiscreteElement<>;
268 template <
class... DDoms,
class = std::enable_if_t<(is_discrete_domain_v<DDoms> && ...)>>
274
275
276
278 [[
maybe_unused]] discrete_element_type
const& element_begin,
298#if !defined(__cpp_impl_three_way_comparison) || __cpp_impl_three_way_comparison < 201902L
302 return !(*
this ==
other);
357 template <
class... ODims>
375template <
class... QueryDDims,
class... DDims>
380 DiscreteElement<QueryDDims...>(domain.front()),
387struct ConvertTypeSeqToDiscreteDomain;
389template <
class... DDims>
390struct ConvertTypeSeqToDiscreteDomain<detail::TypeSeq<DDims...>>
396using convert_type_seq_to_discrete_domain_t =
typename ConvertTypeSeqToDiscreteDomain<T>::type;
402template <
typename... DDoms>
403struct cartesian_prod;
405template <
typename... DDims1,
typename... DDims2,
typename... DDomsTail>
408 using type =
typename cartesian_prod<
DiscreteDomain<DDims1..., DDims2...>, DDomsTail...>::type;
411template <
typename... DDims>
418struct cartesian_prod<>
423template <
typename... DDoms>
424using cartesian_prod_t =
typename cartesian_prod<DDoms...>::type;
427template <
class... DDimsA,
class... DDimsB>
432 using TagSeqA = detail::TypeSeq<DDimsA...>;
433 using TagSeqB = detail::TypeSeq<DDimsB...>;
435 using type_seq_r = type_seq_remove_t<TagSeqA, TagSeqB>;
436 return detail::convert_type_seq_to_discrete_domain_t<type_seq_r>(DDom_a);
442template <
class... DDimsB,
class DDomA>
445 using TagSeqA =
typename detail::ToTypeSeq<DDomA>::type;
446 using TagSeqB = detail::TypeSeq<DDimsB...>;
448 using type_seq_r = type_seq_remove_t<TagSeqA, TagSeqB>;
449 return detail::convert_type_seq_to_discrete_domain_t<type_seq_r>(DDom_a);
453template <
typename DDom,
typename... DDims>
454using remove_dims_of_t =
decltype(remove_dims_of<DDims...>(std::declval<DDom>()));
459template <
typename DDim1,
typename DDim2,
typename DDimA,
typename... DDimsB>
460KOKKOS_FUNCTION
constexpr std::conditional_t<
461 std::is_same_v<DDimA, DDim1>,
466 [[maybe_unused]]
DiscreteDomain<DDimsB...>
const& DDom_b)
noexcept
468 if constexpr (std::is_same_v<DDimA, DDim1>) {
478template <
typename DDim1,
typename DDim2,
typename... DDimsA,
typename... DDimsB>
484 using TagSeqA = detail::TypeSeq<DDimsA...>;
485 using TagSeqB = detail::TypeSeq<DDim1>;
486 using TagSeqC = detail::TypeSeq<DDim2>;
488 using type_seq_r =
ddc::type_seq_replace_t<TagSeqA, TagSeqB, TagSeqC>;
489 return ddc::detail::convert_type_seq_to_discrete_domain_t<type_seq_r>(
490 detail::replace_dim_of_1d<
498template <
typename DDom,
typename DDim1,
typename DDim2>
499using replace_dim_of_t
500 =
decltype(replace_dim_of<
502 DDim2>(std::declval<DDom>(), std::declval<
DiscreteDomain<DDim2>>()));
505template <
class... QueryDDims,
class... DDims>
512template <
class... QueryDDims,
class... DDims>
516 return DiscreteElement<QueryDDims...>(
DiscreteDomain<QueryDDims>(domain).front()...);
519template <
class... QueryDDims,
class... DDims>
523 return DiscreteElement<QueryDDims...>(
DiscreteDomain<QueryDDims>(domain).back()...);
530 DiscreteElement<DDim> m_value = DiscreteElement<DDim>();
533 using iterator_category = std::random_access_iterator_tag;
535 using value_type = DiscreteElement<DDim>;
537 using difference_type = std::ptrdiff_t;
579 if (n >= difference_type(0)) {
580 m_value.uid() +=
static_cast<DiscreteElementType>(n);
582 m_value.uid() -=
static_cast<DiscreteElementType>(-n);
589 if (n >= difference_type(0)) {
590 m_value.uid() -=
static_cast<DiscreteElementType>(n);
592 m_value.uid() +=
static_cast<DiscreteElementType>(-n);
606 return xx.m_value == yy.m_value;
609#if !defined(__cpp_impl_three_way_comparison) || __cpp_impl_three_way_comparison < 201902L
623 return xx.m_value < yy.m_value;
672 return (yy.m_value > xx.m_value) ? (-
static_cast<difference_type>(yy.m_value - xx.m_value))
673 : (xx.m_value - yy.m_value);
static KOKKOS_FUNCTION constexpr discrete_vector_type extents() noexcept
KOKKOS_DEFAULTED_FUNCTION ~DiscreteDomain()=default
KOKKOS_FUNCTION constexpr DiscreteDomain(discrete_element_type const &element_begin, discrete_vector_type const &size)
Construct a DiscreteDomain starting from element_begin with size points.
KOKKOS_FUNCTION constexpr DiscreteDomain remove(discrete_vector_type n1, discrete_vector_type n2) const
KOKKOS_FUNCTION constexpr DiscreteDomain take_last(discrete_vector_type n) const
static KOKKOS_FUNCTION constexpr std::size_t rank()
KOKKOS_DEFAULTED_FUNCTION DiscreteDomain(DiscreteDomain const &x)=default
KOKKOS_DEFAULTED_FUNCTION constexpr DiscreteDomain()=default
KOKKOS_DEFAULTED_FUNCTION DiscreteDomain & operator=(DiscreteDomain &&x)=default
KOKKOS_FUNCTION constexpr operator bool()
static KOKKOS_FUNCTION constexpr std::size_t size()
static KOKKOS_FUNCTION constexpr bool empty() noexcept
KOKKOS_FUNCTION constexpr DiscreteDomain remove_last(discrete_vector_type n) const
static KOKKOS_FUNCTION constexpr discrete_element_type back() noexcept
static KOKKOS_FUNCTION constexpr discrete_element_type front() noexcept
KOKKOS_FUNCTION constexpr DiscreteDomain take_first(discrete_vector_type n) const
KOKKOS_DEFAULTED_FUNCTION DiscreteDomain & operator=(DiscreteDomain const &x)=default
KOKKOS_FUNCTION constexpr DiscreteDomain(DDoms const &... domains)
Construct a DiscreteDomain by copies and merge of domains.
KOKKOS_FUNCTION constexpr bool operator==(DiscreteDomain const &other) const
KOKKOS_FUNCTION constexpr DiscreteDomain remove_first(discrete_vector_type n) const
KOKKOS_FUNCTION constexpr DiscreteDomain restrict_with(DiscreteDomain< ODims... > const &) const
KOKKOS_DEFAULTED_FUNCTION DiscreteDomain(DiscreteDomain &&x)=default
KOKKOS_DEFAULTED_FUNCTION DiscreteDomain(DiscreteDomain const &x)=default
KOKKOS_DEFAULTED_FUNCTION DiscreteDomain(DiscreteDomain &&x)=default
KOKKOS_FUNCTION constexpr DiscreteDomain remove_last(discrete_vector_type n) const
KOKKOS_FUNCTION constexpr DiscreteDomain take_last(discrete_vector_type n) const
KOKKOS_FUNCTION auto begin() const
KOKKOS_FUNCTION constexpr DiscreteDomain remove(discrete_vector_type n1, discrete_vector_type n2) const
KOKKOS_FUNCTION constexpr auto restrict_with(DiscreteDomain< ODDims... > const &odomain) const
static KOKKOS_FUNCTION constexpr std::size_t rank()
KOKKOS_FUNCTION constexpr bool empty() const noexcept
KOKKOS_FUNCTION constexpr std::size_t size() const
friend class DiscreteDomain
KOKKOS_FUNCTION constexpr discrete_vector_type extents() const noexcept
KOKKOS_FUNCTION constexpr DiscreteVector< QueryDDim > extent() const noexcept
KOKKOS_FUNCTION constexpr discrete_element_type front() const noexcept
KOKKOS_FUNCTION constexpr DiscreteDomain(DDoms const &... domains)
Construct a DiscreteDomain by copies and merge of domains.
KOKKOS_DEFAULTED_FUNCTION DiscreteDomain & operator=(DiscreteDomain &&x)=default
KOKKOS_FUNCTION constexpr DiscreteDomain remove_first(discrete_vector_type n) const
KOKKOS_FUNCTION constexpr bool operator==(DiscreteDomain< ODims... > const &other) const
KOKKOS_FUNCTION auto cbegin() const
KOKKOS_FUNCTION auto end() const
KOKKOS_FUNCTION constexpr DiscreteDomain take_first(discrete_vector_type n) const
KOKKOS_DEFAULTED_FUNCTION ~DiscreteDomain()=default
KOKKOS_FUNCTION auto cend() const
KOKKOS_FUNCTION constexpr decltype(auto) operator[](std::size_t n) const
KOKKOS_FUNCTION constexpr discrete_element_type back() const noexcept
KOKKOS_DEFAULTED_FUNCTION DiscreteDomain & operator=(DiscreteDomain const &x)=default
KOKKOS_DEFAULTED_FUNCTION DiscreteDomain()=default
KOKKOS_FUNCTION constexpr operator bool()
KOKKOS_FUNCTION constexpr DiscreteDomain(discrete_element_type const &element_begin, discrete_vector_type const &size)
Construct a DiscreteDomain starting from element_begin with size points.
KOKKOS_FUNCTION constexpr decltype(auto) operator[](std::size_t n)
KOKKOS_DEFAULTED_FUNCTION constexpr DiscreteElement()=default
KOKKOS_FUNCTION constexpr bool operator!=(DiscreteVector< OTags... > const &rhs) const noexcept
KOKKOS_DEFAULTED_FUNCTION constexpr DiscreteVector()=default
The top-level namespace of DDC.
KOKKOS_FUNCTION constexpr DiscreteElement< QueryDDims... > back(DiscreteDomain< DDims... > const &domain) noexcept
KOKKOS_FUNCTION constexpr DiscreteElement< QueryDDims... > front(DiscreteDomain< DDims... > const &domain) noexcept
KOKKOS_FUNCTION constexpr auto remove_dims_of(DDomA const &DDom_a) noexcept
Remove the dimensions DDimsB from DDom_a.
KOKKOS_FUNCTION constexpr DiscreteVector< QueryDDims... > extents(DiscreteDomain< DDims... > const &domain) noexcept
KOKKOS_FUNCTION constexpr auto remove_dims_of(DiscreteDomain< DDimsA... > const &DDom_a, DiscreteDomain< DDimsB... > const &DDom_b) noexcept
KOKKOS_FUNCTION constexpr auto replace_dim_of(DiscreteDomain< DDimsA... > const &DDom_a, DiscreteDomain< DDimsB... > const &DDom_b) noexcept
constexpr bool is_discrete_domain_v
KOKKOS_FUNCTION constexpr DiscreteDomain< QueryDDims... > select(DiscreteDomain< DDims... > const &domain)
KOKKOS_FUNCTION constexpr DiscreteDomainIterator operator--(int)
friend KOKKOS_FUNCTION constexpr bool operator<=(DiscreteDomainIterator const &xx, DiscreteDomainIterator const &yy)
KOKKOS_FUNCTION constexpr DiscreteElement< DDim > operator*() const noexcept
friend KOKKOS_FUNCTION constexpr bool operator>=(DiscreteDomainIterator const &xx, DiscreteDomainIterator const &yy)
KOKKOS_DEFAULTED_FUNCTION DiscreteDomainIterator()=default
KOKKOS_FUNCTION constexpr DiscreteElement< DDim > operator[](difference_type n) const
KOKKOS_FUNCTION constexpr DiscreteDomainIterator & operator--()
KOKKOS_FUNCTION constexpr DiscreteDomainIterator operator++(int)
friend KOKKOS_FUNCTION constexpr DiscreteDomainIterator operator-(DiscreteDomainIterator i, difference_type n)
friend KOKKOS_FUNCTION constexpr DiscreteDomainIterator operator+(DiscreteDomainIterator i, difference_type n)
friend KOKKOS_FUNCTION constexpr bool operator>(DiscreteDomainIterator const &xx, DiscreteDomainIterator const &yy)
friend KOKKOS_FUNCTION constexpr bool operator!=(DiscreteDomainIterator const &xx, DiscreteDomainIterator const &yy)
friend KOKKOS_FUNCTION constexpr bool operator<(DiscreteDomainIterator const &xx, DiscreteDomainIterator const &yy)
KOKKOS_FUNCTION constexpr DiscreteDomainIterator & operator+=(difference_type n)
KOKKOS_FUNCTION constexpr DiscreteDomainIterator & operator++()
friend KOKKOS_FUNCTION constexpr DiscreteDomainIterator operator+(difference_type n, DiscreteDomainIterator i)
friend KOKKOS_FUNCTION constexpr bool operator==(DiscreteDomainIterator const &xx, DiscreteDomainIterator const &yy)
KOKKOS_FUNCTION constexpr DiscreteDomainIterator(DiscreteElement< DDim > value)
KOKKOS_FUNCTION constexpr DiscreteDomainIterator & operator-=(difference_type n)
friend KOKKOS_FUNCTION constexpr difference_type operator-(DiscreteDomainIterator const &xx, DiscreteDomainIterator const &yy)