TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
nda::rect_str< Rank, StaticExtents, StrideOrder, LayoutProp >

#include <nda/layout/rect_str.hpp>

Detailed Description

template<int Rank, uint64_t StaticExtents, uint64_t StrideOrder, layout_prop_e LayoutProp>
class nda::rect_str< Rank, StaticExtents, StrideOrder, LayoutProp >

Layout that specifies how to map multi-dimensional indices including possible string indices to a linear/flat index.

It extends the functionality of nda::idx_map by supporting string indices.

Template Parameters
RankNumber of dimensions.
StaticExtentCompile-time known shape (zero if fully dynamic).
StrideOrderOrder in which the dimensions are stored in memory.
LayoutPropCompile-time guarantees about the layout of the data in memory.

Definition at line 79 of file rect_str.hpp.

Inheritance diagram for nda::rect_str< Rank, StaticExtents, StrideOrder, LayoutProp >:
nda::idx_map< Rank, StaticExtents, StrideOrder, LayoutProp >

Public Member Functions

 rect_str ()=default
 Default constructor.
 
 rect_str (base_t const &idxm) noexcept
 Construct an nda::rect_str from a given nda::idx_map.
 
 rect_str (base_t const &idxm, ind_t const &str_indices) noexcept
 Construct an nda::rect_str from a given nda::idx_map and string indices.
 
 rect_str (nda::array< nda::array< std::string, 1 >, 1 > str_indices) noexcept(false)
 Construct an nda::rect_str from given string indices and with contiguous strides.
 
 rect_str (rect_str &&)=default
 Default move constructor.
 
 rect_str (rect_str const &)=default
 Default copy constructor.
 
template<uint64_t SE, layout_prop_e LP>
 rect_str (rect_str< Rank, SE, StrideOrder, LP > const &rstr) noexcept(false)
 Construct an nda::rect_str from another nda::rect_str with different layout properties and static extents.
 
template<layout_prop_e LP>
 rect_str (rect_str< Rank, StaticExtents, StrideOrder, LP > const &rstr) noexcept
 Construct an nda::rect_str from another nda::rect_str with different layout properties.
 
 rect_str (std::array< long, base_t::n_dynamic_extents > const &shape) noexcept
 Construct an nda::rect_str from an array with its dynamic extents.
 
 rect_str (std::array< long, Rank > const &shape) noexcept
 Construct an nda::rect_str from a given shape and with contiguous strides.
 
 rect_str (std::array< long, Rank > const &shape, std::array< long, Rank > const &strides) noexcept
 Construct an nda::rect_str from a given shape and strides.
 
auto const & get_string_indices () const
 Get the string indices.
 
bool operator!= (rect_str const &rhs)
 Not-equal-to operator for two nda::rect_str objects.
 
template<typename... Args>
__inline__ long operator() (Args const &...args) const
 Function call operator to map a given multi-dimensional index to a linear index.
 
rect_stroperator= (rect_str &&)=default
 Default move assignment operator.
 
rect_stroperator= (rect_str const &)=default
 Default copy assignment operator.
 
bool operator== (rect_str const &rhs) const
 Equal-to operator for two nda::rect_str objects.
 
template<typename... Args>
auto slice (Args const &...args) const
 Get a new nda::rect_str by taking a slice of the current one.
 
template<uint64_t Permutation>
auto transpose () const
 Create a new nda::rect_str by permuting the indices/dimensions with a given permutation.
 
- Public Member Functions inherited from nda::idx_map< Rank, StaticExtents, StrideOrder, LayoutProp >
 idx_map ()
 Default constructor.
 
 idx_map (idx_map &&)=default
 Default move constructor.
 
 idx_map (idx_map const &)=default
 Default copy constructor.
 
template<uint64_t SE, uint64_t SO, layout_prop_e LP>
requires (stride_order_encoded != SO)
 idx_map (idx_map< Rank, SE, SO, LP > const &)
 Construct a new map from an existing map with a different stride order.
 
template<uint64_t SE, layout_prop_e LP>
 idx_map (idx_map< Rank, SE, StrideOrder, LP > const &idxm) noexcept(false)
 Construct a new map from an existing map with different layout properties and different static extents.
 
template<layout_prop_e LP>
 idx_map (idx_map< Rank, StaticExtents, StrideOrder, LP > const &idxm) noexcept
 Construct a new map from an existing map with different layout properties.
 
