5#ifndef DUNE_COMMON_STD_LAYOUT_STRIDE_HH
6#define DUNE_COMMON_STD_LAYOUT_STRIDE_HH
19template <
class Extents>
23 static constexpr typename Extents::rank_type rank_ = Extents::rank();
33 using strides_type = std::array<index_type,rank_>;
46 template <
class OtherIndexType,
47 std::enable_if_t<std::is_convertible_v<const OtherIndexType&, index_type>,
int> = 0,
48 std::enable_if_t<std::is_nothrow_constructible_v<index_type, const OtherIndexType&>,
int> = 0>
58 template <
class OtherIndexType,
59 std::enable_if_t<std::is_convertible_v<const OtherIndexType&, index_type>,
int> = 0,
60 std::enable_if_t<std::is_nothrow_constructible_v<index_type, const OtherIndexType&>,
int> = 0>
71 std::enable_if_t<(M::extents_type::rank() == extents_type::rank()),
int> = 0,
72 std::enable_if_t<(M::is_always_unique()),
int> = 0,
73 std::enable_if_t<(M::is_always_strided()),
int> = 0,
74 decltype(std::declval<M>().
extents(),
bool{}) =
true,
75 decltype(std::declval<M>().
stride(std::declval<rank_type>()),
bool{}) =
true>
77 : extents_(m.extents())
81 strides_[r] = m.stride(r);
92 return size(extents_,strides_);
97 std::enable_if_t<(
sizeof...(Indices) == rank_),
int> = 0,
98 std::enable_if_t<(std::is_convertible_v<Indices, index_type> && ...),
int> = 0,
99 std::enable_if_t<(std::is_nothrow_constructible_v<index_type, Indices> && ...),
int> = 0>
103 return ((
static_cast<index_type>(ii)*strides_[r]) + ... + 0); },
104 std::make_index_sequence<rank_>{});
117 static constexpr bool is_unique () noexcept {
return true; }
118 static constexpr bool is_strided () noexcept {
return true; }
129 constexpr const strides_type&
strides () const noexcept
136 std::enable_if_t<(E::rank() > 0),
int> = 0>
142 template <
class OtherMapping,
143 std::enable_if_t<(OtherMapping::extents_type::rank() == extents_type::rank()),
int> = 0,
144 std::enable_if_t<(OtherMapping::is_always_strided()),
int> = 0>
149 if constexpr(extents_type::rank() == 0)
151 return a.extents_ == b.extents_ && a.strides_ == b.strides_;
155 template <
class E,
class S>
158 if constexpr (E::rank() == 0)
165 for (
rank_type r = 0; r < E::rank(); ++r)
173 static constexpr size_type offset (
const M& m)
noexcept
175 if constexpr (M::extents_type::rank() == 0)
178 if (m.required_span_size() == 0)
182 return m((r,0)...); },
183 std::make_index_sequence<M::extents_type::rank()>{});
190 strides_type strides_;
#define DUNE_NO_UNIQUE_ADDRESS
Definition no_unique_address.hh:24
decltype(auto) constexpr unpackIntegerSequence(F &&f, std::integer_sequence< I, i... > sequence)
Unpack an std::integer_sequence<I,i...> to std::integral_constant<I,i>...
Definition indices.hh:124
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition integersequence.hh:75
Namespace with predefined compile time indices for the range [0,19].
Definition indices.hh:50
Namespace for features backported from new C++ standards.
Definition algorithm.hh:19
Multidimensional index space with dynamic and static extents.
Definition extents.hh:55
constexpr index_type extent(rank_type r) const noexcept
Return the extent of dimension i.
Definition extents.hh:101
A layout where the rightmost extent has stride 1, and strides increase right-to-left as the product o...
Definition fwd_layouts.hh:30
A layout mapping where the strides are user-defined.
Definition fwd_layouts.hh:40
A layout mapping where the strides are user-defined.
Definition layout_stride.hh:21
Extents extents_type
Definition layout_stride.hh:26
layout_stride layout_type
Definition layout_stride.hh:30
constexpr mapping & operator=(const mapping &) noexcept=default
Copy-assignment for the mapping.
constexpr bool is_exhaustive() const noexcept
Definition layout_stride.hh:120
constexpr mapping() noexcept
The default construction initializes the strides from layout_right.
Definition layout_stride.hh:38
constexpr mapping(const extents_type &e, const std::array< OtherIndexType, rank_ > &s) noexcept
Construct the mapping from given extents and strides.
Definition layout_stride.hh:49
constexpr index_type stride(rank_type i) const noexcept
Get the single stride i.
Definition layout_stride.hh:137
typename extents_type::index_type index_type
Definition layout_stride.hh:27
friend class mapping
Definition layout_stride.hh:22
static constexpr bool is_always_exhaustive() noexcept
Definition layout_stride.hh:114
constexpr const extents_type & extents() const noexcept
Definition layout_stride.hh:87
static constexpr bool is_strided() noexcept
Definition layout_stride.hh:118
friend constexpr bool operator==(const mapping &a, const OtherMapping &b) noexcept
Definition layout_stride.hh:145
static constexpr bool is_always_strided() noexcept
Definition layout_stride.hh:115
constexpr index_type required_span_size() const noexcept
Return the sum 1 + (E(0)-1)*S(0) + (E(1)-1)*S(1) + ....
Definition layout_stride.hh:90
constexpr const strides_type & strides() const noexcept
Get the array of all strides.
Definition layout_stride.hh:129
constexpr mapping(const mapping &) noexcept=default
Copy constructor for the mapping.
typename extents_type::rank_type rank_type
Definition layout_stride.hh:29
static constexpr bool is_unique() noexcept
Definition layout_stride.hh:117
constexpr index_type operator()() const noexcept
The default offset for rank-0 tensors is 0.
Definition layout_stride.hh:108
constexpr mapping(const extents_type &e, const std::span< OtherIndexType, rank_ > &s) noexcept
Construct the mapping from given extents and strides.
Definition layout_stride.hh:61
typename extents_type::size_type size_type
Definition layout_stride.hh:28
static constexpr bool is_always_unique() noexcept
Definition layout_stride.hh:113