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

#include <nda/basic_array_view.hpp>

Detailed Description

template<typename ValueType, int Rank, typename LayoutPolicy, char Algebra, typename AccessorPolicy, typename OwningPolicy>
class nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >

A generic view of a multi-dimensional array.

Together with nda::basic_array, this class forms the backbone of the nda library. It is templated with the following parameters:

  • ValueType: This is the type of the elements in the view. Depending on how the view was constructed and on the underlying array, this can be a const or non-const type.
  • Rank: Integer specifying the number of dimensions of the view. This is a compile-time constant.
  • LayoutPolicy: The layout policy specifies how the view accesses its elements. It provides a mapping from multi-dimensional to linear indices and vice versa (see Layout policies).
  • Algebra: The algebra specifies how the view behaves when it is used in an expression. Possible values are 'A' (array), 'M' (matrix) and 'V' (vector) (see nda::get_algebra).
  • AccessorPolicy: The accessor policy specifies how the view accesses the data pointer. This can be useful for optimizations.
  • OwningPolicy: The owning policy specifies the ownership of the data pointer and who is responsible for handling the memory resources (see Handles).

In contrast to regular arrays (see nda::basic_array), views do not own the data they point to. They are a fast and efficient way to access and manipulate already existing data:

// create a regular 3x3 array of ones
auto arr = nda::ones<int>(3, 3);
std::cout << arr << std::endl;
// zero out the first column
arr(nda::range::all, 0) = 0;
std::cout << arr << std::endl;

Output:

[[1,1,1]
[1,1,1]
[1,1,1]]
[[0,1,1]
[0,1,1]
[0,1,1]]

Views are usually created by taking a slice of a regular nda::basic_array or another view. In the example above, arr(nda::range::all, 0) creates a view of the first column of the regular array arr, which is then set to zero. A view of the full array can be created with arr().

Template Parameters
ValueTypeType stored in the array.
RankNumber of dimensions of the view.
LayoutPolicyPolicy determining the memory layout.
AlgebraAlgebra of the view.
AccessorPolicyPolicy determining how the data pointer is accessed.
OwningPolicyPolicy determining the ownership of the data.

Definition at line 127 of file basic_array_view.hpp.

Public Types

using accessor_policy_t = AccessorPolicy
 Type of the accessor policy (see e.g. nda::default_accessor).
 
using const_iterator = array_iterator<iterator_rank, ValueType const, typename AccessorPolicy::template accessor<ValueType>::pointer>
 Const iterator type of the view/array.
 
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 owning_policy_t = OwningPolicy
 Type of the owning policy (see Memory policies).
 
using regular_type = basic_array<std::remove_const_t<ValueType>, Rank, C_layout, Algebra, heap<mem::get_addr_space<storage_t>>>
 The associated regular (nda::basic_array) type.
 
using storage_t = typename OwningPolicy::template handle<ValueType>
 Type of the memory handle (see Handles).
 
using value_type = ValueType
 Type of the values in the view (might be const).
 

Public Member Functions

 basic_array_view ()=default
 Default constructor constructs an empty view with a default constructed memory handle and layout.
 
template<MemoryArrayOfRank< Rank > A>
requires ((get_layout_info<A>.stride_order == layout_t::stride_order_encoded) and (std::is_same_v<std::remove_const_t<ValueType>, get_value_t<A>>) and (std::is_const_v<ValueType> or !std::is_const_v<typename std::decay_t<A>::value_type>))
 basic_array_view (A &&a) noexcept
 Generic constructor from any nda::MemoryArray type.
 
 basic_array_view (basic_array_view &&)=default
 Default move constructor moves the memory handle and layout.
 
 basic_array_view (basic_array_view const &)=default
 Default copy constructor copies the memory handle and layout.
 
 basic_array_view (layout_t const &idxm, storage_t st)
 Construct a view from a given layout and memory handle.
 
 basic_array_view (layout_t const &idxm, ValueType *p) noexcept
 Construct a view from a bare pointer to some contiguous data and a memory layout.
 
