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 parentheses vs bracket operator #842

Open
schnellerhase opened this issue Jul 7, 2024 · 0 comments
Open

mdspan parentheses vs bracket operator #842

schnellerhase opened this issue Jul 7, 2024 · 0 comments

Comments

@schnellerhase
Copy link
Contributor

Currently the Kokkos mdspan implementation is used in its parentheses mode.

After #838 is merged we should, at least in principle, be able to switch to the usage of bracket operators. However, this caused some compile time problems, that were not yet fixed.

For example, the following code does not compile (with gcc version 11.4).

#include "mdspan.hpp"

template <typename T, std::size_t D>
using mdspan_t = MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan<T, MDSPAN_IMPL_STANDARD_NAMESPACE::dextents<std::size_t, D>>;

template<class...IndexType>
void pass(IndexType... indices)
{
    static_assert(sizeof...(IndexType) == 2);
}

void test()
{
    mdspan_t<double, 2> span;
    static_assert(span.rank() == 2);

    std::array<std::size_t, 2> indices = {0, 0};
    static_assert(indices.size() == 2);
    span[indices];

    pass(0, 0);

    static_assert(std::is_convertible_v<decltype((0,0)), mdspan_t<double, 2>::index_type>);
    static_assert(std::is_nothrow_constructible_v<mdspan_t<double, 2>::index_type, decltype((0,0))>);

    span[0, 0]; // but this fails with (rank() == sizeof...(SizeTypes)) evaluating to False
}

To circumvent this and allow the increase of the C++ standard in use, we explicitly enforce the use of parentheses by setting the flag MDSPAN_USE_PAREN_OPERATOR. This needs to be reverted in after fixing the bracket operator problems.

Note: the necessary syntactical changes from (...) to [...] may be found at schnellerhase#2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants