TRIQS/nda 1.3.0
Multi-dimensional array library for C++
|
Various functions to create new array/view objects and to transform existing ones.
We can group the different functions into
Note that some of the functions might return an array, a view, a scalar or a lazy expression depending on the input arguments.
Functions | |
template<std::integral Int = long> | |
auto | nda::arange (long first, long last, long step=1) |
Make a 1-dimensional integer array and initialize it with values of a given nda::range . | |
template<std::integral Int = long> | |
auto | nda::arange (long last) |
Make a 1-dimensional integer array and initialize it with values of a given nda::range with a step size of 1 and a starting value of 0. | |
template<size_t Axis = 0, Array A0, Array... As> | |
auto | nda::concatenate (A0 const &a0, As const &...as) |
Join a sequence of nda::Array types along an existing axis. | |
template<typename V > requires (std::ranges::contiguous_range<V> or ArrayOfRank<V, 1>) | |
ArrayOfRank< 2 > auto | nda::diag (V const &v) |
Get a new nda::matrix with the given values on the diagonal. | |
template<MemoryArrayOfRank< 2 > M> | |
ArrayOfRank< 1 > auto | nda::diagonal (M &m) |
Get a view of the diagonal of a 2-dimensional array/view. | |
template<Scalar S, std::integral Int = long> | |
auto | nda::eye (Int dim) |
Create an identity nda::matrix with ones on the diagonal. | |
template<MemoryArray A> | |
auto | nda::flatten (A &&a) |
Flatten an nda::basic_array or nda::basic_array_view to a 1-dimensional array/view by reshaping it. | |
template<MemoryArray A, typename... IdxGrps> | |
auto | nda::group_indices_view (A &&a, IdxGrps...) |
Create a new nda::basic_array or nda::basic_array_view by grouping indices together of a given array/view. | |
template<typename T , int R, typename LP , char A, typename CP > | |
auto | nda::make_array_const_view (basic_array< T, R, LP, A, CP > const &a) |
Make an nda::array_const_view of a given nda::basic_array. | |
template<typename T , int R, typename LP , char A, typename AP , typename OP > | |
auto | nda::make_array_const_view (basic_array_view< T, R, LP, A, AP, OP > const &a) |
Make an nda::array_const_view of a given nda::basic_array_view. | |
template<typename T , int R, typename LP , char A, typename CP > | |
auto | nda::make_array_view (basic_array< T, R, LP, A, CP > const &a) |
Make an nda::array_view of a given nda::basic_array. | |
template<typename T , int R, typename LP , char A, typename AP , typename OP > | |
auto | nda::make_array_view (basic_array_view< T, R, LP, A, AP, OP > const &a) |
Make an nda::array_view of a given nda::basic_array_view. | |
template<typename T , int R, typename LP , char A, typename CP > | |
auto | nda::make_const_view (basic_array< T, R, LP, A, CP > const &a) |
Make an nda::basic_array_view with a const value type from a given nda::basic_array. | |
template<typename T , int R, typename LP , char A, typename AP , typename OP > | |
auto | nda::make_const_view (basic_array_view< T, R, LP, A, AP, OP > const &a) |
Make an nda::basic_array_view with a const value type from a given nda::basic_array_view. | |
template<typename T , int R, typename LP , char A, typename CP > | |
auto | nda::make_matrix_view (basic_array< T, R, LP, A, CP > const &a) |
Make an nda::matrix_view of a given nda::basic_array. | |
template<typename T , int R, typename LP , char A, typename AP , typename OP > | |
auto | nda::make_matrix_view (basic_array_view< T, R, LP, A, AP, OP > const &a) |
Make an nda::matrix_view of a given nda::basic_array_view. | |
template<typename A , typename A_t = std::decay_t<A>> | |
decltype(auto) | nda::make_regular (A &&a) |
Make a given object regular. | |
template<MemoryArray A, typename NewLayoutType > | |
auto | nda::map_layout_transform (A &&a, NewLayoutType const &new_layout) |
Transform the memory layout of an nda::basic_array or nda::basic_array_view. | |
template<typename T , std::integral... Ints> | |
auto | nda::ones (Ints... is) |
Make an array with the given dimensions and one-initialize it. | |
template<typename T , std::integral Int, auto Rank> requires (nda::is_scalar_v<T>) | |
auto | nda::ones (std::array< Int, Rank > const &shape) |
Make an array of the given shape and one-initialize it. | |
template<uint64_t Permutation, MemoryArray A> | |
auto | nda::permuted_indices_view (A &&a) |
Permute the indices/dimensions of an nda::basic_array or nda::basic_array_view. | |
template<typename RealType = double, std::integral... Ints> | |
auto | nda::rand (Ints... is) |
Make an array of the given dimensions and initialize it with random values from the uniform distribution over [0, 1). | |
template<typename RealType = double, std::integral Int, auto Rank> requires (std::is_floating_point_v<RealType>) | |
auto | nda::rand (std::array< Int, Rank > const &shape) |
Make an array of the given shape and initialize it with random values from the uniform distribution over [0, 1). | |
template<int N, typename A > requires (nda::is_regular_or_view_v<A>) | |
auto | nda::reinterpret_add_fast_dims_of_size_one (A &&a) |
Add N fast varying dimensions of size 1 to a given nda::basic_array or nda::basic_array_view. | |
template<MemoryArray A, std::integral... Ints> | |
auto | nda::reshape (A &&a, Ints... is) |
Reshape an nda::basic_array or nda::basic_array_view. | |
template<MemoryArray A, std::integral Int, auto R> | |
auto | nda::reshape (A &&a, std::array< Int, R > const &new_shape) |
Reshape an nda::basic_array or nda::basic_array_view. | |
template<MemoryArray A, std::integral Int, auto newRank> | |
auto | nda::reshaped_view (A &&a, std::array< Int, newRank > const &new_shape) |
template<typename A > requires (is_regular_or_view_v<A>) | |
void | nda::resize_or_check_if_view (A &a, std::array< long, A::rank > const &sha) |
Resize a given regular array to the given shape or check if a given view as the correct shape. | |
template<MemoryArray A> | |
decltype(auto) | nda::to_device (A &&a) |
Convert an nda::MemoryArray to its regular type on device memory. | |
template<MemoryArray A> | |
decltype(auto) | nda::to_host (A &&a) |
Convert an nda::MemoryArray to its regular type on host memory. | |
template<MemoryArray A> | |
decltype(auto) | nda::to_unified (A &&a) |
Convert an nda::MemoryArray to its regular type on unified memory. | |
template<typename A > requires (MemoryArray<A> or is_instantiation_of_v<expr_call, A>) | |
auto | nda::transpose (A &&a) |
Transpose the memory layout of an nda::MemoryArray or an nda::expr_call. | |
template<int I, int J, MemoryArray A> requires (is_regular_or_view_v<A>) | |
auto | nda::transposed_view (A &&a) |
Transpose two indices/dimensions of an nda::basic_array or nda::basic_array_view. | |
template<ArrayOfRank< 2 > A, ArrayOfRank< 2 > B> requires (std::same_as<get_value_t<A>, get_value_t<B>>) | |
matrix< get_value_t< A > > | nda::vstack (A const &a, B const &b) |
Stack two 2-dimensional arrays/views vertically. | |
template<typename T , mem::AddressSpace AdrSp = mem::Host, std::integral... Ints> | |
auto | nda::zeros (Ints... is) |
Make an array of the given shape on the given address space and zero-initialize it. | |
template<typename T , mem::AddressSpace AdrSp = mem::Host, std::integral Int, auto Rank> | |
auto | nda::zeros (std::array< Int, Rank > const &shape) |
Make an array of the given shape on the given address space and zero-initialize it. | |
auto nda::arange | ( | long | first, |
long | last, | ||
long | step = 1 ) |
#include <nda/basic_functions.hpp>
Make a 1-dimensional integer array and initialize it with values of a given nda::range
.
Int | Integer type/Value type of the created array. |
first | First value of the range. |
last | Last value of the range (excluded). |
step | Step size of the range. |
Definition at line 132 of file basic_functions.hpp.
auto nda::arange | ( | long | last | ) |
#include <nda/basic_functions.hpp>
Make a 1-dimensional integer array and initialize it with values of a given nda::range
with a step size of 1 and a starting value of 0.
Int | Integer type/Value type of the created array. |
last | Last value of the range (excluded). |
Definition at line 148 of file basic_functions.hpp.
auto nda::concatenate | ( | A0 const & | a0, |
As const &... | as ) |
#include <nda/basic_functions.hpp>
Join a sequence of nda::Array types along an existing axis.
The arrays must have the same value type and also shape, except in the dimension corresponding to the given axis (the first, by default).
Axis | The axis (dimension) along which to concatenate (default: 0). |
A0 | nda::Array type. |
As | nda::Array types. |
a0 | First array object. |
as | Remaining array objects. |
Definition at line 603 of file basic_functions.hpp.
ArrayOfRank< 2 > auto nda::diag | ( | V const & | v | ) |
#include <nda/matrix_functions.hpp>
Get a new nda::matrix with the given values on the diagonal.
V | nda::ArrayOfRank<1> or std::ranges::contiguous_range type. |
v | 1-dimensional array/view/container containing the diagonal values. |
Definition at line 123 of file matrix_functions.hpp.
ArrayOfRank< 1 > auto nda::diagonal | ( | M & | m | ) |
#include <nda/matrix_functions.hpp>
Get a view of the diagonal of a 2-dimensional array/view.
M | nda::MemoryArrayOfRank<2> type. |
m | 2-dimensional array/view. |
Definition at line 106 of file matrix_functions.hpp.
auto nda::eye | ( | Int | dim | ) |
#include <nda/matrix_functions.hpp>
Create an identity nda::matrix with ones on the diagonal.
S | nda::Scalar value type of the matrix. |
Int | Integral type. |
dim | Dimension of the square matrix. |
dim x dim
. Definition at line 55 of file matrix_functions.hpp.
auto nda::flatten | ( | A && | a | ) |
#include <nda/layout_transforms.hpp>
Flatten an nda::basic_array or nda::basic_array_view to a 1-dimensional array/view by reshaping it.
It calls nda::reshape with a 1-dimensional shape of the same size as the original array/view.
A | nda::MemoryArray type. |
a | Array/View to flatten. |
Definition at line 159 of file layout_transforms.hpp.
auto nda::group_indices_view | ( | A && | a, |
IdxGrps... | ) |
#include <nda/layout_transforms.hpp>
Create a new nda::basic_array or nda::basic_array_view by grouping indices together of a given array/view.
The resulting array/view has the same number of dimensions as given index groups.
It first calls nda::group_indices_layout to create a new nda::idx_map with the grouped indices and then calls nda::map_layout_transform with the new layout.
It can be used as follows:
In this examples a 4-dimensional array arr
is transformed into a 2-dimensional view by grouping the first and the last two indices together.
A | nda::MemoryArray type. |
IdxGrps | Groups of indices. |
a | Array/View to transform. |
Definition at line 246 of file layout_transforms.hpp.
auto nda::make_array_const_view | ( | basic_array< T, R, LP, A, CP > const & | a | ) |
#include <nda/basic_functions.hpp>
Make an nda::array_const_view of a given nda::basic_array.
T | Value type of the array. |
R | Rank of the array. |
LP | Layout policy of the array. |
A | Algebra of the array. |
CP | Container policy of the array. |
a | nda::basic_array object. |
Definition at line 412 of file basic_functions.hpp.
auto nda::make_array_const_view | ( | basic_array_view< T, R, LP, A, AP, OP > const & | a | ) |
#include <nda/basic_functions.hpp>
Make an nda::array_const_view of a given nda::basic_array_view.
T | Value type of the view. |
R | Rank of the view. |
LP | Layout policy of the view. |
A | Algebra of the view. |
AP | Accessor policy of the view. |
OP | Owning policy of the view. |
a | nda::basic_array_view object. |
Definition at line 430 of file basic_functions.hpp.
auto nda::make_array_view | ( | basic_array< T, R, LP, A, CP > const & | a | ) |
#include <nda/basic_functions.hpp>
Make an nda::array_view of a given nda::basic_array.
T | Value type of the array. |
R | Rank of the array. |
LP | Layout policy of the array. |
A | Algebra of the array. |
CP | Container policy of the array. |
a | nda::basic_array object. |
Definition at line 377 of file basic_functions.hpp.
auto nda::make_array_view | ( | basic_array_view< T, R, LP, A, AP, OP > const & | a | ) |
#include <nda/basic_functions.hpp>
Make an nda::array_view of a given nda::basic_array_view.
T | Value type of the view. |
R | Rank of the view. |
LP | Layout policy of the view. |
A | Algebra of the view. |
AP | Accessor policy of the view. |
OP | Owning policy of the view. |
a | nda::basic_array_view object. |
Definition at line 395 of file basic_functions.hpp.
auto nda::make_const_view | ( | basic_array< T, R, LP, A, CP > const & | a | ) |
#include <nda/basic_functions.hpp>
Make an nda::basic_array_view with a const value type from a given nda::basic_array.
T | Value type of the array. |
R | Rank of the array. |
LP | Layout policy of the array. |
A | Algebra of the array. |
CP | Container policy of the array. |
a | nda::basic_array object. |
Definition at line 342 of file basic_functions.hpp.
auto nda::make_const_view | ( | basic_array_view< T, R, LP, A, AP, OP > const & | a | ) |
#include <nda/basic_functions.hpp>
Make an nda::basic_array_view with a const value type from a given nda::basic_array_view.
T | Value type of the view. |
R | Rank of the view. |
LP | Layout policy of the view. |
Algebra | Algebra of the view. |
AP | Accessor policy of the view. |
OP | Owning policy of the view. |
a | nda::basic_array_view object. |
Definition at line 360 of file basic_functions.hpp.
auto nda::make_matrix_view | ( | basic_array< T, R, LP, A, CP > const & | a | ) |
#include <nda/basic_functions.hpp>
Make an nda::matrix_view of a given nda::basic_array.
T | Value type of the array. |
R | Rank of the array. |
LP | Layout policy of the array. |
A | Algebra of the array. |
CP | Container policy of the array. |
a | nda::basic_array object. |
Definition at line 447 of file basic_functions.hpp.
auto nda::make_matrix_view | ( | basic_array_view< T, R, LP, A, AP, OP > const & | a | ) |
#include <nda/basic_functions.hpp>
Make an nda::matrix_view of a given nda::basic_array_view.
T | Value type of the view. |
R | Rank of the view. |
LP | Layout policy of the view. |
A | Algebra of the view. |
AP | Accessor policy of the view. |
OP | Owning policy of the view. P |
a | nda::basic_array_view object. |
Definition at line 465 of file basic_functions.hpp.
decltype(auto) nda::make_regular | ( | A && | a | ) |
#include <nda/basic_functions.hpp>
Make a given object regular.
The return type of this function depends on the input type A
:
A
is an nda::Array and not regular, then the return type is nda::basic_array.A
has a nested type regular_t
which is not the same as A
, then the return type is A::regular_t
.A | Input type. |
a | Input object to make regular. |
Definition at line 238 of file basic_functions.hpp.
auto nda::map_layout_transform | ( | A && | a, |
NewLayoutType const & | new_layout ) |
#include <nda/layout_transforms.hpp>
Transform the memory layout of an nda::basic_array or nda::basic_array_view.
Depending on the input type A
, the function does the following:
A
is a regular rvalue array, return a new regular array with the given layout.A
if A
is non-const.A
if A
is const.The algebra of the transformed array/view is the same as the input array/view, except if its rank is different. Then the algebra is set to 'A'.
A | nda::MemoryArray type. |
NewLayoutType | nda::idx_map type. |
a | Array/View to transform. |
new_layout | New memory layout. |
Definition at line 70 of file layout_transforms.hpp.
auto nda::ones | ( | Ints... | is | ) |
#include <nda/basic_functions.hpp>
Make an array with the given dimensions and one-initialize it.
For a more specific array type consider using nda::basic_array::ones.
T | Value type of the array. |
Ints | Integer types. |
is | Extent (number of elements) along each dimension. |
Definition at line 118 of file basic_functions.hpp.
auto nda::ones | ( | std::array< Int, Rank > const & | shape | ) |
#include <nda/basic_functions.hpp>
Make an array of the given shape and one-initialize it.
For a more specific array type consider using nda::basic_array::ones.
T | Value type of the array. |
Int | Integer type. |
Rank | Rank of the array. |
shape | Shape of the array. |
Rank == 0
. Definition at line 99 of file basic_functions.hpp.
auto nda::permuted_indices_view | ( | A && | a | ) |
#include <nda/layout_transforms.hpp>
Permute the indices/dimensions of an nda::basic_array or nda::basic_array_view.
It first calls the nda::idx_map::transpose method of the nda::idx_map of the array/view to get the new layout and then calls nda::map_layout_transform.
Permutation | Permutation encoded as an integer to apply to the indices. |
A | nda::MemoryArray type. |
a | Array/View to permute. |
Definition at line 175 of file layout_transforms.hpp.
auto nda::rand | ( | Ints... | is | ) |
#include <nda/basic_functions.hpp>
Make an array of the given dimensions and initialize it with random values from the uniform distribution over [0, 1).
For a more specific array type consider using nda::basic_array::rand.
RealType | Value type of the array. |
Ints | Integer types. |
is | Extent (number of elements) along each dimension. |
Definition at line 189 of file basic_functions.hpp.
auto nda::rand | ( | std::array< Int, Rank > const & | shape | ) |
#include <nda/basic_functions.hpp>
Make an array of the given shape and initialize it with random values from the uniform distribution over [0, 1).
For a more specific array type consider using nda::basic_array::rand.
RealType | Value type of the array. |
Int | Integer type. |
Rank | Rank of the array. |
shape | Shape of the array. |
Rank == 0
. Definition at line 165 of file basic_functions.hpp.
auto nda::reinterpret_add_fast_dims_of_size_one | ( | A && | a | ) |
#include <nda/layout_transforms.hpp>
Add N
fast varying dimensions of size 1 to a given nda::basic_array or nda::basic_array_view.
N | Number of dimensions to add. |
A | nda::MemoryArray type. |
a | Array/View to transform. |
N
dimensions of size 1 added to the original array/view. Definition at line 272 of file layout_transforms.hpp.
auto nda::reshape | ( | A && | a, |
Ints... | is ) |
#include <nda/layout_transforms.hpp>
Reshape an nda::basic_array or nda::basic_array_view.
See nda::reshape(A &&, std::array< Int, R > const &).
A | nda::MemoryArray type. |
Ints | Integral types |
a | Array/View to reshape. |
is | Extents of the new shape. |
Definition at line 139 of file layout_transforms.hpp.
auto nda::reshape | ( | A && | a, |
std::array< Int, R > const & | new_shape ) |
#include <nda/layout_transforms.hpp>
Reshape an nda::basic_array or nda::basic_array_view.
The input array/view is assumed to be contiguous and in C- or Fortran-order and the size of the reshaped array/view must be the same as the input.
It calls nda::map_layout_transform with the given shape.
A | nda::MemoryArray type. |
Int | Integral type. |
R | Number of dimensions of the new shape. |
a | Array/View to reshape. |
new_shape | Shape of the reshaped array/view. |
Definition at line 108 of file layout_transforms.hpp.
auto nda::reshaped_view | ( | A && | a, |
std::array< Int, newRank > const & | new_shape ) |
#include <nda/layout_transforms.hpp>
Definition at line 145 of file layout_transforms.hpp.
void nda::resize_or_check_if_view | ( | A & | a, |
std::array< long, A::rank > const & | sha ) |
#include <nda/basic_functions.hpp>
Resize a given regular array to the given shape or check if a given view as the correct shape.
Regular types are resized (if necessary) by calling nda::basic_array::resize while views are checked for the correct shape.
Throws an exception if the shape of the view does not match the given shape.
A | Type of the object. |
a | Object to resize or check. |
sha | New shape. |
Definition at line 318 of file basic_functions.hpp.
decltype(auto) nda::to_device | ( | A && | a | ) |
#include <nda/basic_functions.hpp>
Convert an nda::MemoryArray to its regular type on device memory.
If the input object is already on device memory, simply forward the argument (independent of its type).
A | nda::MemoryArray type. |
a | nda::MemoryArray object. |
Definition at line 279 of file basic_functions.hpp.
decltype(auto) nda::to_host | ( | A && | a | ) |
#include <nda/basic_functions.hpp>
Convert an nda::MemoryArray to its regular type on host memory.
If the input object is already on host memory, simply forward the argument (independent of its type).
A | nda::MemoryArray type. |
a | nda::MemoryArray object. |
Definition at line 261 of file basic_functions.hpp.
decltype(auto) nda::to_unified | ( | A && | a | ) |
#include <nda/basic_functions.hpp>
Convert an nda::MemoryArray to its regular type on unified memory.
If the input object is already on unified memory, simply forward the argument (independent of its type).
A | nda::MemoryArray type. |
a | nda::MemoryArray object. |
Definition at line 297 of file basic_functions.hpp.
auto nda::transpose | ( | A && | a | ) |
#include <nda/layout_transforms.hpp>
Transpose the memory layout of an nda::MemoryArray or an nda::expr_call.
For nda::MemoryArray types, it calls nda::permuted_indices_view with the reverse identity permutation. For nda::expr_call types, it calls nda::map with the transposed array.
A | nda::MemoryArray or nda::expr_call type. |
a | Array/View or expression call. |
Definition at line 191 of file layout_transforms.hpp.
auto nda::transposed_view | ( | A && | a | ) |
#include <nda/layout_transforms.hpp>
Transpose two indices/dimensions of an nda::basic_array or nda::basic_array_view.
It calls nda::permuted_indices_view with the permutation that represents the transposition of the given indices.
I | First index/dimension to transpose. |
J | Second index/dimension to transpose. |
A | nda::MemoryArray type. |
a | Array/View to transpose. |
Definition at line 215 of file layout_transforms.hpp.
matrix< get_value_t< A > > nda::vstack | ( | A const & | a, |
B const & | b ) |
#include <nda/matrix_functions.hpp>
Stack two 2-dimensional arrays/views vertically.
This is a more restricted implementation then nda::concatenate. It is only for 2D arrays/views.
Given a an array A of size n x q
and an array B of size p x q
, the function returns a new array C of size (n + p) x q
such that C(range(0, n), range::all) == A
and C(range(n, n + p), range::all) == B
is true.
A | nda::ArrayOfRank<2> type. |
B | nda::ArrayOfRank<2> type. |
a | 2-dimensional array/view. |
b | 2-dimensional array/view. |
Definition at line 149 of file matrix_functions.hpp.
auto nda::zeros | ( | Ints... | is | ) |
#include <nda/basic_functions.hpp>
Make an array of the given shape on the given address space and zero-initialize it.
For a more specific array type consider using nda::basic_array::zeros.
T | Value type of the array. |
AdrSp | Address space of the array. |
Ints | Integer types. |
is | Extent (number of elements) along each dimension. |
Definition at line 83 of file basic_functions.hpp.
auto nda::zeros | ( | std::array< Int, Rank > const & | shape | ) |
#include <nda/basic_functions.hpp>
Make an array of the given shape on the given address space and zero-initialize it.
For a more specific array type consider using nda::basic_array::zeros.
T | Value type of the array. |
AdrSp | Address space of the array. |
Int | Integer type. |
Rank | Rank of the array. |
shape | Shape of the array. |
Rank == 0
. Definition at line 61 of file basic_functions.hpp.