kokkos / mdspan

Reference implementation of mdspan targeting C++23
Other
415 stars 69 forks source link

`required_span_size` in `layout_stride` gives incorrect result #195

Closed youyu3 closed 1 year ago

youyu3 commented 2 years ago

In https://github.com/kokkos/mdspan/blob/stable/include/experimental/__p0009_bits/layout_stride.hpp, the line of

span_size = std::max(span_size, static_cast<index_type>(extents().extent(r) * __strides_storage()[r]));`

should be

span_size += static_cast<index_type>(extents().extent(r) - 1 ) * __strides_storage()[r];

to be consistent with the spec (http://eel.is/c++draft/views#mdspan.layout.stride.expo)

otherwise 1 plus the sum of products of (e.extent(r) - 1) and strides[r] for all r in the range [0, e.rank()).

mhoemmen commented 2 years ago

As a follow-on, if we fix this issue, we could simplify layout_stride::mapping::is_exhaustive() into return required_span_size() == size().

mhoemmen commented 2 years ago

See Compiler Explorer example for @youyu3 's original comment: https://godbolt.org/z/5z5T6GeP5