Skip to content

[libc++] mdspan - implement layout_stride #69650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libcxx/docs/FeatureTestMacroTable.rst
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ Status
--------------------------------------------------- -----------------
``__cpp_lib_is_scoped_enum`` ``202011L``
--------------------------------------------------- -----------------
``__cpp_lib_mdspan`` *unimplemented*
``__cpp_lib_mdspan`` ``202207L``
--------------------------------------------------- -----------------
``__cpp_lib_move_only_function`` *unimplemented*
--------------------------------------------------- -----------------
Expand Down
1 change: 0 additions & 1 deletion libcxx/docs/Status/Cxx23.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ Paper Status

.. note::

.. [#note-P0009R18] P0009R18: ``extents``, ``dextents``, ``layout_left``, ``layout_right``, and ``default_accessor`` are implemented.
.. [#note-P0533R9] P0533R9: ``isfinite``, ``isinf``, ``isnan`` and ``isnormal`` are implemented.
.. [#note-P1413R3] P1413R3: ``std::aligned_storage_t`` and ``std::aligned_union_t`` are marked deprecated, but
clang doesn't issue a diagnostic for deprecated using template declarations.
Expand Down
8 changes: 4 additions & 4 deletions libcxx/docs/Status/Cxx23Papers.csv
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"`P2442R1 <https://wg21.link/P2442R1>`__","LWG","Windowing range adaptors: ``views::chunk`` and ``views::slide``","February 2022","","","|ranges|"
"`P2443R1 <https://wg21.link/P2443R1>`__","LWG","``views::chunk_by``","February 2022","|Complete|","18.0","|ranges|"
"","","","","","",""
"`P0009R18 <https://wg21.link/P0009R18>`__","LWG","mdspan: A Non-Owning Multidimensional Array Reference","July 2022","|In progress| [#note-P0009R18]_",""
"`P0009R18 <https://wg21.link/P0009R18>`__","LWG","mdspan: A Non-Owning Multidimensional Array Reference","July 2022","|Complete|","18.0"
"`P0429R9 <https://wg21.link/P0429R9>`__","LWG","A Standard ``flat_map``","July 2022","",""
"`P1169R4 <https://wg21.link/P1169R4>`__","LWG","``static operator()``","July 2022","|Complete|","16.0"
"`P1222R4 <https://wg21.link/P1222R4>`__","LWG","A Standard ``flat_set``","July 2022","",""
Expand Down Expand Up @@ -89,9 +89,9 @@
"`P2549R1 <https://wg21.link/P2549R1>`__","LWG","``std::unexpected`` should have ``error()`` as member accessor","July 2022","|Complete|","16.0"
"`P2585R0 <https://wg21.link/P2585R0>`__","LWG","Improving default container formatting","July 2022","|Complete|","17.0"
"`P2590R2 <https://wg21.link/P2590R2>`__","LWG","Explicit lifetime management","July 2022","",""
"`P2599R2 <https://wg21.link/P2599R2>`__","LWG","``mdspan::size_type`` should be ``index_type``","July 2022","",""
"`P2604R0 <https://wg21.link/P2604R0>`__","LWG","mdspan: rename pointer and contiguous","July 2022","",""
"`P2613R1 <https://wg21.link/P2613R1>`__","LWG","Add the missing ``empty`` to ``mdspan``","July 2022","",""
"`P2599R2 <https://wg21.link/P2599R2>`__","LWG","``mdspan::size_type`` should be ``index_type``","July 2022","|Complete|","18.0"
"`P2604R0 <https://wg21.link/P2604R0>`__","LWG","mdspan: rename pointer and contiguous","July 2022","|Complete|","18.0"
"`P2613R1 <https://wg21.link/P2613R1>`__","LWG","Add the missing ``empty`` to ``mdspan``","July 2022","|Complete|","18.0"
"","","","","","",""
"`P1202R5 <https://wg21.link/P1202R5>`__","LWG", "Asymmetric Fences", "November 2022","","","|concurrency TS|"
"`P1264R2 <https://wg21.link/P1264R2>`__","LWG", "Revising the wording of ``stream`` input operations", "November 2022","|Complete|","9.0",""
Expand Down
1 change: 1 addition & 0 deletions libcxx/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ set(files
__mdspan/extents.h
__mdspan/layout_left.h
__mdspan/layout_right.h
__mdspan/layout_stride.h
__mdspan/mdspan.h
__memory/addressof.h
__memory/align.h
Expand Down
7 changes: 2 additions & 5 deletions libcxx/include/__fwd/mdspan.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,11 @@ struct layout_right {
class mapping;
};

/*
// Will be implemented with follow on revision
// Layout policy with a unique mapping where strides are arbitrary
struct layout_stride {
template<class Extents>
class mapping;
template <class _Extents>
class mapping;
};
*/

#endif // _LIBCPP_STD_VER >= 23

Expand Down
27 changes: 21 additions & 6 deletions libcxx/include/__mdspan/layout_left.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,27 @@ class layout_left::mapping {
"layout_left::mapping converting ctor: other.required_span_size() must be representable as index_type.");
}

// FIXME: add when we add other layouts
# if 0
template<class _OtherExtents>
constexpr explicit(extents_type::rank() > 0)
mapping(const layout_stride::mapping_<OtherExtents>&) noexcept;
# endif
template <class _OtherExtents>
requires(is_constructible_v<extents_type, _OtherExtents>)
_LIBCPP_HIDE_FROM_ABI constexpr explicit(extents_type::rank() > 0)
mapping(const layout_stride::mapping<_OtherExtents>& __other) noexcept
: __extents_(__other.extents()) {
if constexpr (extents_type::rank() > 0) {
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
([&]() {
using _CommonType = common_type_t<typename extents_type::index_type, typename _OtherExtents::index_type>;
for (rank_type __r = 0; __r < extents_type::rank(); __r++)
if (static_cast<_CommonType>(stride(__r)) != static_cast<_CommonType>(__other.stride(__r)))
return false;
return true;
}()),
"layout_left::mapping from layout_stride ctor: strides are not compatible with layout_left.");
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
__mdspan_detail::__is_representable_as<index_type>(__other.required_span_size()),
"layout_left::mapping from layout_stride ctor: other.required_span_size() must be representable as "
"index_type.");
}
}

_LIBCPP_HIDE_FROM_ABI constexpr mapping& operator=(const mapping&) noexcept = default;

Expand Down
27 changes: 21 additions & 6 deletions libcxx/include/__mdspan/layout_right.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,27 @@ class layout_right::mapping {
"layout_right::mapping converting ctor: other.required_span_size() must be representable as index_type.");
}

