Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
arene::base::layout_stride::mapping< Extents > Class Template Reference

A mapping from a logical pack of indices into a single flat physical output index, using a strided algorithm. More...

Inheritance diagram for arene::base::layout_stride::mapping< Extents >:
Inheritance graph

Public Types

using layout_type = layout_stride
 The tag type of the layout used by this mapping.
 

Public Member Functions

constexpr mapping () noexcept
 Construct a default strided mapping for the given extents, which has the same layout as layout_right.
 
constexpr mapping (extents_type const &exts, array< index_type, extents_type::rank()> const &strds, layout_detail::check_bypasser) noexcept
 Construct a mapping with the given strides, bypassing precondition checks.
 
template<class OtherIndexType, constraints< std::enable_if_t< std::is_convertible< OtherIndexType const &, index_type >::value >, std::enable_if_t< std::is_nothrow_constructible< index_type, OtherIndexType const & >::value > > = nullptr>
constexpr mapping (extents_type const &exts, array< OtherIndexType, extents_type::rank()> const &strds) noexcept
 Construct a mapping with the given strides; they must be valid for a default-constructed extents_type.
 
template<class OtherIndexType, constraints< std::enable_if_t< std::is_convertible< OtherIndexType const &, index_type >::value >, std::enable_if_t< std::is_nothrow_constructible< index_type, OtherIndexType const & >::value > > = nullptr>
constexpr mapping (extents_type const &exts, span< OtherIndexType, extents_type::rank()> strds) noexcept
 Construct a mapping with the given strides; they must be valid for a default-constructed extents_type.
 
template<class StridedLayoutMapping, constraints< std::enable_if_t< is_layout_mapping_v< StridedLayoutMapping > >, std::enable_if_t< std::is_constructible< extents_type, typename StridedLayoutMapping::extents_type >::value >, std::enable_if_t< StridedLayoutMapping::is_always_strided()>, std::enable_if_t< StridedLayoutMapping::is_always_unique()>, std::enable_if_t< layout_detail::implicit_conversion_ok< StridedLayoutMapping, mapping >::value > > = nullptr>
constexpr mapping (StridedLayoutMapping const &other) noexcept
 Construct a mapping from another strided mapping; implicit for certain known-safe mapping types.
 
template<class StridedLayoutMapping, constraints< std::enable_if_t< is_layout_mapping_v< StridedLayoutMapping > >, std::enable_if_t< std::is_constructible< extents_type, typename StridedLayoutMapping::extents_type >::value >, std::enable_if_t< StridedLayoutMapping::is_always_strided()>, std::enable_if_t< StridedLayoutMapping::is_always_unique()>, std::enable_if_t<!layout_detail::implicit_conversion_ok< StridedLayoutMapping, mapping >::value > > = nullptr>
constexpr mapping (StridedLayoutMapping const &other) noexcept
 Construct a mapping from another strided mapping; implicit for certain known-safe mapping types.
 
constexpr auto is_exhaustive () const noexcept -> bool
 Return whether or not this instance is exhaustive, i.e. every element is reachable using some indices.
 

Static Public Member Functions

static constexpr auto is_always_exhaustive () noexcept -> bool
 Return whether or not this mapping is always exhaustive, i.e. every element is reachable using some indices.
 

Friends

template<class Left, constraints< std::enable_if_t<!std::is_same< typename Left::layout_type, layout_stride >::value >, std::enable_if_t< is_layout_mapping_v< Left > >, std::enable_if_t< Left::extents_type::rank()==extents_type::rank()>, std::enable_if_t< Left::is_always_strided()> > = nullptr>
constexpr auto operator!= (Left const &left, mapping const &right) noexcept -> bool
 Compare two strided mappings for inequality, of which at least one must be a layout_stride::mapping.
 
template<class Right, constraints< std::enable_if_t< is_layout_mapping_v< Right > >, std::enable_if_t< Right::extents_type::rank()==extents_type::rank()>, std::enable_if_t< Right::is_always_strided()> > = nullptr>
constexpr auto operator!= (mapping const &left, Right const &right) noexcept -> bool
 Compare two strided mappings for inequality, of which at least one must be a layout_stride::mapping.
 
