TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
Array/View utilities

Detailed Description

Type traits, concepts and more functionality related to array and view types.

Concepts

concept  nda::Array
 Check if a given type satisfies the array concept.
 
concept  nda::MemoryArray
 Check if a given type satisfies the memory array concept.
 
concept  nda::ArrayOfRank
 Check if a given type is an nda::Array of a certain rank.
 
concept  nda::MemoryArrayOfRank
 Check if a given type is an nda::MemoryArray of a certain rank.
 
concept  nda::ArrayOrScalar
 Check if if a given type is either an nda::Array or an nda::Scalar.
 
concept  nda::Matrix
 Check if a given type is a matrix, i.e. an nda::ArrayOfRank<2>.
 
concept  nda::Vector
 Check if a given type is a vector, i.e. an nda::ArrayOfRank<1>.
 
concept  nda::MemoryMatrix
 Check if a given type is a memory matrix, i.e. an nda::MemoryArrayOfRank<2>.
 
concept  nda::MemoryVector
 Check if a given type is a memory vector, i.e. an nda::MemoryArrayOfRank<1>.
 
concept  nda::ArrayInitializer
 Check if a given type satisfies the array initializer concept for a given nda::MemoryArray type.
 
concept  nda::HasValueTypeConstructibleFrom
 Check if a given type is constructible from the value type of a given nda::Array type.
 

Classes

class  nda::array_adapter< R, F >
 Adapter that consists of a shape and a callable object, which takes R integers as arguments (just like an nda::basic_array or nda::basic_array_view). More...
 
class  nda::array_iterator< Rank, T, Pointer >
 Iterator for nda::basic_array and nda::basic_array_view types. More...
 
class  nda::array_iterator< 1, T, Pointer >
 Specialization of nda::array_iterator for 1-dimensional grids. More...
 
struct  nda::default_accessor
 Default accessor for various array and view types. More...
 
struct  nda::default_accessor::accessor< T >
 Accessor type of the nda::default_accessor. More...
 
struct  nda::no_alias_accessor
 Accessor for array and view types with no aliasing. More...
 
struct  nda::no_alias_accessor::accessor< T >
 Accessor type of the nda::no_alias_accessor. More...
 

Typedefs

template<typename T , typename RT = get_regular_t<T>>
using nda::get_regular_device_t
 Get the type of the nda::basic_array that would be obtained by constructing an array on device memory from a given type.
 
template<typename T , typename RT = get_regular_t<T>>
using nda::get_regular_host_t
 Get the type of the nda::basic_array that would be obtained by constructing an array on host memory from a given type.
 
template<typename T , typename T2 = std::remove_reference_t<T>>
using nda::get_regular_t = decltype(basic_array{std::declval<T>()})
 Get the type of the nda::basic_array that would be obtained by constructing an array from a given type.
 
template<typename T , typename RT = get_regular_t<T>>
using nda::get_regular_unified_t
 Get the type of the nda::basic_array that would be obtained by constructing an array on unified memory from a given type.
 
template<typename A >
using nda::get_value_t = std::decay_t<decltype(get_first_element(std::declval<A const>()))>
 Get the value type of an array/view or a scalar type.
 
template<typename T , typename T2 = std::remove_reference_t<T>>
using nda::get_view_t = std::remove_reference_t<decltype(basic_array_view{std::declval<T>()})>
 Get the type of the nda::basic_array_view that would be obtained by constructing a view from a given type.
 

Functions

template<Array A>
long nda::first_dim (A const &a)
 Get the extent of the first dimension of the array.
 
template<typename A >
decltype(auto) nda::get_first_element (A const &a)
 Get the first element of an array/view or simply return the scalar if a scalar is given.
 
template<typename A >
requires (is_regular_or_view_v<A>)
std::ostream & nda::operator<< (std::ostream &sout, A const &a)
 Write an nda::basic_array or nda::basic_array_view to a std::ostream.
 
template<int R, typename F >
std::ostream & nda::operator<< (std::ostream &sout, array_adapter< R, F > const &aa)
 Write an nda::array_adapter to a std::ostream.
 
