Multi-dimensional Array

Many of the data structures in the library are backed by a multi-dimensional array class.

template<typename T, typename Dims, typename Alloc = lib::Allocator<T>>
class DenseArray

A N-dimensional array class supporting compile-time dimensionality.

Template Parameters:

T – The value type of the array. Must be a trivial type.

Public Functions

inline constexpr std::array<size_t, ndims()> dims() const

The dimensions of the array.

inline constexpr size_t size() const

Return the total number of elements contained in the array.

inline constexpr size_t bytes() const

Return the memory footprint of the array in bytes.

template<size_t i>
inline size_t getsize() const

Return the value of the ith dimension.

Template Parameters:

i – The dimensions to query. Must be in [0, ndims()].

template<typename ...Is>
inline reference at(Is&&... indices)

Access the specified element.

It is the callers responsibility to ensure that all indices are inbounds.

Parameters:

indices – The indices to access. Must satisfy sizeof...(indices) == ndims()

template<typename ...Is>
inline const_reference at(Is&&... indices) const

Access the specified element.

It is the callers responsibility to ensure that all indices are inbounds.

Parameters:

indices – The indices to access. Must satisfy sizeof...(indices) == ndims()

inline constexpr const_reference first() const

Return a const reference to the first element of the array.

inline constexpr const_reference last() const

Return a const reference to the last element of the array.

template<typename ...Is>
inline span slice(Is&&... indices)

Obtain a std::span over the requested row.

The returned span will have the same extent as the last dimension of the array.

Parameters:

indices – The indices specifying the row to access. Must satisfy sizeof...(indices) == ndims() - 1.

template<typename ...Is>
inline const_span slice(Is&&... indices) const

Obtain a std::span over the requested row.

The returned span will have the same extent as the last dimension of the array.

Parameters:

indices – The indices specifying the row to access. Must satisfy sizeof...(indices) == ndims() - 1.

inline pointer begin()

Return a random access iterator to the beginning of the array.

inline const_pointer begin() const

Return a random access iterator to the beginning of the array.

inline pointer end()

Return A random access iterator to the end of the array.

inline const_pointer end() const

Return A random access iterator to the end of the array.

inline DenseArray<T, Dims, View<T>> view()

Return a mutable view over the memory of this array.

inline DenseArray<const T, Dims, View<const T>> cview() const

Return a constant view over the memory of this array.

inline DenseArray<const T, Dims, View<const T>> view() const

Return a constant view over the memory of this array.

Public Static Functions

static inline constexpr size_t extent()

Return the extent of the span returned for slice.

static inline constexpr size_t ndims()

The number of dimensions for the array.

template<size_t i>
static inline constexpr size_t getextent()

Return the extent (compiletime value) of the ith dimension.

If the queried dimension is dynamically sized, returns svs::Dyanmic.

Template Parameters:

i – The dimensions to query. Must be in [0, ndims()].

Type-deducing constructors

The family of svs::make_dense_array methods assist in array construction.

template<typename T, detail::IsDim... Dims>
auto make_dense_array(Dims... dims)

Construct an uninitialized DenseArray.

The number of dimensions is inferred from the number of arguments.

Each argument must be either convertible to size_t or a `svs::lib::Val. In the latter case, the corresponding dimension of the result array will be static.

Parameters:

dims – The (potentially static) dimensions of the resulting array.

template<typename T, typename Alloc, detail::IsDim... Dims>  requires (!detail::IsDim< Alloc >) auto make_dense_array(const Alloc &allocator

Construct a DenseArray using the given allocator.

The number of dimensions is inferred from the number of arguments.

Each argument must be either convertible to size_t or a `svs::lib::Val. In the latter case, the corresponding dimension of the result array will be static.

Parameters:
  • allocator – The allocator to use for memory.

  • dims – The (potentially static) dimensions of the resulting array.