template<std::integral Int = long>
 idx_map (std::array< Int, Rank > const &shape) noexcept
 Construct a new map from a given shape and with contiguous strides.
 
 idx_map (std::array< long, n_dynamic_extents > const &shape) noexcept
 Construct a new map from an array with its dynamic extents.
 
template<int R>
requires (R != Rank)
 idx_map (std::array< long, R > const &)
 Construct a new map with a shape of a different rank.
 
 idx_map (std::array< long, Rank > const &shape, std::array< long, Rank > const &strides) noexcept(!check_stride_order)
 Construct a new map from a given shape and strides.
 
bool is_contiguous () const noexcept
 Is the data contiguous in memory?
 
bool is_stride_order_valid () const
 Check if the shape and strides of the current map are compatible with its stride order.
 
bool is_strided_1d () const noexcept
 Is the data strided in memory with a constant stride?
 
std::array< long, Rank > const & lengths () const noexcept
 Get the extents of all dimensions.
 
long min_stride () const noexcept
 Get the value of the smallest stride.
 
template<typename... Args>
__inline__ long operator() (Args const &...args) const noexcept(true)
 Function call operator to map a given multi-dimensional index to a linear index.
 
idx_mapoperator= (idx_map &&)=default
 Default move assignment operator.
 
idx_mapoperator= (idx_map const &)=default
 Default copy assignment operator.
 
template<int R, uint64_t SE, uint64_t SO, layout_prop_e LP>
bool operator== (idx_map< R, SE, SO, LP > const &rhs) const
 Equal-to operator for two nda::idx_map objects.
 
long size () const noexcept
 Get the total number of elements.
 
template<typename... Args>
auto slice (Args const &...args) const
 Get a new nda::idx_map by taking a slice of the current one.
 
std::array< long, Rank > const & strides () const noexcept
 Get the strides of all dimensions.
 
std::array< long, Rank > to_idx (long lin_idx) const
 Calculate the multi-dimensional index from a given linear index.
 
template<uint64_t Permutation>
auto transpose () const
 Create a new map by permuting the indices/dimensions of the current map with a given permutation.
 

Static Public Attributes

template<typename T >
static constexpr int argument_is_allowed_for_call = base_t::template argument_is_allowed_for_call<T> or std::is_constructible_v<std::string, T>
 Alias template to check if type T can be used to access a specific element.
 
template<typename T >
static constexpr int argument_is_allowed_for_call_or_slice
 Alias template to check if type T can be used to either access a specific element or a slice of elements.
 
- Static Public Attributes inherited from nda::idx_map< Rank, StaticExtents, StrideOrder, LayoutProp >
template<typename T >
static constexpr int argument_is_allowed_for_call = std::is_constructible_v<long, T>
 Alias template to check if type T can be used to access a single element.
 
template<typename T >
static constexpr int argument_is_allowed_for_call_or_slice
 Alias template to check if type T can be used to either access a single element or a slice of elements.
 
static constexpr layout_info_t layout_info = layout_info_t{stride_order_encoded, layout_prop}
 Compile-time information about the layout (stride order and layout properties).
 
static constexpr layout_prop_e layout_prop = LayoutProp
 Compile-time memory layout properties.
 
static constexpr std::array< int, Rank > static_extents = decode<Rank>(StaticExtents)
 Decoded static extents.
 
static constexpr uint64_t static_extents_encoded = StaticExtents
 Encoded static extents.
 
static constexpr std::array< int, Rank > stride_order = (StrideOrder == 0 ? permutations::identity<Rank>() : decode<Rank>(StrideOrder))
 Decoded stride order.
 
static constexpr uint64_t stride_order_encoded = encode(stride_order)
 Encoded stride order.
 

Additional Inherited Members

- Static Public Member Functions inherited from nda::idx_map< Rank, StaticExtents, StrideOrder, LayoutProp >
static constexpr long ce_size () noexcept
 Get the size known at compile-time.
 
static constexpr bool is_stride_order_C ()
 Is the stride order equal to C-order?
 
static constexpr bool is_stride_order_Fortran ()
 Is the stride order equal to Fortran-order?
 
template<std::integral Int>
static bool is_stride_order_valid (Int *lenptr, Int *strptr)
 Check if a given shape and strides are compatible with the stride order.
 
static constexpr int rank () noexcept
 Get the rank of the map.
 
- Static Protected Attributes inherited from nda::idx_map< Rank, StaticExtents, StrideOrder, LayoutProp >
static constexpr int n_dynamic_extents
 Number of dynamic dimensions/extents.
 

