Gromacs  2024.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Public Types | Public Member Functions
gmx::MultiDimArray< TContainer, Extents, LayoutPolicy > Class Template Reference

#include <gromacs/math/include/gromacs/math/multidimarray.h>

Description

template<class TContainer, class Extents, class LayoutPolicy = layout_right>
class gmx::MultiDimArray< TContainer, Extents, LayoutPolicy >

Multidimensional array that manages its own memory.

Note
No bounds checking when accessing memory
That the view holds a valid pointer to the data is a class invariant.

The Container type that stores the data may be resizable (std::vector or similar) or static (std::array or similar). Copy and move assignment routines as well as swapping are designed to yield good performances in both cases, notably foregoing the copy-swap idiom due to the bad performance in swapping std::array.

This class avoids throwing exceptions, apart from the ones that might be thrown from the containers during resizing an allocation. (bad_malloc from std::vector is a likely candidate)

Holds as many elements as required by a multidimensional view.

Template Parameters
TContainerData type container for the data to be stored as MultiDimArray with random element access and value_type, reference and const_reference exposed
ExtentsAn extents class describing the array dimensions as used in module_mdspan
LayoutPolicyThe data layout as in module_mdspan describes translation of indices to memory offset. Defaults to right aligned, so that the right-most index is contiguous in memory.

Public Types

using value_type = typename TContainer::value_type
 the type of values that are stored
 
using reference = typename TContainer::reference
 reference type to the stored values
 
using const_reference = typename TContainer::const_reference
 const reference type to the stored values
 
using view_type = basic_mdspan< value_type, Extents, LayoutPolicy >
 the view used to access the data
 
using const_view_type = basic_mdspan< const value_type, Extents, LayoutPolicy >
 const view on the data
 
using iterator = typename ArrayRef< value_type >::iterator
 Iterator type for contiguous iteration over the stored data. Used, e.g., in free begin and end functions.
 
using const_iterator = const typename ArrayRef< const value_type >::const_iterator
 Const iterator type for contiguous iteration over the stored data. used, e.g., in free begin and end functions.
 

Public Member Functions

template<class... IndexType, typename T = TContainer, typename = typename std::enable_if_t<detail::is_resizable_v<T>>>
 MultiDimArray (IndexType...dynamicExtent)
 Allocate dynamic array data and set view with the dynamic extents. More...
 
template<typename T = TContainer, typename = typename std::enable_if_t<!detail::is_resizable_v<T>>>
constexpr MultiDimArray (const TContainer &data={}) noexcept
 Construction from fixed sized arrays if the array size is static and layout policy allows compile time determination of the container size. More...
 
constexpr MultiDimArray (const MultiDimArray &o)
 Copy constructor.
 
 MultiDimArray (MultiDimArray &&o) noexcept
 Move constructor.
 
MultiDimArrayoperator= (const MultiDimArray &o)
 Copy assignment.
 
MultiDimArrayoperator= (MultiDimArray &&o) noexcept
 Move assignment.
 
void swap (MultiDimArray &o)
 Swaps content with other.
 
template<class... IndexType>
void resize (IndexType...dynamicExtent)
 Resize the dynamic extents of the array if any and set container size accordingly. More...
 
template<class... IndexType>
reference operator() (IndexType...index) noexcept
 Data access via multidimensional indices. This allows referencing rank R array elements as array(x_0,x_1,x_2, .., x_R) More...
 
template<class... IndexType>
constexpr const_reference operator() (IndexType...index) const noexcept
 Const data access via multidimensional indices. This allows referencing rank R array elements as array(x_0,x_1,x_2, .., x_R) More...
 
ArrayRef< value_typetoArrayRef ()
 Contiguous access to the data. More...
 
constexpr ArrayRef< const
value_type
toArrayRef () const
 Contiguous const access to the data. More...
 
constexpr view_type::index_type extent (int k) const noexcept
 Return the extent. More...
 
