Template Numerical Library: TNL::Containers::NDArrayStorage< Array, Indexer, Permutation, Device > Class Template Reference

Template Numerical Library version\ main:c7077e4fd

Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Attributes | List of all members
TNL::Containers::NDArrayStorage< Array, Indexer, Permutation, Device > Class Template Reference
N-dimensional arrays

Base storage class for NDArray and StaticNDArray. More...

`#include <TNL/Containers/NDArray.h>`

Inheritance diagram for TNL::Containers::NDArrayStorage< Array, Indexer, Permutation, Device >:
[legend]
Collaboration diagram for TNL::Containers::NDArrayStorage< Array, Indexer, Permutation, Device >:
[legend]

## Public Types
using | ConstStorageArrayViewType = typename ViewType::ConstStorageArrayViewType
| Constant view type of the underlying one-dimensional array storing the elements.
using | ConstViewType = NDArrayView< std::add_const_t< ValueType >, DeviceType, IndexerType, PermutationType >
| Compatible constant NDArrayView type.
using | DeviceType = Device
| Type of the device used for running operations on the array.
using | IndexerType = Indexer
| Type of the N-dimensional indexer, NDArrayIndexer.
using | IndexType = typename Indexer::IndexType
| Type of indices used for addressing the array elements.
using | OverlapsType = typename Indexer::OverlapsType
| Sequence of integers representing the overlaps in each dimension of a distributed N-dimensional array.
using | PermutationType = Permutation
| Permutation that determines the internal memory layout of the N-dimensional array.
using | SizesHolderType = typename Indexer::SizesHolderType
| Type of the underlying object which represents the sizes of the N-dimensional array.
using | StorageArrayViewType = typename ViewType::StorageArrayViewType
| View type of the underlying one-dimensional array storing the elements.
using | StridesHolderType = typename Indexer::StridesHolderType
| Type of the underlying object which represents the strides of the N-dimensional array.
using | ValueType = typename Array::ValueType
| Type of the values stored in the array.
using | ViewType = NDArrayView< ValueType, DeviceType, IndexerType, PermutationType >
| Compatible NDArrayView type.

