Skip to content
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

<mdspan>: Remove old tests #3767

Merged

Conversation

JMazurkiewicz
Copy link
Contributor

@JMazurkiewicz JMazurkiewicz commented Jun 13, 2023

The main goal of this PR is to remove old tests implemented by Matt Stephanson:

  • Remove tests/std/tests/P0009R18_mdspan directory,
  • Preserve some tests from P0009R18_mdspan that were not present in new fragmented test suite,
  • Fix layout_right's constructor noexcept specifier,
  • test_mdspan_support.hpp: implement get_mapping_properties function that manually computes properties of layout mapping. This is based on Matt Stephanson's TestMapping function:
    template <class Mapping, enable_if_t<Mapping::extents_type::rank() == 2, int> = 0>
    void TestMapping(const Mapping& map) {
    using IndexT = typename Mapping::index_type;
    using RankT = typename Mapping::rank_type;
    static_assert(is_same_v<IndexT, decltype(declval<Mapping>()(IndexT{0}, IndexT{0}))>);
    static_assert(is_same_v<IndexT, decltype(declval<Mapping>().stride(RankT{0}))>);
    array<IndexT, Mapping::extents_type::rank()> s;
    const auto& e = map.extents();
    size_t num_entries = 1;
    for (size_t i = 0; i < Mapping::extents_type::rank(); ++i) {
    num_entries *= e.extent(i);
    s[i] = map.stride(i);
    }
    vector<IndexT> indices;
    indices.reserve(num_entries);
    for (IndexT i = 0; i < e.extent(0); ++i) {
    for (IndexT j = 0; j < e.extent(1); ++j) {
    const auto idx = i * s[0] + j * s[1];
    assert(map(i, j) == idx);
    indices.push_back(idx);
    }
    }
    bool is_unique = true;
    bool is_exhaust = true;
    sort(indices.begin(), indices.end());
    for (size_t i = 1; i < indices.size(); ++i) {
    const auto diff = indices[i] - indices[i - 1];
    if (diff == 0) {
    is_unique = false;
    } else if (diff != 1) {
    is_exhaust = false;
    }
    }
    assert(map.is_unique() == is_unique);
    assert(map.is_exhaustive() == is_exhaust);
    assert(map.required_span_size() == indices.back() + 1);
    }
    template <class Mapping, enable_if_t<Mapping::extents_type::rank() == 3, int> = 0>
    void TestMapping(const Mapping& map) {
    using IndexT = typename Mapping::index_type;
    using RankT = typename Mapping::rank_type;
    static_assert(is_same_v<IndexT, decltype(declval<Mapping>()(IndexT{0}, IndexT{0}, IndexT{0}))>);
    static_assert(is_same_v<IndexT, decltype(declval<Mapping>().stride(RankT{0}))>);
    array<IndexT, Mapping::extents_type::rank()> s;
    const auto& e = map.extents();
    size_t num_entries = 1;
    for (size_t i = 0; i < Mapping::extents_type::rank(); ++i) {
    num_entries *= e.extent(i);
    s[i] = map.stride(i);
    }
    vector<IndexT> indices;
    indices.reserve(num_entries);
    for (IndexT i = 0; i < e.extent(0); ++i) {
    for (IndexT j = 0; j < e.extent(1); ++j) {
    for (IndexT k = 0; k < e.extent(2); ++k) {
    const auto idx = i * s[0] + j * s[1] + k * s[2];
    assert(map(i, j, k) == idx);
    indices.push_back(idx);
    }
    }
    }
    bool is_unique = true;
    bool is_exhaust = true;
    sort(indices.begin(), indices.end());
    for (size_t i = 1; i < indices.size(); ++i) {
    const auto diff = indices[i] - indices[i - 1];
    if (diff == 0) {
    is_unique = false;
    } else if (diff != 1) {
    is_exhaust = false;
    }
    }
    assert(map.is_unique() == is_unique);
    assert(map.is_exhaustive() == is_exhaust);
    assert(map.required_span_size() == indices.back() + 1);
    }
  • Drive-by: include <test_mdspan_support.hpp> instead of "test_mdspan_support.hpp" in tests,
  • Overall test coverage improvements.

@JMazurkiewicz JMazurkiewicz requested a review from a team as a code owner June 13, 2023 16:30
…st_mdspan_support.hpp>`"

And use `<test_mdspan_support.hpp>` instead of `"test_mdspan_support.hpp"`

This reverts commit 2654405.
@StephanTLavavej StephanTLavavej added test Related to test code mdspan C++23 mdspan labels Jun 13, 2023
@StephanTLavavej
Copy link
Member

StephanTLavavej commented Jun 13, 2023

FYI, I edited your PR description to permalink the TestMapping citation, because a non-permalink will be invalidated after this PR removes that directory.

@StephanTLavavej StephanTLavavej self-assigned this Jun 14, 2023
@StephanTLavavej StephanTLavavej removed their assignment Jun 16, 2023
@StephanTLavavej
Copy link
Member

Thanks! I pushed a conflict-free merge to pick up the recent toolset update, followed by simple changes to fix static_asserts that I'm 99.9% sure about - please meow if I was confused. I'll merge this after the tests pass.

@StephanTLavavej StephanTLavavej merged commit 34405b3 into microsoft:feature/mdspan2 Jun 17, 2023
@JMazurkiewicz JMazurkiewicz deleted the mdspan/remove-old-tests branch June 17, 2023 07:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mdspan C++23 mdspan test Related to test code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants