TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
Factories and transformations

Detailed Description

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.
 

Function Documentation

◆ arange() [1/2]

template<std::integral Int = long>
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.

Template Parameters
IntInteger type/Value type of the created array.
Parameters
firstFirst value of the range.
lastLast value of the range (excluded).
stepStep size of the range.
Returns
1-dimensional integer nda::array.

Definition at line 132 of file basic_functions.hpp.

◆ arange() [2/2]

template<std::integral Int = long>
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.

Template Parameters
IntInteger type/Value type of the created array.
Parameters
lastLast value of the range (excluded).
Returns
1-dimensional integer nda::array.

Definition at line 148 of file basic_functions.hpp.

◆ concatenate()

template<size_t Axis = 0, Array A0, Array... As>
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).

Template Parameters
AxisThe axis (dimension) along which to concatenate (default: 0).
A0nda::Array type.
Asnda::Array types.
Parameters
a0First array object.
asRemaining array objects.
Returns
New nda::array with the concatenated data.

Definition at line 603 of file basic_functions.hpp.

◆ diag()

template<typename V >
requires (std::ranges::contiguous_range<V> or ArrayOfRank<V, 1>)
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.

Template Parameters
Vnda::ArrayOfRank<1> or std::ranges::contiguous_range type.
Parameters
v1-dimensional array/view/container containing the diagonal values.
Returns
nda::matrix with the given values on the diagonal.

Definition at line 123 of file matrix_functions.hpp.

◆ diagonal()

template<MemoryArrayOfRank< 2 > M>
ArrayOfRank< 1 > auto nda::diagonal ( M & m)

#include <nda/matrix_functions.hpp>

Get a view of the diagonal of a 2-dimensional array/view.

Template Parameters
Mnda::MemoryArrayOfRank<2> type.
Parameters
m2-dimensional array/view.
Returns
A view with the 'V' algebra of the diagonal of the array/view.

Definition at line 106 of file matrix_functions.hpp.

◆ eye()

template<Scalar S, std::integral Int = long>
auto nda::eye ( Int dim)

#include <nda/matrix_functions.hpp>

Create an identity nda::matrix with ones on the diagonal.

Template Parameters
Snda::Scalar value type of the matrix.
IntIntegral type.
Parameters
dimDimension of the square matrix.
Returns
Identity nda::matrix of size dim x dim.

Definition at line 55 of file matrix_functions.hpp.

◆ flatten()

template<MemoryArray A>
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.

Template Parameters
Anda::MemoryArray type.
Parameters
aArray/View to flatten.
Returns
An 1-dimensional array/view with the same size as the original array/view.

Definition at line 159 of file layout_transforms.hpp.

◆ group_indices_view()

template<MemoryArray A, typename... IdxGrps>
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:

auto arr = nda::rand<double>(3, 4, 5, 6);
auto rand(std::array< Int, Rank > const &shape)
Make an array of the given shape and initialize it with random values from the uniform distribution o...
auto 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/...
idx_group_t< Is... > idx_group
Variable template for an nda::idx_group_t.

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.

Template Parameters
Anda::MemoryArray type.
IdxGrpsGroups of indices.
Parameters
aArray/View to transform.
Returns
An array/view with grouped indices.

Definition at line 246 of file layout_transforms.hpp.

◆ make_array_const_view() [1/2]

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)

#include <nda/basic_functions.hpp>

Make an nda::array_const_view of a given nda::basic_array.

Template Parameters
TValue type of the array.
RRank of the array.
LPLayout policy of the array.
AAlgebra of the array.
CPContainer policy of the array.
Parameters
anda::basic_array object.
Returns
nda::array_const_view object.

Definition at line 412 of file basic_functions.hpp.

◆ make_array_const_view() [2/2]

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)

#include <nda/basic_functions.hpp>

Make an nda::array_const_view of a given nda::basic_array_view.

Template Parameters
TValue type of the view.
RRank of the view.
LPLayout policy of the view.
AAlgebra of the view.
APAccessor policy of the view.
OPOwning policy of the view.
Parameters
anda::basic_array_view object.
Returns
nda::array_const_view object.

Definition at line 430 of file basic_functions.hpp.

◆ make_array_view() [1/2]

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)

#include <nda/basic_functions.hpp>

Make an nda::array_view of a given nda::basic_array.

Template Parameters
TValue type of the array.
RRank of the array.
LPLayout policy of the array.
AAlgebra of the array.
CPContainer policy of the array.
Parameters
anda::basic_array object.
Returns
nda::array_view object.

Definition at line 377 of file basic_functions.hpp.

◆ make_array_view() [2/2]

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)

#include <nda/basic_functions.hpp>