template<char OP, ArrayOrScalar L, ArrayOrScalar R>
std::ostream & nda::operator<< (std::ostream &sout, expr< OP, L, R > const &ex)
 Write an nda::expr to a std::ostream.
 
template<typename F , typename... As>
std::ostream & nda::operator<< (std::ostream &sout, expr_call< F, As... > const &)
 Write an nda::expr_call to a std::ostream.
 
template<char OP, Array A>
std::ostream & nda::operator<< (std::ostream &sout, expr_unary< OP, A > const &ex)
 Write an nda::expr_unary to a std::ostream.
 
template<ArrayOfRank< 1 > A, std::ranges::contiguous_range R>
bool nda::operator== (A const &a, R const &rg)
 Equal-to comparison operator for a 1-dimensional nda::Array and a std::ranges::contiguous_range.
 
template<Array LHS, Array RHS>
bool nda::operator== (LHS const &lhs, RHS const &rhs)
 Equal-to comparison operator for two nda::Array objects.
 
template<std::ranges::contiguous_range R, ArrayOfRank< 1 > A>
bool nda::operator== (R const &rg, A const &a)
 Equal-to comparison operator for a std::ranges::contiguous_range and a 1-dimensional nda::Array.
 
template<Array A>
long nda::second_dim (A const &a)
 Get the extent of the second dimension of the array.
 
template<typename... Is>
constexpr uint64_t nda::static_extents (int i0, Is... is)
 Encode the given shape into a single integer using the nda::encode function.
 

Variables

template<typename A >
constexpr char nda::get_algebra = 'N'
 Constexpr variable that specifies the algebra of a type.
 
template<typename ValueType , int Rank, typename Layout , char Algebra, typename ContainerPolicy >
constexpr char nda::get_algebra< basic_array< ValueType, Rank, Layout, Algebra, ContainerPolicy > > = Algebra
 Specialization of nda::get_algebra for nda::basic_array types.
 
template<typename ValueType , int Rank, typename Layout , char Algebra, typename AccessorPolicy , typename OwningPolicy >
constexpr char nda::get_algebra< basic_array_view< ValueType, Rank, Layout, Algebra, AccessorPolicy, OwningPolicy > > = Algebra
 Specialization of nda::get_algebra for nda::basic_array_view types.
 
template<char OP, typename L , typename R >
constexpr char nda::get_algebra< expr< OP, L, R > > = expr<OP, L, R>::algebra
 Specialization of nda::get_algebra for nda::expr types.
 
template<typename F , Array... As>
constexpr char nda::get_algebra< expr_call< F, As... > > = detail::_impl_find_common_algebra(get_algebra<As>...)
 Get the resulting algebra of a function call expression involving arrays/views.
 
template<char OP, Array A>
constexpr char nda::get_algebra< expr_unary< OP, A > > = get_algebra<A>
 Specialization of nda::get_algebra for nda::expr_unary types.
 
template<typename ValueType , int Rank, typename Layout , char Algebra, typename ContainerPolicy >
constexpr layout_info_t nda::get_layout_info< basic_array< ValueType, Rank, Layout, Algebra, ContainerPolicy > >
 Specialization of nda::get_layout_info for nda::basic_array types.
 
template<typename ValueType , int Rank, typename Layout , char Algebra, typename AccessorPolicy , typename OwningPolicy >
constexpr layout_info_t nda::get_layout_info< basic_array_view< ValueType, Rank, Layout, Algebra, AccessorPolicy, OwningPolicy > >
 Specialization of nda::get_layout_info for nda::basic_array_view types.
 
template<char OP, typename L , typename R >
constexpr layout_info_t nda::get_layout_info< expr< OP, L, R > > = expr<OP, L, R>::compute_layout_info()
 Specialization of nda::get_layout_info for nda::expr types.
 
template<char OP, Array A>
constexpr layout_info_t nda::get_layout_info< expr_unary< OP, A > > = get_layout_info<A>
 Specialization of nda::get_layout_info for nda::expr_unary types.
 