## Public Member Functions
| NDArrayStorage ()=default
| Constructs an empty storage with zero size.
| NDArrayStorage (const NDArrayStorage &)=default
| Copy constructor (makes a deep copy).
| NDArrayStorage (NDArrayStorage &&) noexcept=default
| Move constructor for initialization from rvalues.
template<typename Device2 = DeviceType, typename Func>
void | forAll (Func f, const typename Device2::LaunchConfiguration &launch_configuration=typename Device2::LaunchConfiguration{}) const
| Evaluates the function f in parallel for all elements of the array.
template<typename Device2 = DeviceType, typename SkipBegins, typename SkipEnds, typename Func>
void | forBoundary (const SkipBegins &skipBegins, const SkipEnds &skipEnds, Func f, const typename Device2::LaunchConfiguration &launch_configuration=typename Device2::LaunchConfiguration{}) const
| Evaluates the function f in parallel for all elements of the array outside the N-dimensional interval [skipBegins, skipEnds).
template<typename Device2 = DeviceType, typename Func>
void | forBoundary (Func f, const typename Device2::LaunchConfiguration &launch_configuration=typename Device2::LaunchConfiguration{}) const
| Evaluates the function f in parallel for all boundary elements of the array.
template<typename Device2 = DeviceType, typename Begins, typename Ends, typename Func>
void | forInterior (const Begins &begins, const Ends &ends, Func f, const typename Device2::LaunchConfiguration &launch_configuration=typename Device2::LaunchConfiguration{}) const
| Evaluates the function f in parallel for all elements of the array inside the N-dimensional interval [begins, ends).
template<typename Device2 = DeviceType, typename Func>
void | forInterior (Func f, const typename Device2::LaunchConfiguration &launch_configuration=typename Device2::LaunchConfiguration{}) const
| Evaluates the function f in parallel for all internal elements of the array.
ConstStorageArrayViewType | getConstStorageArrayView () const
| Returns a non-modifiable view of the underlying storage array.
__cuda_callable__ ConstViewType | getConstView () const
| Returns a non-modifiable view of the array.
__cuda_callable__ ValueType * | getData ()
| Returns a raw pointer to the data.
__cuda_callable__ std::add_const_t< ValueType > * | getData () const
| Returns a const-qualified raw pointer to the data.
template<typename... IndexTypes>
ValueType | getElement (IndexTypes &&... indices) const
| A "safe" accessor for array elements.
__cuda_callable__ const IndexerType & | getIndexer () const
| Returns a const-qualified reference to the underlying indexer.
StorageArrayViewType | getStorageArrayView ()
| Returns a modifiable view of the underlying storage array.
template<std::size_t... Dimensions, typename... IndexTypes>
__cuda_callable__ auto | getSubarrayView (IndexTypes &&... indices)
| Returns a modifiable view of a subarray.
__cuda_callable__ ViewType | getView ()
| Returns a modifiable view of the array.
bool | operator!= (const NDArrayStorage &other) const
| Compares the array with another N-dimensional array.
template<typename... IndexTypes>
__cuda_callable__ ValueType & | operator() (IndexTypes &&... indices)
| Accesses an element of the array.
template<typename... IndexTypes>
__cuda_callable__ const ValueType & | operator() (IndexTypes &&... indices) const
| Accesses an element of the array.
NDArrayStorage & | operator= (const NDArrayStorage &other)=default
| Copy-assignment operator for deep-copying data from another array. Mismatched sizes cause reallocations.
template<typename OtherArray>
NDArrayStorage & | operator= (const OtherArray &other)
| Templated copy-assignment operator for deep-copying data from another array.
NDArrayStorage & | operator= (NDArrayStorage &&) noexcept(false)=default
| Move-assignment operator for acquiring data from rvalues.
bool | operator== (const NDArrayStorage &other) const
| Compares the array with another N-dimensional array.
__cuda_callable__ ValueType & | operator[] (IndexType index)
| Accesses an element in a one-dimensional array.
__cuda_callable__ const ValueType & | operator[] (IndexType index) const
| Accesses an element in a one-dimensional array.
void | reset ()
| Resets the array to the empty state.
void | setLike (const NDArrayStorage &other)
| Sets sizes of the array to the sizes of an existing array.
void | setSize (const SizesHolderType &sizes)
| Sets sizes of the array using an instance of SizesHolder.
template<typename... IndexTypes>
void | setSizes (IndexTypes &&... sizes)
| Sets sizes of the array using raw integers.
void | setValue (ValueType value)
| Sets all elements of the array to given value.

## Protected Attributes
Array | array
| Underlying one-dimensional array which stores the data.

## Detailed Description

template<typename Array, typename Indexer, typename Permutation, typename Device = typename Array::DeviceType>
class TNL::Containers::NDArrayStorage< Array, Indexer, Permutation, Device >

Base storage class for NDArray and StaticNDArray.

Template Parameters

  Type | of the underlying one-dimensional array for storing the elements.
  Type | of the N-dimensional indexer, NDArrayIndexer.
  Type | of the device used for running operations on the array.

Note that the class inherits from the Indexer, i.e. NDArrayIndexer.

See also the Users' Guide.

## Member Function Documentation

## ◆ forAll()

template<typename Array, typename Indexer, typename Permutation, typename Device = typename Array::DeviceType>
template<typename Device2 = DeviceType, typename Func>

void TNL::Containers::NDArrayStorage< Array, Indexer, Permutation, Device >::forAll | ( | Func | f,
|  | const typename Device2::LaunchConfiguration & | launch_configuration = typename Device2::LaunchConfiguration{} ) const
| inline

Evaluates the function f in parallel for all elements of the array.

The function f is called as f(indices...), where indices... are substituted by the actual indices of all array elements. For example, given a 3D array a with int as IndexType, the function can be defined and used as follows:

auto setter = [&a] ( int i, int j, int k )
{
a( i, j, k ) = 1;
};
a.forAll( setter );

## ◆ forBoundary() [1/2]

