kokkos / mdspan

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

Comparison operators of `layout_stride` don't seem to work correctly #196

Closed youyu3 closed 1 year ago

youyu3 commented 2 years ago

Looks like the comparison operators of layout_stride don't work correctly when the extents are different but the strides are the same. See example for operator== here https://godbolt.org/z/Pc9o57xhq or below:

#include <https://raw.githubusercontent.com/kokkos/mdspan/single-header/mdspan.hpp>
#include <array>

namespace stdex = std::experimental;

int main() {

    constexpr auto dyn = stdex::dynamic_extent;

    {
        using index_t = size_t;
        using ext2d_t = stdex::extents<index_t,dyn,dyn>;
        stdex::extents<index_t,16,32> e0;
        stdex::extents<index_t,16,64> e1;
        std::array<index_t,2> a{1,16};
        stdex::layout_stride::mapping<ext2d_t> m0{e0, a};
        stdex::layout_stride::mapping<ext2d_t> m1{e1, a};

        assert( ( m0.extents() == m1.extents() ) == false );
        assert( ( m0 == m1 ) == true );
    }

    return 0;
}

Both _eq_impl and _not_eq_impl only check stride and don't check extent.

crtrott commented 2 years ago

Yeah definitely a bug.