// FIXME: add when we add other layouts
# if 0
template<class _OtherExtents>
constexpr explicit(extents_type::rank() > 0)
mapping(const layout_stride::mapping_<OtherExtents>&) noexcept;
# endif
template <class _OtherExtents>
requires(is_constructible_v<extents_type, _OtherExtents>)
_LIBCPP_HIDE_FROM_ABI constexpr explicit(extents_type::rank() > 0)
mapping(const layout_stride::mapping<_OtherExtents>& __other) noexcept
: __extents_(__other.extents()) {
if constexpr (extents_type::rank() > 0) {
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
([&]() {
using _CommonType = common_type_t<typename extents_type::index_type, typename _OtherExtents::index_type>;
for (rank_type __r = 0; __r < extents_type::rank(); __r++)
if (static_cast<_CommonType>(stride(__r)) != static_cast<_CommonType>(__other.stride(__r)))
return false;
return true;
}()),
"layout_right::mapping from layout_stride ctor: strides are not compatible with layout_right.");
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
__mdspan_detail::__is_representable_as<index_type>(__other.required_span_size()),
"layout_right::mapping from layout_stride ctor: other.required_span_size() must be representable as "
"index_type.");
}
}

_LIBCPP_HIDE_FROM_ABI constexpr mapping& operator=(const mapping&) noexcept = default;

Expand Down
Loading