Skip to content

Commit

Permalink
Merge pull request #286 from crtrott/more-standard-deviations
Browse files Browse the repository at this point in the history
Fix mdspan standard deviations
  • Loading branch information
crtrott authored Nov 1, 2023
2 parents e155162 + a775fd5 commit 417204e
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 76 deletions.
56 changes: 28 additions & 28 deletions include/experimental/__p0009_bits/compressed_pair.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ namespace detail {
// For no unique address emulation, this is the case taken when neither are empty.
// For real `[[no_unique_address]]`, this case is always taken.
template <class _T1, class _T2, class _Enable = void> struct __compressed_pair {
_MDSPAN_NO_UNIQUE_ADDRESS _T1 __t1_val;
_MDSPAN_NO_UNIQUE_ADDRESS _T2 __t2_val;
_MDSPAN_NO_UNIQUE_ADDRESS _T1 __t1_val{};
_MDSPAN_NO_UNIQUE_ADDRESS _T2 __t2_val{};
MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 _T1 &__first() noexcept { return __t1_val; }
MDSPAN_FORCE_INLINE_FUNCTION constexpr _T1 const &__first() const noexcept {
return __t1_val;
Expand All @@ -40,19 +40,19 @@ template <class _T1, class _T2, class _Enable = void> struct __compressed_pair {
}

MDSPAN_INLINE_FUNCTION_DEFAULTED
constexpr __compressed_pair() noexcept = default;
constexpr __compressed_pair() = default;
MDSPAN_INLINE_FUNCTION_DEFAULTED
constexpr __compressed_pair(__compressed_pair const &) noexcept = default;
constexpr __compressed_pair(__compressed_pair const &) = default;
MDSPAN_INLINE_FUNCTION_DEFAULTED
constexpr __compressed_pair(__compressed_pair &&) noexcept = default;
constexpr __compressed_pair(__compressed_pair &&) = default;
MDSPAN_INLINE_FUNCTION_DEFAULTED
_MDSPAN_CONSTEXPR_14_DEFAULTED __compressed_pair &
operator=(__compressed_pair const &) noexcept = default;
operator=(__compressed_pair const &) = default;
MDSPAN_INLINE_FUNCTION_DEFAULTED
_MDSPAN_CONSTEXPR_14_DEFAULTED __compressed_pair &
operator=(__compressed_pair &&) noexcept = default;
operator=(__compressed_pair &&) = default;
MDSPAN_INLINE_FUNCTION_DEFAULTED
~__compressed_pair() noexcept = default;
~__compressed_pair() = default;
template <class _T1Like, class _T2Like>
MDSPAN_INLINE_FUNCTION constexpr __compressed_pair(_T1Like &&__t1, _T2Like &&__t2)
: __t1_val((_T1Like &&) __t1), __t2_val((_T2Like &&) __t2) {}
Expand All @@ -66,7 +66,7 @@ struct __compressed_pair<
_T1, _T2,
std::enable_if_t<_MDSPAN_TRAIT(std::is_empty, _T1) && !_MDSPAN_TRAIT(std::is_empty, _T2)>>
: private _T1 {
_T2 __t2_val;
_T2 __t2_val{};
MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 _T1 &__first() noexcept {
return *static_cast<_T1 *>(this);
}
Expand All @@ -79,19 +79,19 @@ struct __compressed_pair<
}

MDSPAN_INLINE_FUNCTION_DEFAULTED
constexpr __compressed_pair() noexcept = default;
constexpr __compressed_pair() = default;
MDSPAN_INLINE_FUNCTION_DEFAULTED
constexpr __compressed_pair(__compressed_pair const &) noexcept = default;
constexpr __compressed_pair(__compressed_pair const &) = default;
MDSPAN_INLINE_FUNCTION_DEFAULTED
constexpr __compressed_pair(__compressed_pair &&) noexcept = default;
constexpr __compressed_pair(__compressed_pair &&) = default;
MDSPAN_INLINE_FUNCTION_DEFAULTED
_MDSPAN_CONSTEXPR_14_DEFAULTED __compressed_pair &
operator=(__compressed_pair const &) noexcept = default;
operator=(__compressed_pair const &) = default;
MDSPAN_INLINE_FUNCTION_DEFAULTED
_MDSPAN_CONSTEXPR_14_DEFAULTED __compressed_pair &
operator=(__compressed_pair &&) noexcept = default;
operator=(__compressed_pair &&) = default;
MDSPAN_INLINE_FUNCTION_DEFAULTED
~__compressed_pair() noexcept = default;
~__compressed_pair() = default;
template <class _T1Like, class _T2Like>
MDSPAN_INLINE_FUNCTION constexpr __compressed_pair(_T1Like &&__t1, _T2Like &&__t2)
: _T1((_T1Like &&) __t1), __t2_val((_T2Like &&) __t2) {}
Expand All @@ -103,7 +103,7 @@ struct __compressed_pair<
_T1, _T2,
std::enable_if_t<!_MDSPAN_TRAIT(std::is_empty, _T1) && _MDSPAN_TRAIT(std::is_empty, _T2)>>
: private _T2 {
_T1 __t1_val;
_T1 __t1_val{};
MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 _T1 &__first() noexcept { return __t1_val; }
MDSPAN_FORCE_INLINE_FUNCTION constexpr _T1 const &__first() const noexcept {
return __t1_val;
Expand All @@ -116,19 +116,19 @@ struct __compressed_pair<
}

MDSPAN_INLINE_FUNCTION_DEFAULTED
constexpr __compressed_pair() noexcept = default;
constexpr __compressed_pair() = default;
MDSPAN_INLINE_FUNCTION_DEFAULTED
constexpr __compressed_pair(__compressed_pair const &) noexcept = default;
constexpr __compressed_pair(__compressed_pair const &) = default;
MDSPAN_INLINE_FUNCTION_DEFAULTED
constexpr __compressed_pair(__compressed_pair &&) noexcept = default;
constexpr __compressed_pair(__compressed_pair &&) = default;
MDSPAN_INLINE_FUNCTION_DEFAULTED
_MDSPAN_CONSTEXPR_14_DEFAULTED __compressed_pair &
operator=(__compressed_pair const &) noexcept = default;
operator=(__compressed_pair const &) = default;
MDSPAN_INLINE_FUNCTION_DEFAULTED
_MDSPAN_CONSTEXPR_14_DEFAULTED __compressed_pair &
operator=(__compressed_pair &&) noexcept = default;
operator=(__compressed_pair &&) = default;
MDSPAN_INLINE_FUNCTION_DEFAULTED
~__compressed_pair() noexcept = default;
~__compressed_pair() = default;

template <class _T1Like, class _T2Like>
MDSPAN_INLINE_FUNCTION constexpr __compressed_pair(_T1Like &&__t1, _T2Like &&__t2)
Expand Down Expand Up @@ -169,19 +169,19 @@ struct __compressed_pair<
}

MDSPAN_INLINE_FUNCTION_DEFAULTED
constexpr __compressed_pair() noexcept = default;
constexpr __compressed_pair() = default;
MDSPAN_INLINE_FUNCTION_DEFAULTED
constexpr __compressed_pair(__compressed_pair const &) noexcept = default;
constexpr __compressed_pair(__compressed_pair const &) = default;
MDSPAN_INLINE_FUNCTION_DEFAULTED
constexpr __compressed_pair(__compressed_pair &&) noexcept = default;
constexpr __compressed_pair(__compressed_pair &&) = default;
MDSPAN_INLINE_FUNCTION_DEFAULTED
_MDSPAN_CONSTEXPR_14_DEFAULTED __compressed_pair &
operator=(__compressed_pair const &) noexcept = default;
operator=(__compressed_pair const &) = default;
MDSPAN_INLINE_FUNCTION_DEFAULTED
_MDSPAN_CONSTEXPR_14_DEFAULTED __compressed_pair &
operator=(__compressed_pair &&) noexcept = default;
operator=(__compressed_pair &&) = default;
MDSPAN_INLINE_FUNCTION_DEFAULTED
~__compressed_pair() noexcept = default;
~__compressed_pair() = default;
template <class _T1Like, class _T2Like>
MDSPAN_INLINE_FUNCTION constexpr __compressed_pair(_T1Like &&__t1, _T2Like &&__t2) noexcept
: __first_base_t(_T1((_T1Like &&) __t1)),
Expand Down
43 changes: 27 additions & 16 deletions include/experimental/__p0009_bits/mdspan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ class mdspan
ReferenceType __callop(mdspan const& __self, const std::array<SizeType, N>& indices) noexcept {
return __self.__accessor_ref().access(__self.__ptr_ref(), __self.__mapping_ref()(indices[Idxs]...));
}
#ifdef __cpp_lib_span
template <class ReferenceType, class SizeType, size_t N>
MDSPAN_FORCE_INLINE_FUNCTION static constexpr
ReferenceType __callop(mdspan const& __self, const std::span<SizeType, N>& indices) noexcept {
return __self.__accessor_ref().access(__self.__ptr_ref(), __self.__mapping_ref()(indices[Idxs]...));
}
#endif
};

public:
Expand Down Expand Up @@ -183,6 +190,10 @@ class mdspan
_MDSPAN_TRAIT(std::is_constructible, accessor_type, const OtherAccessor&)
)
)
MDSPAN_CONDITIONAL_EXPLICIT(
!_MDSPAN_TRAIT(std::is_convertible, const typename OtherLayoutPolicy::template mapping<OtherExtents>&, mapping_type) ||
!_MDSPAN_TRAIT(std::is_convertible, const OtherAccessor&, accessor_type)
)
MDSPAN_INLINE_FUNCTION
constexpr mdspan(const mdspan<OtherElementType, OtherExtents, OtherLayoutPolicy, OtherAccessor>& other)
: __members(other.__ptr_ref(), __map_acc_pair_t(other.__mapping_ref(), other.__accessor_ref()))
Expand Down Expand Up @@ -226,8 +237,8 @@ class mdspan
MDSPAN_TEMPLATE_REQUIRES(
class SizeType,
/* requires */ (
_MDSPAN_TRAIT(std::is_convertible, SizeType, index_type) &&
_MDSPAN_TRAIT(std::is_nothrow_constructible, index_type, SizeType)
_MDSPAN_TRAIT(std::is_convertible, const SizeType&, index_type) &&
_MDSPAN_TRAIT(std::is_nothrow_constructible, index_type, const SizeType&)
)
)
MDSPAN_FORCE_INLINE_FUNCTION
Expand All @@ -240,8 +251,8 @@ class mdspan
MDSPAN_TEMPLATE_REQUIRES(
class SizeType,
/* requires */ (
_MDSPAN_TRAIT(std::is_convertible, SizeType, index_type) &&
_MDSPAN_TRAIT(std::is_nothrow_constructible, index_type, SizeType)
_MDSPAN_TRAIT(std::is_convertible, const SizeType&, index_type) &&
_MDSPAN_TRAIT(std::is_nothrow_constructible, index_type, const SizeType&)
)
)
MDSPAN_FORCE_INLINE_FUNCTION
Expand Down Expand Up @@ -285,8 +296,8 @@ class mdspan
MDSPAN_TEMPLATE_REQUIRES(
class SizeType,
/* requires */ (
_MDSPAN_TRAIT(std::is_convertible, SizeType, index_type) &&
_MDSPAN_TRAIT(std::is_nothrow_constructible, index_type, SizeType)
_MDSPAN_TRAIT(std::is_convertible, const SizeType&, index_type) &&
_MDSPAN_TRAIT(std::is_nothrow_constructible, index_type, const SizeType&)
)
)
MDSPAN_FORCE_INLINE_FUNCTION
Expand All @@ -299,8 +310,8 @@ class mdspan
MDSPAN_TEMPLATE_REQUIRES(
class SizeType,
/* requires */ (
_MDSPAN_TRAIT(std::is_convertible, SizeType, index_type) &&
_MDSPAN_TRAIT(std::is_nothrow_constructible, index_type, SizeType)
_MDSPAN_TRAIT(std::is_convertible, const SizeType&, index_type) &&
_MDSPAN_TRAIT(std::is_nothrow_constructible, index_type, const SizeType&)
)
)
MDSPAN_FORCE_INLINE_FUNCTION
Expand All @@ -311,7 +322,7 @@ class mdspan
#endif // __cpp_lib_span
#endif // MDSPAN_USE_PAREN_OPERATOR