Make an nda::array_view of a given nda::basic_array_view.

Template Parameters
TValue type of the view.
RRank of the view.
LPLayout policy of the view.
AAlgebra of the view.
APAccessor policy of the view.
OPOwning policy of the view.
Parameters
anda::basic_array_view object.
Returns
nda::array_view object.

Definition at line 395 of file basic_functions.hpp.

◆ make_const_view() [1/2]

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)

#include <nda/basic_functions.hpp>

Make an nda::basic_array_view with a const value type from a given nda::basic_array.

Template Parameters
TValue type of the array.
RRank of the array.
LPLayout policy of the array.
AAlgebra of the array.
CPContainer policy of the array.
Parameters
anda::basic_array object.
Returns
nda::basic_array_view object with a const value type.

Definition at line 342 of file basic_functions.hpp.

◆ make_const_view() [2/2]

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)

#include <nda/basic_functions.hpp>

Make an nda::basic_array_view with a const value type from a given nda::basic_array_view.

Template Parameters
TValue type of the view.
RRank of the view.
LPLayout policy of the view.
AlgebraAlgebra of the view.
APAccessor policy of the view.
OPOwning policy of the view.
Parameters
anda::basic_array_view object.
Returns
nda::basic_array_view object with a const value type.

Definition at line 360 of file basic_functions.hpp.

◆ make_matrix_view() [1/2]

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)

#include <nda/basic_functions.hpp>

Make an nda::matrix_view of a given nda::basic_array.

Template Parameters
TValue type of the array.
RRank of the array.
LPLayout policy of the array.
AAlgebra of the array.
CPContainer policy of the array.
Parameters
anda::basic_array object.
Returns
nda::matrix_view object.

Definition at line 447 of file basic_functions.hpp.

◆ make_matrix_view() [2/2]

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)

#include <nda/basic_functions.hpp>

Make an nda::matrix_view of a given nda::basic_array_view.

Template Parameters
TValue type of the view.
RRank of the view.
LPLayout policy of the view.
AAlgebra of the view.
APAccessor policy of the view.
OPOwning policy of the view. P
Parameters
anda::basic_array_view object.
Returns
nda::matrix_view object.

Definition at line 465 of file basic_functions.hpp.

◆ make_regular()

template<typename A , typename A_t = std::decay_t<A>>
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:

  • If A is an nda::Array and not regular, then the return type is nda::basic_array.
  • If A has a nested type regular_t which is not the same as A, then the return type is A::regular_t.
  • Otherwise, the input type is simply forwarded.
Note
Rvalue references will be moved, while lvalue references will be copied.
Template Parameters
AInput type.
Parameters
aInput object to make regular.
Returns
Regular object.

Definition at line 238 of file basic_functions.hpp.

◆ map_layout_transform()

template<MemoryArray A, typename NewLayoutType >
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:

  • If A is a regular rvalue array, return a new regular array with the given layout.
  • Otherwise it returns a view with the given layout and
    • the same value type as A if A is non-const.
    • the const value type of 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'.

Template Parameters
Anda::MemoryArray type.
NewLayoutTypenda::idx_map type.
Parameters
aArray/View to transform.
new_layoutNew memory layout.
Returns
If the input is an rvalue array, return a new array with the given layout. Otherwise, return a view with the given layout.

Definition at line 70 of file layout_transforms.hpp.

◆ ones() [1/2]

template<typename T , std::integral... Ints>
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.

Template Parameters
TValue type of the array.
IntsInteger types.
Parameters
isExtent (number of elements) along each dimension.
Returns
One-initialized nda::array or scalar if no arguments are given.

Definition at line 118 of file basic_functions.hpp.

◆ ones() [2/2]

template<typename T , std::integral Int, auto Rank>
requires (nda::is_scalar_v<T>)
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.

Template Parameters
TValue type of the array.
IntInteger type.
RankRank of the array.
Parameters
shapeShape of the array.
Returns
One-initialized nda::array or scalar if Rank == 0.

Definition at line 99 of file basic_functions.hpp.

◆ permuted_indices_view()

template<uint64_t Permutation, MemoryArray A>
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.

Template Parameters
PermutationPermutation encoded as an integer to apply to the indices.
Anda::MemoryArray type.
Parameters
aArray/View to permute.
Returns
An array/view with permuted indices/dimensions.

Definition at line 175 of file layout_transforms.hpp.

◆ rand() [1/2]

template<typename RealType = double, std::integral... Ints>
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.

Template Parameters
RealTypeValue type of the array.
IntsInteger types.
Parameters
isExtent (number of elements) along each dimension.
Returns
Random-initialized nda::array or scalar if no arguments are given.

Definition at line 189 of file basic_functions.hpp.

