Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy > Class Template Reference

Non-owning view of a contiguous buffer as a multidimensional grid. More...

#include <ah-mdspan.H>

Collaboration diagram for Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >:
[legend]

Public Types

using extents_type = Extents
 
using layout_type = LayoutPolicy
 
using accessor_type = AccessorPolicy
 
using mapping_type = typename layout_type::template mapping< extents_type >
 
using element_type = T
 
using value_type = std::remove_cv_t< T >
 
using index_type = typename extents_type::index_type
 
using rank_type = typename extents_type::rank_type
 
using data_handle_type = typename accessor_type::data_handle_type
 
using reference = typename accessor_type::reference
 

Public Member Functions

constexpr mdspan () noexcept=default
 Empty view: data_handle() == nullptr, every extent is 0.
 
constexpr mdspan (const mdspan &) noexcept=default
 
constexpr mdspan (mdspan &&) noexcept=default
 
constexpr mdspan & operator= (const mdspan &) noexcept=default
 
constexpr mdspan & operator= (mdspan &&) noexcept=default
 
template<class OtherT , class OtherAccessor >
requires (not std::is_same_v<OtherT, T> and std::is_convertible_v<OtherT (*)[], T (*)[]>)
constexpr mdspan (const mdspan< OtherT, Extents, LayoutPolicy, OtherAccessor > &other) noexcept
 Converting constructor: view a non-const element type as a const-qualified one (mdspan<T,...> -> mdspan<const T,...>), mirroring how T* converts to const T*.
 
constexpr mdspan (data_handle_type p, const extents_type &e) noexcept
 View p through the shape e.
 
constexpr mdspan (data_handle_type p, const mapping_type &m) noexcept
 View p through an already-built mapping.
 
constexpr mdspan (data_handle_type p, const mapping_type &m, const accessor_type &a) noexcept
 View p through mapping m, reading via accessor a.
 
template<class... IndexTypes>
requires (sizeof...(IndexTypes) >= 1 and (std::is_convertible_v<IndexTypes, index_type> and ...))
constexpr mdspan (data_handle_type p, IndexTypes... exts) noexcept
 View p as a grid with the given per-axis sizes.
 
template<class OtherIndexType >
requires std::is_convertible_v<const OtherIndexType &, index_type>
constexpr mdspan (data_handle_type p, const std::array< OtherIndexType, extents_type::rank_dynamic()> &dyn) noexcept
 View p as a grid whose dynamic axes are packed in an array.
 
constexpr index_type extent (rank_type r) const noexcept
 Run-time size of axis r.
 
constexpr const extents_type & extents () const noexcept
 The shape of this view.
 
constexpr const mapping_type & mapping () const noexcept
 The index-to-offset mapping (layout + shape) of this view.
 
constexpr const accessor_type & accessor () const noexcept
 The element-access policy of this view.
 
constexpr data_handle_type data_handle () const noexcept
 Underlying pointer to the first element (nullptr for a default-built view).
 
constexpr data_handle_type data () const noexcept
 
constexpr index_type size () const noexcept
 Total element count: the product of every extent(r).
 
constexpr bool empty () const noexcept
 Checks if the view has no elements.
 
template<class... Indices>
requires (sizeof...(Indices) == extents_type::rank())
constexpr reference operator() (Indices... idxs) const
 Unchecked element access.
 
template<class... Indices>
requires (sizeof...(Indices) == extents_type::rank())
constexpr reference at (Indices... idxs) const
 Bounds-checked element access.
 

Static Public Member Functions

static constexpr rank_type rank () noexcept
 Number of axes (compile-time constant).
 

Private Attributes

data_handle_type ptr_ {}
 
mapping_type map_ {}
 
accessor_type acc_ {}
 

Detailed Description

template<class T, class Extents, class LayoutPolicy = layout_right, class AccessorPolicy = default_accessor<T>>
class Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >

Non-owning view of a contiguous buffer as a multidimensional grid.

