3

I'm trying out the Kokkos reference mdspan implementation to see if it could be used to simplify some bits of code in our codebase. One thing that I would have intuitively assumed to be possible is to pick a row of a two dimensional std::mdspan and assign it to a std::span, e.g. somewhat like

float* data = ...

std::mdspan matrix (data, 2, 5);

std::span vector = matrix[0]; // <-- should be a std::span<float, std::dynamic_extent> viewing row 0 of matrix

After some research I didn't find an obvious straightforward way to achieve that, neither with member functions of mdspan nor with free functions from the std library. The only possibility I see at the moment I going back to the raw pointer level and write my own free functions to do that, which is not really as elegant as I expected. Am I overlooking something or is that really no feature of mdspan?

PluginPenguin
  • 1,576
  • 11
  • 25
  • 2
    Maybe [`submdspan`](https://github.com/kokkos/mdspan/blob/stable/include/experimental/__p2630_bits/submdspan.hpp) can help. – 康桓瑋 Aug 15 '23 at 13:21
  • Thanks, but this does not offer direct conversion to `std::span`, right? – PluginPenguin Aug 15 '23 at 14:17
  • 1
    The `5` can not conveniently be a template parameter because it is a runtime variable. By providing the 5 to the constructor of `matrix` there is no reasonable way to make the `mdspan` aware at compile time that the second extent always has 5 elements. The best you can do here is `std::span`. – Mestkon Aug 15 '23 at 14:28
  • Ah yes of course @Mestkon. I'm aware of that, fixed it in the question above – PluginPenguin Aug 15 '23 at 14:53

0 Answers0