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?
submdspan
can help. – Underglazestd::span
, right? – Autosome5
can not conveniently be a template parameter because it is a runtime variable. By providing the 5 to the constructor ofmatrix
there is no reasonable way to make themdspan
aware at compile time that the second extent always has 5 elements. The best you can do here isstd::span<float, std::dynamic_extent>
. – Ventomdspan
, e.g.std::layout_left
will give contiguous columns but strided rows. For this reason there can't be a direct conversion tostd::span
. Maybe one could add a direct conversion to astd::ranges::stride_view
in the future but even that wont work for some custom layouts. – Hoofed