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 mlength_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 mlength_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)...);
175 template <
class... ODDims>
178 assert(((uid<ODDims>(m_element_begin) <= uid<ODDims>(odomain.m_element_begin)) && ...));
179 assert(((uid<ODDims>(m_element_end) >= uid<ODDims>(odomain.m_element_end)) && ...));
183 DiscreteElement<DDims...>(
184 (uid_or<DDims>(odomain.m_element_begin, uid<DDims>(m_element_begin)))...),
185 DiscreteVector<DDims...>((get_or<DDims>(oextents, get<DDims>(myextents)))...));
199 std::size_t N =
sizeof...(DDims),
200 class DDim0 = std::enable_if_t<N == 1, std::tuple_element_t<0, std::tuple<DDims...>>>>
207 std::size_t N =
sizeof...(DDims),
208 class DDim0 = std::enable_if_t<N == 1, std::tuple_element_t<0, std::tuple<DDims...>>>>
215 std::size_t N =
sizeof...(DDims),
216 class DDim0 = std::enable_if_t<N == 1, std::tuple_element_t<0, std::tuple<DDims...>>>>
223 std::size_t N =
sizeof...(DDims),
224 class DDim0 = std::enable_if_t<N == 1, std::tuple_element_t<0, std::tuple<DDims...>>>>
231 std::size_t N =
sizeof...(DDims),
232 class = std::enable_if_t<N == 1, std::tuple_element_t<0, std::tuple<DDims...>>>>
239 std::size_t N =
sizeof...(DDims),
240 class = std::enable_if_t<N == 1, std::tuple_element_t<0, std::tuple<DDims...>>>>
254 using discrete_element_type = DiscreteElement<>;
266 template <
class... ODDims>
273
274
275
277 [[
maybe_unused]] discrete_element_type
const& element_begin,
297#if !defined(__cpp_impl_three_way_comparison) || __cpp_impl_three_way_comparison < 201902L
301 return !(*
this ==
other);
352 template <
class... ODims>
369template <
class... QueryDDims,
class... DDims>
374 select<QueryDDims...>(domain.front()),
375 select<QueryDDims...>(domain.extents()));
381struct ConvertTypeSeqToDiscreteDomain;
383template <
class... DDims>
384struct ConvertTypeSeqToDiscreteDomain<detail::TypeSeq<DDims...>>
390using convert_type_seq_to_discrete_domain_t =
typename ConvertTypeSeqToDiscreteDomain<T>::type;
396template <
typename... DDom>
397struct cartesian_prod;
399template <
typename... DDim1,
typename... DDim2>
405template <
typename DDom>
406struct cartesian_prod<DDom>
412struct cartesian_prod<>
417template <
typename DDom1,
typename DDom2,
typename... Tail>
418struct cartesian_prod<DDom1, DDom2, Tail...>
421 typename cartesian_prod<
typename cartesian_prod<DDom1, DDom2>::type, Tail...>::type;
424template <
typename... DDom>
425using cartesian_prod_t =
typename cartesian_prod<DDom...>::type;
428template <
class... DDimsA,
class... DDimsB>
433 using TagSeqA = detail::TypeSeq<DDimsA...>;
434 using TagSeqB = detail::TypeSeq<DDimsB...>;
436 using type_seq_r = type_seq_remove_t<TagSeqA, TagSeqB>;
437 return detail::convert_type_seq_to_discrete_domain_t<type_seq_r>(DDom_a);
443template <
class... DDimsB,
class DDomA>
446 using TagSeqA =
typename detail::ToTypeSeq<DDomA>::type;
447 using TagSeqB = detail::TypeSeq<DDimsB...>;
449 using type_seq_r = type_seq_remove_t<TagSeqA, TagSeqB>;
450 return detail::convert_type_seq_to_discrete_domain_t<type_seq_r>(DDom_a);
454template <
typename DDom,
typename... DDims>
455using remove_dims_of_t =
decltype(remove_dims_of<DDims...>(std::declval<DDom>()));
460template <
typename DDim1,
typename DDim2,
typename DDimA,
typename... DDimsB>
461KOKKOS_FUNCTION
constexpr std::conditional_t<
462 std::is_same_v<DDimA, DDim1>,
467 [[maybe_unused]]
DiscreteDomain<DDimsB...>
const& DDom_b)
noexcept
469 if constexpr (std::is_same_v<DDimA, DDim1>) {
470 return ddc::select<DDim2>(DDom_b);
479template <
typename DDim1,
typename DDim2,
typename... DDimsA,
typename... DDimsB>
485 using TagSeqA = detail::TypeSeq<DDimsA...>;
486 using TagSeqB = detail::TypeSeq<DDim1>;
487 using TagSeqC = detail::TypeSeq<DDim2>;
489 using type_seq_r =
ddc::type_seq_replace_t<TagSeqA, TagSeqB, TagSeqC>;
490 return ddc::detail::convert_type_seq_to_discrete_domain_t<type_seq_r>(
491 detail::replace_dim_of_1d<
495 DDimsB...>(
ddc::select<DDimsA>(DDom_a), DDom_b)...);
499template <
typename DDom,
typename DDim1,
typename DDim2>
500using replace_dim_of_t
501 =
decltype(replace_dim_of<
503 DDim2>(std::declval<DDom>(), std::declval<
DiscreteDomain<DDim2>>()));
506template <
class... QueryDDims,
class... DDims>
510 return DiscreteVector<QueryDDims...>(select<QueryDDims>(domain).size()...);
513template <
class... QueryDDims,
class... DDims>
517 return DiscreteElement<QueryDDims...>(select<QueryDDims>(domain).front()...);
520template <
class... QueryDDims,
class... DDims>
524 return DiscreteElement<QueryDDims...>(select<QueryDDims>(domain).back()...);
531 DiscreteElement<DDim> m_value = DiscreteElement<DDim>();
534 using iterator_category = std::random_access_iterator_tag;
536 using value_type = DiscreteElement<DDim>;
538 using difference_type = std::ptrdiff_t;
580 if (n >= difference_type(0)) {
581 m_value.uid() +=
static_cast<DiscreteElementType>(n);
583 m_value.uid() -=
static_cast<DiscreteElementType>(-n);
590 if (n >= difference_type(0)) {
591 m_value.uid() -=
static_cast<DiscreteElementType>(n);
593 m_value.uid() +=
static_cast<DiscreteElementType>(-n);
607 return xx.m_value == yy.m_value;
610#if !defined(__cpp_impl_three_way_comparison) || __cpp_impl_three_way_comparison < 201902L
624 return xx.m_value < yy.m_value;
673 return (yy.m_value > xx.m_value) ? (-
static_cast<difference_type>(yy.m_value - xx.m_value))
674 : (xx.m_value - yy.m_value);
KOKKOS_DEFAULTED_FUNCTION ~DiscreteDomain()=default
static KOKKOS_FUNCTION constexpr mlength_type extents() noexcept
KOKKOS_FUNCTION constexpr DiscreteDomain take_first(mlength_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
static KOKKOS_FUNCTION constexpr discrete_element_type back() noexcept
KOKKOS_FUNCTION constexpr DiscreteDomain remove_first(mlength_type n) const
KOKKOS_FUNCTION constexpr DiscreteDomain remove_last(mlength_type n) const
static KOKKOS_FUNCTION constexpr discrete_element_type front() noexcept
KOKKOS_DEFAULTED_FUNCTION DiscreteDomain & operator=(DiscreteDomain const &x)=default
KOKKOS_FUNCTION constexpr DiscreteDomain(DiscreteDomain< ODDims... > const &domain)
KOKKOS_FUNCTION constexpr DiscreteDomain restrict(DiscreteDomain< ODims... > const &) const
KOKKOS_FUNCTION constexpr DiscreteDomain remove(mlength_type n1, mlength_type n2) const
KOKKOS_FUNCTION constexpr bool operator==(DiscreteDomain const &other) const
KOKKOS_FUNCTION constexpr DiscreteDomain take_last(mlength_type n) const
KOKKOS_FUNCTION constexpr DiscreteDomain(discrete_element_type const &element_begin, mlength_type const &size)
Construct a DiscreteDomain starting from element_begin with size points.
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 take_first(mlength_type n) const
KOKKOS_FUNCTION auto begin() 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 DiscreteDomain remove_last(mlength_type n) const
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_FUNCTION constexpr DiscreteDomain(discrete_element_type const &element_begin, mlength_type const &size)
Construct a DiscreteDomain starting from element_begin with size points.
KOKKOS_DEFAULTED_FUNCTION DiscreteDomain & operator=(DiscreteDomain &&x)=default
KOKKOS_FUNCTION constexpr bool operator==(DiscreteDomain< ODims... > const &other) const
KOKKOS_FUNCTION constexpr DiscreteDomain take_last(mlength_type n) const
KOKKOS_FUNCTION constexpr DiscreteDomain remove_first(mlength_type n) const
KOKKOS_FUNCTION auto cbegin() const
KOKKOS_FUNCTION auto end() const
KOKKOS_DEFAULTED_FUNCTION ~DiscreteDomain()=default
KOKKOS_FUNCTION auto cend() const
KOKKOS_FUNCTION constexpr DiscreteDomain remove(mlength_type n1, mlength_type n2) const
KOKKOS_FUNCTION constexpr auto restrict(DiscreteDomain< ODDims... > const &odomain) 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_FUNCTION constexpr mlength_type extents() const noexcept
KOKKOS_DEFAULTED_FUNCTION DiscreteDomain()=default
KOKKOS_FUNCTION constexpr operator bool()
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)