template<class Left, constraints< std::enable_if_t<!std::is_same< typename Left::layout_type, layout_stride >::value >, std::enable_if_t< is_layout_mapping_v< Left > >, std::enable_if_t< Left::extents_type::rank()==extents_type::rank()>, std::enable_if_t< Left::is_always_strided()> > = nullptr>
constexpr auto operator== (Left const &left, mapping const &right) noexcept -> bool
 Compare two strided mappings for equality, of which at least one must be a layout_stride::mapping.
 
template<class Right, constraints< std::enable_if_t< is_layout_mapping_v< Right > >, std::enable_if_t< Right::extents_type::rank()==extents_type::rank()>, std::enable_if_t< Right::is_always_strided()> > = nullptr>
constexpr auto operator== (mapping const &left, Right const &right) noexcept -> bool
 Compare two strided mappings for equality, of which at least one must be a layout_stride::mapping.
 
template<class SrcMapping, class... CanonicalSliceSpecifiers, constraints< std::enable_if_t< sizeof...(CanonicalSliceSpecifiers)==extents_type::rank()>, std::enable_if_t< mdspan_detail::all_valid_submdspan_slice_types_for_v< extents_type, CanonicalSliceSpecifiers... > > > = nullptr>
constexpr auto submdspan_mapping (SrcMapping const &src, CanonicalSliceSpecifiers... slices) noexcept -> submdspan_mapping_result< layout_stride::mapping< submdspan_subextents_type_t< extents_type, CanonicalSliceSpecifiers... > > >
 compute submdspan mapping and offset for a layout_stride mapping
 

Detailed Description

template<class Extents>
class arene::base::layout_stride::mapping< Extents >

A mapping from a logical pack of indices into a single flat physical output index, using a strided algorithm.

Template Parameters
Theextents of the space used for this mapping; must be a specialization of extents

Member Typedef Documentation

◆ layout_type

template<class Extents>
using arene::base::layout_stride::mapping< Extents >::layout_type = layout_stride

The tag type of the layout used by this mapping.

Constructor & Destructor Documentation

◆ mapping() [1/6]

template<class Extents>
arene::base::layout_stride::mapping< Extents >::mapping ( extents_type const & exts,
array< index_type, extents_type::rank()> const & strds,
layout_detail::check_bypasser  )
inlineconstexprnoexcept

Construct a mapping with the given strides, bypassing precondition checks.

Note
This can only be called from classes which inherit from layout_stride::mapping. It is used when slicing a layout_stride::mapping if the slice arguments are valid, so that the preconditions on the public constructors need not be re-checked.
Parameters
extsA set of extents to use for this mapping
strdsA set of strides to use for this mapping

◆ mapping() [2/6]

template<class Extents>
arene::base::layout_stride::mapping< Extents >::mapping ( )
inlineconstexprnoexcept

Construct a default strided mapping for the given extents, which has the same layout as layout_right.

◆ mapping() [3/6]

template<class Extents>
template<class OtherIndexType, constraints< std::enable_if_t< std::is_convertible< OtherIndexType const &, index_type >::value >, std::enable_if_t< std::is_nothrow_constructible< index_type, OtherIndexType const & >::value > > = nullptr>
arene::base::layout_stride::mapping< Extents >::mapping ( extents_type const & exts,
span< OtherIndexType, extents_type::rank()> strds )
inlineconstexprnoexcept

Construct a mapping with the given strides; they must be valid for a default-constructed extents_type.

Template Parameters
OtherIndexTypeThe original index type used by strds; must be convertible to index_type
Parameters
extsA set of extents to use for this mapping
strdsA set of strides to use for this mapping
Precondition
All strides are positive when converted to index_type
Size of the output index space is representable as index_type
strds defines a unique (one-to-one) mapping from exts

◆ mapping() [4/6]

template<class Extents>
template<class OtherIndexType, constraints< std::enable_if_t< std::is_convertible< OtherIndexType const &, index_type >::value >, std::enable_if_t< std::is_nothrow_constructible< index_type, OtherIndexType const & >::value > > = nullptr>
arene::base::layout_stride::mapping< Extents >::mapping ( extents_type const & exts,
array< OtherIndexType, extents_type::rank()> const & strds )
inlineconstexprnoexcept

Construct a mapping with the given strides; they must be valid for a default-constructed extents_type.

