|
TRIQS/nda 2.0.0
Multi-dimensional array library for C++
|
#include <nda/basic_array.hpp>
A generic multi-dimensional array.
Together with nda::basic_array_view, this class forms the backbone of the nda library. It is templated with the following parameters:
In contrast to views (see nda::basic_array_view), regular arrays own the memory they use for data storage.
Output:
Arrays and views share a lot of the same operations and functionalities. To turn a view into a regular array, use nda::make_regular.
| ValueType | Type stored in the array. |
| Rank | Number of dimensions of the array. |
| LayoutPolicy | Policy determining the memory layout. |
| Algebra | Algebra of the array. |
| ContainerPolicy | Policy determining how and where the data is stored. |
Definition at line 91 of file basic_array.hpp.
Public Types | |
| using | const_iterator = array_iterator<iterator_rank, ValueType const, typename AccessorPolicy::template accessor<ValueType>::pointer> |
| Const iterator type of the view/array. | |
| using | container_policy_t = ContainerPolicy |
| Type of the container policy (see Memory policies). | |
| using | iterator = array_iterator<iterator_rank, ValueType, typename AccessorPolicy::template accessor<ValueType>::pointer> |
| Iterator type of the view/array. | |
| using | layout_policy_t = LayoutPolicy |
| Type of the memory layout policy (see Layout policies). | |
| using | layout_t = typename LayoutPolicy::template mapping<Rank> |
| Type of the memory layout (an nda::idx_map). | |
| using | regular_type = basic_array |
| The associated regular type. | |
| using | storage_t = typename ContainerPolicy::template handle<ValueType> |
| Type of the memory handle (see Handles). | |
| using | value_type = ValueType |
| Type of the values in the array (can not be const). | |
Public Member Functions | |
| basic_array () | |
| Default constructor constructs an empty array with a default constructed memory handle and layout. | |
| template<ArrayOfRank< Rank > A> requires (HasValueTypeConstructibleFrom<A, ValueType>) | |
| basic_array (A const &a) | |
| Construct an array from an nda::ArrayOfRank object with the same rank by copying each element. | |
| basic_array (basic_array &&)=default | |
| Default move constructor moves the memory handle and layout. | |
| basic_array (basic_array const &a)=default | |
| Default copy constructor copies the memory handle and layout. | |
| template<char A2> requires (Rank == 2) | |
| basic_array (basic_array< ValueType, 2, LayoutPolicy, A2, ContainerPolicy > &&a) noexcept | |
| Construct a 2-dimensional array from another 2-dimensional array with a different algebra. | |
| template<char A, typename CP> | |
| basic_array (basic_array< ValueType, Rank, LayoutPolicy, A, CP > a) noexcept | |
| Construct an array from another array with a different algebra and/or container policy. | |
| template<ArrayInitializer< basic_array > Initializer> | |
| basic_array (Initializer const &initializer) | |
| Construct an array from an nda::ArrayInitializer object. | |
| template<std::integral Int, typename RHS> requires ((Rank == 1 and is_scalar_for_v<RHS, basic_array>)) | |
| basic_array (Int sz, RHS const &val) | |
| Construct a 1-dimensional array with the given size and initialize each element to the given scalar value. | |
| template<std::integral... Ints> requires (sizeof...(Ints) == Rank) | |
| basic_array (Ints... is) | |
| Construct an array with the given dimensions. | |
| basic_array (layout_t const &layout) | |
| Construct an array with the given memory layout. | |
| basic_array (layout_t const &layout, storage_t &&storage) noexcept | |
| Construct an array with the given memory layout and with an existing memory handle/storage. | |
| template<std::integral Int = long> requires (std::is_default_constructible_v<ValueType>) | |
| basic_array (std::array< Int, Rank > const &shape) | |
| Construct an array with the given shape. | |
| basic_array (std::initializer_list< std::initializer_list< std::initializer_list< ValueType > > > const &l3) | |
| Construct a 3-dimensional array from a triple nested initializer list. | |
| basic_array (std::initializer_list< std::initializer_list< ValueType > > const &l2) | |
| Construct a 2-dimensional array from a double nested initializer list. | |
| basic_array (std::initializer_list< ValueType > const &l) | |
| Construct a 1-dimensional array from an initializer list. | |
| auto | as_array_view () |
| Convert the current array to a view with an 'A' (array) algebra. | |
| auto | as_array_view () const |
| Convert the current array to a view with an 'A' (array) algebra. | |
| const_iterator | begin () const noexcept |
| Get a const iterator to the beginning of the view/array. | |
| iterator | begin () noexcept |
| Get an iterator to the beginning of the view/array. | |
| const_iterator | cbegin () const noexcept |
| Get a const iterator to the beginning of the view/array. | |
| const_iterator | cend () const noexcept |
| Get a const iterator to the end of the view/array. | |
| ValueType const * | data () const noexcept |
| Get a pointer to the actual data (in general this is not the beginning of the memory block for a view). | |
| ValueType * | data () noexcept |
| Get a pointer to the actual data (in general this is not the beginning of the memory block for a view). | |
| bool | empty () const |
| Is the view/array empty? | |
| const_iterator | end () const noexcept |
| Get a const iterator to the end of the view/array. | |
| iterator | end () noexcept |
| Get an iterator to the end of the view/array. | |
| long | extent (int i) const noexcept |
| Get the extent of the ith dimension. | |
| long | has_positive_strides () const noexcept |
| Are all the strides of the memory layout of the view/array positive? | |
| constexpr auto const & | indexmap () const noexcept |
| Get the memory layout of the view/array. | |
| auto | indices () const noexcept |
| Get a range that generates all valid index tuples. | |
| long | is_contiguous () const noexcept |
| Is the memory layout of the view/array contiguous? | |
| bool | is_empty () const noexcept |
| decltype(auto) | operator() (_linear_index_t idx) const noexcept |
| Access the element of the view/array at the given nda::_linear_index_t. | |
| decltype(auto) | operator() (_linear_index_t idx) noexcept |
| Non-const overload of nda::basic_array_view::operator()(_linear_index_t) const. | |
| template<typename... Ts> | |
| __inline__ decltype(auto) | operator() (Ts const &...idxs) &&noexcept(has_no_boundcheck) |
| Rvalue overload of nda::basic_array_view::operator()(Ts const &...) const &. | |
| template<typename... Ts> | |
| __inline__ decltype(auto) | operator() (Ts const &...idxs) &noexcept(has_no_boundcheck) |
| Non-const overload of nda::basic_array_view::operator()(Ts const &...) const &. | |
| template<typename... Ts> | |
| __inline__ decltype(auto) | operator() (Ts const &...idxs) const &noexcept(has_no_boundcheck) |
| Function call operator to access the view/array. | |
| template<typename RHS> | |
| auto & | operator*= (RHS const &rhs) noexcept |
| Multiplication assignment operator. | |
| template<typename RHS> | |
| auto & | operator+= (RHS const &rhs) noexcept |
| Addition assignment operator. | |
| template<typename RHS> | |
| auto & | operator-= (RHS const &rhs) noexcept |
| Subtraction assignment operator. | |
| template<typename RHS> | |
| auto & | operator/= (RHS const &rhs) noexcept |
| Division assignment operator. | |
| basic_array & | operator= (basic_array &&)=default |
| Default move assignment moves the memory handle and layout from the right hand side array. | |
| basic_array & | operator= (basic_array const &)=default |
| Default copy assignment copies the memory handle and layout from the right hand side array. | |
| template<char A, typename CP> | |
| basic_array & | operator= (basic_array< ValueType, Rank, LayoutPolicy, A, CP > const &rhs) |
| Assignment operator makes a deep copy of another array with a different algebra and/or container policy. | |
| template<ArrayInitializer< basic_array > Initializer> | |
| basic_array & | operator= (Initializer const &initializer) |
| Assignment operator uses an nda::ArrayInitializer to assign to the array. | |
| template<std::ranges::contiguous_range R> requires (Rank == 1 and not MemoryArray<R> and not is_scalar_for_v<R, self_t>) | |
| auto & | operator= (R const &rhs) noexcept |
| Assignment operator makes a deep copy of a general contiguous range and assigns it to the 1-dimensional view/array. | |
| template<ArrayOfRank< Rank > RHS> | |
| basic_array & | operator= (RHS const &rhs) |
| Assignment operator makes a deep copy of an nda::ArrayOfRank object. | |
| template<typename RHS> requires (is_scalar_for_v<RHS, basic_array>) | |
| basic_array & | operator= (RHS const &rhs) noexcept |
| Assignment operator assigns a scalar to the array. | |
| template<typename T> | |
| decltype(auto) | operator[] (T const &idx) const &noexcept(has_no_boundcheck) |
| Subscript operator to access the 1-dimensional view/array. | |
| template<typename T> | |
| decltype(auto) | operator[] (T const &x) &&noexcept(has_no_boundcheck) |
| Rvalue overload of nda::basic_array_view::operator[](T const &) const &. | |
| template<typename T> | |
| decltype(auto) | operator[] (T const &x) &noexcept(has_no_boundcheck) |
| Non-const overload of nda::basic_array_view::operator[](T const &) const &. | |
| template<std::integral... Ints> | |
| void | resize (Ints const &...is) |
| Resize the array to a new shape. | |
| void | resize (std::array< long, Rank > const &shape) |
| Resize the array to a new shape. | |
| auto const & | shape () const noexcept |
| Get the shape of the view/array. | |
| long | shape (int i) const noexcept |
| long | size () const noexcept |
| Get the total size of the view/array. | |
| storage_t | storage () &&noexcept |
| Get the data storage of the view/array. | |
| storage_t & | storage () &noexcept |
| Get the data storage of the view/array. | |
| storage_t const & | storage () const &noexcept |
| Get the data storage of the view/array. | |
| constexpr auto | stride_order () const noexcept |
| Get the stride order of the memory layout of the view/array (see nda::idx_map for more details on how we define stride orders). | |
| auto const & | strides () const noexcept |
| Get the strides of the view/array (see nda::idx_map for more details on how we define strides). | |
| auto | transpose () |
| auto | transpose () const |
Static Public Member Functions | |
| template<char ResultAlgebra, bool SelfIsRvalue, typename Self, typename... Ts> | |
| static __inline__ decltype(auto) | call (Self &&self, Ts const &...idxs) noexcept(has_no_boundcheck) |
| Implementation of the function call operator. | |
| static constexpr bool | is_stride_order_C () noexcept |
| Is the stride order of the view/array in C-order? | |
| static constexpr bool | is_stride_order_Fortran () noexcept |
| Is the stride order of the view/array in Fortran-order? | |
| template<std::integral... Ints> requires (sizeof...(Ints) == Rank) | |
| static basic_array | ones (Ints... is) |
| Make a one-initialized array with the given dimensions. | |
| template<std::integral Int = long> requires (nda::is_scalar_v<ValueType>) | |
| static basic_array | ones (std::array< Int, Rank > const &shape) |
| Make a one-initialized array with the given shape. | |
| template<std::integral... Ints> requires (sizeof...(Ints) == Rank) | |
| static basic_array | rand (Ints... is) |
| Make a random-initialized array with the given dimensions. | |
| template<std::integral Int = long> requires (std::is_floating_point_v<ValueType> or nda::is_complex_v<ValueType>) | |
| static basic_array | rand (std::array< Int, Rank > const &shape) |
| Make a random-initialized array with the given shape. | |
| template<std::integral... Ints> requires (sizeof...(Ints) == Rank) | |
| static basic_array | zeros (Ints... is) |
| Make a zero-initialized array with the given dimensions. | |
| template<std::integral Int = long> requires (std::is_standard_layout_v<ValueType> && std::is_trivially_copyable_v<ValueType>) | |
| static basic_array | zeros (std::array< Int, Rank > const &shape) |
| Make a zero-initialized array with the given shape. | |
Static Public Attributes | |
| static constexpr int | iterator_rank = (has_strided_1d(layout_t::layout_prop) ? 1 : Rank) |
| Rank of the nda::array_iterator for the view/array. | |
| static constexpr int | rank = Rank |
| Number of dimensions of the array. | |
|
inlineexplicitnoexcept |
Construct an array from another array with a different algebra and/or container policy.
It takes the memory layout of the other array and copies the data from the memory handle.
| A | Algebra of the other array. |
| CP | Container policy of the other array. |
| a | Other array. |
Definition at line 195 of file basic_array.hpp.
|
inlineexplicit |
Construct an array with the given dimensions.
The integer type must be convertible to long and there must be exactly Rank arguments. It depends on the value type and the container policy whether the data is initialized with zeros or not.
| Ints | Integer types. |
| is | Extent (number of elements) along each dimension. |
Definition at line 208 of file basic_array.hpp.
|
inlineexplicit |
Construct a 1-dimensional array with the given size and initialize each element to the given scalar value.
| Int | Integer type. |
| RHS | Type of the scalar value to initialize the array with. |
| sz | Size of the array. |
| val | Value to initialize the array with. |
Definition at line 223 of file basic_array.hpp.
|
inlineexplicit |
Construct an array with the given shape.
Whether the data is initialized with zeros depends on the value type and the container policy.
| Int | Integer type. |
| shape | Shape of the array. |
Definition at line 238 of file basic_array.hpp.
|
inlineexplicit |
Construct an array with the given memory layout.
Whether the data is initialized with zeros depends on the value type and the container policy.
| layout | Memory layout. |
Definition at line 249 of file basic_array.hpp.
|
inlineexplicitnoexcept |
Construct an array with the given memory layout and with an existing memory handle/storage.
The memory handle is moved and the layout is copied into the array.
| layout | Memory layout. |
| storage | Memory handle/storage. |
Definition at line 261 of file basic_array.hpp.
|
inline |
Construct an array from an nda::ArrayOfRank object with the same rank by copying each element.
| A | nda::ArrayOfRank type. |
| a | nda::ArrayOfRank object. |
Definition at line 271 of file basic_array.hpp.
|
inline |
Construct an array from an nda::ArrayInitializer object.
An nda::ArrayInitializer is typically returned by delayed operations (see e.g. nda::mpi_gather). The constructor can then be used to create the resulting array.
| Initializer | nda::ArrayInitializer type. |
| initializer | nda::ArrayInitializer object. |
Definition at line 295 of file basic_array.hpp.
|
inline |
Construct a 1-dimensional array from an initializer list.
| l | Initializer list. |
Definition at line 317 of file basic_array.hpp.
|
inline |
Construct a 2-dimensional array from a double nested initializer list.
| l2 | Initializer list. |
Definition at line 328 of file basic_array.hpp.
|
inline |
Construct a 3-dimensional array from a triple nested initializer list.
| l3 | Initializer list. |
Definition at line 343 of file basic_array.hpp.
|
inlineexplicitnoexcept |
Construct a 2-dimensional array from another 2-dimensional array with a different algebra.
The given array is moved into the constructed array. Note that for nda::stack_array or other array types, this might still involve a copy of the data.
| A2 | Algebra of the given array. |
| a | Other array. |
Definition at line 368 of file basic_array.hpp.
|
inline |
Convert the current array to a view with an 'A' (array) algebra.
Definition at line 154 of file basic_array.hpp.
|
inline |
Convert the current array to a view with an 'A' (array) algebra.
Definition at line 160 of file basic_array.hpp.
|
inlinestaticnoexcept |
Implementation of the function call operator.
This function is an implementation detail and should be private. Since the Green's function library in TRIQS uses this function, it is kept public (for now).
| ResultAlgebra | Algebra of the resulting view/array. |
| SelfIsRvalue | True if the view/array is an rvalue. |
| Self | Type of the calling view/array. |
| T | Types of the arguments. |
| self | Calling view. |
| idxs | Multi-dimensional index consisting of long, nda::range, nda::range::all_t, nda::ellipsis or lazy arguments. |
Definition at line 755 of file basic_array.hpp.
|
inlinenodiscardnoexcept |
Get a pointer to the actual data (in general this is not the beginning of the memory block for a view).
Definition at line 619 of file basic_array.hpp.
|
inlinenodiscardnoexcept |
Get a pointer to the actual data (in general this is not the beginning of the memory block for a view).
Definition at line 625 of file basic_array.hpp.
|
inlinenodiscard |
Is the view/array empty?
Definition at line 661 of file basic_array.hpp.
|
inlinenodiscardnoexcept |
Get the extent of the ith dimension.
Definition at line 670 of file basic_array.hpp.
|
inlinenodiscardnoexcept |
Are all the strides of the memory layout of the view/array positive?
Definition at line 655 of file basic_array.hpp.
|
inlinenodiscardconstexprnoexcept |
Get the memory layout of the view/array.
Definition at line 587 of file basic_array.hpp.
|
inlinenodiscardnoexcept |
Get a range that generates all valid index tuples.
Definition at line 687 of file basic_array.hpp.
|
inlinenodiscardnoexcept |
Is the memory layout of the view/array contiguous?
Definition at line 649 of file basic_array.hpp.
|
inlinenodiscardnoexcept |
Definition at line 664 of file basic_array.hpp.
|
inlinestaticconstexprnoexcept |
Is the stride order of the view/array in C-order?
Definition at line 693 of file basic_array.hpp.
|
inlinestaticconstexprnoexcept |
Is the stride order of the view/array in Fortran-order?
Definition at line 699 of file basic_array.hpp.
|
inlinestatic |
Make a one-initialized array with the given dimensions.
| Ints | Integer types. |
| is | Extent (number of elements) along each dimension. |
Definition at line 424 of file basic_array.hpp.
|
inlinestatic |
Make a one-initialized array with the given shape.
| Int | Integer type. |
| shape | Shape of the array. |
Definition at line 408 of file basic_array.hpp.
|
inlinenoexcept |
Access the element of the view/array at the given nda::_linear_index_t.
The linear index specifies the position of the element in the view/array and not the position of the element w.r.t. to the data pointer (i.e. any possible strides should not be taken into account).
| idx | nda::_linear_index_t object. |
Definition at line 710 of file basic_array.hpp.
|
inlinenoexcept |
Function call operator to access the view/array.
Depending on the type of the calling object and the given arguments, this function call does the following:
| Ts | Types of the function arguments. |
| idxs | Multi-dimensional index consisting of long, nda::range, nda::range::all_t, nda::ellipsis or lazy arguments. |
Definition at line 820 of file basic_array.hpp.
|
inlinenoexcept |
Multiplication assignment operator.
It first performs the (lazy) multiplication with the right hand side operand and then assigns the result to the left hand side view/array.
See nda::operator*(L &&, R &&) and nda::operator*(A &&, S &&) for more details.
| RHS | nda::Scalar or nda::Array type. |
| rhs | Right hand side operand of the multiplication assignment operation. |
Definition at line 976 of file basic_array.hpp.
|
inlinenoexcept |
Addition assignment operator.
It first performs the (lazy) addition with the right hand side operand and then assigns the result to the left hand side view/array.
See nda::operator+(L &&, R &&) and nda::operator+(A &&, S &&) for more details.
| RHS | nda::Scalar or nda::Array type. |
| rhs | Right hand side operand of the addition assignment operation. |
Definition at line 940 of file basic_array.hpp.
|
inlinenoexcept |
Subtraction assignment operator.
It first performs the (lazy) subtraction with the right hand side operand and then assigns the result to the left hand side view/array.
See nda::operator-(L &&, R &&) and nda::operator-(A &&, S &&) for more details.
| RHS | nda::Scalar or nda::Array type. |
| rhs | Right hand side operand of the subtraction assignment operation. |
Definition at line 958 of file basic_array.hpp.
|
inlinenoexcept |
Division assignment operator.
It first performs the (lazy) division with the right hand side operand and then assigns the result to the left hand side view/array.
See nda::operator/(L &&, R &&) and nda::operator/(A &&, S &&) for more details.
| RHS | nda::Scalar or nda::Array type. |
| rhs | Right hand side operand of the division assignment operation. |
Definition at line 994 of file basic_array.hpp.
|
inline |
Assignment operator makes a deep copy of another array with a different algebra and/or container policy.
A new array object is constructed from the right hand side array and then moved into the current array. This will invalidate all references/views to the existing storage.
| A | Algebra of the other array. |
| CP | Container policy of the other array. |
| rhs | Right hand side of the assignment operation. |
Definition at line 491 of file basic_array.hpp.
|
inline |
Assignment operator uses an nda::ArrayInitializer to assign to the array.
The array is resized to the shape of the initializer. This might invalidate all references/views to the existing storage.
| Initializer | nda::ArrayInitializer type. |
| initializer | Initializer object. |
Definition at line 540 of file basic_array.hpp.
|
inlinenoexcept |
Assignment operator makes a deep copy of a general contiguous range and assigns it to the 1-dimensional view/array.
| R | Range type. |
| rhs | Right hand side range object. |
Definition at line 1008 of file basic_array.hpp.
|
inline |
Assignment operator makes a deep copy of an nda::ArrayOfRank object.
The array is first resized to the shape of the right hand side and the elements are copied. This might invalidate all references/views to the existing storage.
| RHS | nda::ArrayOfRank type. |
| rhs | Right hand side of the assignment operation. |
Definition at line 506 of file basic_array.hpp.
|
inlinenoexcept |
Assignment operator assigns a scalar to the array.
The behavior depends on the algebra of the array:
| RHS | Type of the scalar. |
| rhs | Right hand side of the assignment operation. |
Definition at line 523 of file basic_array.hpp.
|
inlinenoexcept |
Subscript operator to access the 1-dimensional view/array.
Depending on the type of the calling object and the given argument, this subscript operation does the following:
| T | Type of the argument. |
| idx | 1-dimensional index that is either a long, nda::range, nda::range::all_t, nda::ellipsis or a lazy argument. |
Definition at line 860 of file basic_array.hpp.
|
inlinestatic |
Make a random-initialized array with the given dimensions.
The random values are taken from a uniform distribution over [0, 1). For a complex array, both real and imaginary parts are initialized with random values.
| Ints | Integer types. |
| is | Extent (number of elements) along each dimension. |
Definition at line 468 of file basic_array.hpp.
|
inlinestatic |
Make a random-initialized array with the given shape.
The random values are taken from a uniform distribution over [0, 1). For a complex array, both real and imaginary parts are initialized with random values.
| Int | Integer type. |
| shape | Shape of the array. |
Definition at line 441 of file basic_array.hpp.
|
inline |
Resize the array to a new shape.
Resizing is only performed if the storage is not null and if the new size is different from the previous size. If resizing is performed, the content of the resulting array is undefined since it makes no copy of the previous data and all references/views to the existing storage will be invalidated.
| Ints | Integer types. |
| is | New extent (number of elements) along each dimension. |
Definition at line 557 of file basic_array.hpp.
|
inline |
Resize the array to a new shape.
Resizing is only performed if the storage is not null and if the new size is different from the previous size. If resizing is performed, the content of the resulting array is undefined since it makes no copy of the previous data and all references/views to the existing storage will be invalidated.
| shape | New shape of the array. |
Definition at line 572 of file basic_array.hpp.
|
inlinenodiscardnoexcept |
Get the shape of the view/array.
Definition at line 631 of file basic_array.hpp.
|
inlinenodiscardnoexcept |
Definition at line 681 of file basic_array.hpp.
|
inlinenodiscardnoexcept |
Get the total size of the view/array.
Definition at line 643 of file basic_array.hpp.
|
inlinenodiscardnoexcept |
Get the data storage of the view/array.
Definition at line 605 of file basic_array.hpp.
|
inlinenodiscardnoexcept |
Get the data storage of the view/array.
Definition at line 599 of file basic_array.hpp.
|
inlinenodiscardnoexcept |
Get the data storage of the view/array.
Definition at line 593 of file basic_array.hpp.
|
inlinenodiscardconstexprnoexcept |
Get the stride order of the memory layout of the view/array (see nda::idx_map for more details on how we define stride orders).
Definition at line 613 of file basic_array.hpp.
|
inlinenodiscardnoexcept |
Get the strides of the view/array (see nda::idx_map for more details on how we define strides).
Definition at line 637 of file basic_array.hpp.
|
inline |
Definition at line 163 of file basic_array.hpp.
|
inline |
Definition at line 170 of file basic_array.hpp.
|
inlinestatic |
Make a zero-initialized array with the given dimensions.
| Ints | Integer types. |
| is | Extent (number of elements) along each dimension. |
Definition at line 394 of file basic_array.hpp.
|
inlinestatic |
Make a zero-initialized array with the given shape.
| Int | Integer type. |
| shape | Shape of the array. |
Definition at line 380 of file basic_array.hpp.