template<typename A >
constexpr int nda::get_rank
 Constexpr variable that specifies the rank of an nda::Array or of a contiguous 1-dimensional range.
 
template<typename A0 , typename... As>
constexpr bool nda::have_same_rank_v = ((get_rank<A0> == get_rank<As>)and... and true)
 Constexpr variable that is true if all types in As have the same rank as A0.
 
template<typename A0 , typename... As>
constexpr bool nda::have_same_value_type_v = (std::is_same_v<get_value_t<A0>, get_value_t<As>> and ... and true)
 Constexpr variable that is true if all types in As have the same value type as A0.
 
template<typename A >
constexpr bool nda::is_matrix_or_view_v = is_regular_or_view_v<A> and (get_algebra<A> == 'M') and (get_rank<A> == 2)
 Constexpr variable that is true if type A is a regular matrix or a view of a matrix.
 
template<typename A >
constexpr bool nda::is_regular_or_view_v = is_regular_v<A> or is_view_v<A>
 Constexpr variable that is true if type A is either a regular array or a view.
 
template<typename A >
constexpr bool nda::is_regular_v = false
 Constexpr variable that is true if type A is a regular array, i.e. an nda::basic_array.
 
template<typename ValueType , int Rank, typename Layout , char Algebra, typename ContainerPolicy >
constexpr bool nda::is_regular_v< basic_array< ValueType, Rank, Layout, Algebra, ContainerPolicy > > = true
 Specialization of nda::is_regular_v for nda::basic_array.
 
template<typename A >
constexpr bool nda::is_view_v = false
 Constexpr variable that is true if type A is a view, i.e. an nda::basic_array_view.
 
template<typename ValueType , int Rank, typename Layout , char Algebra, typename AccessorPolicy , typename OwningPolicy >
constexpr bool nda::is_view_v< basic_array_view< ValueType, Rank, Layout, Algebra, AccessorPolicy, OwningPolicy > > = true
 Specialization of nda::is_view_v for nda::basic_array_view.
 

Typedef Documentation

◆ get_regular_device_t

template<typename T , typename RT = get_regular_t<T>>
using nda::get_regular_device_t

#include <nda/declarations.hpp>

Initial value:
std::conditional_t<mem::on_device<RT>, RT,
basic_array<get_value_t<RT>, get_rank<RT>, get_contiguous_layout_policy<get_rank<RT>, get_layout_info<RT>.stride_order>,
get_algebra<RT>, heap<mem::Device>>>

Get the type of the nda::basic_array that would be obtained by constructing an array on device memory from a given type.

Template Parameters
TType to construct an array from.

Definition at line 381 of file declarations.hpp.

◆ get_regular_host_t

template<typename T , typename RT = get_regular_t<T>>
using nda::get_regular_host_t

#include <nda/declarations.hpp>

Initial value:
std::conditional_t<mem::on_host<RT>, RT,
basic_array<get_value_t<RT>, get_rank<RT>, get_contiguous_layout_policy<get_rank<RT>, get_layout_info<RT>.stride_order>,
get_algebra<RT>, heap<mem::Host>>>

Get the type of the nda::basic_array that would be obtained by constructing an array on host memory from a given type.

Template Parameters
TType to construct an array from.

Definition at line 369 of file declarations.hpp.

◆ get_regular_t

template<typename T , typename T2 = std::remove_reference_t<T>>
using nda::get_regular_t = decltype(basic_array{std::declval<T>()})

#include <nda/declarations.hpp>

Get the type of the nda::basic_array that would be obtained by constructing an array from a given type.

Template Parameters
TType to construct an array from.

Definition at line 360 of file declarations.hpp.

◆ get_regular_unified_t

template<typename T , typename RT = get_regular_t<T>>
using nda::get_regular_unified_t

#include <nda/declarations.hpp>