See the file-level documentation for the overview, the rationale for operator() over multi-argument operator[], and the bounds-checking policy (operator() is unchecked, .at() is checked).

Template Parameters
Telement type (may be const-qualified for a read-only view).
Extentsan Aleph::extents<IndexType, ...> (typically Aleph::dextents<IndexType, Rank>).
LayoutPolicyAleph::layout_right (default, row-major) or Aleph::layout_left (column-major).
AccessorPolicyAleph::default_accessor<T> (default).
Thread-safety
Concurrent reads on different cells are safe. Concurrent writes to overlapping cells are not synchronised.

Definition at line 575 of file ah-mdspan.H.

Member Typedef Documentation

◆ accessor_type

template<class T , class Extents , class LayoutPolicy = layout_right, class AccessorPolicy = default_accessor<T>>
using Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::accessor_type = AccessorPolicy

Definition at line 580 of file ah-mdspan.H.

◆ data_handle_type

template<class T , class Extents , class LayoutPolicy = layout_right, class AccessorPolicy = default_accessor<T>>
using Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::data_handle_type = typename accessor_type::data_handle_type

Definition at line 586 of file ah-mdspan.H.

◆ element_type

template<class T , class Extents , class LayoutPolicy = layout_right, class AccessorPolicy = default_accessor<T>>
using Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::element_type = T

Definition at line 582 of file ah-mdspan.H.

◆ extents_type

template<class T , class Extents , class LayoutPolicy = layout_right, class AccessorPolicy = default_accessor<T>>
using Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::extents_type = Extents

Definition at line 578 of file ah-mdspan.H.

◆ index_type

template<class T , class Extents , class LayoutPolicy = layout_right, class AccessorPolicy = default_accessor<T>>
using Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::index_type = typename extents_type::index_type

Definition at line 584 of file ah-mdspan.H.

◆ layout_type

template<class T , class Extents , class LayoutPolicy = layout_right, class AccessorPolicy = default_accessor<T>>
using Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::layout_type = LayoutPolicy

Definition at line 579 of file ah-mdspan.H.

◆ mapping_type

template<class T , class Extents , class LayoutPolicy = layout_right, class AccessorPolicy = default_accessor<T>>
using Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::mapping_type = typename layout_type::template mapping<extents_type>

Definition at line 581 of file ah-mdspan.H.

◆ rank_type

template<class T , class Extents , class LayoutPolicy = layout_right, class AccessorPolicy = default_accessor<T>>
using Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::rank_type = typename extents_type::rank_type

Definition at line 585 of file ah-mdspan.H.

◆ reference

template<class T , class Extents , class LayoutPolicy = layout_right, class AccessorPolicy = default_accessor<T>>
using Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::reference = typename accessor_type::reference

Definition at line 587 of file ah-mdspan.H.

◆ value_type

template<class T , class Extents , class LayoutPolicy = layout_right, class AccessorPolicy = default_accessor<T>>
using Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::value_type = std::remove_cv_t<T>

Definition at line 583 of file ah-mdspan.H.

Constructor & Destructor Documentation

◆ mdspan() [1/9]

template<class T , class Extents , class LayoutPolicy = layout_right, class AccessorPolicy = default_accessor<T>>
constexpr Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::mdspan ( )
constexprdefaultnoexcept

Empty view: data_handle() == nullptr, every extent is 0.

◆ mdspan() [2/9]

template<class T , class Extents , class LayoutPolicy = layout_right, class AccessorPolicy = default_accessor<T>>
constexpr Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::mdspan ( const mdspan< T, Extents, LayoutPolicy, AccessorPolicy > &  )
constexprdefaultnoexcept

◆ mdspan() [3/9]

template<class T , class Extents , class LayoutPolicy = layout_right, class AccessorPolicy = default_accessor<T>>
constexpr Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::mdspan ( mdspan< T, Extents, LayoutPolicy, AccessorPolicy > &&  )
constexprdefaultnoexcept

◆ mdspan() [4/9]

