Open crtrott opened 1 year ago
mdarray
Creating a simple 2D array with mdspan requires multiple steps because mdspan is non-owning.
mdspan
// Create a mapping: layout_left map(extents(N,M)); // Create an allocation vector<int> data(map.required_span_size()); // Create mdspan: mdspan a(data.data(), map);
mdarray is a multidimensional array with value-semantics and makes the above simpler
// default layout mdarray a(N,M); // other layout mdarray b(layout_left(extents(N,M)));
mdarray has the
element_type
extents
The accessor policy is replaced by a container type.
template<class ElementType, class Extents, class Layout, class Accessor> class mdspan { public: ... template<class ... Indices> reference operator [] (Indices ... idx) const { return acc_.access(ptr_, map_(idx...)); } private: typename Accessor::data_handle_type ptr_; Layout::mapping<Extents> map_; Accessor acc_; }; template<class ElementType, class Extents, class Layout, class Container> class mdarray { public: ... template<class ... Indices> reference operator [] (Indices ... idx) { return ctr_[map_(idx...)]); } private: Layout::mapping<Extents> map_; Container ctr_; };
The following table gives an overview of the three approaches. In this table we use these shorthands:
mda_t
c_t
container_type
e
m
me
c
a
v
mda_t::value_type
mda
mds
mda_t::to_mdspan
Super Brief
mdarray
introductionWhy we want
mdarray
Creating a simple 2D array with
mdspan
requires multiple steps becausemdspan
is non-owning.mdarray
is a multidimensional array with value-semantics and makes the above simplerWhat aspects of
mdspan
doesmdarray
havemdarray
has theelement_type
,extents
andmdspan
The accessor policy is replaced by a container type.
Design issues left at last time
Constructor
Overview Table
The following table gives an overview of the three approaches. In this table we use these shorthands:
mda_t
: a specialization ofmdarray
c_t
: thecontainer_type
ofmda_t
e
: anextents
objectm
: a layout mapping objectme
: aextents
object or a layout mapping objectc
: an instance ofc_t
a
: an allocator objectv
: a value (something convertible tomda_t::value_type
mda
: anmdarray
object, not necessarily the same type asmda_t
mds
: anmdspan
obejct, not necessarily the same as returned bymda_t::to_mdspan