Skip to content

Commit

Permalink
Merge pull request #212 from crtrott/new-extents-impl
Browse files Browse the repository at this point in the history
New extents implementation
  • Loading branch information
crtrott authored Apr 4, 2023
2 parents b31a635 + 2d8f8ef commit a9489ae
Show file tree
Hide file tree
Showing 18 changed files with 583 additions and 1,517 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,10 @@ if(MDSPAN_ENABLE_EXAMPLES)
endif()

if(MDSPAN_ENABLE_BENCHMARKS)
if(NOT MDSPAN_CXX_STANDARD STREQUAL "14")
if(NOT MDSPAN_CXX_STANDARD STREQUAL "14" AND NOT MDSPAN_CXX_STANDARD STREQUAL "23")
add_subdirectory(benchmarks)
else()
MESSAGE(FATAL_ERROR "Benchmarks are not available in C++14 mode. Turn MDSPAN_ENABLE_BENCHMARKS OFF or use C++17 or newer.")
MESSAGE(FATAL_ERROR "Benchmarks are not available in C++14 or C++23 mode. Turn MDSPAN_ENABLE_BENCHMARKS OFF or use C++17 or C++20.")
endif()
endif()

Expand Down
97 changes: 90 additions & 7 deletions compilation_tests/ctest_extents_ctors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

namespace stdex = std::experimental;