template<class T , class Extents , class LayoutPolicy = layout_right, class AccessorPolicy = default_accessor<T>>
template<class OtherT , class OtherAccessor >
requires (not std::is_same_v<OtherT, T> and std::is_convertible_v<OtherT (*)[], T (*)[]>)
constexpr Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::mdspan ( const mdspan< OtherT, Extents, LayoutPolicy, OtherAccessor > &  other)
inlineconstexprnoexcept

Converting constructor: view a non-const element type as a const-qualified one (mdspan<T,...> -> mdspan<const T,...>), mirroring how T* converts to const T*.

Only participates when OtherT actually converts to T (so this does not become a silent implicit cast between unrelated element types) and the shapes/layouts/accessors match.

Definition at line 613 of file ah-mdspan.H.

◆ mdspan() [5/9]

template<class T , class Extents , class LayoutPolicy = layout_right, class AccessorPolicy = default_accessor<T>>
constexpr Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::mdspan ( data_handle_type  p,
const extents_type &  e 
)
inlineconstexprnoexcept

View p through the shape e.

Parameters
ppointer to the first element of the buffer to view.
eextents object defining the shape.

Definition at line 621 of file ah-mdspan.H.

◆ mdspan() [6/9]

template<class T , class Extents , class LayoutPolicy = layout_right, class AccessorPolicy = default_accessor<T>>
constexpr Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::mdspan ( data_handle_type  p,
const mapping_type &  m 
)
inlineconstexprnoexcept

View p through an already-built mapping.

Parameters
ppointer to the first element of the buffer to view.
mmapping object defining the layout.

Definition at line 629 of file ah-mdspan.H.

◆ mdspan() [7/9]

template<class T , class Extents , class LayoutPolicy = layout_right, class AccessorPolicy = default_accessor<T>>
constexpr Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::mdspan ( data_handle_type  p,
const mapping_type &  m,
const accessor_type &  a 
)
inlineconstexprnoexcept

View p through mapping m, reading via accessor a.

Parameters
ppointer to the first element of the buffer to view.
mmapping object defining the layout.
aaccessor object defining element access.

Definition at line 638 of file ah-mdspan.H.

◆ mdspan() [8/9]

template<class T , class Extents , class LayoutPolicy = layout_right, class AccessorPolicy = default_accessor<T>>
template<class... IndexTypes>
requires (sizeof...(IndexTypes) >= 1 and (std::is_convertible_v<IndexTypes, index_type> and ...))
constexpr Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::mdspan ( data_handle_type  p,
IndexTypes...  exts 
)
inlineexplicitconstexprnoexcept

View p as a grid with the given per-axis sizes.

Convenience constructor equivalent to mdspan(p, extents_type(exts...)).

Parameters
ppointer to the first element of the buffer to view.
extsone size per dynamic axis of Extents, in rank order.

Definition at line 651 of file ah-mdspan.H.

◆ mdspan() [9/9]

template<class T , class Extents , class LayoutPolicy = layout_right, class AccessorPolicy = default_accessor<T>>
template<class OtherIndexType >
requires std::is_convertible_v<const OtherIndexType &, index_type>
constexpr Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::mdspan ( data_handle_type  p,
const std::array< OtherIndexType, extents_type::rank_dynamic()> &  dyn 
)
inlineconstexprnoexcept

View p as a grid whose dynamic axes are packed in an array.

Convenience constructor equivalent to mdspan(p, extents_type(dyn)). Matches CA::Dense_Cell_Storage::extents_type (a std::array of all per-axis sizes for a fully-dynamic dextents shape), so a lattice's own extents can be forwarded directly without unpacking them.

Definition at line 664 of file ah-mdspan.H.

Member Function Documentation

◆ accessor()

template<class T , class Extents , class LayoutPolicy = layout_right, class AccessorPolicy = default_accessor<T>>
constexpr const accessor_type & Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::accessor ( ) const
inlineconstexprnoexcept

The element-access policy of this view.

Definition at line 690 of file ah-mdspan.H.

References Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::acc_.

◆ at()