Template Parameters
OtherIndexTypeThe original index type used by strds; must be convertible to index_type
Parameters
extsA set of extents to use for this mapping
strdsA set of strides to use for this mapping
Precondition
All strides are positive when converted to index_type, else ARENE_PRECONDITION violation
Size of the output index space is representable as index_type, else ARENE_PRECONDITION violation
strds defines a unique (one-to-one) mapping from exts, else ARENE_PRECONDITION violation

◆ mapping() [5/6]

template<class Extents>
template<class StridedLayoutMapping, constraints< std::enable_if_t< is_layout_mapping_v< StridedLayoutMapping > >, std::enable_if_t< std::is_constructible< extents_type, typename StridedLayoutMapping::extents_type >::value >, std::enable_if_t< StridedLayoutMapping::is_always_strided()>, std::enable_if_t< StridedLayoutMapping::is_always_unique()>, std::enable_if_t< layout_detail::implicit_conversion_ok< StridedLayoutMapping, mapping >::value > > = nullptr>
arene::base::layout_stride::mapping< Extents >::mapping ( StridedLayoutMapping const & other)
inlineconstexprnoexcept

Construct a mapping from another strided mapping; implicit for certain known-safe mapping types.

Template Parameters
StridedLayoutMappingA layout mapping satisfying [mdspan.layout.reqmts] which is always strided and unique
Parameters
otherA mapping to convert
Precondition
All strides are positive when converted to index_type, else ARENE_PRECONDITION violation
Size of the output index space is representable as index_type, else ARENE_PRECONDITION violation
other(0, 0, 0...) == 0, else ARENE_PRECONDITION violation

◆ mapping() [6/6]

template<class Extents>
template<class StridedLayoutMapping, constraints< std::enable_if_t< is_layout_mapping_v< StridedLayoutMapping > >, std::enable_if_t< std::is_constructible< extents_type, typename StridedLayoutMapping::extents_type >::value >, std::enable_if_t< StridedLayoutMapping::is_always_strided()>, std::enable_if_t< StridedLayoutMapping::is_always_unique()>, std::enable_if_t<!layout_detail::implicit_conversion_ok< StridedLayoutMapping, mapping >::value > > = nullptr>
arene::base::layout_stride::mapping< Extents >::mapping ( StridedLayoutMapping const & other)
inlineexplicitconstexprnoexcept

Construct a mapping from another strided mapping; implicit for certain known-safe mapping types.

Template Parameters
StridedLayoutMappingA layout mapping satisfying [mdspan.layout.reqmts] which is always strided and unique
Parameters
otherA mapping to convert
Precondition
All strides are positive when converted to index_type, else ARENE_PRECONDITION violation
Size of the output index space is representable as index_type, else ARENE_PRECONDITION violation
other(0, 0, 0...) == 0, else ARENE_PRECONDITION violation

Member Function Documentation

◆ is_always_exhaustive()

template<class Extents>
static constexpr auto arene::base::layout_stride::mapping< Extents >::is_always_exhaustive ( ) -> bool
inlinestaticconstexprnoexcept

Return whether or not this mapping is always exhaustive, i.e. every element is reachable using some indices.

Returns
false because it's possible to construct non-exhaustive mappings using this class
Note
In mathematical terms this asks if the mapping is always surjective/onto.

◆ is_exhaustive()

template<class Extents>
auto arene::base::layout_stride::mapping< Extents >::is_exhaustive ( ) const -> bool
inlineconstexprnoexcept

Return whether or not this instance is exhaustive, i.e. every element is reachable using some indices.

Returns
true if every provided stride is the product of the extents corresponding to some subset of the other strides, otherwise false
Note
In mathematical terms this asks if the mapping is surjective/onto.

Friends And Related Symbol Documentation

◆ operator!= [1/2]

template<class Extents>
template<class Left, constraints< std::enable_if_t<!std::is_same< typename Left::layout_type, layout_stride >::value >, std::enable_if_t< is_layout_mapping_v< Left > >, std::enable_if_t< Left::extents_type::rank()==extents_type::rank()>, std::enable_if_t< Left::is_always_strided()> > = nullptr>
auto operator!= ( Left const & left,
mapping< Extents > const & right ) -> bool
friend

Compare two strided mappings for inequality, of which at least one must be a layout_stride::mapping.