Initial value:
std::conditional_t<mem::on_unified<RT>, RT,
basic_array<get_value_t<RT>, get_rank<RT>, get_contiguous_layout_policy<get_rank<RT>, get_layout_info<RT>.stride_order>,
get_algebra<RT>, heap<mem::Unified>>>

Get the type of the nda::basic_array that would be obtained by constructing an array on unified memory from a given type.

Template Parameters
TType to construct an array from.

Definition at line 393 of file declarations.hpp.

◆ get_value_t

template<typename A >
using nda::get_value_t = std::decay_t<decltype(get_first_element(std::declval<A const>()))>

#include <nda/traits.hpp>

Get the value type of an array/view or a scalar type.

Template Parameters
AArray/View/Scalar type.

Definition at line 192 of file traits.hpp.

◆ get_view_t

template<typename T , typename T2 = std::remove_reference_t<T>>
using nda::get_view_t = std::remove_reference_t<decltype(basic_array_view{std::declval<T>()})>

#include <nda/declarations.hpp>

Get the type of the nda::basic_array_view that would be obtained by constructing a view from a given type.

Template Parameters
TType to construct a view from.

Definition at line 353 of file declarations.hpp.

Function Documentation

◆ first_dim()

template<Array A>
long nda::first_dim ( A const & a)

#include <nda/basic_functions.hpp>

Get the extent of the first dimension of the array.

Equivalent to a.extent(0) and a.shape()[0].

Template Parameters
Anda::Array type.
Parameters
anda::Array object.
Returns
Extent of the first dimension.

Definition at line 204 of file basic_functions.hpp.

◆ get_first_element()

template<typename A >
decltype(auto) nda::get_first_element ( A const & a)

#include <nda/traits.hpp>

Get the first element of an array/view or simply return the scalar if a scalar is given.

Template Parameters
AArray/View/Scalar type.
Parameters
aInput array/view/scalar.
Returns
If an array/view is given, return its first element. Otherwise, return the given scalar.

Definition at line 177 of file traits.hpp.

◆ operator<<() [1/5]

template<typename A >
requires (is_regular_or_view_v<A>)
std::ostream & nda::operator<< ( std::ostream & sout,
A const & a )

#include <nda/print.hpp>

Write an nda::basic_array or nda::basic_array_view to a std::ostream.

Template Parameters
AType of the nda::basic_array or nda::basic_array_view.
Parameters
soutstd::ostream object.
anda::basic_array or nda::basic_array_view object.
Returns
Reference to std::ostream object.

Definition at line 90 of file print.hpp.

◆ operator<<() [2/5]

template<int R, typename F >
std::ostream & nda::operator<< ( std::ostream & sout,
array_adapter< R, F > const & aa )

#include <nda/print.hpp>

Write an nda::array_adapter to a std::ostream.

Template Parameters
RRank of the nda::array_adapter.
FCallable type of the nda::array_adapter.
Parameters
soutstd::ostream object.
aanda::array_adapter object.
Returns
Reference to std::ostream object.

Definition at line 137 of file print.hpp.

◆ operator<<() [3/5]

template<char OP, ArrayOrScalar L, ArrayOrScalar R>
std::ostream & nda::operator<< ( std::ostream & sout,
expr< OP, L, R > const & ex )

#include <nda/print.hpp>

Write an nda::expr to a std::ostream.

Template Parameters
OPBinary operator.
Lnda::ArrayOrScalar type of left hand side.
Rnda::ArrayOrScalar type of right hand side.
Parameters
soutstd::ostream object.
exnda::expr object.
Returns
Reference to std::ostream object.

Definition at line 175 of file print.hpp.

◆ operator<<() [4/5]

template<typename F , typename... As>
std::ostream & nda::operator<< ( std::ostream & sout,
expr_call< F, As... > const &  )

#include <nda/print.hpp>

Write an nda::expr_call to a std::ostream.

Template Parameters
FCallable type.
AsArgument types.
Parameters
soutstd::ostream object.
Returns
Reference to std::ostream object.

Definition at line 188 of file print.hpp.

◆ operator<<() [5/5]