template<std::ranges::contiguous_range R>
requires (Rank == 1 and not MemoryArray<R> and (std::is_same_v<std::ranges::range_value_t<R>, ValueType> or std::is_same_v<const std::ranges::range_value_t<R>, ValueType>))
 basic_array_view (R &rg) noexcept
 Construct a 1-dimensional view of a general contiguous range.
 
 basic_array_view (std::array< long, Rank > const &shape, ValueType *p) noexcept
 Construct a view from a bare pointer to some contiguous data and a shape.
 
template<size_t N>
requires (Rank == 1 and std::is_const_v<ValueType>)
 basic_array_view (std::array< std::remove_const_t< ValueType >, N > const &a) noexcept
 Construct a 1-dimensional view of a std::array.
 
template<size_t N>
requires (Rank == 1)
 basic_array_view (std::array< ValueType, N > &a) noexcept
 Construct a 1-dimensional view of a std::array.
 
auto as_array_view ()
 
auto as_array_view () const
 
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_array_viewoperator= (basic_array_view const &rhs) noexcept
 Copy assignment operator makes a deep copy of the contents of the view.
 
template<ArrayInitializer< basic_array_view > Initializer>
basic_array_viewoperator= (Initializer const &initializer) noexcept
 Assignment operator uses an nda::ArrayInitializer to assign to the view.
 
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_array_viewoperator= (RHS const &rhs) noexcept
 Assignment operator makes a deep copy of the contents of an nda::ArrayOfRank object.
 
template<typename RHS >
requires (is_scalar_for_v<RHS, basic_array_view>)
basic_array_viewoperator= (RHS const &rhs) noexcept
 Assignment operator assigns a scalar to the view.
 
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<typename T , int R, typename LP , char A, typename AP , typename OP >
void rebind (basic_array_view< T, R, LP, A, AP, OP > v) noexcept
 Rebind the current view to another view.
 
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).
 

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?
 

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

Friends

void deep_swap (basic_array_view a, basic_array_view b) noexcept
 Swap two views by swapping their data.
 
void swap (basic_array_view &a, basic_array_view &b) noexcept
 Swap two views by swapping their memory handles and layouts.
 

Constructor & Destructor Documentation

◆ basic_array_view() [1/7]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >::basic_array_view ( layout_t const & idxm,
storage_t st )
inline

Construct a view from a given layout and memory handle.

Warning
This should not be used directly. Use one of the other constructors instead.
Parameters
idxmLayout of the view.
stMemory handle of the view.

Definition at line 197 of file basic_array_view.hpp.

◆ basic_array_view() [2/7]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
template<MemoryArrayOfRank< Rank > A>
requires ((get_layout_info<A>.stride_order == layout_t::stride_order_encoded) and (std::is_same_v<std::remove_const_t<ValueType>, get_value_t<A>>) and (std::is_const_v<ValueType> or !std::is_const_v<typename std::decay_t<A>::value_type>))
nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >::basic_array_view ( A && a)
inlineexplicitnoexcept

Generic constructor from any nda::MemoryArray type.

It simply copies the memory layout and initializes the memory handle with the handle of the given nda::MemoryArray object.

Template Parameters
Anda::MemoryArray type of the same rank as the view.
Parameters
anda::MemoryArray object.

Definition at line 232 of file basic_array_view.hpp.

◆ basic_array_view() [3/7]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >::basic_array_view ( std::array< long, Rank > const & shape,
ValueType * p )
inlinenoexcept

Construct a view from a bare pointer to some contiguous data and a shape.

Note
We do not have any control over the specified dimensions. The caller has to ensure their correctness and their compatibility with the given data pointer.
Parameters
shapeShape of the view.
pPointer to the data.

Definition at line 244 of file basic_array_view.hpp.

◆ basic_array_view() [4/7]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >::basic_array_view ( layout_t const & idxm,
ValueType * p )
inlinenoexcept

Construct a view from a bare pointer to some contiguous data and a memory layout.

Note
We do not have any control over the given layout. The caller has to ensure its correctness and its compatibility with the given data pointer.
Parameters
idxmLayout of the view.
pPointer to the data.

Definition at line 255 of file basic_array_view.hpp.