template<typename Array, typename Indexer, typename Permutation, typename Device = typename Array::DeviceType>
template<typename Device2 = DeviceType, typename SkipBegins, typename SkipEnds, typename Func>

void TNL::Containers::NDArrayStorage< Array, Indexer, Permutation, Device >::forBoundary | ( | const SkipBegins & | skipBegins,
|  | const SkipEnds & | skipEnds,
|  | Func | f,
|  | const typename Device2::LaunchConfiguration & | launch_configuration = typename Device2::LaunchConfiguration{} ) const
| inline

Evaluates the function f in parallel for all elements of the array outside the N-dimensional interval [skipBegins, skipEnds).

The function f is called as f(indices...), where indices... are substituted by the actual indices of all array elements.

## ◆ forBoundary() [2/2]

template<typename Array, typename Indexer, typename Permutation, typename Device = typename Array::DeviceType>
template<typename Device2 = DeviceType, typename Func>

void TNL::Containers::NDArrayStorage< Array, Indexer, Permutation, Device >::forBoundary | ( | Func | f,
|  | const typename Device2::LaunchConfiguration & | launch_configuration = typename Device2::LaunchConfiguration{} ) const
| inline

Evaluates the function f in parallel for all boundary elements of the array.

The function f is called as f(indices...), where indices... are substituted by the actual indices of all array elements. For example, given a 3D array a with int as IndexType, the function can be defined and used as follows:

auto setter = [&a] ( int i, int j, int k )
{
a( i, j, k ) = 1;
};
a.forAll( setter );

## ◆ forInterior() [1/2]

template<typename Array, typename Indexer, typename Permutation, typename Device = typename Array::DeviceType>
template<typename Device2 = DeviceType, typename Begins, typename Ends, typename Func>

void TNL::Containers::NDArrayStorage< Array, Indexer, Permutation, Device >::forInterior | ( | const Begins & | begins,
|  | const Ends & | ends,
|  | Func | f,
|  | const typename Device2::LaunchConfiguration & | launch_configuration = typename Device2::LaunchConfiguration{} ) const
| inline

Evaluates the function f in parallel for all elements of the array inside the N-dimensional interval [begins, ends).

The function f is called as f(indices...), where indices... are substituted by the actual indices of all array elements.

## ◆ forInterior() [2/2]

template<typename Array, typename Indexer, typename Permutation, typename Device = typename Array::DeviceType>
template<typename Device2 = DeviceType, typename Func>

void TNL::Containers::NDArrayStorage< Array, Indexer, Permutation, Device >::forInterior | ( | Func | f,
|  | const typename Device2::LaunchConfiguration & | launch_configuration = typename Device2::LaunchConfiguration{} ) const
| inline

Evaluates the function f in parallel for all internal elements of the array.

The function f is called as f(indices...), where indices... are substituted by the actual indices of all array elements. For example, given a 3D array a with int as IndexType, the function can be defined and used as follows:

auto setter = [&a] ( int i, int j, int k )
{
a( i, j, k ) = 1;
};
a.forAll( setter );

## ◆ getData() [1/2]

template<typename Array, typename Indexer, typename Permutation, typename Device = typename Array::DeviceType>

__cuda_callable__ ValueType * TNL::Containers::NDArrayStorage< Array, Indexer, Permutation, Device >::getData | ( |  | ) |
| inlinenodiscard

Returns a raw pointer to the data.

This method can be called from device kernels.

## ◆ getData() [2/2]

template<typename Array, typename Indexer, typename Permutation, typename Device = typename Array::DeviceType>

__cuda_callable__ std::add_const_t< ValueType > * TNL::Containers::NDArrayStorage< Array, Indexer, Permutation, Device >::getData | ( |  | ) | const
| inlinenodiscard

Returns a const-qualified raw pointer to the data.

This method can be called from device kernels.

## ◆ getElement()

template<typename Array, typename Indexer, typename Permutation, typename Device = typename Array::DeviceType>
template<typename... IndexTypes>

ValueType TNL::Containers::NDArrayStorage< Array, Indexer, Permutation, Device >::getElement | ( | IndexTypes &&... | indices | ) | const
| inlinenodiscard

A "safe" accessor for array elements.

It can be called only from the host code and it will do a slow copy from the device.

## ◆ getSubarrayView()

template<typename Array, typename Indexer, typename Permutation, typename Device = typename Array::DeviceType>
template<std::size_t... Dimensions, typename... IndexTypes>

__cuda_callable__ auto TNL::Containers::NDArrayStorage< Array, Indexer, Permutation, Device >::getSubarrayView | ( | IndexTypes &&... | indices | ) |
| inlinenodiscard

Returns a modifiable view of a subarray.

Template Parameters

  Dimensions | Sequence of integers representing the dimensions of the array which selects the subset of dimensions to appear in the subarray.

Parameters

  indices | Indices of the origin of the subarray in the whole array. The number of indices supplied must be equal to N, i.e. getDimension().

Returns
  NDArrayView instantiated for ValueType, DeviceType and an NDArrayIndexer matching the specified dimensions and subarray sizes.

## ◆ operator()() [1/2]

template<typename Array, typename Indexer, typename Permutation, typename Device = typename Array::DeviceType>
template<typename... IndexTypes>

__cuda_callable__ ValueType & TNL::Containers::NDArrayStorage< Array, Indexer, Permutation, Device >::operator() | ( | IndexTypes &&... | indices | ) |
| inlinenodiscard

Accesses an element of the array.

Parameters

  indices | Indices of the element in the N-dimensional array. The number of indices supplied must be equal to N, i.e. getDimension().

Returns
  Reference to the array element.

## ◆ operator()() [2/2]

template<typename Array, typename Indexer, typename Permutation, typename Device = typename Array::DeviceType>
template<typename... IndexTypes>

__cuda_callable__ const ValueType & TNL::Containers::NDArrayStorage< Array, Indexer, Permutation, Device >::operator() | ( | IndexTypes &&... | indices | ) | const
| inlinenodiscard

Accesses an element of the array.

Parameters

  indices | Indices of the element in the N-dimensional array. The number of indices supplied must be equal to N, i.e. getDimension().

Returns
  Constant reference to the array element.

## ◆ operator[]() [1/2]

template<typename Array, typename Indexer, typename Permutation, typename Device = typename Array::DeviceType>

__cuda_callable__ ValueType & TNL::Containers::NDArrayStorage< Array, Indexer, Permutation, Device >::operator[] | ( | IndexType | index | ) |
| inlinenodiscard

Accesses an element in a one-dimensional array.

Warning
  This function can be used only when the dimension of the array is equal to 1.

Parameters

  index | Index of the element in the one-dimensional array.

Returns
  Reference to the array element.

## ◆ operator[]() [2/2]

template<typename Array, typename Indexer, typename Permutation, typename Device = typename Array::DeviceType>

__cuda_callable__ const ValueType & TNL::Containers::NDArrayStorage< Array, Indexer, Permutation, Device >::operator[] | ( | IndexType | index | ) | const
| inlinenodiscard

Accesses an element in a one-dimensional array.

Warning
  This function can be used only when the dimension of the array is equal to 1.

Parameters

  index | Index of the element in the one-dimensional array.

Returns
  Constant reference to the array element.

## ◆ reset()

template<typename Array, typename Indexer, typename Permutation, typename Device = typename Array::DeviceType>

void TNL::Containers::NDArrayStorage< Array, Indexer, Permutation, Device >::reset | ( |  | ) |
| inline

Resets the array to the empty state.

The current data will be deallocated, thus all pointers and views to the array elements will become invalid.

## ◆ setLike()

template<typename Array, typename Indexer, typename Permutation, typename Device = typename Array::DeviceType>

void TNL::Containers::NDArrayStorage< Array, Indexer, Permutation, Device >::setLike | ( | const NDArrayStorage< Array, Indexer, Permutation, Device > & | other | ) |
| inline

Sets sizes of the array to the sizes of an existing array.

If the array size changes, the current data will be deallocated, thus all pointers and views to the array elements will become invalid.

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

- src/TNL/Containers/NDArray.h