MDSPAN_STATIC_TEST(
std::is_constructible<
stdex::extents<size_t,1, 2, stdex::dynamic_extent>,
Expand Down Expand Up @@ -56,10 +57,11 @@ MDSPAN_STATIC_TEST(
>::value
);

// constructibility test from integrals
MDSPAN_STATIC_TEST(
std::is_constructible<
stdex::extents<size_t,stdex::dynamic_extent, stdex::dynamic_extent, stdex::dynamic_extent>,
int, int, int
int, size_t, int
>::value
);

Expand All @@ -77,6 +79,7 @@ MDSPAN_STATIC_TEST(
>::value
);

// conversion construction from extents
MDSPAN_STATIC_TEST(
std::is_constructible<
stdex::extents<size_t,stdex::dynamic_extent, stdex::dynamic_extent, stdex::dynamic_extent>,
Expand All @@ -92,35 +95,95 @@ MDSPAN_STATIC_TEST(
>::value
);

MDSPAN_STATIC_TEST(
std::is_constructible<
stdex::extents<size_t,2, stdex::dynamic_extent>,
stdex::extents<size_t,2, 3>
>::value
);

#if MDSPAN_HAS_CXX_20
// GNU gets the is_convertible with conditional explicit
// wrong in some older versions.
#if !defined(__GNUC__) || (__GNUC__ > 10)
MDSPAN_STATIC_TEST(
!std::is_convertible<
stdex::extents<size_t,3, 2>,
stdex::extents<size_t,2, stdex::dynamic_extent>
stdex::extents<size_t,2, stdex::dynamic_extent>,
stdex::extents<size_t,2, 3>
>::value
);
#endif
#endif


MDSPAN_STATIC_TEST(
std::is_constructible<
stdex::extents<size_t,2, stdex::dynamic_extent>,
stdex::extents<size_t,2, 3>
stdex::extents<size_t>,
stdex::extents<int>
>::value
);

MDSPAN_STATIC_TEST(
std::is_convertible<
stdex::extents<int>,
stdex::extents<size_t>
>::value
);

MDSPAN_STATIC_TEST(
std::is_constructible<
stdex::extents<int>,
stdex::extents<size_t>
>::value
);

#if MDSPAN_HAS_CXX_20
// GNU gets the is_convertible with conditional explicit
// wrong in some older versions.
#if !defined(__GNUC__) || (__GNUC__ > 10)
MDSPAN_STATIC_TEST(
!std::is_convertible<
stdex::extents<size_t>,
stdex::extents<int>
>::value
);
#endif
#endif

MDSPAN_STATIC_TEST(
std::is_constructible<
stdex::extents<size_t,2, stdex::dynamic_extent>,
std::array<int,1>
std::array<int, 1>
>::value
);

MDSPAN_STATIC_TEST(
std::is_convertible<
std::array<int, 1>,
stdex::extents<size_t,2, stdex::dynamic_extent>
>::value
);

MDSPAN_STATIC_TEST(
std::is_constructible<
stdex::extents<size_t,2, stdex::dynamic_extent>,
std::array<int,2>
std::array<int, 2>
>::value
);

#if MDSPAN_HAS_CXX_20
// GNU gets the is_convertible with conditional explicit
// wrong in some older versions.
#if !defined(__GNUC__) || (__GNUC__ > 10)
MDSPAN_STATIC_TEST(
!std::is_convertible<
std::array<int, 2>,
stdex::extents<size_t,2, stdex::dynamic_extent>
>::value
);
#endif
#endif

MDSPAN_STATIC_TEST(
!std::is_constructible<
stdex::extents<size_t,2, stdex::dynamic_extent>,
Expand All @@ -136,13 +199,33 @@ MDSPAN_STATIC_TEST(
>::value
);

MDSPAN_STATIC_TEST(
std::is_convertible<
std::span<int,1>,
stdex::extents<size_t,2, stdex::dynamic_extent>
>::value
);

MDSPAN_STATIC_TEST(
std::is_constructible<
stdex::extents<size_t,2, stdex::dynamic_extent>,
std::span<int,2>
>::value
);

#if MDSPAN_HAS_CXX_20
// GNU gets the is_convertible with conditional explicit
// wrong in some older versions.
#if !defined(__GNUC__) || (__GNUC__ > 10)
MDSPAN_STATIC_TEST(
!std::is_convertible<
std::span<int, 2>,
stdex::extents<size_t,2, stdex::dynamic_extent>
>::value
);
#endif
#endif

// this is not supported in the standard
MDSPAN_STATIC_TEST(
!std::is_constructible<
Expand Down
2 changes: 2 additions & 0 deletions compilation_tests/ctest_no_unique_address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ MDSPAN_STATIC_TEST(
sizeof(stdex::extents<size_t,45, stdex::dynamic_extent, 1>) == sizeof(ptrdiff_t)
);

#ifdef _MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS
MDSPAN_STATIC_TEST(
std::is_empty<stdex::extents<size_t,1, 2, 3>>::value
);

MDSPAN_STATIC_TEST(
std::is_empty<stdex::extents<size_t,42>>::value
);
#endif

// </editor-fold> end extents }}}1
//==============================================================================
Expand Down
19 changes: 0 additions & 19 deletions compilation_tests/ctest_standard_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,6 @@

namespace stdex = std::experimental;

//==============================================================================
// <editor-fold desc="helper utilities"> {{{1

MDSPAN_STATIC_TEST(
!std::is_base_of<stdex::extents<int, 1, 2, 3>, stdex::detail::__partially_static_sizes<int, size_t, 1, 2, 3>>::value
);

MDSPAN_STATIC_TEST(
!std::is_base_of<stdex::detail::__partially_static_sizes<int, size_t, 1, 2, 3>, stdex::extents<int, 1, 2, 3>>::value
);

MDSPAN_STATIC_TEST(
std::is_standard_layout<
stdex::detail::__partially_static_sizes<int, size_t, 1, 2, 3>
>::value
);

// </editor-fold> end helper utilities }}}1
//==============================================================================

//==============================================================================
// <editor-fold desc="extents"> {{{1
Expand Down
19 changes: 0 additions & 19 deletions compilation_tests/ctest_trivially_copyable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,6 @@

namespace stdex = std::experimental;

//==============================================================================
// <editor-fold desc="helper utilities"> {{{1

MDSPAN_STATIC_TEST(
!std::is_base_of<stdex::extents<int, 1, 2, 3>, stdex::detail::__partially_static_sizes<int, size_t, 1, 2, 3>>::value
);

MDSPAN_STATIC_TEST(
!std::is_base_of<stdex::detail::__partially_static_sizes<int, size_t, 1, 2, 3>, stdex::extents<int, 1, 2, 3>>::value
);

MDSPAN_STATIC_TEST(
std::is_trivially_copyable<
stdex::detail::__partially_static_sizes<int, size_t, 1, 2, 3>
>::value
);

// </editor-fold> end helper utilities }}}1
//==============================================================================

//==============================================================================
// <editor-fold desc="extents"> {{{1
Expand Down
8 changes: 8 additions & 0 deletions examples/dot_product/dot_product.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ T dot_product(
T result = 0;
for(int i = 0; i < a.extent(0); ++i) {
for(int j = 0; j < a.extent(1); ++j) {
#if MDSPAN_USE_BRACKET_OPERATOR
result += a[i, j] * b[i, j];
#else
result += a(i, j) * b(i, j);
#endif
}
}
return result;
Expand All @@ -78,7 +82,11 @@ void fill_in_order(
T count = 0;
for(int i = 0; i < a.extent(0); ++i) {
for(int j = 0; j < a.extent(1); ++j) {
#if MDSPAN_USE_BRACKET_OPERATOR
a[i, j] = count++;
#else
a(i, j) = count++;
#endif
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions examples/tiled_layout/simple_tiled_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,23 @@ int main() {
int failures = 0;
for (int irow = 0; irow < n_rows; ++irow) {
for (int icol = 0; icol < n_cols; ++icol) {
#if MDSPAN_USE_BRACKET_OPERATOR
if(tiled[irow, icol] != row_major[irow, icol]) {
std::cout << "Mismatch for entry " << irow << ", " << icol << ":" << std::endl;
std::cout << " tiled(" << irow << ", " << icol << ") = "
<< tiled[irow, icol] << std::endl;
std::cout << " row_major(" << irow << ", " << icol << ") = "
<< row_major[irow, icol] << std::endl;
#else
if(tiled(irow, icol) != row_major(irow, icol)) {
std::cout << "Mismatch for entry " << irow << ", " << icol << ":" << std::endl;
std::cout << " tiled(" << irow << ", " << icol << ") = "
<< tiled(irow, icol) << std::endl;
std::cout << " row_major(" << irow << ", " << icol << ") = "
<< row_major(irow, icol) << std::endl;
#endif
++failures;

}

}
Expand Down
Loading

0 comments on commit a9489ae

Please sign in to comment.