cppqed-multidiagonal 0.4.0
Multidiagonal sparse operator algebra for C++QED
Loading...
Searching...
No Matches
cppqedutils::MultiArrayView< T, RANK > Class Template Reference

A non-owning, strided view over a contiguous buffer. Should be passed by value. More...

#include <multidiagonal/MultiArray.h>

Inheritance diagram for cppqedutils::MultiArrayView< T, RANK >:

Public Member Functions

 MultiArrayView (const MultiArrayView &)=default
 
 MultiArrayView (MultiArrayView &&)=default
 
 MultiArrayView ()=default
 
MultiArrayView & operator= (const MultiArrayView &)=default
 
MultiArrayView & operator= (MultiArrayView &&)=default
 
 MultiArrayView (Extents< RANK > extents, Extents< RANK > strides, size_t offset, auto &&... dataView)
 Constructs a view with explicit extents, strides, offset, and data span. The offset accumulates from prior slicing operations.
 
 operator MultiArrayView< const T, RANK > () const
 Implicit conversion to a const view (MultiArrayView<const T, RANK>).
 
void checkBounds (std::convertible_to< size_t > auto ... i) const
 Bounds-check all indices against extents. Active only in debug builds (NDEBUG not defined).
 
T & operator() (Extents< RANK > idx) const
 Subscript by Extents<RANK> multi-index. Always const — does not modify the view, only potentially the underlying data.
 
T & operator() (std::convertible_to< size_t > auto ... i) const
 Subscript by individual indices, one per rank. Requires sizeof...(i) == RANK.
 
T & operator() (std::convertible_to< size_t > auto i) const
 Rank-1 specialization: single-index subscript.
 
T & operator() (std::convertible_to< size_t > auto i, std::convertible_to< size_t > auto j) const
 Rank-2 specialization: two-index subscript.
 
auto operator() (std::convertible_to< size_t > auto i, multiarray::Placeholder) const
 Rank-2 row slice: mav(i, _) returns a rank-1 view of row i.
 
auto operator() (multiarray::Placeholder, std::convertible_to< size_t > auto j) const
 Rank-2 column slice: mav(_, j) returns a rank-1 view of column j.
 

Public Attributes

Extents< RANK > extents
 
Extents< RANK > strides
 
size_t offset
 
std::span< T > dataView
 

Detailed Description

template<typename T, size_t RANK>
class cppqedutils::MultiArrayView< T, RANK >

A non-owning, strided view over a contiguous buffer. Should be passed by value.

Follows pointer-like (reference) semantics regarding constness: a const MultiArrayView<T,R> still allows mutation of the underlying data, just as a T* const does. All four combinations of (const) MultiArrayView<(const) T, RANK> are usable.

The flat storage index for multi-index \((i_0,\ldots,i_{R-1})\) is

\[ \text{offset} + \sum_{\iota=0}^{R-1} s_\iota\, i_\iota \]

where \(s\) are the strides and \(\text{offset}\) accumulates from prior slicing.

Todo:
Alternative design: MultiArrayBase<StorageType> parameterized on storage, unifying view and owning cases without inheritance.

Constructor & Destructor Documentation

◆ MultiArrayView() [1/4]

template<typename T , size_t RANK>
cppqedutils::MultiArrayView< T, RANK >::MultiArrayView ( const MultiArrayView< T, RANK > &  )
default

◆ MultiArrayView() [2/4]

template<typename T , size_t RANK>
cppqedutils::MultiArrayView< T, RANK >::MultiArrayView ( MultiArrayView< T, RANK > &&  )
default

◆ MultiArrayView() [3/4]

template<typename T , size_t RANK>
cppqedutils::MultiArrayView< T, RANK >::MultiArrayView ( )
default

◆ MultiArrayView() [4/4]

template<typename T , size_t RANK>
cppqedutils::MultiArrayView< T, RANK >::MultiArrayView ( Extents< RANK >  extents,
Extents< RANK >  strides,
size_t  offset,
auto &&...  dataView 
)
inline

Constructs a view with explicit extents, strides, offset, and data span. The offset accumulates from prior slicing operations.

Member Function Documentation

◆ checkBounds()

template<typename T , size_t RANK>
void cppqedutils::MultiArrayView< T, RANK >::checkBounds ( std::convertible_to< size_t > auto ...  i) const
inline

Bounds-check all indices against extents. Active only in debug builds (NDEBUG not defined).

◆ operator MultiArrayView< const T, RANK >()

template<typename T , size_t RANK>
cppqedutils::MultiArrayView< T, RANK >::operator MultiArrayView< const T, RANK > ( ) const
inline

Implicit conversion to a const view (MultiArrayView<const T, RANK>).

◆ operator()() [1/6]

template<typename T , size_t RANK>
T & cppqedutils::MultiArrayView< T, RANK >::operator() ( Extents< RANK >  idx) const
inline

Subscript by Extents<RANK> multi-index. Always const — does not modify the view, only potentially the underlying data.

The flat index is

\[ o + \sum_{\iota=0}^{R-1} s_\iota\, i_\iota \]

computed via fold_left over zip(idx, strides).

◆ operator()() [2/6]

template<typename T , size_t RANK>
auto cppqedutils::MultiArrayView< T, RANK >::operator() ( multiarray::Placeholder  ,
std::convertible_to< size_t > auto  j 
) const
inline

Rank-2 column slice: mav(_, j) returns a rank-1 view of column j.

Todo:
Generalize to arbitrary RANK.

◆ operator()() [3/6]

template<typename T , size_t RANK>
T & cppqedutils::MultiArrayView< T, RANK >::operator() ( std::convertible_to< size_t > auto ...  i) const
inline

Subscript by individual indices, one per rank. Requires sizeof...(i) == RANK.

◆ operator()() [4/6]

template<typename T , size_t RANK>
T & cppqedutils::MultiArrayView< T, RANK >::operator() ( std::convertible_to< size_t > auto  i) const
inline

Rank-1 specialization: single-index subscript.

◆ operator()() [5/6]

template<typename T , size_t RANK>
auto cppqedutils::MultiArrayView< T, RANK >::operator() ( std::convertible_to< size_t > auto  i,
multiarray::Placeholder   
) const
inline

Rank-2 row slice: mav(i, _) returns a rank-1 view of row i.

Todo:
Generalize to arbitrary RANK.

◆ operator()() [6/6]

template<typename T , size_t RANK>
T & cppqedutils::MultiArrayView< T, RANK >::operator() ( std::convertible_to< size_t > auto  i,
std::convertible_to< size_t > auto  j 
) const
inline

Rank-2 specialization: two-index subscript.

◆ operator=() [1/2]

template<typename T , size_t RANK>
MultiArrayView & cppqedutils::MultiArrayView< T, RANK >::operator= ( const MultiArrayView< T, RANK > &  )
default

◆ operator=() [2/2]

template<typename T , size_t RANK>
MultiArrayView & cppqedutils::MultiArrayView< T, RANK >::operator= ( MultiArrayView< T, RANK > &&  )
default

Member Data Documentation

◆ dataView

template<typename T , size_t RANK>
std::span<T> cppqedutils::MultiArrayView< T, RANK >::dataView

◆ extents

template<typename T , size_t RANK>
Extents<RANK> cppqedutils::MultiArrayView< T, RANK >::extents

◆ offset

template<typename T , size_t RANK>
size_t cppqedutils::MultiArrayView< T, RANK >::offset

◆ strides

template<typename T , size_t RANK>
Extents<RANK> cppqedutils::MultiArrayView< T, RANK >::strides

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