5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_LINALG_LAYOUT_TRANSPOSE_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_LINALG_LAYOUT_TRANSPOSE_HPP_
11#include "arene/base/mdspan/detail/do_submdspan_mapping.hpp"
12#include "arene/base/mdspan/detail/reverse_extents.hpp"
15#include "arene/base/stdlib_choice/declval.hpp"
16#include "arene/base/stdlib_choice/enable_if.hpp"
17#include "arene/base/stdlib_choice/move.hpp"
29namespace transpose_detail {
35template <
class NestedMapping, constra
ints<std::enable_if_t<NestedMapping::is_always_str
ided()>> =
nullptr>
36constexpr auto check_nested_mapping_is_strided(NestedMapping
const&)
noexcept ->
void {}
42template <
class NestedMapping, constra
ints<std::enable_if_t<!NestedMapping::is_always_str
ided()>> =
nullptr>
43constexpr auto check_nested_mapping_is_strided(NestedMapping
const& nested)
noexcept ->
void {
54template <
class NestedLayout>
66 template <
class Extents>
68 class mapping :
private NestedLayout::template
mapping<mdspan_detail::reverse_extents_t<Extents>> {
73 static_assert(Extents::rank() == 2U,
"Extents must be rank 2.");
93 extents_{nested.extents().extent(1U), nested.extents().extent(0U)} {}
115 template <
class Index0,
class Index1>
122 static constexpr auto is_always_unique() noexcept ->
bool {
return nested_mapping_type::is_always_unique(); }
127 return nested_mapping_type::is_always_exhaustive();
132 static constexpr auto is_always_strided() noexcept ->
bool {
return nested_mapping_type::is_always_strided(); }
153 transpose_detail::check_nested_mapping_is_strided(
nested_mapping());
169 extents_type::rank() == OtherExtents::rank(),
172 return left.nested_mapping() == right.nested_mapping();
184 extents_type::rank() == OtherExtents::rank(),
187 return !(left == right);
195 template <
class Mapping>
197 mdspan_detail::reverse_extents_t<typename Mapping::extents_type>>;
206 template <
class Mapping, constra
ints<std::enable_if_t<Mapping::extents_type::rank() == 2U>> =
nullptr>
209 return {transposed_sub_mapping_t<Mapping>{
result.mapping},
result.offset};
218 template <
class Mapping, constra
ints<std::enable_if_t<Mapping::extents_type::rank() < 2U>> =
nullptr>
219 static constexpr auto transpose_result(submdspan_mapping_result<Mapping> result) noexcept
220 -> submdspan_mapping_result<Mapping> {
240 template <
class CanonicalSlice0,
class CanonicalSlice1,
class Mapping = mapping>
242 noexcept(transpose_result(mdspan_detail::do_submdspan_mapping(
248 ->
decltype(transpose_result(mdspan_detail::do_submdspan_mapping(
253 return transpose_result(
254 mdspan_detail::do_submdspan_mapping(src.nested_mapping(),
std::move(slice1),
std::move(slice0))
274template <
class LayoutMapping>
The mapping type produced by layout_transpose for a given set of extents.
Definition layout_transpose.hpp:68
static constexpr auto is_always_exhaustive() noexcept -> bool
Determine if this mapping is always exhaustive.
Definition layout_transpose.hpp:126
friend constexpr auto operator!=(mapping const left, mapping< OtherExtents > const right) noexcept -> bool
Compare two transposed mappings for inequality.
Definition layout_transpose.hpp:186
constexpr auto stride(rank_type rank_index) const noexcept -> index_type
Obtain the stride along the specified (transposed) dimension.
Definition layout_transpose.hpp:151
constexpr mapping(nested_mapping_type const &nested) noexcept
Construct a transposed mapping from a nested mapping.
Definition layout_transpose.hpp:91
constexpr auto required_span_size() const noexcept -> index_type
Obtain the required span size.
Definition layout_transpose.hpp:107
typename extents_type::rank_type rank_type
The rank type of this mapping.
Definition layout_transpose.hpp:83
typename extents_type::size_type size_type
The size type of this mapping.
Definition layout_transpose.hpp:79
typename NestedLayout::template mapping< mdspan_detail::reverse_extents_t< extents_type > > nested_mapping_type
The wrapped (un-transposed) mapping type.
Definition layout_transpose.hpp:87
constexpr auto is_strided() const noexcept -> bool
Determine if this mapping is strided.
Definition layout_transpose.hpp:144
friend constexpr auto operator==(mapping const left, mapping< OtherExtents > const right) noexcept -> bool
Compare two transposed mappings for equality.
Definition layout_transpose.hpp:171
constexpr auto extents() const noexcept -> extents_type const &
Obtain the (transposed) extents of this mapping.
Definition layout_transpose.hpp:97
constexpr auto nested_mapping() const noexcept -> nested_mapping_type const &
Obtain the wrapped (un-transposed) mapping.
Definition layout_transpose.hpp:101
constexpr auto is_exhaustive() const noexcept -> bool
Determine if this mapping is exhaustive.
Definition layout_transpose.hpp:140
static constexpr auto is_always_strided() noexcept -> bool
Determine if this mapping is always strided.
Definition layout_transpose.hpp:132
friend constexpr auto submdspan_mapping(mapping const src, CanonicalSlice0 slice0, CanonicalSlice1 slice1) noexcept(noexcept(transpose_result(mdspan_detail::do_submdspan_mapping(std::declval< Mapping const & >().nested_mapping(), std::move(std::declval< CanonicalSlice1 >()), std::move(std::declval< CanonicalSlice0 >()))))) ->
Compute the sub-mapping and offset for a transposed mapping.
Definition layout_transpose.hpp:241
typename extents_type::index_type index_type
The index type of this mapping.
Definition layout_transpose.hpp:81
static constexpr auto is_always_unique() noexcept -> bool
Determine if this mapping is always unique.
Definition layout_transpose.hpp:122
layout_transpose layout_type
The tag type of the layout used by this mapping.
Definition layout_transpose.hpp:85
constexpr auto operator()(Index0 index0, Index1 index1) const noexcept -> index_type
Access the flat element index for the given two-dimensional index.
Definition layout_transpose.hpp:116
constexpr auto is_unique() const noexcept -> bool
Determine if this mapping is unique.
Definition layout_transpose.hpp:136
Extents extents_type
This mapping's extents type.
Definition layout_transpose.hpp:77
A layout mapping policy that swaps the two indices, extents, and strides of a rank-2 mapping.
Definition layout_transpose.hpp:55
NestedLayout nested_layout_type
The wrapped (un-transposed) layout type.
Definition layout_transpose.hpp:58
A sum type which can hold either a value or an error. Similar to std::expected.
Definition result.hpp:104
#define ARENE_PRECONDITION(condition)
Check that a precondition holds, and terminate the application if it does not.
Definition contract.hpp:150
Definition accumulate.hpp:37
constexpr bool is_layout_mapping_v
Helper trait to indicate if the given type has all the basic properties required of a layout mapping:
constexpr bool is_equality_comparable_v
Definition accumulate.hpp:36
constexpr auto move(T &&value) noexcept -> remove_reference_t< T > &&
Cast a value to an rvalue.
Definition move.hpp:30
typename enable_if< Condition, Type >::type enable_if_t
Type alias to support constraining templates. Is an alias for the specified type if the Condition is ...
Definition enable_if.hpp:41
auto declval() noexcept -> T &&
A dummy function that is declared but not defined, with a user-specified return type,...
Specializations of submdspan_mapping_result are returned by overloads of submdspan_mapping.
Definition submdspan_mapping_result.hpp:18