DUNE PDELab (git)
Dune::Std::mdarray< Element, Extents, LayoutPolicy, Container > Class Template Reference
An owning multi-dimensional array analog of mdspan. More...
#include <dune/common/std/mdarray.hh>
Public Member Functions | |
constexpr const mapping_type & | mapping () const noexcept |
Index mapping of a layout policy. | |
constexpr const container_type & | container () const noexcept |
The underlying storage container. | |
constexpr container_type && | extract_container () &&noexcept |
Move the container out of the mdarray. More... | |
Related Functions | |
(Note that these are not member functions.) | |
constexpr const extents_type & | extents () const noexcept |
Number of elements in all dimensions of the array,. | |
Comparison operators | |
constexpr bool | operator== (const mdarray &lhs, const mdarray &rhs) noexcept |
Conversion into mdspan | |
container_type | container_ |
DUNE_NO_UNIQUE_ADDRESS mapping_type | mapping_ |
template<class V , class E , class L , class A , std::enable_if_t< std::is_assignable_v< mdspan< V, E, L, A >, mdspan_type >, int > = 0> | |
constexpr | operator mdspan< V, E, L, A > () |
Conversion operator to mdspan. | |
template<class V , class E , class L , class A , std::enable_if_t< std::is_assignable_v< mdspan< V, E, L, A >, const_mdspan_type >, int > = 0> | |
constexpr | operator mdspan< V, E, L, A > () const |
Conversion operator to mdspan. | |
template<class AccessorPolicy = Std::default_accessor<element_type>, std::enable_if_t< std::is_assignable_v< mdspan_type, mdspan< element_type, extents_type, layout_type, AccessorPolicy > >, int > = 0> | |
constexpr mdspan< element_type, extents_type, layout_type, AccessorPolicy > | to_mdspan (const AccessorPolicy &a=AccessorPolicy{}) |
Conversion function to mdspan. | |
template<class AccessorPolicy = Std::default_accessor<const element_type>, std::enable_if_t< std::is_assignable_v< const_mdspan_type, mdspan< const element_type, extents_type, layout_type, AccessorPolicy > >, int > = 0> | |
constexpr mdspan< const element_type, extents_type, layout_type, AccessorPolicy > | to_mdspan (const AccessorPolicy &a=AccessorPolicy{}) const |
Conversion function to mdspan. | |
mdarray constructors | |
template<class E = extents_type, class C = container_type, class M = mapping_type, std::enable_if_t<(E::rank_dynamic() !=0), int > = 0, std::enable_if_t< std::is_default_constructible_v< C >, int > = 0, std::enable_if_t< std::is_default_constructible_v< M >, int > = 0> | |
constexpr | mdarray () |
A default constructor; needed only if the constructor for dynamic extents does not apply. | |
template<class... IndexTypes, std::enable_if_t<(... &&std::is_convertible_v< IndexTypes, index_type >), int > = 0, std::enable_if_t< std::is_constructible_v< extents_type, IndexTypes... >, int > = 0, std::enable_if_t<(... &&std::is_nothrow_constructible_v< index_type, IndexTypes >), int > = 0> | |
constexpr | mdarray (IndexTypes... exts) |
Construct from the dynamic extents. | |
constexpr | mdarray (const extents_type &e) |
Construct from the extents of the array. | |
template<class C = container_type, decltype(construct_container< C >(std::declval< std::size_t >()), bool{}) = true> | |
constexpr | mdarray (const mapping_type &m) |
Construct from the layout mapping of the array. | |
constexpr | mdarray (const extents_type &e, const value_type &v) |
Construct from extents and initial value. | |
template<class C = container_type, decltype(construct_container< C >(std::declval< std::size_t >(), std::declval< const value_type & >()), bool{}) = true> | |
constexpr | mdarray (const mapping_type &m, const value_type &v) |
Construct from layout mapping and initial value. | |
template<class E = extents_type, std::enable_if_t< std::is_constructible_v< mapping_type, const E & >, int > = 0> | |
constexpr | mdarray (const E &e, const container_type &c) |
Construct from extents and the storage container. | |
template<class E = extents_type, std::enable_if_t< std::is_constructible_v< mapping_type, const E & >, int > = 0> | |
constexpr | mdarray (const E &e, container_type &&c) |
Construct from extents and the storage container. | |
constexpr | mdarray (const mapping_type &m, const container_type &c) |
Construct from layout mapping and the storage container. | |
constexpr | mdarray (const mapping_type &m, container_type &&c) |
Construct from layout mapping and the storage container. | |
template<class OtherElementType , class OtherExtents , class OtherLayoutPolicy , class OtherContainer , std::enable_if_t< std::is_constructible_v< Container, const OtherContainer & >, int > = 0, std::enable_if_t< std::is_constructible_v< extents_type, OtherExtents >, int > = 0, std::enable_if_t< std::is_constructible_v< mapping_type, const typename OtherLayoutPolicy::template mapping< OtherExtents > & >, int > = 0> | |
constexpr | mdarray (const mdarray< OtherElementType, OtherExtents, OtherLayoutPolicy, OtherContainer > &other) |
Converting constructor from other mdarray. | |
template<class OtherElementType , class OtherExtents , class OtherLayoutPolicy , class Accessor , std::enable_if_t< std::is_constructible_v< value_type, typename Accessor::reference >, int > = 0, std::enable_if_t< std::is_assignable_v< typename Accessor::reference, value_type >, int > = 0, std::enable_if_t< std::is_constructible_v< mapping_type, const typename OtherLayoutPolicy::template mapping< OtherExtents > & >, int > = 0, decltype(construct_container< container_type >(std::declval< std::size_t >()), bool{}) = true> | |
constexpr | mdarray (const mdspan< OtherElementType, OtherExtents, OtherLayoutPolicy, Accessor > &other) |
Converting constructor from mdspan. | |
template<class Alloc , std::enable_if_t< std::is_constructible_v< container_type, std::size_t, Alloc >, int > = 0> | |
constexpr | mdarray (const extents_type &e, const Alloc &a) |
Construct from the extents of the array and allocator. | |
template<class Alloc , std::enable_if_t< std::is_constructible_v< container_type, std::size_t, Alloc >, int > = 0> | |
constexpr | mdarray (const mapping_type &m, const Alloc &a) |
Construct from the layout mapping of the array and allocator. | |
template<class Alloc > | |
constexpr | mdarray (const extents_type &e, const value_type &v, const Alloc &a) |
Construct from extents, initial value and allocator. | |
template<class Alloc , std::enable_if_t< std::is_constructible_v< container_type, std::size_t, value_type, Alloc >, int > = 0> | |
constexpr | mdarray (const mapping_type &m, const value_type &v, const Alloc &a) |
Construct from layout mapping, initial value and allocator. | |
template<class Alloc , std::enable_if_t< std::is_constructible_v< container_type, container_type, Alloc >, int > = 0> | |
constexpr | mdarray (const extents_type &e, const container_type &c, const Alloc &a) |
Construct from extents, container and allocator. | |
template<class Alloc , std::enable_if_t< std::is_constructible_v< container_type, container_type, Alloc >, int > = 0> | |
constexpr | mdarray (const extents_type &e, container_type &&c, const Alloc &a) |
Construct from extents, container and allocator. | |
template<class Alloc , std::enable_if_t< std::is_constructible_v< container_type, container_type, Alloc >, int > = 0> | |
constexpr | mdarray (const mapping_type &m, const container_type &c, const Alloc &a) |
Construct from layout mapping, container and allocator. | |
template<class Alloc , std::enable_if_t< std::is_constructible_v< container_type, container_type, Alloc >, int > = 0> | |
constexpr | mdarray (const mapping_type &m, container_type &&c, const Alloc &a) |
Construct from layout mapping, container and allocator. | |
template<class V , class E , class L , class C , class Alloc , std::enable_if_t< std::is_constructible_v< container_type, C, Alloc >, int > = 0> | |
constexpr | mdarray (const mdarray< V, E, L, C > &other, const Alloc &a) noexcept |
Converting constructor with alternative allocator. | |
template<class V , class E , class L , class A , class Alloc , class C = container_type, class Al = typename C::allocator_type, std::enable_if_t< std::is_constructible_v< C, std::size_t, Alloc >, int > = 0> | |
constexpr | mdarray (const mdspan< V, E, L, A > &other, const Alloc &a) |
Converting constructor from mdspan. | |
Multi index access | |
template<class... Indices, std::enable_if_t<(sizeof...(Indices)==extents_type::rank()), int > = 0, std::enable_if_t<(... &&std::is_convertible_v< Indices, index_type >), int > = 0> | |
constexpr reference | operator() (Indices... indices) |
Access element at position (i0,i1,...) More... | |
template<class... Indices, std::enable_if_t<(sizeof...(Indices)==extents_type::rank()), int > = 0, std::enable_if_t<(... &&std::is_convertible_v< Indices, index_type >), int > = 0> | |
constexpr const_reference | operator() (Indices... indices) const |
Access element at position (i0,i1,...) More... | |
template<class Index , class E = extents_type, std::enable_if_t< std::is_convertible_v< Index, index_type >, int > = 0, std::enable_if_t<(E::rank()==1), int > = 0> | |
constexpr reference | operator[] (Index index) |
Access specified element at position [i0] For a rank one mdarray, the operator[i] is added to support bracket access before __cpp_multidimensional_subscript is supported. | |
template<class Index , class E = extents_type, std::enable_if_t< std::is_convertible_v< Index, index_type >, int > = 0, std::enable_if_t<(E::rank()==1), int > = 0> | |
constexpr const_reference | operator[] (Index index) const |
Access specified element at position [i0] For a rank one mdarray, the operator[i] is added to support bracket access before __cpp_multidimensional_subscript is supported. | |
template<class Index , std::enable_if_t< std::is_convertible_v< const Index &, index_type >, int > = 0> | |
constexpr reference | operator[] (Std::span< Index, extents_type::rank()> indices) |
Access element at position [{i0,i1,...}]. | |
template<class Index , std::enable_if_t< std::is_convertible_v< const Index &, index_type >, int > = 0> | |
constexpr const_reference | operator[] (Std::span< Index, extents_type::rank()> indices) const |
Access element at position [{i0,i1,...}]. | |
template<class Index , std::enable_if_t< std::is_convertible_v< const Index &, index_type >, int > = 0> | |
constexpr reference | operator[] (const std::array< Index, extents_type::rank()> &indices) |
Access element at position [{i0,i1,...}]. | |
template<class Index , std::enable_if_t< std::is_convertible_v< const Index &, index_type >, int > = 0> | |
constexpr const_reference | operator[] (const std::array< Index, extents_type::rank()> &indices) const |
Access element at position [{i0,i1,...}]. | |
Detailed Description
template<class Element, class Extents, class LayoutPolicy = Std::layout_right, class Container = std::vector<Element>>
class Dune::Std::mdarray< Element, Extents, LayoutPolicy, Container >
class Dune::Std::mdarray< Element, Extents, LayoutPolicy, Container >
An owning multi-dimensional array analog of mdspan.
The implementation is inspired by the mdarray c++ standard proposals P1684R5.
Example:
// two-dimensional array with 2 rows and 6 columns of static shape
// same two-dimensional array but with dynamic shape
// storage type similar to the Dune::FieldMatrix
template <class T, int m, int n>
Dune::Std::extents<int,m,n>, Dune::Std::layout_right, std::array<T,m*n>>;
// store data into the array using two indices
for (std::size_t i = 0; i != m1.extent(0); i++)
for (std::size_t j = 0; j != m1.extent(1); j++)
m1(i, j) = i + j; // or m1[i, j]
Multidimensional index space with dynamic and static extents.
Definition: extents.hh:55
A layout where the rightmost extent has stride 1, and strides increase right-to-left as the product o...
Definition: fwd_layouts.hh:30
- Note
- The interface of
Std::mdarray
provides theoperator[]
with multiple indices overload only if available in c++23. For older c++ versions theoperator()
overload is implemented.
- Template Parameters
-
Element The element type; a complete object type that is neither an abstract class type nor an array type. Extents Specifies number of dimensions, their sizes, and which are known at compile time. Must be a specialization of Std::extents
.LayoutPolicy Specifies how to convert multi-dimensional index to underlying flat index. Container A container type accessible by a single index provided by the layout mapping.
Member Function Documentation
◆ extract_container()
template<class Element , class Extents , class LayoutPolicy = Std::layout_right, class Container = std::vector<Element>>
|
inlineconstexprnoexcept |
Move the container out of the mdarray.
Note that after moving out the container the mdarray remains in a valid but an unspecified state. One can destruct it or move-assign to it (i.e. restore the container in some way).
◆ operator()() [1/2]
template<class Element , class Extents , class LayoutPolicy = Std::layout_right, class Container = std::vector<Element>>
template<class... Indices, std::enable_if_t<(sizeof...(Indices)==extents_type::rank()), int > = 0, std::enable_if_t<(... &&std::is_convertible_v< Indices, index_type >), int > = 0>
|
inlineconstexpr |
Access element at position (i0,i1,...)
- Note
- The
operator()
is not in the std proposal, but is provided for using mdspan without c++23. For compatibility reasons it should only be used if the macro DUNE_HAVE_CXX_STD_MDARRAY is explicitly set to 0.
◆ operator()() [2/2]
template<class Element , class Extents , class LayoutPolicy = Std::layout_right, class Container = std::vector<Element>>
template<class... Indices, std::enable_if_t<(sizeof...(Indices)==extents_type::rank()), int > = 0, std::enable_if_t<(... &&std::is_convertible_v< Indices, index_type >), int > = 0>
|
inlineconstexpr |
Access element at position (i0,i1,...)
- Note
- The
operator()
is not in the std proposal, but is provided for using mdspan without c++23.
The documentation for this class was generated from the following file:
- dune/common/std/mdarray.hh
|
Legal Statements / Impressum |
Hosted by TU Dresden |
generated with Hugo v0.111.3
(Nov 23, 23:29, 2024)