tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
layout_left.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2023 Tobias Hienzsch
3
4#ifndef TETL_MDSPAN_LAYOUT_LEFT_HPP
5#define TETL_MDSPAN_LAYOUT_LEFT_HPP
6
7#include <etl/_contracts/check.hpp>
8#include <etl/_mdspan/extents.hpp>
9#include <etl/_mdspan/is_extents.hpp>
10#include <etl/_mdspan/layout.hpp>
11#include <etl/_mdspan/submdspan_extents.hpp>
12#include <etl/_mdspan/submdspan_mapping_result.hpp>
13#include <etl/_type_traits/is_convertible.hpp>
14#include <etl/_type_traits/is_nothrow_constructible.hpp>
15#include <etl/_utility/index_sequence.hpp>
16
17namespace etl {
18
19template <typename Extents>
20struct layout_left::mapping {
21 using extents_type = Extents;
22 using index_type = typename extents_type::index_type;
23 using size_type = typename extents_type::size_type;
24 using rank_type = typename extents_type::rank_type;
25 using layout_type = layout_left;
26
27 constexpr mapping() noexcept = default;
28 constexpr mapping(mapping const&) noexcept = default;
29
30 constexpr mapping(extents_type const& ext) noexcept
31 : _extents{ext}
32 {
33 }
34
35 template <typename OtherExtents>
36 requires is_constructible_v<extents_type, OtherExtents>
38 mapping<OtherExtents> const& other
39 ) noexcept
40 : _extents{other.extents()}
41 {
42 }
43
44 template <typename OtherExtents>
45 requires(extents_type::rank() <= 1) && is_constructible_v<extents_type, OtherExtents>
47 layout_right::mapping<OtherExtents> const& other
48 ) noexcept
49 : _extents{other.extents()}
50 {
51 }
52
53 template <typename OtherExtents>
54 explicit(extents_type::rank() > 0) constexpr mapping(layout_stride::mapping<OtherExtents> const&);
55
56 constexpr auto operator=(mapping const&) noexcept -> mapping& = default;
57
58 [[nodiscard]] constexpr auto extents() const noexcept -> extents_type const&
59 {
60 return _extents;
61 }
62
63 [[nodiscard]] constexpr auto required_span_size() const noexcept -> index_type
64 {
65 return static_cast<index_type>(extents().fwd_prod_of_extents(extents_type::rank()));
66 }
67
68 template <typename... Indices>
69 requires(sizeof...(Indices) == extents_type::rank())
70 && (is_convertible_v<Indices, index_type> && ...)
71 && (is_nothrow_constructible_v<index_type, Indices> && ...)
72 [[nodiscard]] constexpr auto operator()(Indices... indices) const noexcept -> index_type
73 {
74 return [&]<size_t... Is>(index_sequence<Is...> /*seq*/) {
75 return static_cast<index_type>(((static_cast<index_type>(indices) * stride(Is)) + ... + 0));
76 }(index_sequence_for<Indices...>{});
77 }
78
79 [[nodiscard]] constexpr auto stride(rank_type r) const noexcept -> index_type
80 requires(extents_type::rank() > 0)
81 {
82 TETL_PRECONDITION(r < extents_type::rank());
83 return static_cast<index_type>(_extents.fwd_prod_of_extents(r));
84 }
85
86 [[nodiscard]] static constexpr auto is_always_unique() noexcept -> bool
87 {
88 return true;
89 }
90 [[nodiscard]] static constexpr auto is_always_exhaustive() noexcept -> bool
91 {
92 return true;
93 }
94 [[nodiscard]] static constexpr auto is_always_strided() noexcept -> bool
95 {
96 return true;
97 }
98
99 [[nodiscard]] static constexpr auto is_unique() noexcept -> bool
100 {
101 return true;
102 }
103 [[nodiscard]] static constexpr auto is_exhaustive() noexcept -> bool
104 {
105 return true;
106 }
107 [[nodiscard]] static constexpr auto is_strided() noexcept -> bool
108 {
109 return true;
110 }
111
112 template <typename OtherExtents>
113 friend constexpr auto operator==(mapping const& lhs, mapping<OtherExtents> const& rhs) noexcept -> bool
114 {
115 return lhs.extents() == rhs.extents();
116 }
117
118private:
119 // template <typename... SliceSpecifiers>
120 // [[nodiscard]] constexpr auto submdspan_mapping_impl(SliceSpecifiers... slices) const
121 // {
122 // auto sub_ext = etl::submdspan_extents(extents(), slices...);
123 // using SubExtents = decltype(sub_ext);
124 // static_assert(sizeof(SubExtents) > 0);
125
126 // // auto sub_strides = {};
127
128 // if constexpr (Extents::rank() == 0) {
129 // return etl::submdspan_mapping_result {*this, 0};
130 // } else {
131 // static_assert(etl::always_false<SliceSpecifiers...>);
132 // }
133 // }
134
135 // template <typename... SliceSpecifiers>
136 // friend constexpr auto submdspan_mapping(mapping const& src, SliceSpecifiers... slices)
137 // {
138 // return src.submdspan_mapping_impl(slices...);
139 // }
140
141 TETL_NO_UNIQUE_ADDRESS extents_type _extents{};
142};
143
144} // namespace etl
145
146#endif // TETL_MDSPAN_LAYOUT_LEFT_HPP
Definition adjacent_find.hpp:9
constexpr mapping(extents_type const &ext) noexcept
Definition layout_left.hpp:30
constexpr auto operator()(Indices... indices) const noexcept -> index_type
Definition layout_left.hpp:72
constexpr mapping() noexcept=default
explicit(extents_type::rank() > 0) const expr mapping(layout_stride constexpr auto operator=(mapping const &) noexcept -> mapping &=default
static constexpr auto is_exhaustive() noexcept -> bool
Definition layout_left.hpp:103
static constexpr auto is_always_exhaustive() noexcept -> bool
Definition layout_left.hpp:90
friend constexpr auto operator==(mapping const &lhs, mapping< OtherExtents > const &rhs) noexcept -> bool
Definition layout_left.hpp:113
constexpr explicit(not is_convertible_v< OtherExtents, extents_type >) mapping(layout_right
Definition layout_left.hpp:46
static constexpr auto is_always_strided() noexcept -> bool
Definition layout_left.hpp:94
static constexpr auto is_strided() noexcept -> bool
Definition layout_left.hpp:107
static constexpr auto is_always_unique() noexcept -> bool
Definition layout_left.hpp:86
constexpr auto stride(rank_type r) const noexcept -> index_type requires(extents_type::rank() > 0)
Definition layout_left.hpp:79
static constexpr auto is_unique() noexcept -> bool
Definition layout_left.hpp:99
constexpr mapping(mapping const &) noexcept=default
constexpr auto extents() const noexcept -> extents_type const &
Definition layout_left.hpp:58
constexpr explicit(not is_convertible_v< OtherExtents, extents_type >) mapping(mapping< OtherExtents > const &other) noexcept
Definition layout_left.hpp:37
constexpr auto required_span_size() const noexcept -> index_type
Definition layout_left.hpp:63
Definition layout.hpp:9
Definition layout.hpp:14
Definition layout.hpp:19