Constructor & Destructor Documentation

◆ rect_str() [1/9]

template<int Rank, uint64_t StaticExtents, uint64_t StrideOrder, layout_prop_e LayoutProp>
nda::rect_str< Rank, StaticExtents, StrideOrder, LayoutProp >::rect_str ( )
default

Default constructor.

The string indices are not initialized and the underlying nda::idx_map is default constructed.

◆ rect_str() [2/9]

template<int Rank, uint64_t StaticExtents, uint64_t StrideOrder, layout_prop_e LayoutProp>
nda::rect_str< Rank, StaticExtents, StrideOrder, LayoutProp >::rect_str ( base_t const & idxm)
inlinenoexcept

Construct an nda::rect_str from a given nda::idx_map.

Parameters
idxmnda::idx_map object.

Definition at line 143 of file rect_str.hpp.

◆ rect_str() [3/9]

template<int Rank, uint64_t StaticExtents, uint64_t StrideOrder, layout_prop_e LayoutProp>
nda::rect_str< Rank, StaticExtents, StrideOrder, LayoutProp >::rect_str ( base_t const & idxm,
ind_t const & str_indices )
inlinenoexcept

Construct an nda::rect_str from a given nda::idx_map and string indices.

Warning
The shape of the string indices is not checked to be consistent with the shape of the nda::idx_map.
Parameters
idxmnda::idx_map object.
str_indicesString indices.

Definition at line 153 of file rect_str.hpp.

◆ rect_str() [4/9]

template<int Rank, uint64_t StaticExtents, uint64_t StrideOrder, layout_prop_e LayoutProp>
template<layout_prop_e LP>
nda::rect_str< Rank, StaticExtents, StrideOrder, LayoutProp >::rect_str ( rect_str< Rank, StaticExtents, StrideOrder, LP > const & rstr)
inlinenoexcept

Construct an nda::rect_str from another nda::rect_str with different layout properties.

Template Parameters
LPLayout properties of the other nda::rect_str.
Parameters
rstrOther nda::rect_str object.

Definition at line 162 of file rect_str.hpp.

◆ rect_str() [5/9]

template<int Rank, uint64_t StaticExtents, uint64_t StrideOrder, layout_prop_e LayoutProp>
template<uint64_t SE, layout_prop_e LP>
nda::rect_str< Rank, StaticExtents, StrideOrder, LayoutProp >::rect_str ( rect_str< Rank, SE, StrideOrder, LP > const & rstr)
inline

Construct an nda::rect_str from another nda::rect_str with different layout properties and static extents.

Template Parameters
SEStatic extents of the other nda::rect_str.
LPLayout properties of the other nda::rect_str.
Parameters
rstrOther nda::rect_str object.

Definition at line 173 of file rect_str.hpp.

◆ rect_str() [6/9]

template<int Rank, uint64_t StaticExtents, uint64_t StrideOrder, layout_prop_e LayoutProp>
nda::rect_str< Rank, StaticExtents, StrideOrder, LayoutProp >::rect_str ( std::array< long, Rank > const & shape,
std::array< long, Rank > const & strides )
inlinenoexcept

Construct an nda::rect_str from a given shape and strides.

Parameters
shapeShape of the map.
stridesStrides of the map.

Definition at line 182 of file rect_str.hpp.

◆ rect_str() [7/9]

template<int Rank, uint64_t StaticExtents, uint64_t StrideOrder, layout_prop_e LayoutProp>
nda::rect_str< Rank, StaticExtents, StrideOrder, LayoutProp >::rect_str ( std::array< long, Rank > const & shape)
inlinenoexcept

Construct an nda::rect_str from a given shape and with contiguous strides.

Parameters
shapeShape of the map.

Definition at line 188 of file rect_str.hpp.

◆ rect_str() [8/9]

template<int Rank, uint64_t StaticExtents, uint64_t StrideOrder, layout_prop_e LayoutProp>
nda::rect_str< Rank, StaticExtents, StrideOrder, LayoutProp >::rect_str ( nda::array< nda::array< std::string, 1 >, 1 > str_indices)
inline

Construct an nda::rect_str from given string indices and with contiguous strides.

Parameters
str_indicesString indices.

Definition at line 194 of file rect_str.hpp.

◆ rect_str() [9/9]

