kokkos / mdspan

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

Submdspan returns rank 0 mdspan when all slice specifiers are integral value #322

Closed caaatch22 closed 7 months ago

caaatch22 commented 7 months ago
  std::array<int, 12> a;
  std::iota(a.begin(), a.end(), 0);

  auto sp = std::mdspan(a.data(), 2, 2, 3);
  auto p = std::submdspan(sp, 0, 1, std::full_extent);
  std::cout << "p.rank : " << p.rank() << '\n';  // p.rank : 1
  auto d = std::submdspan(sp, 0, 1, 2);
  std::cout << "d.rank : " << d.rank() << '\n';  // d.rank : 0
  std::cout << p[0] << '\n';
//   std::cout << d[0] << '\n'; // this won't compile

Is this a bug or intention? since we may need a mdspan with only one value by submdspan method or we must write auto d = std::submdspan(sp, 0, 0, tuple{0, 1}) ?

dalg24 commented 7 months ago

It is by design. When you do auto d = std::submdspan(sp, 0, 1, 2);, d is rank-0 and you access the unique element via d[].