Template Parameters
LeftThe type of the left side of the comparison; must be strided and satisfy is_layout_mapping_v
Parameters
leftAn instance of Left
rightAn instance of layout_stride::mapping
Returns
true if left and right have different extents or strides, or one doesn't map (0,0,...) to 0

◆ operator!= [2/2]

template<class Extents>
template<class Right, constraints< std::enable_if_t< is_layout_mapping_v< Right > >, std::enable_if_t< Right::extents_type::rank()==extents_type::rank()>, std::enable_if_t< Right::is_always_strided()> > = nullptr>
auto operator!= ( mapping< Extents > const & left,
Right const & right ) -> bool
friend

Compare two strided mappings for inequality, of which at least one must be a layout_stride::mapping.

Template Parameters
RightThe type of the right side of the comparison; must be strided and satisfy is_layout_mapping_v
Parameters
leftAn instance of layout_stride::mapping
rightAn instance of Right
Returns
true if left and right have different extents or strides, or one doesn't map (0,0,...) to 0

◆ operator== [1/2]

template<class Extents>
template<class Left, constraints< std::enable_if_t<!std::is_same< typename Left::layout_type, layout_stride >::value >, std::enable_if_t< is_layout_mapping_v< Left > >, std::enable_if_t< Left::extents_type::rank()==extents_type::rank()>, std::enable_if_t< Left::is_always_strided()> > = nullptr>
auto operator== ( Left const & left,
mapping< Extents > const & right ) -> bool
friend

Compare two strided mappings for equality, of which at least one must be a layout_stride::mapping.

Template Parameters
LeftThe type of the left side of the comparison; must be strided and satisfy is_layout_mapping_v
Parameters
leftAn instance of Left
rightAn instance of layout_stride::mapping
Returns
true if left and right have the same extents and strides, and both map (0,0,...) to 0

◆ operator== [2/2]

template<class Extents>
template<class Right, constraints< std::enable_if_t< is_layout_mapping_v< Right > >, std::enable_if_t< Right::extents_type::rank()==extents_type::rank()>, std::enable_if_t< Right::is_always_strided()> > = nullptr>
auto operator== ( mapping< Extents > const & left,
Right const & right ) -> bool
friend

Compare two strided mappings for equality, of which at least one must be a layout_stride::mapping.

Template Parameters
RightThe type of the right side of the comparison; must be strided and satisfy is_layout_mapping_v
Parameters
leftAn instance of layout_stride::mapping
rightAn instance of Right
Returns
true if left and right have the same extents and strides, and both map (0,0,...) to 0

◆ submdspan_mapping

template<class Extents>
template<class SrcMapping, class... CanonicalSliceSpecifiers, constraints< std::enable_if_t< sizeof...(CanonicalSliceSpecifiers)==extents_type::rank()>, std::enable_if_t< mdspan_detail::all_valid_submdspan_slice_types_for_v< extents_type, CanonicalSliceSpecifiers... > > > = nullptr>
auto submdspan_mapping ( SrcMapping const & src,
CanonicalSliceSpecifiers... slices ) -> submdspan_mapping_result< layout_stride::mapping<submdspan_subextents_type_t<extents_type, CanonicalSliceSpecifiers...>>>
friend

compute submdspan mapping and offset for a layout_stride mapping

Template Parameters
CanonicalSliceSpecifierssubmdspan slice specifier types
Parameters
srcsource layout_stride::mapping to slice
slicessubmdspan slice specifiers

Uses slices to compute the sub-extents, sub-strides, and offset of the submdspan. The slices must be in canonical form.

Returns
A submdspan_mapping_result containing the sub-mapping and offset such that indexing the sub-mapping and adding the offset recovers the corresponding index in the original mapping.
Note
Constraints
  • sizeof...(CanonicalSliceSpecifiers) == extents_type::rank()
  • for each rank index k of src.extents(), CanonicalSliceSpecifiers...[k] is a valid submdspan slice type for the k-th extent of extents_type
Preconditions
  • for each rank index k of src.extents(), slices...[k] denotes a valid submdspan slice for the k-th extent of src.extents()
Remarks
  • this function is found via argument-dependent lookup as a friend of layout_stride::mapping
  • the layout_stride specialization of submdspan_mapping always produces a layout_stride mapping for the submdspan.

The documentation for this class was generated from the following file: