TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >

#include <nda/basic_array.hpp>

Detailed Description

template<typename ValueType, int Rank, typename LayoutPolicy, char Algebra, typename ContainerPolicy>
class nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >

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:

  • ValueType: This is the type of the elements stored in the array. Most of the time, this will be a scalar type like an int, double or std::complex<double>, but it can also be a more complex type like a custom class or a another nda::basic_array.
  • Rank: Integer specifying the number of dimensions of the array. This is a compile-time constant.
  • LayoutPolicy: The layout policy specifies how the array views the memory it uses and how it accesses its elements. It provides a mapping from multi-dimensional to linear indices and vice versa (see Layout policies).
  • Algebra: The algebra specifies how an array behaves when it is used in an expression. Possible values are 'A' (array), 'M' (matrix) and 'V' (vector) (see nda::get_algebra).
  • ContainerPolicy: The container policy specifies how and where the data is stored. It is responsible for allocating/deallocating the memory (see Handles).

In contrast to views (see nda::basic_array_view), regular arrays own the memory they use for data storage.

// create a regular 3x2 array of ones
auto arr = nda::ones<int>(3, 2);
std::cout << arr << std::endl;
// assign the value 42 to the first row
arr(0, nda::ellipsis{}) = 42;
std::cout << arr << std::endl;
Mimics Python's ... syntax.
Definition range.hpp:49

Output:

[[1,1]
[1,1]
[1,1]]
[[42,42]
[1,1]
[1,1]]

Arrays and views share a lot of the same operations and functionalities. To turn a view into a regular array, use nda::make_regular.

Template Parameters
ValueTypeType stored in the array.
RankNumber of dimensions of the array.
LayoutPolicyPolicy determining the memory layout.
AlgebraAlgebra of the array.
ContainerPolicyPolicy determining how and where the data is stored.

Definition at line 113 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, value_type>)
 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 thr 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.
 
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_arrayoperator= (basic_array &&)=default
 Default move assignment moves the memory handle and layout from the right hand side array.
 
basic_arrayoperator= (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_arrayoperator= (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_arrayoperator= (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>)
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_arrayoperator= (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_arrayoperator= (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_tstorage () &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.
 

Constructor & Destructor Documentation

◆ basic_array() [1/12]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
template<char A, typename CP >
nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::basic_array ( basic_array< ValueType, Rank, LayoutPolicy, A, CP > a)
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.

Template Parameters
AAlgebra of the other array.
CPContainer policy of the other array.
Parameters
aOther array.

Definition at line 217 of file basic_array.hpp.

◆ basic_array() [2/12]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
template<std::integral... Ints>
requires (sizeof...(Ints) == Rank)
nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::basic_array ( Ints... is)
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.

Template Parameters
IntsInteger types.
Parameters
isExtent (number of elements) along each dimension.

Definition at line 230 of file basic_array.hpp.

◆ basic_array() [3/12]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
template<std::integral Int, typename RHS >
requires ((Rank == 1 and is_scalar_for_v<RHS, basic_array>))
nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::basic_array ( Int sz,
RHS const & val )
inlineexplicit

Construct a 1-dimensional array with the given size and initialize each element to the given scalar value.

Template Parameters
IntInteger type.
RHSType of the scalar value to initialize the array with.
Parameters
szSize of the array.
valValue to initialize the array with.

Definition at line 245 of file basic_array.hpp.

◆ basic_array() [4/12]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
template<std::integral Int = long>
requires (std::is_default_constructible_v<ValueType>)
nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::basic_array ( std::array< Int, Rank > const & shape)
inlineexplicit

Construct an array with the given shape.

It depends on the value type and the container policy whether the data is initialized with zeros or not.

Template Parameters
IntInteger type.
Parameters
shapeShape of the array.

Definition at line 260 of file basic_array.hpp.

◆ basic_array() [5/12]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::basic_array ( layout_t const & layout)
inlineexplicit

Construct an array with the given memory layout.

It depends on the value type and the container policy whether the data is initialized with zeros or not.

Parameters
layoutMemory layout.

Definition at line 271 of file basic_array.hpp.

◆ basic_array() [6/12]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::basic_array ( layout_t const & layout,
storage_t && storage )
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.

Parameters
layoutMemory layout.
storageMemory handle/storage.

Definition at line 283 of file basic_array.hpp.

◆ basic_array() [7/12]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
template<ArrayOfRank< Rank > A>
requires (HasValueTypeConstructibleFrom<A, value_type>)
nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::basic_array ( A const & a)
inline

Construct an array from an nda::ArrayOfRank object with the same rank by copying each element.

Template Parameters
Anda::ArrayOfRank type.
Parameters
anda::ArrayOfRank object.

Definition at line 293 of file basic_array.hpp.

◆ basic_array() [8/12]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
template<ArrayInitializer< basic_array > Initializer>
nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::basic_array ( Initializer const & initializer)
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.

Template Parameters
Initializernda::ArrayInitializer type.
Parameters
initializernda::ArrayInitializer object.

Definition at line 314 of file basic_array.hpp.

◆ basic_array() [9/12]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::basic_array ( std::initializer_list< ValueType > const & l)
inline

Construct a 1-dimensional array from an initializer list.

Parameters
lInitializer list.

Definition at line 336 of file basic_array.hpp.

◆ basic_array() [10/12]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::basic_array ( std::initializer_list< std::initializer_list< ValueType > > const & l2)
inline

Construct a 2-dimensional array from a double nested initializer list.

Parameters
l2Initializer list.

Definition at line 347 of file basic_array.hpp.

◆ basic_array() [11/12]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::basic_array ( std::initializer_list< std::initializer_list< std::initializer_list< ValueType > > > const & l3)
inline

Construct a 3-dimensional array from a triple nested initializer list.

Parameters
l3Initializer list.

Definition at line 362 of file basic_array.hpp.

◆ basic_array() [12/12]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
template<char A2>
requires (Rank == 2)
nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::basic_array ( basic_array< ValueType, 2, LayoutPolicy, A2, ContainerPolicy > && a)
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.

Template Parameters
A2Algebra of the given array.
Parameters
aOther array.

Definition at line 387 of file basic_array.hpp.

Member Function Documentation

◆ as_array_view() [1/2]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
auto nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::as_array_view ( )
inline

Convert the current array to a view with an 'A' (array) algebra.

Returns
An nda::basic_array_view of the current array.

Definition at line 176 of file basic_array.hpp.

◆ as_array_view() [2/2]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
auto nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::as_array_view ( ) const
inline

Convert the current array to a view with an 'A' (array) algebra.

Returns
An nda::basic_array_view of the current array with const value type.

Definition at line 182 of file basic_array.hpp.

◆ call()

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
template<char ResultAlgebra, bool SelfIsRvalue, typename Self , typename... Ts>
static __inline__ decltype(auto) nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::call ( Self && self,
Ts const &... idxs )
inlinestaticnoexcept

Implementation of the function call operator.

This function is an implementation detail an should be private. Since the Green's function library in TRIQS uses this function, it is kept public (for now).

Template Parameters
ResultAlgebraAlgebra of the resulting view/array.
SelfIsRvalueTrue if the view/array is an rvalue.
SelfType of the calling view/array.
TTypes of the arguments.
Parameters
selfCalling view.
idxsMulti-dimensional index consisting of long, nda::range, nda::range::all_t, nda::ellipsis or lazy arguments.
Returns
Result of the function call depending on the given arguments and type of the view/array.

Definition at line 777 of file basic_array.hpp.

◆ data() [1/2]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
ValueType const * nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::data ( ) const
inlinenodiscardnoexcept

Get a pointer to the actual data (in general this is not the beginning of the memory block for a view).

Returns
Const pointer to the first element of the view/array.

Definition at line 647 of file basic_array.hpp.

◆ data() [2/2]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
ValueType * nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::data ( )
inlinenodiscardnoexcept

Get a pointer to the actual data (in general this is not the beginning of thr memory block for a view).

Returns
Pointer to the first element of the view/array.

Definition at line 653 of file basic_array.hpp.

◆ empty()

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
bool nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::empty ( ) const
inlinenodiscard

Is the view/array empty?

Returns
True if the view/array does not contain any elements.

Definition at line 683 of file basic_array.hpp.

◆ extent()

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
long nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::extent ( int i) const
inlinenodiscardnoexcept

Get the extent of the ith dimension.

Returns
Number of elements along the ith dimension.

Definition at line 692 of file basic_array.hpp.

◆ indexmap()

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
auto const & nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::indexmap ( ) const
inlinenodiscardconstexprnoexcept

Get the memory layout of the view/array.

Returns
nda::idx_map specifying the layout of the view/array.

Definition at line 615 of file basic_array.hpp.

◆ indices()

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
auto nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::indices ( ) const
inlinenodiscardnoexcept

Get a range that generates all valid index tuples.

Returns
An itertools::multiplied range that can be used to iterate over all valid index tuples.

Definition at line 709 of file basic_array.hpp.

◆ is_contiguous()

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
long nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::is_contiguous ( ) const
inlinenodiscardnoexcept

Is the memory layout of the view/array contiguous?

Returns
True if the nda::idx_map is contiguous, false otherwise.

Definition at line 677 of file basic_array.hpp.

◆ is_empty()

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
bool nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::is_empty ( ) const
inlinenodiscardnoexcept
Deprecated
Use empty() instead.

Definition at line 686 of file basic_array.hpp.

◆ is_stride_order_C()

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
static constexpr bool nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::is_stride_order_C ( )
inlinestaticconstexprnoexcept

Is the stride order of the view/array in C-order?

Returns
True if the stride order of the nda::idx_map is C-order, false otherwise.

Definition at line 715 of file basic_array.hpp.

◆ is_stride_order_Fortran()

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
static constexpr bool nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::is_stride_order_Fortran ( )
inlinestaticconstexprnoexcept

Is the stride order of the view/array in Fortran-order?

Returns
True if the stride order of the nda::idx_map is Fortran-order, false otherwise.

Definition at line 721 of file basic_array.hpp.

◆ ones() [1/2]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
template<std::integral... Ints>
requires (sizeof...(Ints) == Rank)
static basic_array nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::ones ( Ints... is)
inlinestatic

Make a one-initialized array with the given dimensions.

Template Parameters
IntsInteger types.
Parameters
isExtent (number of elements) along each dimension.
Returns
One-initialized array.

Definition at line 443 of file basic_array.hpp.

◆ ones() [2/2]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
template<std::integral Int = long>
requires (nda::is_scalar_v<ValueType>)
static basic_array nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::ones ( std::array< Int, Rank > const & shape)
inlinestatic

Make a one-initialized array with the given shape.

Template Parameters
IntInteger type.
Parameters
shapeShape of the array.
Returns
One-initialized array.

Definition at line 427 of file basic_array.hpp.

◆ operator()() [1/2]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
decltype(auto) nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::operator() ( _linear_index_t idx) const
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).

Parameters
idxnda::_linear_index_t object.
Returns
Const reference to the element at the given linear index.

Definition at line 732 of file basic_array.hpp.

◆ operator()() [2/2]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
template<typename... Ts>
__inline__ decltype(auto) nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::operator() ( Ts const &... idxs) const &
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:

  • If any of the arguments is lazy, an nda::clef::expr with the nda::clef::tags::function tag is returned.
  • If no arguments are given, a full view of the calling object is returned:
    • If the calling object itself or its value type is const, a view with a const value type is returned.
    • Otherwise, a view with a non-const value type is returned.
  • If the number of arguments is equal to the rank of the calling object and all arguments are convertible to long, a single element is accessed:
    • If the calling object is a view or an lvalue, a (const) reference to the element is returned.
    • Otherwise, a copy of the element is returned.
  • Otherwise a slice of the calling object is returned with the same value type and accessor and owning policies as the calling object. The algebra of the slice is the same as well, except if a 1-dimensional slice of a matrix is taken. In this case, the algebra is changed to 'V'.
Template Parameters
TsTypes of the function arguments.
Parameters
idxsMulti-dimensional index consisting of long, nda::range, nda::range::all_t, nda::ellipsis or lazy arguments.
Returns
Result of the function call depending on the given arguments and type of the view/array.

Definition at line 842 of file basic_array.hpp.

◆ operator*=()

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
template<typename RHS >
auto & nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::operator*= ( RHS const & rhs)
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.

Template Parameters
RHSnda::Scalar or nda::Array type.
Parameters
rhsRight hand side operand of the multiplication assignment operation.
Returns
Reference to this object.

Definition at line 998 of file basic_array.hpp.

◆ operator+=()

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
template<typename RHS >
auto & nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::operator+= ( RHS const & rhs)
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.

Template Parameters
RHSnda::Scalar or nda::Array type.
Parameters
rhsRight hand side operand of the addition assignment operation.
Returns
Reference to this object.

Definition at line 962 of file basic_array.hpp.

◆ operator-=()

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
template<typename RHS >
auto & nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::operator-= ( RHS const & rhs)
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.

Template Parameters
RHSnda::Scalar or nda::Array type.
Parameters
rhsRight hand side operand of the subtraction assignment operation.
Returns
Reference to this object.

Definition at line 980 of file basic_array.hpp.

◆ operator/=()

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
template<typename RHS >
auto & nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::operator/= ( RHS const & rhs)
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.

Template Parameters
RHSnda::Scalar or nda::Array type.
Parameters
rhsRight hand side operand of the division assignment operation.
Returns
Reference to this object.

Definition at line 1016 of file basic_array.hpp.

◆ operator=() [1/5]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
template<char A, typename CP >
basic_array & nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::operator= ( basic_array< ValueType, Rank, LayoutPolicy, A, CP > const & rhs)
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.

Template Parameters
AAlgebra of the other array.
CPContainer policy of the other array.
Parameters
rhsRight hand side of the assignment operation.

Definition at line 508 of file basic_array.hpp.

◆ operator=() [2/5]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
template<ArrayInitializer< basic_array > Initializer>
basic_array & nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::operator= ( Initializer const & initializer)
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.

Template Parameters
Initializernda::ArrayInitializer type.
Parameters
initializerInitializer object.

Definition at line 557 of file basic_array.hpp.

◆ operator=() [3/5]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
template<std::ranges::contiguous_range R>
requires (Rank == 1 and not MemoryArray<R>)
auto & nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::operator= ( R const & rhs)
inlinenoexcept

Assignment operator makes a deep copy of a general contiguous range and assigns it to the 1-dimensional view/array.

Template Parameters
RRange type.
Parameters
rhsRight hand side range object.
Returns
Reference to this object.

Definition at line 1030 of file basic_array.hpp.

◆ operator=() [4/5]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
template<ArrayOfRank< Rank > RHS>
basic_array & nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::operator= ( RHS const & rhs)
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.

Template Parameters
RHSnda::ArrayOfRank type.
Parameters
rhsRight hand side of the assignment operation.

Definition at line 523 of file basic_array.hpp.

◆ operator=() [5/5]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
template<typename RHS >
requires (is_scalar_for_v<RHS, basic_array>)
basic_array & nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::operator= ( RHS const & rhs)
inlinenoexcept

Assignment operator assigns a scalar to the array.

The behavior depends on the algebra of the array:

  • 'A' (array) and 'V' (vector): The scalar is assigned to all elements of the array.
  • 'M' (matrix): The scalar is assigned to the diagonal elements of the shorter dimension.
Template Parameters
RHSType of the scalar.
Parameters
rhsRight hand side of the assignment operation.

Definition at line 540 of file basic_array.hpp.

◆ operator[]()

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
template<typename T >
decltype(auto) nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::operator[] ( T const & idx) const &
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:

  • If the argument is lazy, an nda::clef::expr with the nda::clef::tags::function tag is returned.
  • If the argument is convertible to long, a single element is accessed:
    • If the calling object is a view or an lvalue, a (const) reference to the element is returned.
    • Otherwise, a copy of the element is returned.
  • Otherwise a slice of the calling object is returned with the same value type, algebra and accessor and owning policies as the calling object.
Template Parameters
TType of the argument.
Parameters
idx1-dimensional index that is either a long, nda::range, nda::range::all_t, nda::ellipsis or a lazy argument.
Returns
Result of the subscript operation depending on the given argument and type of the view/array.

Definition at line 882 of file basic_array.hpp.

◆ rand() [1/2]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
template<std::integral... Ints>
requires (sizeof...(Ints) == Rank)
static basic_array nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::rand ( Ints... is)
inlinestatic

Make a random-initialized array with the given dimensions.

The random values are take from a uniform distribution over [0, 1). For a complex array, both real and imaginary parts are initialized with random values.

Template Parameters
IntsInteger types.
Parameters
isExtent (number of elements) along each dimension.
Returns
Random-initialized array.

Definition at line 485 of file basic_array.hpp.

◆ rand() [2/2]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
template<std::integral Int = long>
requires (std::is_floating_point_v<ValueType> or nda::is_complex_v<ValueType>)
static basic_array nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::rand ( std::array< Int, Rank > const & shape)
inlinestatic

Make a random-initialized array with the given shape.

The random values are take from a uniform distribution over [0, 1). For a complex array, both real and imaginary parts are initialized with random values.

Template Parameters
IntInteger type.
Parameters
shapeShape of the array.
Returns
Random-initialized array.

Definition at line 460 of file basic_array.hpp.

◆ resize() [1/2]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
template<std::integral... Ints>
void nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::resize ( Ints const &... is)
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.

Template Parameters
IntsInteger types.
Parameters
isNew extent (number of elements) along each dimension.

Definition at line 574 of file basic_array.hpp.

◆ resize() [2/2]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
void nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::resize ( std::array< long, Rank > const & shape)
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.

Parameters
shapeNew shape of the array.

Definition at line 589 of file basic_array.hpp.

◆ shape() [1/2]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
auto const & nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::shape ( ) const
inlinenodiscardnoexcept

Get the shape of the view/array.

Returns
std::array<long, Rank> object specifying the shape of the view/array.

Definition at line 659 of file basic_array.hpp.

◆ shape() [2/2]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
long nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::shape ( int i) const
inlinenodiscardnoexcept
Deprecated
Use extent(i) or shape()[i] instead.

Definition at line 703 of file basic_array.hpp.

◆ size()

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
long nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::size ( ) const
inlinenodiscardnoexcept

Get the total size of the view/array.

Returns
Number of elements contained in the view/array.

Definition at line 671 of file basic_array.hpp.

◆ storage() [1/3]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
storage_t nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::storage ( ) &&
inlinenodiscardnoexcept

Get the data storage of the view/array.

Returns
A copy of the memory handle of the view/array.

Definition at line 633 of file basic_array.hpp.

◆ storage() [2/3]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
storage_t & nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::storage ( ) &
inlinenodiscardnoexcept

Get the data storage of the view/array.

Returns
A reference to the memory handle of the view/array.

Definition at line 627 of file basic_array.hpp.

◆ storage() [3/3]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
storage_t const & nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::storage ( ) const &
inlinenodiscardnoexcept

Get the data storage of the view/array.

Returns
A const reference to the memory handle of the view/array.

Definition at line 621 of file basic_array.hpp.

◆ stride_order()

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
auto nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::stride_order ( ) const
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).

Returns
std::array<int, Rank> object specifying the stride order.

Definition at line 641 of file basic_array.hpp.

◆ strides()

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
auto const & nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::strides ( ) const
inlinenodiscardnoexcept

Get the strides of the view/array (see nda::idx_map for more details on how we define strides).

Returns
std::array<long, Rank> object specifying the strides of the view/array.

Definition at line 665 of file basic_array.hpp.

◆ transpose() [1/2]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
auto nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::transpose ( )
inline
Deprecated
Create the transpose of a 2-dimensional array. Use nda::transpose instead.

Definition at line 185 of file basic_array.hpp.

◆ transpose() [2/2]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
auto nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::transpose ( ) const
inline
Deprecated
Create the transpose of a 2-dimensional array. Use nda::transpose instead.

Definition at line 192 of file basic_array.hpp.

◆ zeros() [1/2]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
template<std::integral... Ints>
requires (sizeof...(Ints) == Rank)
static basic_array nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::zeros ( Ints... is)
inlinestatic

Make a zero-initialized array with the given dimensions.

Template Parameters
IntsInteger types.
Parameters
isExtent (number of elements) along each dimension.
Returns
Zero-initialized array.

Definition at line 413 of file basic_array.hpp.

◆ zeros() [2/2]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename ContainerPolicy >
template<std::integral Int = long>
requires (std::is_standard_layout_v<ValueType> && std::is_trivially_copyable_v<ValueType>)
static basic_array nda::basic_array< ValueType, Rank, LayoutPolicy, Algebra, ContainerPolicy >::zeros ( std::array< Int, Rank > const & shape)
inlinestatic

Make a zero-initialized array with the given shape.

Template Parameters
IntInteger type.
Parameters
shapeShape of the array.
Returns
Zero-initialized array.

Definition at line 399 of file basic_array.hpp.


The documentation for this class was generated from the following file: