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

Constraint on layout_{left|right|stride}::stride is not implemented #201

Open
youyu3 opened this issue Oct 20, 2022 · 6 comments
Open

Constraint on layout_{left|right|stride}::stride is not implemented #201

youyu3 opened this issue Oct 20, 2022 · 6 comments

Comments

@youyu3
Copy link
Contributor

youyu3 commented Oct 20, 2022

Per http://eel.is/c++draft/mdspan.layout.left.obs#5, should have

constexpr index_type stride(rank_type i) const;
Constraints: extents_­type​::​rank() > 0 is true

But is not implemented, for example: https://github.com/kokkos/mdspan/blob/stable/include/experimental/__p0009_bits/layout_left.hpp#L206

stride(0) returns 1 for a 0-D mapping (stdex::extents<size_t>).

@youyu3
Copy link
Contributor Author

youyu3 commented Oct 20, 2022

One possible fix is to have the following

    MDSPAN_TEMPLATE_REQUIRES(
      class E = Extents,
      /* requires */ (
        E::rank() > 0
      )
    )
    MDSPAN_INLINE_FUNCTION
    constexpr index_type stride(rank_type i) const noexcept {
      ...
    }

@youyu3
Copy link
Contributor Author

youyu3 commented Oct 20, 2022

stride isn't listed on http://eel.is/c++draft/mdspan.layout.stride.obs for layout_stride (it is on http://eel.is/c++draft/mdspan.layout.stride.overview), but I suppose it should have the same constraint?

@mhoemmen
Copy link
Contributor

mhoemmen commented Oct 20, 2022

@youyu3 We defined layout_stride::mapping::stride using the exposition-only array<index_type, rank_> strides_. I suppose that one could be constrained too, but it doesn't need any constraints. It gets its precondition -- that the input is in [0, rank()) -- indirectly from the operator[] sequence container requirements.

@youyu3
Copy link
Contributor Author

youyu3 commented Oct 20, 2022

So is the behavior here https://godbolt.org/z/qWsnjeebT expected, i.e., stride(0) doesn't lead to a compilation error when the rank of the extent is 0?

@mhoemmen
Copy link
Contributor

That is not the correct behavior per http://eel.is/c++draft/views#mdspan.layout.left.obs .

youyu3 added a commit to youyu3/libcudacxx that referenced this issue Oct 20, 2022
* Return type of `layout_stride::operator()` should be `index_type` (kokkos/mdspan#200)
* Constraint on `stride()` is not implemented (kokkos/mdspan#201)
@crtrott
Copy link
Member

crtrott commented Nov 22, 2022

@youyu3 can you issue that PR against kokkos/mdspan too?

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

No branches or pull requests

3 participants