template<char OP, Array A>
std::ostream & nda::operator<< ( std::ostream & sout,
expr_unary< OP, A > const & ex )

#include <nda/print.hpp>

Write an nda::expr_unary to a std::ostream.

Template Parameters
OPUnary operator.
Anda::Array type.
Parameters
soutstd::ostream object.
exnda::expr_unary object.
Returns
Reference to std::ostream object.

Definition at line 160 of file print.hpp.

◆ operator==() [1/3]

template<ArrayOfRank< 1 > A, std::ranges::contiguous_range R>
bool nda::operator== ( A const & a,
R const & rg )

#include <nda/basic_functions.hpp>

Equal-to comparison operator for a 1-dimensional nda::Array and a std::ranges::contiguous_range.

Template Parameters
Anda::Array type of left hand side.
Rstd::ranges::contiguous_range type of right hand side.
Parameters
aLeft hand side array operand.
rgRight hand side range operand.
Returns
True if all elements are equal, false otherwise.

Definition at line 503 of file basic_functions.hpp.

◆ operator==() [2/3]

template<Array LHS, Array RHS>
bool nda::operator== ( LHS const & lhs,
RHS const & rhs )

#include <nda/basic_functions.hpp>

Equal-to comparison operator for two nda::Array objects.

Template Parameters
LHSnda::Array type of left hand side.
RHSnda::Array type of right hand side.
Parameters
lhsLeft hand side array operand.
rhsRight hand side array operand.
Returns
True if all elements are equal, false otherwise.

Definition at line 480 of file basic_functions.hpp.

◆ operator==() [3/3]

template<std::ranges::contiguous_range R, ArrayOfRank< 1 > A>
bool nda::operator== ( R const & rg,
A const & a )

#include <nda/basic_functions.hpp>

Equal-to comparison operator for a std::ranges::contiguous_range and a 1-dimensional nda::Array.

Template Parameters
Rstd::ranges::contiguous_range type of left hand side.
Anda::Array type of right hand side.
Parameters
rgLeft hand side range operand.
aRight hand side array operand.
Returns
True if all elements are equal, false otherwise.

Definition at line 518 of file basic_functions.hpp.

◆ second_dim()

template<Array A>
long nda::second_dim ( A const & a)

#include <nda/basic_functions.hpp>

Get the extent of the second dimension of the array.

Equivalent to a.extent(1) and a.shape()[1].

Template Parameters
Anda::Array type.
Parameters
anda::Array object.
Returns
Extent of the second dimension.

Definition at line 219 of file basic_functions.hpp.

◆ static_extents()

template<typename... Is>
uint64_t nda::static_extents ( int i0,
Is... is )
constexpr

#include <nda/declarations.hpp>

Encode the given shape into a single integer using the nda::encode function.

Template Parameters
IsInteger sequence describing the shape.
Parameters
i0Size of the first dimension.
isSizes of the other dimensions.
Returns
uint64_t encoded shape.

Definition at line 187 of file declarations.hpp.

Variable Documentation

◆ get_algebra

template<typename A >
char nda::get_algebra = 'N'
inlineconstexpr

#include <nda/traits.hpp>

Constexpr variable that specifies the algebra of a type.

The possible values are:

  • 'N' = none
  • 'A' = array
  • 'M' = matrix
  • 'V' = vector

The algebra defines the behavior of objects in certain situations, e.g. matrix multiplication of two matrices ('M' algebra) vs. element-wise multiplication of two arrays ('A' algebra).

Template Parameters
AType to get the algebra of.

Definition at line 126 of file traits.hpp.

◆ get_algebra< expr_call< F, As... > >

template<typename F , Array... As>
char nda::get_algebra< expr_call< F, As... > > = detail::_impl_find_common_algebra(get_algebra<As>...)
constexpr

#include <nda/map.hpp>

Get the resulting algebra of a function call expression involving arrays/views.

If one of the algebras of the arguments is different, the resulting algebra is 'N'.

Template Parameters
FCallable object of the expression.
Asnda::Array argument types.

Definition at line 64 of file map.hpp.