MDSPAN_INLINE_FUNCTION constexpr size_t size() const noexcept {
MDSPAN_INLINE_FUNCTION constexpr size_type size() const noexcept {
return __impl::__size(*this);
};

Expand Down Expand Up @@ -346,13 +357,13 @@ class mdspan
//--------------------------------------------------------------------------------
// [mdspan.basic.obs], mdspan observers of the mapping

MDSPAN_INLINE_FUNCTION static constexpr bool is_always_unique() noexcept { return mapping_type::is_always_unique(); };
MDSPAN_INLINE_FUNCTION static constexpr bool is_always_exhaustive() noexcept { return mapping_type::is_always_exhaustive(); };
MDSPAN_INLINE_FUNCTION static constexpr bool is_always_strided() noexcept { return mapping_type::is_always_strided(); };
MDSPAN_INLINE_FUNCTION static constexpr bool is_always_unique() { return mapping_type::is_always_unique(); };
MDSPAN_INLINE_FUNCTION static constexpr bool is_always_exhaustive() { return mapping_type::is_always_exhaustive(); };
MDSPAN_INLINE_FUNCTION static constexpr bool is_always_strided() { return mapping_type::is_always_strided(); };

MDSPAN_INLINE_FUNCTION constexpr bool is_unique() const noexcept { return __mapping_ref().is_unique(); };
MDSPAN_INLINE_FUNCTION constexpr bool is_exhaustive() const noexcept { return __mapping_ref().is_exhaustive(); };
MDSPAN_INLINE_FUNCTION constexpr bool is_strided() const noexcept { return __mapping_ref().is_strided(); };
MDSPAN_INLINE_FUNCTION constexpr bool is_unique() const { return __mapping_ref().is_unique(); };
MDSPAN_INLINE_FUNCTION constexpr bool is_exhaustive() const { return __mapping_ref().is_exhaustive(); };
MDSPAN_INLINE_FUNCTION constexpr bool is_strided() const { return __mapping_ref().is_strided(); };
MDSPAN_INLINE_FUNCTION constexpr index_type stride(size_t r) const { return __mapping_ref().stride(r); };

private:
Expand All @@ -374,7 +385,7 @@ class mdspan
#if defined(_MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION)
MDSPAN_TEMPLATE_REQUIRES(
class ElementType, class... SizeTypes,
/* requires */ _MDSPAN_FOLD_AND(_MDSPAN_TRAIT(std::is_integral, SizeTypes) /* && ... */) &&
/* requires */ _MDSPAN_FOLD_AND(_MDSPAN_TRAIT(std::is_convertible, SizeTypes, size_t) /* && ... */) &&
(sizeof...(SizeTypes) > 0)
)
MDSPAN_DEDUCTION_GUIDE explicit mdspan(ElementType*, SizeTypes...)
Expand Down
10 changes: 6 additions & 4 deletions include/experimental/__p1684_bits/mdarray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,9 @@ class mdarray {
class OtherElementType, class OtherExtents,
class OtherLayoutType, class OtherAccessorType,
/* requires */ (
_MDSPAN_TRAIT(std::is_assignable, mdspan_type,
mdspan<OtherElementType, OtherExtents, OtherLayoutType, OtherAccessorType>)
_MDSPAN_TRAIT(std::is_assignable,
mdspan<OtherElementType, OtherExtents, OtherLayoutType, OtherAccessorType>,
mdspan_type)
)
)
constexpr operator mdspan<OtherElementType, OtherExtents, OtherLayoutType, OtherAccessorType> () {
Expand All @@ -445,8 +446,9 @@ class mdarray {
class OtherElementType, class OtherExtents,
class OtherLayoutType, class OtherAccessorType,
/* requires */ (
_MDSPAN_TRAIT(std::is_assignable, const_mdspan_type,
mdspan<OtherElementType, OtherExtents, OtherLayoutType, OtherAccessorType>)
_MDSPAN_TRAIT(std::is_assignable,
mdspan<OtherElementType, OtherExtents, OtherLayoutType, OtherAccessorType>,
const_mdspan_type)
)
)
constexpr operator mdspan<OtherElementType, OtherExtents, OtherLayoutType, OtherAccessorType> () const {
Expand Down
1 change: 1 addition & 0 deletions tests/libcxx-backports/CustomTestLayouts.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ class layout_wrapping_integral<WrapArg>::mapping {

#if MDSPAN_HAS_CXX_23
friend constexpr void swap(mapping& x, mapping& y) noexcept {
using std::swap;
swap(x.extents_, y.extents_);
if !consteval {
swap_counter()++;
Expand Down
6 changes: 3 additions & 3 deletions tests/libcxx-backports/mdspan/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mdspan_add_test(mdspan.assign.pass)
#mdspan_add_test(mdspan.conversion.pass) //FIXME
mdspan_add_test(mdspan.conversion.pass)
#mdspan_add_test(mdspan.conversion.verify)
mdspan_add_test(mdspan.ctor.copy.pass)
mdspan_add_test(mdspan.ctor.default.pass)
Expand All @@ -13,9 +13,9 @@ mdspan_add_test(mdspan.ctor.move.pass)
mdspan_add_test(mdspan.deduction.pass)
#mdspan_add_test(mdspan.element_type.verify)
#mdspan_add_test(mdspan.extents.verify)
#mdspan_add_test(mdspan.index_operator.pass) //FIXME
mdspan_add_test(mdspan.index_operator.pass)
#mdspan_add_test(mdspan.mapping.verify)
mdspan_add_test(mdspan.move.pass)
mdspan_add_test(mdspan.properties.pass)
#mdspan_add_test(mdspan.swap.pass) //FIXME
mdspan_add_test(mdspan.swap.pass)
mdspan_add_test(mdspan.types.pass)
2 changes: 1 addition & 1 deletion tests/libcxx-backports/mdspan/mdspan.ctor.copy.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ constexpr void test_mdspan_types(const H& handle, const M& map, const A& acc) {

MDS m_org(handle, map, acc);
MDS m(m_org);
//static_assert(noexcept(MDS(m_org)) == (noexcept(H(handle))&& noexcept(M(map))&& noexcept(A(acc)))); //FIXME
static_assert(noexcept(MDS(m_org)) == (noexcept(H(handle))&& noexcept(M(map))&& noexcept(A(acc))));
static_assert(
std::is_trivially_copyable_v<MDS> ==
(std::is_trivially_copyable_v<H> && std::is_trivially_copyable_v<M> && std::is_trivially_copyable_v<A>));
Expand Down
4 changes: 2 additions & 2 deletions tests/libcxx-backports/mdspan/mdspan.ctor.default.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ constexpr void test_mdspan_types(const H&, const M&, const A&) {

if constexpr (MDS::rank_dynamic() > 0 && hc && mc && ac) {
MDS m;
//static_assert(noexcept(MDS()) == (noexcept(H())&& noexcept(M())&& noexcept(A()))); //FIXME
static_assert(noexcept(MDS()) == (noexcept(H())&& noexcept(M())&& noexcept(A())));
assert(m.extents() == typename MDS::extents_type());
if constexpr (std::equality_comparable<H>)
assert(m.data_handle() == H());
Expand Down Expand Up @@ -106,6 +106,6 @@ constexpr bool test() {
}
int main(int, char**) {
test();
// static_assert(test()); //FIXME
static_assert(test());
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ constexpr void test_mdspan_types(const H& handle, const M& map, const A&) {
if constexpr (std::equality_comparable<A>)
assert(m.accessor() == A());
} else {
//static_assert(!std::is_constructible_v<MDS, const H&, const typename M::extents_type&>); //FIXME
static_assert(!std::is_constructible_v<MDS, const H&, const typename M::extents_type&>);
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/libcxx-backports/mdspan/mdspan.ctor.dh_span.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ constexpr void test_mdspan_ctor(const H& handle, const M& map, const A& acc) {
template <bool mec, bool ac, class H, class L, class A>
constexpr void mixin_extents(const H& handle, const L& layout, const A& acc) {
constexpr size_t D = std::dynamic_extent;
//test_mdspan_ctor<mec, ac>(handle, construct_mapping(layout, std::extents<int>()), acc); //FIXME
test_mdspan_ctor<mec, ac>(handle, construct_mapping(layout, std::extents<int>()), acc);
test_mdspan_ctor<mec, ac>(handle, construct_mapping(layout, std::extents<char, D>(7)), acc);
//test_mdspan_ctor<mec, ac>(handle, construct_mapping(layout, std::extents<unsigned, 7>()), acc); //FIXME
test_mdspan_ctor<mec, ac>(handle, construct_mapping(layout, std::extents<unsigned, 7>()), acc);
test_mdspan_ctor<mec, ac>(handle, construct_mapping(layout, std::extents<size_t, D, 4, D>(2, 3)), acc);
test_mdspan_ctor<mec, ac>(handle, construct_mapping(layout, std::extents<char, D, 7, D>(0, 3)), acc);
test_mdspan_ctor<mec, ac>(
Expand Down
2 changes: 1 addition & 1 deletion tests/libcxx-backports/mdspan/mdspan.deduction.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ constexpr bool test_no_layout_deduction_guides(const H& handle, const A&) {
// deduction from pointer alone
ASSERT_SAME_TYPE(decltype(std::mdspan(handle)), std::mdspan<T, std::extents<size_t>>);
// deduction from pointer and integral like
//ASSERT_SAME_TYPE(decltype(std::mdspan(handle, 5, SizeTIntType(6))), std::mdspan<T, std::dextents<size_t, 2>>); //FIXME
ASSERT_SAME_TYPE(decltype(std::mdspan(handle, 5, SizeTIntType(6))), std::mdspan<T, std::dextents<size_t, 2>>);

std::array<char, 3> exts;
// deduction from pointer and array
Expand Down
6 changes: 6 additions & 0 deletions tests/libcxx-backports/mdspan/mdspan.index_operator.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
#include "../ConvertibleToIntegral.h"
#include "../CustomTestLayouts.h"

// This test uses the bracket operator, but its not something we have at configure time
#if MDSPAN_USE_BRACKET_OPERATOR

// Clang 16 does not support argument packs as input to operator []
#if defined(__clang_major__) && __clang_major__ < 17
template <class MDS>
Expand Down Expand Up @@ -254,6 +257,9 @@ int main(int, char**) {
test_large();
return 0;
}

#endif // MDSPAN_USE_BRACKET_OPERATOR

#if defined(__GNUC__) && !defined(__clang_major__)
# pragma GCC diagnostic pop
#endif
Loading

0 comments on commit 417204e

Please sign in to comment.