template<class T , class Extents , class LayoutPolicy = layout_right, class AccessorPolicy = default_accessor<T>>
template<class... Indices>
requires (sizeof...(Indices) == extents_type::rank())
constexpr reference Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::at ( Indices...  idxs) const
inlineconstexpr

◆ data()

template<class T , class Extents , class LayoutPolicy = layout_right, class AccessorPolicy = default_accessor<T>>
constexpr data_handle_type Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::data ( ) const
inlineconstexprnoexcept

◆ data_handle()

template<class T , class Extents , class LayoutPolicy = layout_right, class AccessorPolicy = default_accessor<T>>
Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::data_handle ( ) const
inlineconstexprnoexcept

Underlying pointer to the first element (nullptr for a default-built view).

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 693 of file ah-mdspan.H.

References Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::ptr_.

◆ empty()

template<class T , class Extents , class LayoutPolicy = layout_right, class AccessorPolicy = default_accessor<T>>
constexpr bool Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::empty ( ) const
inlineconstexprnoexcept

Checks if the view has no elements.

Returns
true if any axis has extent 0, false otherwise.

Definition at line 710 of file ah-mdspan.H.

References Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::extent(), r, and Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::rank().

◆ extent()

template<class T , class Extents , class LayoutPolicy = layout_right, class AccessorPolicy = default_accessor<T>>
constexpr index_type Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::extent ( rank_type  r) const
inlineconstexprnoexcept

◆ extents()

template<class T , class Extents , class LayoutPolicy = layout_right, class AccessorPolicy = default_accessor<T>>
constexpr const extents_type & Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::extents ( ) const
inlineconstexprnoexcept

The shape of this view.

Definition at line 684 of file ah-mdspan.H.

References Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::map_.

◆ mapping()

template<class T , class Extents , class LayoutPolicy = layout_right, class AccessorPolicy = default_accessor<T>>
constexpr const mapping_type & Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::mapping ( ) const
inlineconstexprnoexcept

The index-to-offset mapping (layout + shape) of this view.

Definition at line 687 of file ah-mdspan.H.

References Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::map_.

◆ operator()()

template<class T , class Extents , class LayoutPolicy = layout_right, class AccessorPolicy = default_accessor<T>>
template<class... Indices>
requires (sizeof...(Indices) == extents_type::rank())
constexpr reference Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::operator() ( Indices...  idxs) const
inlineconstexpr

Unchecked element access.

Parameters
idxsone index per axis, in rank order.
Returns
A reference to the accessed element.
Warning
Undefined behavior if any idxs[r] is outside [0, extent(r)) — matches std::mdspan::operator[]'s contract exactly. Use at() for a bounds-checked variant.

Definition at line 728 of file ah-mdspan.H.

References Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::acc_, Aleph::blossom_maximum_cardinality_matching(), Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::map_, and Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::ptr_.

◆ operator=() [1/2]

template<class T , class Extents , class LayoutPolicy = layout_right, class AccessorPolicy = default_accessor<T>>
constexpr mdspan & Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::operator= ( const mdspan< T, Extents, LayoutPolicy, AccessorPolicy > &  )
constexprdefaultnoexcept

◆ operator=() [2/2]

template<class T , class Extents , class LayoutPolicy = layout_right, class AccessorPolicy = default_accessor<T>>
constexpr mdspan & Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::operator= ( mdspan< T, Extents, LayoutPolicy, AccessorPolicy > &&  )
constexprdefaultnoexcept

◆ rank()

template<class T , class Extents , class LayoutPolicy = layout_right, class AccessorPolicy = default_accessor<T>>
static constexpr rank_type Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::rank ( )
inlinestaticconstexprnoexcept

◆ size()

template<class T , class Extents , class LayoutPolicy = layout_right, class AccessorPolicy = default_accessor<T>>
constexpr index_type Aleph::mdspan< T, Extents, LayoutPolicy, AccessorPolicy >::size ( ) const
inlineconstexprnoexcept

Member Data Documentation

◆ acc_

◆ map_

◆ ptr_


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