◆ basic_array_view() [5/7]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
template<size_t N>
requires (Rank == 1)
nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >::basic_array_view ( std::array< ValueType, N > & a)
inlineexplicitnoexcept

Construct a 1-dimensional view of a std::array.

Template Parameters
NSize of the std::array.
Parameters
aReference to a std::array object.

Definition at line 265 of file basic_array_view.hpp.

◆ basic_array_view() [6/7]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
template<size_t N>
requires (Rank == 1 and std::is_const_v<ValueType>)
nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >::basic_array_view ( std::array< std::remove_const_t< ValueType >, N > const & a)
inlineexplicitnoexcept

Construct a 1-dimensional view of a std::array.

Template Parameters
NSize of the std::array.
Parameters
aConst reference to a std::array object.

Definition at line 275 of file basic_array_view.hpp.

◆ basic_array_view() [7/7]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
template<std::ranges::contiguous_range R>
requires (Rank == 1 and not MemoryArray<R> and (std::is_same_v<std::ranges::range_value_t<R>, ValueType> or std::is_same_v<const std::ranges::range_value_t<R>, ValueType>))
nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >::basic_array_view ( R & rg)
inlineexplicitnoexcept

Construct a 1-dimensional view of a general contiguous range.

Template Parameters
RType of the range.
Parameters
rgRange object.

Definition at line 286 of file basic_array_view.hpp.

Member Function Documentation

◆ as_array_view() [1/2]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
auto nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >::as_array_view ( )
inline
Deprecated
Convert the current view to a view with an 'A' (array) algebra.

Definition at line 202 of file basic_array_view.hpp.

◆ as_array_view() [2/2]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
auto nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >::as_array_view ( ) const
inline
Deprecated
Convert the current view to a view with an 'A' (array) algebra.

Definition at line 205 of file basic_array_view.hpp.

◆ call()

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
template<char ResultAlgebra, bool SelfIsRvalue, typename Self , typename... Ts>
static __inline__ decltype(auto) nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >::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 594 of file basic_array_view.hpp.

◆ data() [1/2]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
ValueType const * nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >::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 464 of file basic_array_view.hpp.

◆ data() [2/2]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
ValueType * nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >::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 470 of file basic_array_view.hpp.

◆ empty()

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
bool nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >::empty ( ) const
inlinenodiscard

Is the view/array empty?

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

Definition at line 500 of file basic_array_view.hpp.

◆ extent()

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

Get the extent of the ith dimension.

Returns
Number of elements along the ith dimension.

Definition at line 509 of file basic_array_view.hpp.

◆ indexmap()

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
auto const & nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >::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 432 of file basic_array_view.hpp.

◆ indices()

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
auto nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >::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 526 of file basic_array_view.hpp.

◆ is_contiguous()

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
long nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >::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 494 of file basic_array_view.hpp.

◆ is_empty()

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

Definition at line 503 of file basic_array_view.hpp.

◆ is_stride_order_C()

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
static constexpr bool nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >::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 532 of file basic_array_view.hpp.

◆ is_stride_order_Fortran()

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
static constexpr bool nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >::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 538 of file basic_array_view.hpp.

◆ operator()() [1/2]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
decltype(auto) nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >::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 549 of file basic_array_view.hpp.

◆ operator()() [2/2]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
template<typename... Ts>
__inline__ decltype(auto) nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >::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 659 of file basic_array_view.hpp.

◆ operator*=()

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
template<typename RHS >
auto & nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >::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 815 of file basic_array_view.hpp.

◆ operator+=()

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
template<typename RHS >
auto & nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >::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 779 of file basic_array_view.hpp.

◆ operator-=()

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
template<typename RHS >
auto & nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >::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 797 of file basic_array_view.hpp.

◆ operator/=()

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
template<typename RHS >
auto & nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >::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 833 of file basic_array_view.hpp.

◆ operator=() [1/5]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
basic_array_view & nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >::operator= ( basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy > const & rhs)
inlinenoexcept

Copy assignment operator makes a deep copy of the contents of the view.

The dimension of the right hand side must be large enough or the behaviour is undefined. If NDA_ENFORCE_BOUNDCHECK is defined, bounds checking is enabled.

