8#include "ddc_aliases.hpp"
14template <
class Gr
id1D>
22template <
class... Tags>
36template <
class... Dims>
39 static_assert(
sizeof...(Dims) > 0);
43 using tags_seq = ddc::detail::TypeSeq<Dims...>;
46 IdxStep<Dims...> m_size;
47 IdxStep<Dims...> m_stride;
65 IdxStep<Dims...>
size,
80 class = std::enable_if_t<(is_subidx_range_collection_v<DDoms> && ...)>>
82 : m_front(valid_indices.
front()...)
83 , m_size(valid_indices.
extents()...)
84 , m_stride(valid_indices.
strides()...)
95 template <
class... DDims>
96 KOKKOS_FUNCTION
bool contains(Idx<DDims...> elem)
const
99 (ddc::in_tags_v<DDims, tags_seq> && ...),
100 "Requested Tag absent from IdxRangeSlice");
102 IdxStep<DDims...> distance(elem - ddc::select<DDims...>(m_front));
103 return (((ddc::get<DDims>(distance) % ddc::get<DDims>(m_stride)) == 0) && ...);
114 template <
class... DDims>
115 KOKKOS_FUNCTION
bool contains(IdxRange<DDims...> idx_range)
const
118 (ddc::in_tags_v<DDims, tags_seq> && ...),
119 "Requested Tag absent from IdxRangeSlice");
121 && (((idx_range.template extent<DDims>().value() == 1)
122 || (ddc::select<DDims>(m_stride) == 1))
134 template <
class Dim,
class = std::enable_if_t<ddc::in_tags_v<Dim, tags_seq>>>
135 KOKKOS_FUNCTION std::size_t
get_index(Idx<Dim> elem)
const
138 return (elem - ddc::select<Dim>(m_front)).value() / ddc::get<Dim>(m_stride);
146 KOKKOS_FUNCTION
constexpr IdxStep<Dims...>
extents() const noexcept
158 template <
class QueryDDim>
159 KOKKOS_FUNCTION
constexpr IdxStep<QueryDDim>
extent() const noexcept
161 return ddc::select<QueryDDim>(m_size);
169 KOKKOS_FUNCTION
constexpr std::size_t
size()
const
171 return (1ul * ... * (ddc::get<Dims>(m_size)));
179 KOKKOS_FUNCTION
constexpr Idx<Dims...>
front() const noexcept
189 KOKKOS_FUNCTION
constexpr Idx<Dims...>
back() const noexcept
191 return m_front + m_stride * (m_size - 1);
201 template <
class QueryDim>
202 KOKKOS_FUNCTION
constexpr IdxStep<QueryDim>
stride() const noexcept
204 return ddc::select<QueryDim>(m_stride);
212 KOKKOS_FUNCTION
constexpr IdxStep<Dims...>
strides() const noexcept
225 static_assert(
sizeof...(Dims) == 1);
235 KOKKOS_FUNCTION
auto end()
const
237 static_assert(
sizeof...(Dims) == 1);
245template <
class Gr
id1D>
250 IdxStep<Grid1D> m_stride;
275 IdxStep<Grid1D> stride)
285 KOKKOS_FUNCTION
constexpr Idx<Grid1D>
operator*() const noexcept
296 m_value = m_value + m_stride;
317 m_value = m_value - m_stride;
339 m_value = m_value + n * m_stride;
350 m_value = m_value - n * m_stride;
362 return m_value + n * m_stride;
370 return xx.m_value == yy.m_value;
378 return xx.m_value != yy.m_value;
386 return xx.m_value < yy.m_value;
442 assert(xx.m_stride == yy.m_stride);
443 return (yy.m_value > xx.m_value)
445 / ddc::get<Grid1D>(xx.m_stride))
446 : ((xx.m_value - yy.m_value) / ddc::get<Grid1D>(xx.m_stride));
454template <
class... Dims>
A class which describes a collection of equally spaced Idxs which form a index range.
Definition idx_range_slice.hpp:38
KOKKOS_FUNCTION IdxRangeSlice(Idx< Dims... > front, IdxStep< Dims... > size, IdxStep< Dims... > stride)
Build a IdxRangeSlice from vectors of valid Idxs in each dimension.
Definition idx_range_slice.hpp:63
KOKKOS_FUNCTION IdxRangeSlice(DDoms const &... valid_indices)
Build a IdxRangeSlice from a set of 1D IdxRangeSlices.
Definition idx_range_slice.hpp:81
KOKKOS_FUNCTION std::size_t get_index(Idx< Dim > elem) const
Get the index of the Idx within the index range slice.
Definition idx_range_slice.hpp:135
KOKKOS_FUNCTION constexpr std::size_t size() const
Get the total number of elements in the index range slice.
Definition idx_range_slice.hpp:169
KOKKOS_FUNCTION constexpr IdxStep< QueryDDim > extent() const noexcept
Get the size of the index range slice in the specified dimension.
Definition idx_range_slice.hpp:159
KOKKOS_FUNCTION auto end() const
Get the iterator to the end of the IdxRangeSlice.
Definition idx_range_slice.hpp:235
KOKKOS_FUNCTION constexpr Idx< Dims... > front() const noexcept
Get the first element in the index range slice.
Definition idx_range_slice.hpp:179
KOKKOS_FUNCTION constexpr IdxStep< QueryDim > stride() const noexcept
Get the stride from one element of the index range slice to another.
Definition idx_range_slice.hpp:202
KOKKOS_FUNCTION auto begin() const
Get the iterator to the first element of the IdxRangeSlice.
Definition idx_range_slice.hpp:223
KOKKOS_FUNCTION bool contains(Idx< DDims... > elem) const
Check if the specified Idx is found in this index range slice.
Definition idx_range_slice.hpp:96
KOKKOS_FUNCTION constexpr IdxStep< Dims... > strides() const noexcept
Get the strides from one element of the index range slice to another.
Definition idx_range_slice.hpp:212
KOKKOS_FUNCTION constexpr Idx< Dims... > back() const noexcept
Get the last element in the index range slice.
Definition idx_range_slice.hpp:189
IdxRangeSlice()=default
Default constructor for IdxRangeSlice creating an empty index range.
KOKKOS_FUNCTION constexpr IdxStep< Dims... > extents() const noexcept
Get the size of the index range slice in each dimension.
Definition idx_range_slice.hpp:146
KOKKOS_FUNCTION bool contains(IdxRange< DDims... > idx_range) const
Check if all elements of the specified IdxRange are found in this index range slice.
Definition idx_range_slice.hpp:115
An iterator type for the IdxRangeSlice.
Definition idx_range_slice.hpp:247
friend KOKKOS_FUNCTION constexpr bool operator<=(IdxRangeSliceIterator const &xx, IdxRangeSliceIterator const &yy)
Compare the order of iterators.
Definition idx_range_slice.hpp:398
friend KOKKOS_FUNCTION constexpr bool operator>=(IdxRangeSliceIterator const &xx, IdxRangeSliceIterator const &yy)
Compare the order of iterators.
Definition idx_range_slice.hpp:406
IdxStep< Grid1D > stride_type
The type of the stride between values.
Definition idx_range_slice.hpp:260
friend KOKKOS_FUNCTION constexpr bool operator>(IdxRangeSliceIterator const &xx, IdxRangeSliceIterator const &yy)
Compare the order of iterators.
Definition idx_range_slice.hpp:390
KOKKOS_FUNCTION constexpr Idx< Grid1D > operator[](difference_type n) const
Access the n-th following element.
Definition idx_range_slice.hpp:360
friend KOKKOS_FUNCTION constexpr bool operator==(IdxRangeSliceIterator const &xx, IdxRangeSliceIterator const &yy)
Compare iterator equality.
Definition idx_range_slice.hpp:366
KOKKOS_FUNCTION constexpr IdxRangeSliceIterator & operator++()
The prefix increment operator.
Definition idx_range_slice.hpp:294
friend KOKKOS_FUNCTION constexpr IdxRangeSliceIterator operator-(IdxRangeSliceIterator i, difference_type n)
Decrement an iterator by n elements.
Definition idx_range_slice.hpp:430
KOKKOS_FUNCTION constexpr IdxRangeSliceIterator(Idx< Grid1D > value, IdxStep< Grid1D > stride)
Build an iterator using the current value and the distance to the following element.
Definition idx_range_slice.hpp:273
KOKKOS_FUNCTION constexpr IdxRangeSliceIterator & operator--()
The prefix decrement operator.
Definition idx_range_slice.hpp:315
KOKKOS_FUNCTION constexpr IdxRangeSliceIterator operator++(int)
The postfix increment operator.
Definition idx_range_slice.hpp:304
friend KOKKOS_FUNCTION constexpr difference_type operator-(IdxRangeSliceIterator const &xx, IdxRangeSliceIterator const &yy)
Decrement an iterator by n elements.
Definition idx_range_slice.hpp:438
friend KOKKOS_FUNCTION constexpr IdxRangeSliceIterator operator+(IdxRangeSliceIterator i, difference_type n)
Increment an iterator by n elements.
Definition idx_range_slice.hpp:414
KOKKOS_FUNCTION constexpr IdxRangeSliceIterator & operator+=(difference_type n)
Increment the current iterator by n elements.
Definition idx_range_slice.hpp:337
std::ptrdiff_t difference_type
The type that can be used to increment the iterator.
Definition idx_range_slice.hpp:263
friend KOKKOS_FUNCTION constexpr bool operator!=(IdxRangeSliceIterator const &xx, IdxRangeSliceIterator const &yy)
Compare iterator non-equality.
Definition idx_range_slice.hpp:374
friend KOKKOS_FUNCTION constexpr IdxRangeSliceIterator operator+(difference_type n, IdxRangeSliceIterator i)
Increment an iterator by n elements.
Definition idx_range_slice.hpp:422
KOKKOS_FUNCTION constexpr Idx< Grid1D > operator*() const noexcept
Get the value referred to by the iterator.
Definition idx_range_slice.hpp:285
Idx< Grid1D > value_type
The type of the values stored in the iterator.
Definition idx_range_slice.hpp:257
KOKKOS_FUNCTION constexpr IdxRangeSliceIterator operator--(int)
The postfix decrement operator.
Definition idx_range_slice.hpp:325
KOKKOS_FUNCTION constexpr IdxRangeSliceIterator & operator-=(difference_type n)
Decrement the current iterator by n elements.
Definition idx_range_slice.hpp:348
friend KOKKOS_FUNCTION constexpr bool operator<(IdxRangeSliceIterator const &xx, IdxRangeSliceIterator const &yy)
Compare the order of iterators.
Definition idx_range_slice.hpp:382
std::random_access_iterator_tag iterator_category
The type of iterator.
Definition idx_range_slice.hpp:254
A class to create a IdxRangeSlice type from a TypeSeq.
Definition idx_range_slice.hpp:452
Definition idx_range_slice.hpp:19