Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
mdspan: Facilities For Multidimensional Arrays

The mdspan sub-package provides a set of classes and functions for manipulating multidimensional arrays.

The public header is

The Bazel target is

//:mdspan

Introduction

This package provides the following classes and functions for describing and viewing multidimensional array data, as backports of the corresponding facilities from C++23.

Extensions

This package provides the following type traits as extensions on the C++23 facilities.

Axis views

arene::base::axis_view<Axis> takes an mdspan and returns a range over its slices along axis Axis. The i-th element of that range is the slice obtained by fixing axis Axis at i while keeping every other axis in full, so each slice has a rank one less than the source.

// Iterate the rows and columns of a rank-2 mdspan.
void print_rows_and_columns(arene::base::mdspan<int const, arene::base::dextents<std::size_t, 2>> matrix) {
for (auto row : arene::base::axis_view<0>(matrix)) {
// row == submdspan(matrix, i, full_extent) for successive i: the i-th row of matrix
std::cout << "row of length " << row.extent(0) << "\n";
}
for (auto column : arene::base::axis_view<1>(matrix)) {
// column == submdspan(matrix, full_extent, i) for successive i: the i-th column of matrix
std::cout << "column of length " << column.extent(0) << "\n";
}
}

The slices are views of the source rather than copies, so no elements are copied. For the rank-2 case, arene::base::linalg::row_view and arene::base::linalg::column_view name the same operation in matrix terms.