template<int Rank, uint64_t StaticExtents, uint64_t StrideOrder, layout_prop_e LayoutProp>
nda::rect_str< Rank, StaticExtents, StrideOrder, LayoutProp >::rect_str ( std::array< long, base_t::n_dynamic_extents > const & shape)
inlinenoexcept

Construct an nda::rect_str from an array with its dynamic extents.

The missing extents are taken from the static extents.

Parameters
shapesta::array containing the dynamic extents only.

Definition at line 202 of file rect_str.hpp.

Member Function Documentation

◆ get_string_indices()

template<int Rank, uint64_t StaticExtents, uint64_t StrideOrder, layout_prop_e LayoutProp>
auto const & nda::rect_str< Rank, StaticExtents, StrideOrder, LayoutProp >::get_string_indices ( ) const
inline

Get the string indices.

If the string indices are not yet initialized, they are initialized with the default values, i.e. "0", "1", "2", ..., and so on.

Returns
String indices.

Definition at line 110 of file rect_str.hpp.

◆ operator!=()

template<int Rank, uint64_t StaticExtents, uint64_t StrideOrder, layout_prop_e LayoutProp>
bool nda::rect_str< Rank, StaticExtents, StrideOrder, LayoutProp >::operator!= ( rect_str< Rank, StaticExtents, StrideOrder, LayoutProp > const & rhs)
inline

Not-equal-to operator for two nda::rect_str objects.

Parameters
rhsRight hand side nda::rect_str operand.
Returns
True if they are not equal, false otherwise.

Definition at line 315 of file rect_str.hpp.

◆ operator()()

template<int Rank, uint64_t StaticExtents, uint64_t StrideOrder, layout_prop_e LayoutProp>
template<typename... Args>
__inline__ long nda::rect_str< Rank, StaticExtents, StrideOrder, LayoutProp >::operator() ( Args const &... args) const
inline

Function call operator to map a given multi-dimensional index to a linear index.

See also nda::idx_map.

Template Parameters
ArgsTypes of the arguments.
Parameters
argsMulti-dimensional index, including possible string indices.
Returns
Linear/Flat index.

Definition at line 253 of file rect_str.hpp.

◆ operator==()

template<int Rank, uint64_t StaticExtents, uint64_t StrideOrder, layout_prop_e LayoutProp>
bool nda::rect_str< Rank, StaticExtents, StrideOrder, LayoutProp >::operator== ( rect_str< Rank, StaticExtents, StrideOrder, LayoutProp > const & rhs) const
inline

Equal-to operator for two nda::rect_str objects.

Parameters
rhsRight hand side nda::rect_str operand.
Returns
True if the underlying nda::idx_map and the string indices are equal, false otherwise.

Definition at line 305 of file rect_str.hpp.

◆ slice()

template<int Rank, uint64_t StaticExtents, uint64_t StrideOrder, layout_prop_e LayoutProp>
template<typename... Args>
auto nda::rect_str< Rank, StaticExtents, StrideOrder, LayoutProp >::slice ( Args const &... args) const
inline

Get a new nda::rect_str by taking a slice of the current one.

Warning
nda::ellipsis that cover more than 1 dimension will not work properly. Use nda::range::all_t instead.
Template Parameters
ArgsTypes of the arguments.
Parameters
argsMulti-dimensional index consisting of strings, long, nda::range, nda::range::all_t or nda::ellipsis objects.
Returns
A std::pair containing the offset in memory, i.e. the flat index of the first element of the slice and the new nda::rect_str.

Definition at line 295 of file rect_str.hpp.

◆ transpose()

template<int Rank, uint64_t StaticExtents, uint64_t StrideOrder, layout_prop_e LayoutProp>
template<uint64_t Permutation>
auto nda::rect_str< Rank, StaticExtents, StrideOrder, LayoutProp >::transpose ( ) const
inline

Create a new nda::rect_str by permuting the indices/dimensions with a given permutation.

Let A be the current and A' the new, permuted map. P is the given permutation. We define the permuted nda::rect_str A' to be the one with the following properties:

  • A'(i_0,...,i_{n-1}) = A(i_{P[0]},...,i_{P[n-1]})
  • A'.lengths()[k] == A.lengths()[P^{-1}[k]]
  • A'.strides()[k] == A.strides()[P^{-1}[k]]
  • The stride order of A' is the composition of P and the stride order of A (note that the stride order itself is a permutation).
Template Parameters
PermutationPermutation to apply.
Returns
New nda::rect_str with permuted indices.

Definition at line 332 of file rect_str.hpp.


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