dune-common 2.12-git
Loading...
Searching...
No Matches
submdspan.hh File Reference

Slicing utilities for Dune::Std::mdspan. More...

Go to the source code of this file.

Namespaces

namespace  Dune
 Dune namespace
 
namespace  Dune::Std
 Namespace for features backported from new C++ standards.
 

Functions

template<class IndexType , std::size_t... exts, class... SliceSpecifiers, std::enable_if_t<(sizeof...(SliceSpecifiers)==sizeof...(exts)), int > = 0>
constexpr auto Dune::Std::subextents (const extents< IndexType, exts... > &src, SliceSpecifiers... slices)
 Return the extents produced by slicing a source extents object.
 
template<class Mapping , class... SliceSpecifiers, std::enable_if_t<(sizeof...(SliceSpecifiers)==Mapping::extents_type::rank()), int > = 0>
constexpr auto Dune::Std::submdspan_mapping (const Mapping &mapping, SliceSpecifiers... slices)
 Create the mapping and source-data offset produced by slicing a layout mapping.
 
template<class ElementType , class Extents , class LayoutPolicy , class AccessorPolicy , class... SliceSpecifiers, std::enable_if_t<(sizeof...(SliceSpecifiers)==Extents::rank()), int > = 0>
constexpr auto Dune::Std::submdspan (const mdspan< ElementType, Extents, LayoutPolicy, AccessorPolicy > &src, SliceSpecifiers... slices)
 Create an mdspan view by slicing an existing mdspan.
 

Detailed Description

Slicing utilities for Dune::Std::mdspan.

submdspan creates a non-owning view into an existing Dune::Std::mdspan. It follows the interface of std::submdspan from P2630R4 and the C++ standard working draft [mdspan.sub].

A slice specifier is provided for every source dimension. Each slice either fixes a dimension and removes it from the result rank, or keeps a dimension with a full, contiguous, or strided index set.

Supported slice specifiers:

The returned mdspan aliases the source data. The implementation preserves layout_right for fixed leading indices followed by full dimensions, e.g. row slices of a row-major tensor, and preserves layout_left for the symmetric fixed trailing-index case. Following P2642R0, contiguous submatrix-like slices of layout_left, layout_right, and the corresponding padded layouts return layout_left_padded or layout_right_padded when the resulting strides can be represented by those layouts. Other regular slices use layout_stride.

Examples:

Dune::Std::mdspan a(data.data(), 3, 4);
// Fix the first index: a rank-1 row view.
// Keep a half-open range of columns.
// Keep every second column.
// Fix both indices: a rank-0 mdspan.
auto entry = Dune::Std::submdspan(a, 1, 2);
constexpr auto submdspan(const mdspan< ElementType, Extents, LayoutPolicy, AccessorPolicy > &src, SliceSpecifiers... slices)
Create an mdspan view by slicing an existing mdspan.
Definition submdspan.hh:128
constexpr full_extent_t full_extent
Slice specifier selecting the full extent in one mdspan dimension.
Definition submdspan_slices.hh:33
A multi-dimensional non-owning array view.
Definition mdspan.hh:67
Slice specifier selecting extent entries starting at offset with a stride.
Definition submdspan_slices.hh:44
Slice specifier selecting the half-open range [first,last) with a stride.
Definition submdspan_slices.hh:68