Loading...
Searching...
No Matches
mdarray.hh
Go to the documentation of this file.
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
#ifndef DUNE_COMMON_STD_MDARRAY_HH
#define DUNE_COMMON_STD_MDARRAY_HH
#include <algorithm>
#include <array>
#include <memory>
#include <vector>
#include <span>
#include <tuple>
#include <type_traits>
#if __has_include(<version>)
#include <version>
#endif
#include <dune/common/indices.hh>
#include <dune/common/rangeutilities.hh>
#include <dune/common/std/default_accessor.hh>
#include <dune/common/std/mdspan.hh>
#include <dune/common/std/no_unique_address.hh>
#include <dune/common/std/impl/containerconstructiontraits.hh>
namespace Dune::Std {
template <class Element, class Extents, class LayoutPolicy = Std::layout_right,
class Container = std::vector<Element>>
class mdarray
{
template <class,class,class,class> friend class mdarray;
static_assert(std::is_object_v<Element>);
static_assert(!std::is_abstract_v<Element>);
static_assert(!std::is_array_v<Element>);
static_assert(std::is_same_v<Element, typename Container::value_type>);
public:
using element_type = Element;
using extents_type = Extents;
using layout_type = LayoutPolicy;
using container_type = Container;
using value_type = element_type;
using mapping_type = typename layout_type::template mapping<extents_type>;
using index_type = typename extents_type::index_type;
using size_type = typename extents_type::size_type;
using rank_type = typename extents_type::rank_type;
using mdspan_type = mdspan<element_type,extents_type,layout_type>;
using const_mdspan_type = mdspan<const element_type,extents_type,layout_type>;
using pointer = decltype(std::to_address(std::declval<container_type>().begin()));
using reference = typename container_type::reference;
using const_pointer = decltype(std::to_address(std::declval<container_type>().cbegin()));
using const_reference = typename container_type::const_reference;
static_assert(std::is_constructible_v<mapping_type, extents_type>);
private:
// helper function to construct the container
template <class C, class... Args>
static constexpr auto construct_container (Args&&... args)
-> decltype(Impl::ContainerConstructionTraits<C>::construct(std::forward<Args>(args)...))
{
return Impl::ContainerConstructionTraits<C>::construct(std::forward<Args>(args)...);
}
public:
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 ()
: container_{}
, mapping_{}
{}
// -------------------------------------
// constructors from extents or mappings
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>
explicit constexpr mdarray (IndexTypes... exts)
: mdarray(extents_type(index_type(std::move(exts))...))
{}
explicit constexpr mdarray (const extents_type& e)
: mdarray(mapping_type(e))
{}
template <class C = container_type,
decltype(construct_container<C>(std::declval<std::size_t>()), bool{}) = true>
explicit constexpr mdarray (const mapping_type& m)
: container_(construct_container<C>(m.required_span_size()))
, mapping_(m)
{}
// ---------------------------------------
// constructors with a given initial value
constexpr mdarray (const extents_type& e, const value_type& v)
: mdarray(mapping_type(e), v)
{}
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)
: container_(construct_container<C>(m.required_span_size(), v))
, mapping_(m)
{}
// -----------------------------------
// constructors with a given 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, const container_type& c)
: container_(c)
, mapping_(e)
{}
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)
: container_(std::move(c))
, mapping_(e)
{}
constexpr mdarray (const mapping_type& m, const container_type& c)
: container_(c)
, mapping_(m)
{}
constexpr mdarray (const mapping_type& m, container_type&& c)
: container_(std::move(c))
, mapping_(m)
{}
// -----------------------
// converting constructors
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>
#if __cpp_conditional_explicit >= 201806L
explicit(
!std::is_convertible_v<const typename OtherLayoutPolicy::template mapping<OtherExtents>&, mapping_type> ||
!std::is_convertible_v<const OtherContainer&, container_type>)
#endif
constexpr mdarray (const mdarray<OtherElementType,OtherExtents,OtherLayoutPolicy,OtherContainer>& other)
: container_(other.container_)
, mapping_(other.mapping_)
{}
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<value_type&, typename Accessor::reference>, 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>
#if __cpp_conditional_explicit >= 201806L
explicit(
!std::is_convertible_v<const typename OtherLayoutPolicy::template mapping<OtherExtents>&, mapping_type> ||
!std::is_convertible_v<typename Accessor::reference, value_type>)
#endif
constexpr mdarray (const mdspan<OtherElementType,OtherExtents,OtherLayoutPolicy,Accessor>& other)
: container_(construct_container<container_type>(other.size()))
, mapping_(other.mapping())
{
init_from_mdspan(other);
}
// ----------------------------
// constructors with allocators
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)
: mdarray(mapping_type(e), a)
{}
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)
: container_(m.required_span_size(), a)
, mapping_(m)
{}
template <class Alloc>
constexpr mdarray (const extents_type& e, const value_type& v, const Alloc& a)
: mdarray(mapping_type(e), v, a)
{}
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)
: container_(m.required_span_size(), v, a)
, mapping_(m)
{}
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)
: container_(c, a)
, mapping_(e)
{}
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)
: container_(std::move(c), a)
, mapping_(e)
{}
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)
: container_(c, a)
, mapping_(m)
{}
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)
: container_(std::move(c), a)
, mapping_(m)
{}
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>
#if __cpp_conditional_explicit >= 201806L
explicit(
!std::is_convertible_v<const typename L::template mapping<E>&, mapping_type> ||
!std::is_convertible_v<const C&, container_type>)
#endif
constexpr mdarray (const mdarray<V,E,L,C>& other, const Alloc& a) noexcept
: container_(other.container_, a)
, mapping_(other.mapping_)
{}
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>
#if __cpp_conditional_explicit >= 201806L
explicit(
!std::is_convertible_v<const typename L::template mapping<E>&, mapping_type> ||
!std::is_convertible_v<typename A::reference, value_type> ||
!std::is_convertible_v<Alloc, Al>)
#endif
constexpr mdarray (const mdspan<V,E,L,A>& other, const Alloc& a)
: container_(other.size(), a)
, mapping_(other.mapping_)
{
init_from_mdspan(other);
}
private:
template <class V, class E, class L, class A, class... Indices>
void init_from_mdspan (const mdspan<V,E,L,A>& other, Indices... ii)
{
constexpr rank_type pos = sizeof...(Indices);
if constexpr(pos < rank()) {
for (typename E::index_type i = 0; i < other.extent(pos); ++i)
init_from_mdspan(other,ii...,i);
} else {
using I = std::array<typename E::index_type,E::rank()>;
container_[mapping_(index_type(ii)...)] = other[I{ii...}];
}
}
public:
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)
{
return container_[mapping_(index_type(std::move(indices))...)];
}
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
{
return container_[mapping_(index_type(std::move(indices))...)];
}
#if __cpp_multidimensional_subscript >= 202110L
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)
{
return container_[mapping_(index_type(std::move(indices))...)];
}
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
{
return container_[mapping_(index_type(std::move(indices))...)];
}
#else
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)
{
return container_[mapping_(index_type(std::move(index)))];
}
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
{
return container_[mapping_(index_type(std::move(index)))];
}
#endif
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)
{
return unpackIntegerSequence([&](auto... ii) -> reference {
return container_[mapping_(index_type(indices[ii])...)]; },
std::make_index_sequence<extents_type::rank()>{});
}
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
{
return unpackIntegerSequence([&](auto... ii) -> const_reference {
return container_[mapping_(index_type(indices[ii])...)]; },
std::make_index_sequence<extents_type::rank()>{});
}
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)
{
return std::apply([&](auto... ii) -> reference {
return container_[mapping_(index_type(ii)...)]; }, indices);
}
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
{
return std::apply([&](auto... ii) -> const_reference {
return container_[mapping_(index_type(ii)...)]; }, indices);
}
constexpr const extents_type& extents () const noexcept { return mapping_.extents(); }
constexpr const mapping_type& mapping () const noexcept { return mapping_; }
constexpr const container_type& container () const noexcept { return container_; }
constexpr container_type&& extract_container () && noexcept { return std::move(container_); }
static constexpr rank_type rank () noexcept { return extents_type::rank(); }
static constexpr rank_type rank_dynamic () noexcept { return extents_type::rank_dynamic(); }
static constexpr std::size_t static_extent (rank_type r) noexcept { return extents_type::static_extent(r); }
constexpr index_type extent (rank_type r) const noexcept { return extents().extent(r); }
constexpr size_type size () const noexcept
{
size_type s = 1;
for (rank_type r = 0; r < rank(); ++r)
s *= extent(r);
return s;
}
constexpr std::size_t container_size () const { return container_.size(); }
[[nodiscard]] constexpr bool empty () const noexcept { return size() == 0; }
constexpr index_type stride (rank_type r) const { return mapping().stride(r); };
static constexpr bool is_always_unique () noexcept { return mapping_type::is_always_unique(); }
static constexpr bool is_always_exhaustive () noexcept { return mapping_type::is_always_exhaustive(); }
static constexpr bool is_always_strided () noexcept { return mapping_type::is_always_strided(); }
constexpr bool is_unique () const noexcept { return mapping_.is_unique(); }
constexpr bool is_exhaustive () const noexcept { return mapping_.is_exhaustive(); }
constexpr bool is_strided () const noexcept { return mapping_.is_strided(); }
constexpr pointer container_data () noexcept { return std::to_address(container_.begin()); }
constexpr const_pointer container_data () const noexcept { return std::to_address(container_.begin()); }
friend constexpr void swap (mdarray& x, mdarray& y) noexcept
{
using std::swap;
swap(x.container_, y.container_);
swap(x.mapping_, y.mapping_);
}
friend constexpr bool operator== (const mdarray& lhs, const mdarray& rhs) noexcept
{
return lhs.mapping() == rhs.mapping() && lhs.container() == rhs.container();
}
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> ()
{
return mdspan_type(container_data(), mapping());
}
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
{
return const_mdspan_type(container_data(), mapping());
}
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{})
{
return mdspan<element_type,extents_type,layout_type,AccessorPolicy>(container_data(), mapping(), a);
}
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
{
return mdspan<const element_type,extents_type,layout_type,AccessorPolicy>(container_data(), mapping(), a);
}
protected:
container_type container_;
DUNE_NO_UNIQUE_ADDRESS mapping_type mapping_;
};
template <class IndexType, std::size_t... exts, class Container>
mdarray (const Std::extents<IndexType, exts...>&, const Container&)
-> mdarray<typename Container::value_type, Std::extents<IndexType, exts...>, layout_right, Container>;
template <class Mapping, class Container>
mdarray (const Mapping&, const Container&)
-> mdarray<typename Container::value_type, typename Mapping::extents_type, typename Mapping::layout_type, Container>;
template <class IndexType, std::size_t... exts, class Container>
mdarray (const Std::extents<IndexType, exts...>&, Container&&)
-> mdarray<typename Container::value_type, Std::extents<IndexType, exts...>, layout_right, Container>;
template <class Mapping, class Container>
mdarray (const Mapping&, Container&&)
-> mdarray<typename Container::value_type, typename Mapping::extents_type, typename Mapping::layout_type, Container>;
template <class Element, class Extents, class Layout, class Accessor>
mdarray (const mdspan<Element, Extents, Layout, Accessor>&)
-> mdarray<std::remove_cv_t<Element>, Extents, Layout>;
template <class IndexType, std::size_t... exts, class Container, class Alloc>
mdarray (const Std::extents<IndexType, exts...>&, const Container&, const Alloc&)
-> mdarray<typename Container::value_type, Std::extents<IndexType, exts...>, layout_right, Container>;
template <class Mapping, class Container, class Alloc>
mdarray (const Mapping&, const Container&, const Alloc&)
-> mdarray<typename Container::value_type, typename Mapping::extents_type, typename Mapping::layout_type, Container>;
template <class IndexType, std::size_t... exts, class Container, class Alloc>
mdarray (const Std::extents<IndexType, exts...>&, Container&&, const Alloc&)
-> mdarray<typename Container::value_type, Std::extents<IndexType, exts...>, layout_right, Container>;
template <class Mapping, class Container, class Alloc>
mdarray (const Mapping&, Container&&, const Alloc&)
-> mdarray<typename Container::value_type, typename Mapping::extents_type, typename Mapping::layout_type, Container>;
template <class Element, class Extents, class Layout, class Accessor, class Alloc>
mdarray (const mdspan<Element, Extents, Layout, Accessor>&, const Alloc&)
-> mdarray<std::remove_cv_t<Element>, Extents, Layout>;
template <class Element, class Extents, class Layout, class Container>
mdspan (mdarray<Element, Extents, Layout, Container>) -> mdspan<
typename decltype(std::declval<mdarray<Element, Extents, Layout, Container>>().to_mdspan())::element_type,
typename decltype(std::declval<mdarray<Element, Extents, Layout, Container>>().to_mdspan())::extents_type,
typename decltype(std::declval<mdarray<Element, Extents, Layout, Container>>().to_mdspan())::layout_type,
typename decltype(std::declval<mdarray<Element, Extents, Layout, Container>>().to_mdspan())::accessor_type>;
} // end namespace Dune::Std
#endif // DUNE_COMMON_STD_MDARRAY_HH
default_accessor.hh
containerconstructiontraits.hh
mdspan.hh
no_unique_address.hh
DUNE_NO_UNIQUE_ADDRESS
#define DUNE_NO_UNIQUE_ADDRESS
Definition no_unique_address.hh:24
indices.hh
rangeutilities.hh
Utilities for reduction like operations on ranges.
Dune::unpackIntegerSequence
decltype(auto) constexpr unpackIntegerSequence(F &&f, std::integer_sequence< I, i... > sequence)
Unpack an std::integer_sequence<I,i...> to std::integral_constant<I,i>...
Definition indices.hh:124
std
STL namespace.
Dune::Indices
Namespace with predefined compile time indices for the range [0,19].
Definition indices.hh:50
Dune::Std
Namespace for features backported from new C++ standards.
Definition algorithm.hh:19
Dune::Std::mdspan
mdspan(CArray &) -> mdspan< std::remove_all_extents_t< CArray >, Std::extents< std::size_t, std::extent_v< CArray, 0 > > >
Dune::const_reference
Get the 'const' version of a reference to a mutable object.
Definition genericiterator.hh:87
Dune::Std::extents
Multidimensional index space with dynamic and static extents.
Definition extents.hh:55
Dune::Std::layout_right
A layout where the rightmost extent has stride 1, and strides increase right-to-left as the product o...
Definition fwd_layouts.hh:30
Dune::Std::mdarray
An owning multi-dimensional array analog of mdspan.
Definition mdarray.hh:69
Dune::Std::mdarray::const_mdspan_type
mdspan< const element_type, extents_type, layout_type > const_mdspan_type
Definition mdarray.hh:91
Dune::Std::mdarray::mdarray
constexpr mdarray(const mapping_type &m, const container_type &c, const Alloc &a)
Construct from layout mapping, container and allocator.
Definition mdarray.hh:288
Dune::Std::mdarray::const_reference
typename container_type::const_reference const_reference
Definition mdarray.hh:96
Dune::Std::mdarray::mdarray
constexpr mdarray(const mapping_type &m, container_type &&c)
Construct from layout mapping and the storage container.
Definition mdarray.hh:194
Dune::Std::mdarray::container_type
Container container_type
Definition mdarray.hh:81
Dune::Std::mdarray::extents_type
Extents extents_type
Definition mdarray.hh:79
Dune::Std::mdarray::mdarray
constexpr mdarray(const E &e, const container_type &c)
Construct from extents and the storage container.
Definition mdarray.hh:174
Dune::Std::mdarray::is_always_exhaustive
static constexpr bool is_always_exhaustive() noexcept
Definition mdarray.hh:522
Dune::Std::mdarray::to_mdspan
constexpr mdspan< const element_type, extents_type, layout_type, AccessorPolicy > to_mdspan(const AccessorPolicy &a=AccessorPolicy{}) const
Conversion function to mdspan.
Definition mdarray.hh:594
Dune::Std::mdarray::stride
constexpr index_type stride(rank_type r) const
The stride along the specified dimension.
Definition mdarray.hh:516
Dune::Std::mdarray::is_unique
constexpr bool is_unique() const noexcept
Definition mdarray.hh:525
Dune::Std::mdarray::extent
constexpr index_type extent(rank_type r) const noexcept
Number of elements in the r'th dimension of the tensor.
Definition mdarray.hh:498
Dune::Std::mdarray::mdarray
constexpr mdarray(const extents_type &e, const Alloc &a)
Construct from the extents of the array and allocator.
Definition mdarray.hh:243
Dune::Std::mdarray::static_extent
static constexpr std::size_t static_extent(rank_type r) noexcept
Number of elements in the r'th dimension of the tensor.
Definition mdarray.hh:495
Dune::Std::mdarray::mdarray
constexpr mdarray(const mdspan< OtherElementType, OtherExtents, OtherLayoutPolicy, Accessor > &other)
Converting constructor from mdspan.
Definition mdarray.hh:229
Dune::Std::mdarray::mapping_type
typename layout_type::template mapping< extents_type > mapping_type
Definition mdarray.hh:84
Dune::Std::mdarray::container_data
constexpr const_pointer container_data() const noexcept
Direct access to the underlying const data in the container.
Definition mdarray.hh:537
Dune::Std::mdarray::mapping_
DUNE_NO_UNIQUE_ADDRESS mapping_type mapping_
Definition mdarray.hh:601
Dune::Std::mdarray::mdarray
friend class mdarray
Definition mdarray.hh:70
Dune::Std::mdarray::mdarray
constexpr mdarray(const extents_type &e, const value_type &v)
Construct from extents and initial value.
Definition mdarray.hh:155
Dune::Std::mdarray::mdarray
constexpr mdarray(const mapping_type &m, const Alloc &a)
Construct from the layout mapping of the array and allocator.
Definition mdarray.hh:250
Dune::Std::mdarray::container_data
constexpr pointer container_data() noexcept
Direct access to the underlying data in the container.
Definition mdarray.hh:534
Dune::Std::mdarray::is_exhaustive
constexpr bool is_exhaustive() const noexcept
Definition mdarray.hh:526
Dune::Std::mdarray::const_pointer
decltype(std::to_address(std::declval< container_type >().cbegin())) const_pointer
Definition mdarray.hh:95
Dune::Std::mdarray::operator[]
constexpr reference operator[](Index index)
Access specified element at position [i0] For a rank one mdarray, the operator[i] is added to support...
Definition mdarray.hh:408
Dune::Std::mdarray::extents
constexpr const extents_type & extents() const noexcept
Number of elements in all dimensions of the array,.
Definition mdarray.hh:468
Dune::Std::mdarray::is_strided
constexpr bool is_strided() const noexcept
Definition mdarray.hh:527
Dune::Std::mdarray::mdarray
constexpr mdarray(const mapping_type &m, const container_type &c)
Construct from layout mapping and the storage container.
Definition mdarray.hh:188
Dune::Std::mdarray::is_always_unique
static constexpr bool is_always_unique() noexcept
Definition mdarray.hh:521
Dune::Std::mdarray::mdarray
constexpr mdarray(const mapping_type &m, container_type &&c, const Alloc &a)
Construct from layout mapping, container and allocator.
Definition mdarray.hh:296
Dune::Std::mdarray::mdarray
constexpr mdarray(const E &e, container_type &&c)
Construct from extents and the storage container.
Definition mdarray.hh:182
Dune::Std::mdarray::container
constexpr const container_type & container() const noexcept
The underlying storage container.
Definition mdarray.hh:474
Dune::Std::mdarray::container_size
constexpr std::size_t container_size() const
Size of the underlying container.
Definition mdarray.hh:510
Dune::Std::mdarray::size_type
typename extents_type::size_type size_type
Definition mdarray.hh:87
Dune::Std::mdarray::rank
static constexpr rank_type rank() noexcept
Number of dimensions of the array.
Definition mdarray.hh:489
Dune::Std::mdarray::empty
constexpr bool empty() const noexcept
Check whether the index space is empty.
Definition mdarray.hh:513
Dune::Std::mdarray::mdarray
constexpr mdarray(const extents_type &e, container_type &&c, const Alloc &a)
Construct from extents, container and allocator.
Definition mdarray.hh:280
Dune::Std::mdarray::mdspan_type
mdspan< element_type, extents_type, layout_type > mdspan_type
Definition mdarray.hh:90
Dune::Std::mdarray::size
constexpr size_type size() const noexcept
Size of the multi-dimensional index space.
Definition mdarray.hh:501
Dune::Std::mdarray::pointer
decltype(std::to_address(std::declval< container_type >().begin())) pointer
Definition mdarray.hh:93
Dune::Std::mdarray::operator==
friend constexpr bool operator==(const mdarray &lhs, const mdarray &rhs) noexcept
Definition mdarray.hh:553
Dune::Std::mdarray::swap
friend constexpr void swap(mdarray &x, mdarray &y) noexcept
Definition mdarray.hh:542
Dune::Std::mdarray::mapping
constexpr const mapping_type & mapping() const noexcept
Index mapping of a layout policy.
Definition mdarray.hh:471
Dune::Std::mdarray::element_type
Element element_type
Definition mdarray.hh:78
Dune::Std::mdarray::mdarray
constexpr mdarray(const mapping_type &m, const value_type &v, const Alloc &a)
Construct from layout mapping, initial value and allocator.
Definition mdarray.hh:264
Dune::Std::mdarray::mdarray
constexpr mdarray(const mapping_type &m, const value_type &v)
Construct from layout mapping and initial value.
Definition mdarray.hh:162
Dune::Std::mdarray::mdarray
constexpr mdarray(const extents_type &e, const value_type &v, const Alloc &a)
Construct from extents, initial value and allocator.
Definition mdarray.hh:257
Dune::Std::mdarray::reference
typename container_type::reference reference
Definition mdarray.hh:94
Dune::Std::mdarray::to_mdspan
constexpr mdspan< element_type, extents_type, layout_type, AccessorPolicy > to_mdspan(const AccessorPolicy &a=AccessorPolicy{})
Conversion function to mdspan.
Definition mdarray.hh:584
Dune::Std::mdarray::value_type
element_type value_type
Definition mdarray.hh:83
Dune::Std::mdarray::layout_type
LayoutPolicy layout_type
Definition mdarray.hh:80
Dune::Std::mdarray::extract_container
constexpr container_type && extract_container() &&noexcept
Move the container out of the mdarray.
Definition mdarray.hh:482
Dune::Std::mdarray::mdarray
constexpr mdarray(const extents_type &e, const container_type &c, const Alloc &a)
Construct from extents, container and allocator.
Definition mdarray.hh:272
Dune::Std::mdarray::rank_type
typename extents_type::rank_type rank_type
Definition mdarray.hh:88
Dune::Std::mdarray::rank_dynamic
static constexpr rank_type rank_dynamic() noexcept
Number of dimension with dynamic size.
Definition mdarray.hh:492
Dune::Std::mdarray::operator()
constexpr reference operator()(Indices... indices)
Access element at position (i0,i1,...).
Definition mdarray.hh:363
Dune::Std::mdarray::mdarray
constexpr mdarray(const mapping_type &m)
Construct from the layout mapping of the array.
Definition mdarray.hh:145
Dune::Std::mdarray::mdarray
constexpr mdarray(const mdarray< OtherElementType, OtherExtents, OtherLayoutPolicy, OtherContainer > &other)
Converting constructor from other mdarray.
Definition mdarray.hh:213
Dune::Std::mdarray::mdarray
constexpr mdarray(const extents_type &e)
Construct from the extents of the array.
Definition mdarray.hh:138
Dune::Std::mdarray::container_
container_type container_
Definition mdarray.hh:600
Dune::Std::mdarray::index_type
typename extents_type::index_type index_type
Definition mdarray.hh:86
Dune::Std::mdarray::mdarray
constexpr mdarray(const mdarray< V, E, L, C > &other, const Alloc &a) noexcept
Converting constructor with alternative allocator.
Definition mdarray.hh:309
Dune::Std::mdarray::mdarray
constexpr mdarray(IndexTypes... exts)
Construct from the dynamic extents.
Definition mdarray.hh:133
Dune::Std::mdarray::is_always_strided
static constexpr bool is_always_strided() noexcept
Definition mdarray.hh:523
Dune::Std::mdspan
A multi-dimensional non-owning array view.
Definition mdspan.hh:65
Dune::Std::mdspan::extent
constexpr index_type extent(rank_type r) const noexcept
Number of elements in the r'th dimension of the tensor.
Definition mdspan.hh:276
Dune::Std::mdspan::size
constexpr size_type size() const noexcept
The number of elements accessible by this multi-dimensional span.
Definition mdspan.hh:279