◆ rand() [2/2]

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)

#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.

Template Parameters
RealTypeValue type of the array.
IntInteger type.
RankRank of the array.
Parameters
shapeShape of the array.
Returns
Random-initialized nda::array or scalar if Rank == 0.

Definition at line 165 of file basic_functions.hpp.

◆ reinterpret_add_fast_dims_of_size_one()

template<int N, typename A >
requires (nda::is_regular_or_view_v<A>)
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.

Template Parameters
NNumber of dimensions to add.
Anda::MemoryArray type.
Parameters
aArray/View to transform.
Returns
An array/view with N dimensions of size 1 added to the original array/view.

Definition at line 272 of file layout_transforms.hpp.

◆ reshape() [1/2]

template<MemoryArray A, std::integral... Ints>
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 &).

Template Parameters
Anda::MemoryArray type.
IntsIntegral types
Parameters
aArray/View to reshape.
isExtents of the new shape.
Returns
An array/view with the new shape.

Definition at line 139 of file layout_transforms.hpp.

◆ reshape() [2/2]

template<MemoryArray A, std::integral Int, auto R>
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.

Template Parameters
Anda::MemoryArray type.
IntIntegral type.
RNumber of dimensions of the new shape.
Parameters
aArray/View to reshape.
new_shapeShape of the reshaped array/view.
Returns
An array/view with the new shape.

Definition at line 108 of file layout_transforms.hpp.

◆ reshaped_view()

template<MemoryArray A, std::integral Int, auto newRank>
auto nda::reshaped_view ( A && a,
std::array< Int, newRank > const & new_shape )

#include <nda/layout_transforms.hpp>

Deprecated
Use nda::reshape instead.

Definition at line 145 of file layout_transforms.hpp.

◆ resize_or_check_if_view()

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 )

#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.

Template Parameters
AType of the object.
Parameters
aObject to resize or check.
shaNew shape.

Definition at line 318 of file basic_functions.hpp.

◆ to_device()

template<MemoryArray A>
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).

Template Parameters
Anda::MemoryArray type.
Parameters
anda::MemoryArray object.
Returns
(Regular) object on device memory.

Definition at line 279 of file basic_functions.hpp.

◆ to_host()

template<MemoryArray A>
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).

Template Parameters
Anda::MemoryArray type.
Parameters
anda::MemoryArray object.
Returns
(Regular) object on host memory.

Definition at line 261 of file basic_functions.hpp.

◆ to_unified()

template<MemoryArray A>
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).

Template Parameters
Anda::MemoryArray type.
Parameters
anda::MemoryArray object.
Returns
(Regular) object on unified memory.

Definition at line 297 of file basic_functions.hpp.

◆ transpose()

template<typename A >
requires (MemoryArray<A> or is_instantiation_of_v<expr_call, A>)
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.

Template Parameters
Anda::MemoryArray or nda::expr_call type.
Parameters
aArray/View or expression call.
Returns
An array/view with transposed memory layout or a new nda::expr_call with the transposed array as the argument.

Definition at line 191 of file layout_transforms.hpp.

◆ transposed_view()

template<int I, int J, MemoryArray A>
requires (is_regular_or_view_v<A>)
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.

Template Parameters
IFirst index/dimension to transpose.
JSecond index/dimension to transpose.
Anda::MemoryArray type.
Parameters
aArray/View to transpose.
Returns
An array/view with transposed indices/dimensions.

Definition at line 215 of file layout_transforms.hpp.

◆ vstack()

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 )

#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.

Template Parameters
Anda::ArrayOfRank<2> type.
Bnda::ArrayOfRank<2> type.
Parameters
a2-dimensional array/view.
b2-dimensional array/view.
Returns
A new 2-dimensional array/view with the two arrays stacked vertically.

Definition at line 149 of file matrix_functions.hpp.

◆ zeros() [1/2]

template<typename T , mem::AddressSpace AdrSp = mem::Host, std::integral... Ints>
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.

Template Parameters
TValue type of the array.
AdrSpAddress space of the array.
IntsInteger types.
Parameters
isExtent (number of elements) along each dimension.
Returns
Zero-initialized nda::array or nda::cuarray or scalar if no arguments are given.

Definition at line 83 of file basic_functions.hpp.

◆ zeros() [2/2]

template<typename T , mem::AddressSpace AdrSp = mem::Host, std::integral Int, auto Rank>
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.

Template Parameters
TValue type of the array.
AdrSpAddress space of the array.
IntInteger type.
RankRank of the array.
Parameters
shapeShape of the array.
Returns
Zero-initialized nda::array or nda::cuarray or scalar if Rank == 0.

Definition at line 61 of file basic_functions.hpp.