cppqed-multidiagonal 0.4.0
Multidiagonal sparse operator algebra for C++QED
Loading...
Searching...
No Matches
MultiArray.h File Reference
#include "Traits.h"
#include <boost/serialization/array.hpp>
#include <boost/serialization/vector.hpp>
#include <array>
#include <concepts>
#include <span>
#include <stdexcept>
#include <ranges>
#include <vector>
Include dependency graph for MultiArray.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  cppqedutils::multiarray::Placeholder
 Sentinel type for rank-2 slice notation: mav(i, _) returns the i-th row as a rank-1 view. More...
 
class  cppqedutils::MultiArrayView< T, RANK >
 A non-owning, strided view over a contiguous buffer. Should be passed by value. More...
 
struct  cppqedutils::ReferenceMF< MultiArrayView< T, RANK > >
 
struct  cppqedutils::ConstReferenceMF< MultiArrayView< T, RANK > >
 
class  cppqedutils::MultiArray< T, RANK >
 Owning, move-only, rank-RANK array. Non-copyable; follows value semantics regarding constness. More...
 

Namespaces

namespace  cppqedutils
 Namespace alias for Boost.Hana, used for compile-time sequences and heterogeneous containers.
 
namespace  cppqedutils::multiarray
 

Typedefs

template<size_t RANK>
using cppqedutils::Extents = std::array< size_t, RANK >
 Compile-time–fixed shape and stride descriptor for a rank-RANK array. Should be passed by value, but can be std::moved in class constructors.
 
template<typename T , size_t RANK>
using cppqedutils::MultiArrayConstView = MultiArrayView< const T, RANK >
 Convenience alias: a view over immutable elements.
 
template<typename T >
using cppqedutils::multiarray::StorageType = std::vector< T >
 Underlying storage type: std::vector<T>. May eventually be replaced by kokkos::View or std::valarray.
 

Functions

template<typename Type , std::size_t... sizes>
constexpr auto cppqedutils::concatenate (const std::array< Type, sizes > &... arrays)
 Concatenates multiple std::array instances of different sizes into one.
 
template<size_t RANK>
auto & cppqedutils::incrementMultiIndex (Extents< RANK > &idx, Extents< RANK > extents)
 Increments a multi-index in last-index-fastest order, in-place.
 
auto & cppqedutils::incrementMultiIndex (Extents< 0 > &idx, Extents< 0 >)
 Rank-0 no-op overload of incrementMultiIndex to satisfy template instantiation for degenerate cases.
 
template<typename T1 , typename T2 , size_t RANK>
void cppqedutils::checkExtents (MultiArrayConstView< T1, RANK > m1, MultiArrayConstView< T2, RANK > m2, std::string message)
 Debug-mode extent check between two views. Throws std::runtime_error on mismatch.
 
template<typename T1 , typename T2 , size_t RANK>
bool cppqedutils::isEqual (MultiArrayConstView< T1, RANK > m1, MultiArrayConstView< T2, RANK > m2)
 Element-by-element equality test. Traverses all elements via incrementMultiIndex.
 
template<size_t RANK>
auto cppqedutils::multiarray::calculateStrides (Extents< RANK > extents)
 Computes first-index-fastest strides from extents (std::layout_left; column-major for rank 2): strides[0]=1, strides[i]=strides[i-1]*extents[i-1].
 
template<size_t RANK>
auto cppqedutils::multiarray::calculateExtent (Extents< RANK > extents)
 Returns the total number of elements: the product of all extents.
 
template<typename T >
auto cppqedutils::multiarray::copyInit (const std::ranges::sized_range auto &input)
 Initializer that copies from a sized range, checking that its size matches the requested extent.
 
template<typename T , size_t RANK>
void cppqedutils::checkContiguous (MultiArrayView< T, RANK > mav, std::string message)
 Debug-mode check that a view covers its storage as an owning MultiArray of the same extents would: offset 0 and first-index-fastest strides. Throws std::invalid_argument otherwise. For functions that address the flat storage directly; a sub-block or slice view fails it.
 

Variables

constexpr struct cppqedutils::multiarray::Placeholder cppqedutils::multiarray::_
 
template<typename T , size_t RANK>
constexpr auto cppqedutils::passByValue_v< MultiArrayView< T, RANK > > = true
 MultiArrayView is cheap to copy and should always be passed by value.
 
template<typename T >
constexpr auto cppqedutils::multiarray::noInit = [] (size_t e) -> std::vector<T> {return std::vector<T>(e);}
 Initializer for storage of size e whose contents the caller overwrites before reading them.
 
template<typename T >
constexpr auto cppqedutils::multiarray::zeroInit = [] (size_t e) -> std::vector<T> {return std::vector<T>(e,T(0.));}
 Initializer that allocates storage of size e and zero-initializes all elements via T(0.).
 
template<typename T , size_t RANK>
constexpr auto cppqedutils::passByValue_v< MultiArray< T, RANK > > = false
 MultiArray owns its data and must not be passed by value.