constexpr view_type asView () noexcept
 Conversion to multidimensional view on the data.
 
constexpr const_view_type asConstView () const noexcept
 Conversion to const multidimensional view on the data.
 

Constructor & Destructor Documentation

template<class TContainer, class Extents, class LayoutPolicy = layout_right>
template<class... IndexType, typename T = TContainer, typename = typename std::enable_if_t<detail::is_resizable_v<T>>>
gmx::MultiDimArray< TContainer, Extents, LayoutPolicy >::MultiDimArray ( IndexType...  dynamicExtent)
inline

Allocate dynamic array data and set view with the dynamic extents.

Parameters
[in]dynamicExtentA parameter pack that describes the dynamic size of the array. Empty if purely static.
Template Parameters
IndexTypeParameter pack type holding the dynamic extents of the multidimensional array
template<class TContainer, class Extents, class LayoutPolicy = layout_right>
template<typename T = TContainer, typename = typename std::enable_if_t<!detail::is_resizable_v<T>>>
constexpr gmx::MultiDimArray< TContainer, Extents, LayoutPolicy >::MultiDimArray ( const TContainer &  data = {})
inlinenoexcept

Construction from fixed sized arrays if the array size is static and layout policy allows compile time determination of the container size.

Enables the expected initialization MultiDimArray<std::array<float, 9>, extents<3,3>> arr = {{1,2...}}

Template Parameters
TTemplate parameter for activation via SFINAE.

Member Function Documentation

template<class TContainer, class Extents, class LayoutPolicy = layout_right>
constexpr view_type::index_type gmx::MultiDimArray< TContainer, Extents, LayoutPolicy >::extent ( int  k) const
inlinenoexcept

Return the extent.

Parameters
[in]kdimension to query for extent
Returns
extent along specified dimension
template<class TContainer, class Extents, class LayoutPolicy = layout_right>
template<class... IndexType>
reference gmx::MultiDimArray< TContainer, Extents, LayoutPolicy >::operator() ( IndexType...  index)
inlinenoexcept

Data access via multidimensional indices. This allows referencing rank R array elements as array(x_0,x_1,x_2, .., x_R)

Parameters
[in]indexmultidimensional indices as parameter pack the number of parameters must match the rank of the array.
Returns
reference to array element
template<class TContainer, class Extents, class LayoutPolicy = layout_right>
template<class... IndexType>
constexpr const_reference gmx::MultiDimArray< TContainer, Extents, LayoutPolicy >::operator() ( IndexType...  index) const
inlinenoexcept

Const data access via multidimensional indices. This allows referencing rank R array elements as array(x_0,x_1,x_2, .., x_R)

Parameters
[in]indexmultidimensional indices as parameter pack the number of parameters must match the rank of the array.
Returns
const reference to array element
template<class TContainer, class Extents, class LayoutPolicy = layout_right>
template<class... IndexType>
void gmx::MultiDimArray< TContainer, Extents, LayoutPolicy >::resize ( IndexType...  dynamicExtent)
inline

Resize the dynamic extents of the array if any and set container size accordingly.

Invalidates data and views of this array.

Parameters
[in]dynamicExtentA parameter pack that describes the dynamic size of the array. Empty if purely static.
Template Parameters
IndexTypeParameter pack type holding the dynamic extents of the multidimensional array
template<class TContainer, class Extents, class LayoutPolicy = layout_right>
ArrayRef<value_type> gmx::MultiDimArray< TContainer, Extents, LayoutPolicy >::toArrayRef ( )
inline

Contiguous access to the data.

Returns
ArrayRef to stored data.
template<class TContainer, class Extents, class LayoutPolicy = layout_right>
constexpr ArrayRef<const value_type> gmx::MultiDimArray< TContainer, Extents, LayoutPolicy >::toArrayRef ( ) const
inline

Contiguous const access to the data.

Returns
ArrayRef to stored data.

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