Parameters
rhsRight hand side of the assignment operation.

Definition at line 296 of file basic_array_view.hpp.

◆ operator=() [2/5]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
template<ArrayInitializer< basic_array_view > Initializer>
basic_array_view & nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >::operator= ( Initializer const & initializer)
inlinenoexcept

Assignment operator uses an nda::ArrayInitializer to assign to the view.

The shape of the view is expected to be the same as the shape of the initializer.

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

Definition at line 345 of file basic_array_view.hpp.

◆ operator=() [3/5]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
template<std::ranges::contiguous_range R>
requires (Rank == 1 and not MemoryArray<R>)
auto & nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >::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 847 of file basic_array_view.hpp.

◆ operator=() [4/5]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
template<ArrayOfRank< Rank > RHS>
basic_array_view & nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >::operator= ( RHS const & rhs)
inlinenoexcept

Assignment operator makes a deep copy of the contents of an nda::ArrayOfRank object.

The dimension of the right hand side must be large enough or the behaviour is undefined. If NDA_ENFORCE_BOUNDCHECK is defined, bounds checking is enabled.

Template Parameters
RHSnda::ArrayOfRank type with the same rank as the view.
Parameters
rhsRight hand side of the assignment operation.

Definition at line 311 of file basic_array_view.hpp.

◆ operator=() [5/5]

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

Assignment operator assigns a scalar to the view.

The behavior depends on the algebra of the view:

  • 'A' (array) and 'V' (vector): The scalar is assigned to all elements of the view.
  • '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 328 of file basic_array_view.hpp.

◆ operator[]()

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
template<typename T >
decltype(auto) nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >::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 699 of file basic_array_view.hpp.

◆ rebind()

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
template<typename T , int R, typename LP , char A, typename AP , typename OP >
void nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >::rebind ( basic_array_view< T, R, LP, A, AP, OP > v)
inlinenoexcept

Rebind the current view to another view.

It simply copies the layout and memory handle of the other view.

Template Parameters
TValue type of the other view.
RRank of the other view.
LPLayout policy of the other view.
AAlgebra of the other view.
APAccessor policy of the other view.
OPOwning policy of the other view.
Parameters
vOther view.

Definition at line 366 of file basic_array_view.hpp.

◆ shape() [1/2]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
auto const & nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >::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 476 of file basic_array_view.hpp.

◆ shape() [2/2]

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

Definition at line 520 of file basic_array_view.hpp.

◆ size()

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
long nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >::size ( ) const
inlinenodiscardnoexcept

Get the total size of the view/array.

Returns
Number of elements contained in the view/array.

Definition at line 488 of file basic_array_view.hpp.

◆ storage() [1/3]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
storage_t nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >::storage ( ) &&
inlinenodiscardnoexcept

Get the data storage of the view/array.

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

Definition at line 450 of file basic_array_view.hpp.

◆ storage() [2/3]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
storage_t & nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >::storage ( ) &
inlinenodiscardnoexcept

Get the data storage of the view/array.

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

Definition at line 444 of file basic_array_view.hpp.

◆ storage() [3/3]

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
storage_t const & nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >::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 438 of file basic_array_view.hpp.

◆ stride_order()

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
auto nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >::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 458 of file basic_array_view.hpp.

◆ strides()

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
auto const & nda::basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy >::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 482 of file basic_array_view.hpp.

Friends And Related Symbol Documentation

◆ deep_swap

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
void deep_swap ( basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy > a,
basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy > b )
friend

Swap two views by swapping their data.

This modifies the data the views point to.

Parameters
aFirst view.
bSecond view.

Definition at line 405 of file basic_array_view.hpp.

◆ swap

template<typename ValueType , int Rank, typename LayoutPolicy , char Algebra, typename AccessorPolicy , typename OwningPolicy >
void swap ( basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy > & a,
basic_array_view< ValueType, Rank, LayoutPolicy, Algebra, AccessorPolicy, OwningPolicy > & b )
friend

Swap two views by swapping their memory handles and layouts.

This does not modify the data the views point to.

Parameters
aFirst view.
bSecond view.

Definition at line 392 of file basic_array_view.hpp.


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