TRIQS/nda 1.3.0
Multi-dimensional array library for C++
|
Enums, type traits, bounds checking, looping over multi-dimensional indices, structs that mimic Python's :
and ...
syntax and more.
Classes | |
struct | nda::_linear_index_t |
A small wrapper around a single long integer to be used as a linear index. More... | |
struct | nda::ellipsis |
Mimics Python's ... syntax. More... | |
struct | nda::idx_group_t< Is > |
A group of indices. More... | |
struct | nda::layout_info_t |
Stores information about the memory layout and the stride order of an array/view. More... | |
Enumerations | |
enum class | nda::layout_prop_e : uint64_t |
Compile-time guarantees of the memory layout of an array/view. More... | |
Functions | |
template<typename... Args> | |
void | nda::assert_in_bounds (int rank, long const *lengths, Args const &...args) |
Check if the given indices/arguments are within the bounds of an array/view. | |
template<typename F , auto R, std::integral Int = long> | |
__inline__ void | nda::for_each (std::array< Int, R > const &shape, F &&f) |
Loop over all possible index values of a given shape and apply a function to them. | |
template<uint64_t StaticExtents, uint64_t StrideOrder, typename F , auto R, std::integral Int = long> | |
__inline__ void | nda::for_each_static (std::array< Int, R > const &shape, F &&f) |
Loop over all possible index values of a given shape and apply a function to them. | |
template<MemoryArray A> | |
auto | nda::get_block_layout (A const &a) |
Check if a given nda::MemoryArray has a block-strided layout. | |
template<int Rank, uint64_t StaticExtents, uint64_t StrideOrder, layout_prop_e LayoutProp, typename... IdxGrps> | |
auto | nda::group_indices_layout (idx_map< Rank, StaticExtents, StrideOrder, LayoutProp > const &idxm, IdxGrps...) |
Given an nda::idx_map and a partition of its indices, return a new nda::idx_map with the grouped indices. | |
constexpr bool | nda::has_contiguous (layout_prop_e lp) |
Checks if a layout property has the contiguous property. | |
constexpr bool | nda::has_smallest_stride_is_one (layout_prop_e lp) |
Checks if a layout property has the smallest_stride_is_one property. | |
constexpr bool | nda::has_strided_1d (layout_prop_e lp) |
Checks if a layout property has the strided_1d property. | |
constexpr bool | nda::layout_property_compatible (layout_prop_e from, layout_prop_e to) |
Checks if two layout properties are compatible with each other. | |
constexpr layout_info_t | nda::operator& (layout_info_t lhs, layout_info_t rhs) |
Bitwise AND operator for layout infos. | |
constexpr layout_prop_e | nda::operator& (layout_prop_e lhs, layout_prop_e rhs) |
Bitwise AND operator for two layout properties. | |
std::ostream & | nda::operator<< (std::ostream &os, ellipsis) noexcept |
Write nda::ellipsis to a std::ostream as ___ . | |
std::ostream & | nda::operator<< (std::ostream &os, range::all_t) noexcept |
Write nda::range::all_t to a std::ostream as _ . | |
template<int Rank, uint64_t StaticExtents, uint64_t StrideOrder, layout_prop_e LayoutProp> | |
std::ostream & | nda::operator<< (std::ostream &sout, idx_map< Rank, StaticExtents, StrideOrder, LayoutProp > const &idxm) |
Write an nda::idx_map to a std::ostream. | |
std::ostream & | nda::operator<< (std::ostream &sout, layout_prop_e p) |
Write an nda::layout_prop_e to a std::ostream. | |
constexpr layout_prop_e | nda::operator| (layout_prop_e lhs, layout_prop_e rhs) |
Bitwise OR operator for two layout properties. | |
Variables | |
template<typename... Args> | |
constexpr bool | nda::ellipsis_is_present = is_any_of<ellipsis, std::remove_cvref_t<Args>...> |
Constexpr variable that is true if the parameter pack Args contains an nda::ellipsis. | |
template<typename A > | |
constexpr layout_info_t | nda::get_layout_info = layout_info_t{} |
Constexpr variable that specifies the nda::layout_info_t of type A . | |
template<typename A > | |
constexpr bool | nda::has_contiguous_layout = (has_contiguous(get_layout_info<A>.prop)) |
Constexpr variable that is true if type A has the contiguous nda::layout_prop_e guarantee. | |
template<typename A > | |
constexpr bool | nda::has_layout_smallest_stride_is_one = (has_smallest_stride_is_one(get_layout_info<A>.prop)) |
Constexpr variable that is true if type A has the smallest_stride_is_one nda::layout_prop_e guarantee. | |
template<typename A > | |
constexpr bool | nda::has_layout_strided_1d = (has_strided_1d(get_layout_info<A>.prop)) |
Constexpr variable that is true if type A has the strided_1d nda::layout_prop_e guarantee. | |
template<int... Is> | |
idx_group_t< Is... > | nda::idx_group = {} |
Variable template for an nda::idx_group_t. | |
template<typename T > | |
constexpr bool | nda::is_range_or_ellipsis = is_any_of<std::remove_cvref_t<T>, range, range::all_t, ellipsis> |
Constexpr variable that is true if the type T is either an nda::range , an nda::range::all_t or an nda::ellipsis. | |
|
strong |
#include <nda/traits.hpp>
Compile-time guarantees of the memory layout of an array/view.
The possible values are:
none
: No guarantees.strided_1d
: There is a constant overall stride in memory.smallest_stride_is_one
: The stride in the fastest dimension is 1.contiguous
: The array/view is contiguous in memory, i.e. it is strided_1d
and smallest_stride_is_one
.Furthermore, the set of values has a partial order:
contiguous
> strided_1d
> none
contiguous
> smallest_stride_is_one
> none
Definition at line 222 of file traits.hpp.
void nda::assert_in_bounds | ( | int | rank, |
long const * | lengths, | ||
Args const &... | args ) |
#include <nda/layout/bound_check_worker.hpp>
Check if the given indices/arguments are within the bounds of an array/view.
It uses the shape and rank of the array/view to check if the given arguments are within bounds. If an error is detected, it throws a std::runtime_error with the error message.
Args | Types of the arguments to be checked. |
rank | Rank of the array/view. |
lengths | Shape of the array/view. |
args | Arguments (long indices, nda::range , nda::range::all_t or nda::ellipsis) to be checked. |
Definition at line 106 of file bound_check_worker.hpp.
__inline__ void nda::for_each | ( | std::array< Int, R > const & | shape, |
F && | f ) |
#include <nda/layout/for_each.hpp>
Loop over all possible index values of a given shape and apply a function to them.
It traverses all possible indices in C-order, i.e. the last index varies the fastest. The shape is specified at runtime and the given function f
must be callable with as many long values as the number of dimensions in the shape array, e.g. for a 3-dimensional shape the function must be callable as f(long, long, long)
.
F | Callable type. |
R | Number of dimensions. |
Int | Integer type used in the shape array. |
shape | Shape to loop over (index bounds). |
f | Callable object. |
Definition at line 129 of file for_each.hpp.
__inline__ void nda::for_each_static | ( | std::array< Int, R > const & | shape, |
F && | f ) |
#include <nda/layout/for_each.hpp>
Loop over all possible index values of a given shape and apply a function to them.
It traverses all possible indices in the order given by the encoded StrideOrder
parameter. The shape is either specified at runtime (StaticExtents == 0
) or, partially or fully, at compile time (StaticExtents != 0
). The given function f
must be callable with as many long values as the number of dimensions in the shape array, e.g. for a 3-dimensional shape the function must be callable as f(long, long, long)
.
StaticExtents | Encoded static extents. |
StrideOrder | Encoded stride order. |
F | Callable type. |
R | Number of dimensions. |
Int | Integer type used in the shape array. |
shape | Shape to loop over (index bounds). |
f | Callable object. |
Definition at line 108 of file for_each.hpp.
auto nda::get_block_layout | ( | A const & | a | ) |
#include <nda/basic_functions.hpp>
Check if a given nda::MemoryArray has a block-strided layout.
If the array is block-strided, return the number of blocks, their size and the stride.
An array is considered to be block-strided if its data in memory is laid out as contiguous blocks of the same size (> 1) repeated with a single stride in memory.
A block-strided array has at most 1 non-contiguous index m
, i.e. strides[order[m]] != strides[order[m+1]] * shape[order[m+1]]
.
A | nda::MemoryArray type. |
a | Array object. |
Definition at line 560 of file basic_functions.hpp.
auto nda::group_indices_layout | ( | idx_map< Rank, StaticExtents, StrideOrder, LayoutProp > const & | idxm, |
IdxGrps... | ) |
#include <nda/group_indices.hpp>
Given an nda::idx_map and a partition of its indices, return a new nda::idx_map with the grouped indices.
It is used to create an nda::group_indices_view: group_indices_view(A, idx_group<i,j,...>, idx_group<k,l,...>, ...)
. The resulting index map is of rank sizeof...(IdxGrps)
with merged indices, one for each group.
Preconditions:
{0, 1, ..., R - 1}
where R
is the rank.For example, let's look at the following strider order: S = (2, 1, 0)
. That means that dimension 0 is the fastest varying index, then dimension 1 and dimension 2 is slowest. We say that dimensions 0 and 1 are consecutive in memory. The same goes for dimensions 2 and 1. However, dimensions 0 and 2 are not consecutive in memory.
To check if a group of indices are consecutive in memory, we look at the inverse permutation of the stride order. The stride order S
is a permutation which maps an integer j to a dimension/index i of the array such that S[j] = i
is the (j+1)-th slowest varying index, i.e. S[0]
is the slowest index and S[R - 1]
is the fastest. The inverse permutation, M = S^{-1}
, therefore tells us how fast a given index varies, e.g. M[i] = j
means that index i varies the (j+1)-th slowest.
Rank | Rank of the original nda::idx_map. |
StaticExtents | Static extents of the original nda::idx_map. |
StrideOrder | Stride order of the original nda::idx_map. |
LayoutProp | Layout property of the original nda::idx_map. |
IdxGrps | Groups of indices. |
idxm | Original nda::idx_map. |
Definition at line 157 of file group_indices.hpp.
|
inlineconstexpr |
#include <nda/traits.hpp>
Checks if a layout property has the contiguous
property.
lp | nda::layout_prop_e to check. |
contiguous
property, false otherwise. Definition at line 282 of file traits.hpp.
|
inlineconstexpr |
#include <nda/traits.hpp>
Checks if a layout property has the smallest_stride_is_one
property.
lp | nda::layout_prop_e to check. |
smallest_stride_is_one
property, false otherwise. Definition at line 274 of file traits.hpp.
|
inlineconstexpr |
#include <nda/traits.hpp>
Checks if a layout property has the strided_1d
property.
lp | nda::layout_prop_e to check. |
strided_1d
property, false otherwise. Definition at line 266 of file traits.hpp.
|
inlineconstexpr |
#include <nda/traits.hpp>
Checks if two layout properties are compatible with each other.
from | Source nda::layout_prop_e. |
to | Target nda::layout_prop_e. |
Definition at line 237 of file traits.hpp.
|
constexpr |
#include <nda/traits.hpp>
Bitwise AND operator for layout infos.
lhs | Left hand side nda::layout_info_t operand. |
rhs | Right hand side nda::layout_info_t operand. |
Definition at line 312 of file traits.hpp.
|
constexpr |
#include <nda/traits.hpp>
Bitwise AND operator for two layout properties.
lhs | Left hand side nda::layout_prop_e operand. |
rhs | Right hand side nda::layout_prop_e operand. |
Definition at line 258 of file traits.hpp.
|
inlinenoexcept |
#include <nda/layout/range.hpp>
Write nda::ellipsis to a std::ostream as ___
.
os | Output stream. |
|
inlinenoexcept |
#include <nda/layout/range.hpp>
Write nda::range::all_t
to a std::ostream as _
.
os | Output stream. |
std::ostream & nda::operator<< | ( | std::ostream & | sout, |
idx_map< Rank, StaticExtents, StrideOrder, LayoutProp > const & | idxm ) |
#include <nda/print.hpp>
Write an nda::idx_map to a std::ostream.
Rank | Rank of the nda::idx_map. |
StaticExtents | StaticExtents of the nda::idx_map. |
StrideOrder | StrideOrder of the nda::idx_map. |
LayoutProp | Layout property of the nda::idx_map. |
sout | std::ostream object. |
idxm | nda::idx_map object. |
|
inline |
#include <nda/print.hpp>
Write an nda::layout_prop_e to a std::ostream.
sout | std::ostream object. |
p | nda::layout_prop_e object. |
|
constexpr |
#include <nda/traits.hpp>
Bitwise OR operator for two layout properties.
lhs | Left hand side nda::layout_prop_e operand. |
rhs | Right hand side nda::layout_prop_e operand. |
Definition at line 249 of file traits.hpp.
|
inline |
#include <nda/group_indices.hpp>
Variable template for an nda::idx_group_t.
Is | Indices. |
Definition at line 124 of file group_indices.hpp.