Template Numerical Library version\ main:94209208
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Attributes | List of all members
TNL::Containers::ArrayView< Value, Device, Index > Class Template Reference

ArrayView is a simple data structure which provides a non-owning encapsulation of array data. That is, ArrayView is like Array without memory management. More...

#include <TNL/Containers/ArrayView.h>

Inheritance diagram for TNL::Containers::ArrayView< Value, Device, Index >:
Inheritance graph
[legend]

Public Types

using ConstViewType = ArrayView< std::add_const_t< Value >, Device, Index >
 Compatible constant ArrayView type.
 
using DeviceType = Device
 Device used to run operations on the array.
 
using IndexType = Index
 Type being used for the array elements indexing.
 
template<typename _Value , typename _Device = Device, typename _Index = Index>
using Self = ArrayView< _Value, _Device, _Index >
 A template which allows to quickly obtain an ArrayView type with changed template parameters.
 
using ValueType = Value
 Type of elements stored in this array.
 
using ViewType = ArrayView< Value, Device, Index >
 Compatible ArrayView type.
 

Public Member Functions

__cuda_callable__ ArrayView ()=default
 Constructs an empty array view.
 
__cuda_callable__ ArrayView (ArrayView &&view) noexcept=default
 Move constructor for initialization from rvalues.
 
__cuda_callable__ ArrayView (const ArrayView &view)=default
 Shallow copy constructor.
 
template<typename Value_ >
__cuda_callable__ ArrayView (const ArrayView< Value_, Device, Index > &view)
 "Templated" shallow copy constructor.
 
__cuda_callable__ ArrayView (ValueType *data, IndexType size)
 Constructs an array view by binding to the given data pointer and size.
 
__cuda_callable__ void bind (ArrayView view)
 Method for rebinding (reinitialization) using another array view.
 
__cuda_callable__ void bind (ValueType *data, IndexType size)
 Method for rebinding (reinitialization) using a raw pointer and size.
 
__cuda_callable__ bool empty () const
 Returns true if the current array view size is zero.
 
template<typename Function >
void forAllElements (Function &&f)
 Process the lambda function f for each array element.
 
template<typename Function >
void forAllElements (Function &&f) const
 Process the lambda function f for each array element for constant instances.
 
template<typename Function >
void forElements (IndexType begin, IndexType end, Function &&f)
 Process the lambda function f for each array element in interval [ begin, end).
 
template<typename Function >
void forElements (IndexType begin, IndexType end, Function &&f) const
 Process the lambda function f for each array element in interval [ begin, end) for constant instances of the array.
 
__cuda_callable__ ValueTypegetArrayData ()
 Returns a raw pointer to the data.
 
__cuda_callable__ const ValueTypegetArrayData () const
 Returns a const-qualified raw pointer to the data.
 
__cuda_callable__ ConstViewType getConstView (IndexType begin=0, IndexType end=0) const
 Returns a non-modifiable view of the array view.
 
__cuda_callable__ ValueTypegetData ()
 Returns a raw pointer to the data.
 
__cuda_callable__ const ValueTypegetData () const
 Returns a const-qualified raw pointer to the data.
 
__cuda_callable__ ValueType getElement (IndexType i) const
 Returns the value of the i-th element.
 
__cuda_callable__ IndexType getSize () const
 Returns the current size of the array view.
 
__cuda_callable__ ViewType getView (IndexType begin=0, IndexType end=0)
 Returns a modifiable view of the array view.
 
void load (const std::string &fileName)
 Method for loading the data from a binary file fileName.
 
template<typename ArrayT >
bool operator!= (const ArrayT &array) const
 Compares the array view with another array-like container.
 
__cuda_callable__ Valueoperator() (IndexType i)
 Accesses the i-th element of the array.
 
__cuda_callable__ const Valueoperator() (IndexType i) const
 Accesses the i-th element of the array.
 
ArrayViewoperator= (const ArrayView &view)
 Deep copy assignment operator for copying data from another array view.
 
template<typename T , typename... , typename = std::enable_if_t< std::is_convertible_v< T, ValueType > || IsArrayType< T >::value >>
ArrayViewoperator= (const T &data)
 Assigns either array-like container or a single value.
 
template<typename T , typename... , typename >
ArrayView< Value, Device, Index > & operator= (const T &data)
 
template<typename ArrayT >
bool operator== (const ArrayT &array) const
 Compares the array view with another array-like container.
 
__cuda_callable__ Valueoperator[] (IndexType i)
 Accesses the i-th element of the array view.
 
__cuda_callable__ const Valueoperator[] (IndexType i) const
 Accesses the i-th element of the array view.
 
__cuda_callable__ void reset ()
 
void save (const std::string &fileName) const
 Method for saving the data to a binary file fileName.
 
__cuda_callable__ void setElement (IndexType i, ValueType value)
 Sets the value of the i-th element to v.
 
void setValue (ValueType value, IndexType begin=0, IndexType end=0)
 Sets elements of the array view to given value.
 
__cuda_callable__ void swap (ArrayView &view)
 Swaps this array view with another.
 

Protected Attributes

ValueTypedata = nullptr
 Pointer to the data.
 
IndexType size = 0
 Array view size.
 

Detailed Description

template<typename Value, typename Device = Devices::Host, typename Index = int>
class TNL::Containers::ArrayView< Value, Device, Index >

ArrayView is a simple data structure which provides a non-owning encapsulation of array data. That is, ArrayView is like Array without memory management.

The meaning of the template parameters is the same as in Array.

Template Parameters
ValueThe type of array elements.
DeviceThe device where the array is allocated. This ensures the compile-time checks of correct pointers manipulation. It can be any class defined in the TNL::Devices namespace.
IndexThe indexing type.

ArrayView provides access to array elements and general array operations same as Array, but it does not manage memory. The construction of an ArrayView does not make a memory allocation, but it can be bound to an existing portion of memory specified by a raw pointer, another ArrayView, or an Array. Similarly, ArrayView is not resizable, so there is no setSize method. Note that ArrayView does not own its data, so it does not deallocate it in the destructor.

Another important difference between ArrayView and Array is in the copy semantics. While the copy-constructor of Array makes a deep copy of the data, ArrayView makes only a shallow copy in the copy-constructor, i.e. it changes only its pointer and size. As a result, array views can be efficiently passed by value (even to device kernels) or captured by value in lambda functions (even in device lambda functions). Note that operator= in both ArrayView and Array still makes a deep copy of the data.

See also Array, Vector, VectorView.

Example
#include <iostream>
#include <TNL/Containers/Array.h>
#include <TNL/Containers/ArrayView.h>
using namespace TNL;
/***
* The following works for any device (CPU, GPU ...).
*/
template< typename Device >
void
arrayViewExample()
{
const int size = 10;
using IndexType = typename ArrayType::IndexType;
ArrayType a1( size ), a2( size );
ViewType a1_view = a1.getView();
ViewType a2_view = a2.getView();
/***
* You may initiate the array view using setElement
*/
for( int i = 0; i < size; i++ )
a1_view.setElement( i, i );
/***
* You may also assign value to all array view elements ...
*/
a2_view = 0;
/***
* More efficient way of array view elements manipulation is with the lambda functions
*/
ArrayType a3( size );
ViewType a3_view = a3.getView();
auto f1 = [] __cuda_callable__( IndexType i, int& value )
{
value = 2 * i;
};
a3_view.forAllElements( f1 );
for( int i = 0; i < size; i++ )
if( a3_view.getElement( i ) != 2 * i )
std::cerr << "Something is wrong!!!" << std::endl;
/***
* You may swap array view data with the swap method.
*/
a1_view.swap( a3_view );
/***
* You may save it to file and load again
*/
File( "a1_view.tnl", std::ios_base::out ) << a1_view;
File( "a1_view.tnl", std::ios_base::in ) >> a2_view;
std::remove( "a1_view.tnl" );
if( a2_view != a1_view )
std::cerr << "Something is wrong!!!" << std::endl;
std::cout << "a2_view = " << a2_view << std::endl;
}
int
main()
{
std::cout << "The first test runs on CPU ..." << std::endl;
arrayViewExample< Devices::Host >();
#ifdef __CUDACC__
std::cout << "The second test runs on GPU ..." << std::endl;
arrayViewExample< Devices::Cuda >();
#endif
}
#define __cuda_callable__
Definition Macros.h:49
ArrayView is a simple data structure which provides a non-owning encapsulation of array data....
Definition ArrayView.h:55
__cuda_callable__ void swap(ArrayView &view)
Swaps this array view with another.
Definition ArrayView.hpp:111
void forAllElements(Function &&f)
Process the lambda function f for each array element.
Definition ArrayView.hpp:312
__cuda_callable__ void setElement(IndexType i, ValueType value)
Sets the value of the i-th element to v.
Definition ArrayView.hpp:177
__cuda_callable__ ViewType getView(IndexType begin=0, IndexType end=0)
Returns a modifiable view of the array view.
Definition ArrayView.hpp:58
__cuda_callable__ ValueType getElement(IndexType i) const
Returns the value of the i-th element.
Definition ArrayView.hpp:187
Index IndexType
Type being used for the array elements indexing.
Definition ArrayView.h:72
Array is responsible for memory management, access to array elements, and general array operations.
Definition Array.h:64
This class serves for binary IO. It allows to do IO even for data allocated on GPU together with on-t...
Definition File.h:25
T endl(T... args)
The main TNL namespace.
Definition AtomicOperations.h:9
T remove(T... args)
Output
The first test runs on CPU ...
a2_view = [ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18 ]
The second test runs on GPU ...
a2_view = [ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18 ]

Member Typedef Documentation

◆ DeviceType

template<typename Value , typename Device = Devices::Host, typename Index = int>
using TNL::Containers::ArrayView< Value, Device, Index >::DeviceType = Device

Device used to run operations on the array.

See TNL::Devices for the available options.

Constructor & Destructor Documentation

◆ ArrayView() [1/5]

template<typename Value , typename Device = Devices::Host, typename Index = int>
__cuda_callable__ TNL::Containers::ArrayView< Value, Device, Index >::ArrayView ( )
default

Constructs an empty array view.

This method can be called from device kernels.

◆ ArrayView() [2/5]

template<typename Value , typename Device , typename Index >
__cuda_callable__ TNL::Containers::ArrayView< Value, Device, Index >::ArrayView ( ValueType * data,
IndexType size )

Constructs an array view by binding to the given data pointer and size.

This method can be called from device kernels.

Parameters
dataThe data pointer to be bound.
sizeThe number of elements in the array view.

◆ ArrayView() [3/5]

template<typename Value , typename Device = Devices::Host, typename Index = int>
__cuda_callable__ TNL::Containers::ArrayView< Value, Device, Index >::ArrayView ( const ArrayView< Value, Device, Index > & view)
default

Shallow copy constructor.

This method can be called from device kernels.

Parameters
viewThe array view to be copied.

◆ ArrayView() [4/5]

template<typename Value , typename Device = Devices::Host, typename Index = int>
template<typename Value_ >
__cuda_callable__ TNL::Containers::ArrayView< Value, Device, Index >::ArrayView ( const ArrayView< Value_, Device, Index > & view)
inline

"Templated" shallow copy constructor.

This method can be called from device kernels.

Template Parameters
Value_The template parameter can be any cv-qualified variant of ValueType.
Parameters
viewThe array view to be copied.

◆ ArrayView() [5/5]

template<typename Value , typename Device = Devices::Host, typename Index = int>
__cuda_callable__ TNL::Containers::ArrayView< Value, Device, Index >::ArrayView ( ArrayView< Value, Device, Index > && view)
defaultnoexcept

Move constructor for initialization from rvalues.

This method can be called from device kernels.

Parameters
viewThe array view to be moved.

Member Function Documentation

◆ bind() [1/2]

template<typename Value , typename Device , typename Index >
__cuda_callable__ void TNL::Containers::ArrayView< Value, Device, Index >::bind ( ArrayView< Value, Device, Index > view)

Method for rebinding (reinitialization) using another array view.

Note that you can also bind directly to an Array instance and other objects whose type is implicitly convertible to ArrayView.

This method can be called from device kernels.

Parameters
viewThe array view to be bound.

◆ bind() [2/2]

template<typename Value , typename Device , typename Index >
__cuda_callable__ void TNL::Containers::ArrayView< Value, Device, Index >::bind ( ValueType * data,
IndexType size )

Method for rebinding (reinitialization) using a raw pointer and size.

This method can be called from device kernels.

Parameters
dataThe data pointer to be bound to the array view.
sizeThe number of elements in the array view.

◆ empty()

template<typename Value , typename Device , typename Index >
__cuda_callable__ bool TNL::Containers::ArrayView< Value, Device, Index >::empty ( ) const

Returns true if the current array view size is zero.

This method can be called from device kernels.

◆ forAllElements() [1/2]

template<typename Value , typename Device , typename Index >
template<typename Function >
void TNL::Containers::ArrayView< Value, Device, Index >::forAllElements ( Function && f)

Process the lambda function f for each array element.

The lambda function is supposed to be declared as

Value ValueType
Type of elements stored in this array.
Definition ArrayView.h:60
Subrange< Index > splitRange(Index rangeBegin, Index rangeEnd, int rank, int num_subintervals)
A helper function which splits a one-dimensional range.
Definition BlockPartitioning.h:27

where

  • elementIdx is an index of the array element being currently processed
  • elementValue is a value of the array element being currently processed

This is performed at the same place where the array is allocated, i.e. it is efficient even on GPU.

Parameters
fThe lambda function to be processed.
Example
#include <iostream>
#include <TNL/Containers/Array.h>
#include <TNL/Containers/ArrayView.h>
using namespace TNL;
template< typename Device >
void
forElementsExample()
{
/****
* Create new arrays
*/
const int size = 10;
Containers::Array< float, Device > a( size ), b( size );
b = 0;
/****
* Create an ArrayView and use it for initiation of elements of array `a`
*/
auto a_view = a.getView();
a_view.forAllElements(
[] __cuda_callable__( int i, float& value )
{
value = i;
} );
/****
* Initiate elements of array `b` with indexes 0-4 using `a_view`
*/
b.getView().forElements( 0,
5,
[ = ] __cuda_callable__( int i, float& value )
{
value = a_view[ i ] + 4.0;
} );
/****
* Print the results
*/
std::cout << " a = " << a << std::endl;
std::cout << " b = " << b << std::endl;
}
int
main( int argc, char* argv[] )
{
std::cout << "Running example on the host system: " << std::endl;
forElementsExample< Devices::Host >();
#ifdef __CUDACC__
std::cout << "Running example on the CUDA device: " << std::endl;
forElementsExample< Devices::Cuda >();
#endif
}
Output
Running example on the host system:
a = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
b = [ 4, 5, 6, 7, 8, 0, 0, 0, 0, 0 ]
Running example on the CUDA device:
a = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
b = [ 4, 5, 6, 7, 8, 0, 0, 0, 0, 0 ]

◆ forAllElements() [2/2]

template<typename Value , typename Device , typename Index >
template<typename Function >
void TNL::Containers::ArrayView< Value, Device, Index >::forAllElements ( Function && f) const

Process the lambda function f for each array element for constant instances.

The lambda function is supposed to be declared as

where

  • elementIdx is an index of the array element being currently processed
  • elementValue is a value of the array element being currently processed

This is performed at the same place where the array is allocated, i.e. it is efficient even on GPU.

Parameters
fThe lambda function to be processed.
Example
#include <iostream>
#include <TNL/Containers/Array.h>
#include <TNL/Containers/ArrayView.h>
using namespace TNL;
template< typename Device >
void
forElementsExample()
{
/****
* Create new arrays
*/
const int size = 10;
Containers::Array< float, Device > a( size ), b( size );
b = 0;
/****
* Create an ArrayView and use it for initiation of elements of array `a`
*/
auto a_view = a.getView();
a_view.forAllElements(
[] __cuda_callable__( int i, float& value )
{
value = i;
} );
/****
* Initiate elements of array `b` with indexes 0-4 using `a_view`
*/
b.getView().forElements( 0,
5,
[ = ] __cuda_callable__( int i, float& value )
{
value = a_view[ i ] + 4.0;
} );
/****
* Print the results
*/
std::cout << " a = " << a << std::endl;
std::cout << " b = " << b << std::endl;
}
int
main( int argc, char* argv[] )
{
std::cout << "Running example on the host system: " << std::endl;
forElementsExample< Devices::Host >();
#ifdef __CUDACC__
std::cout << "Running example on the CUDA device: " << std::endl;
forElementsExample< Devices::Cuda >();
#endif
}
Output
Running example on the host system:
a = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
b = [ 4, 5, 6, 7, 8, 0, 0, 0, 0, 0 ]
Running example on the CUDA device:
a = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
b = [ 4, 5, 6, 7, 8, 0, 0, 0, 0, 0 ]

◆ forElements() [1/2]

template<typename Value , typename Device , typename Index >
template<typename Function >
void TNL::Containers::ArrayView< Value, Device, Index >::forElements ( IndexType begin,
IndexType end,
Function && f )

Process the lambda function f for each array element in interval [ begin, end).

The lambda function is supposed to be declared as

where

  • elementIdx is an index of the array element being currently processed
  • elementValue is a value of the array element being currently processed

This is performed at the same place where the array is allocated, i.e. it is efficient even on GPU.

Parameters
beginThe beginning of the array elements interval.
endThe end of the array elements interval.
fThe lambda function to be processed.
Example
#include <iostream>
#include <TNL/Containers/Array.h>
#include <TNL/Containers/ArrayView.h>
using namespace TNL;
template< typename Device >
void
forElementsExample()
{
/****
* Create new arrays
*/
const int size = 10;
Containers::Array< float, Device > a( size ), b( size );
b = 0;
/****
* Create an ArrayView and use it for initiation of elements of array `a`
*/
auto a_view = a.getView();
a_view.forAllElements(
[] __cuda_callable__( int i, float& value )
{
value = i;
} );
/****
* Initiate elements of array `b` with indexes 0-4 using `a_view`
*/
b.getView().forElements( 0,
5,
[ = ] __cuda_callable__( int i, float& value )
{
value = a_view[ i ] + 4.0;
} );
/****
* Print the results
*/
std::cout << " a = " << a << std::endl;
std::cout << " b = " << b << std::endl;
}
int
main( int argc, char* argv[] )
{
std::cout << "Running example on the host system: " << std::endl;
forElementsExample< Devices::Host >();
#ifdef __CUDACC__
std::cout << "Running example on the CUDA device: " << std::endl;
forElementsExample< Devices::Cuda >();
#endif
}
Output
Running example on the host system:
a = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
b = [ 4, 5, 6, 7, 8, 0, 0, 0, 0, 0 ]
Running example on the CUDA device:
a = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
b = [ 4, 5, 6, 7, 8, 0, 0, 0, 0, 0 ]

◆ forElements() [2/2]

template<typename Value , typename Device , typename Index >
template<typename Function >
void TNL::Containers::ArrayView< Value, Device, Index >::forElements ( IndexType begin,
IndexType end,
Function && f ) const

Process the lambda function f for each array element in interval [ begin, end) for constant instances of the array.

The lambda function is supposed to be declared as

where

  • elementIdx is an index of the array element being currently processed
  • elementValue is a value of the array element being currently processed

This is performed at the same place where the array is allocated, i.e. it is efficient even on GPU.

Parameters
beginThe beginning of the array elements interval.
endThe end of the array elements interval.
fThe lambda function to be processed.
Example
#include <iostream>
#include <TNL/Containers/Array.h>
#include <TNL/Containers/ArrayView.h>
using namespace TNL;
template< typename Device >
void
forElementsExample()
{
/****
* Create new arrays
*/
const int size = 10;
Containers::Array< float, Device > a( size ), b( size );
b = 0;
/****
* Create an ArrayView and use it for initiation of elements of array `a`
*/
auto a_view = a.getView();
a_view.forAllElements(
[] __cuda_callable__( int i, float& value )
{
value = i;
} );
/****
* Initiate elements of array `b` with indexes 0-4 using `a_view`
*/
b.getView().forElements( 0,
5,
[ = ] __cuda_callable__( int i, float& value )
{
value = a_view[ i ] + 4.0;
} );
/****
* Print the results
*/
std::cout << " a = " << a << std::endl;
std::cout << " b = " << b << std::endl;
}
int
main( int argc, char* argv[] )
{
std::cout << "Running example on the host system: " << std::endl;
forElementsExample< Devices::Host >();
#ifdef __CUDACC__
std::cout << "Running example on the CUDA device: " << std::endl;
forElementsExample< Devices::Cuda >();
#endif
}
Output
Running example on the host system:
a = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
b = [ 4, 5, 6, 7, 8, 0, 0, 0, 0, 0 ]
Running example on the CUDA device:
a = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
b = [ 4, 5, 6, 7, 8, 0, 0, 0, 0, 0 ]

◆ getArrayData() [1/2]

template<typename Value , typename Device , typename Index >
__cuda_callable__ Value * TNL::Containers::ArrayView< Value, Device, Index >::getArrayData ( )

Returns a raw pointer to the data.

Use this method in algorithms where you want to emphasize that C-style array pointer is required.

This method can be called from device kernels.

◆ getArrayData() [2/2]

template<typename Value , typename Device , typename Index >
__cuda_callable__ const Value * TNL::Containers::ArrayView< Value, Device, Index >::getArrayData ( ) const

Returns a const-qualified raw pointer to the data.

Use this method in algorithms where you want to emphasize that C-style array pointer is required.

This method can be called from device kernels.

◆ getConstView()

template<typename Value , typename Device , typename Index >
__cuda_callable__ ArrayView< Value, Device, Index >::ConstViewType TNL::Containers::ArrayView< Value, Device, Index >::getConstView ( IndexType begin = 0,
IndexType end = 0 ) const

Returns a non-modifiable view of the array view.

By default, a view for the whole array is returned. If begin or end is set to a non-zero value, a view only for the sub-interval [begin, end) is returned.

Parameters
beginThe beginning of the array view sub-interval. It is 0 by default.
endThe end of the array view sub-interval. The default value is 0 which is, however, replaced with the array size.

◆ getData() [1/2]

template<typename Value , typename Device , typename Index >
__cuda_callable__ Value * TNL::Containers::ArrayView< Value, Device, Index >::getData ( )

Returns a raw pointer to the data.

This method can be called from device kernels.

◆ getData() [2/2]

template<typename Value , typename Device , typename Index >
__cuda_callable__ const Value * TNL::Containers::ArrayView< Value, Device, Index >::getData ( ) const

Returns a const-qualified raw pointer to the data.

This method can be called from device kernels.

◆ getElement()

template<typename Value , typename Device , typename Index >
__cuda_callable__ Value TNL::Containers::ArrayView< Value, Device, Index >::getElement ( IndexType i) const

Returns the value of the i-th element.

This method can be called from both the host system and the device where the array is allocated.

Parameters
iThe index of the element to be returned.

◆ getSize()

template<typename Value , typename Device , typename Index >
__cuda_callable__ Index TNL::Containers::ArrayView< Value, Device, Index >::getSize ( ) const

Returns the current size of the array view.

This method can be called from device kernels.

◆ getView()

template<typename Value , typename Device , typename Index >
__cuda_callable__ ArrayView< Value, Device, Index >::ViewType TNL::Containers::ArrayView< Value, Device, Index >::getView ( IndexType begin = 0,
IndexType end = 0 )

Returns a modifiable view of the array view.

By default, a view for the whole array is returned. If begin or end is set to a non-zero value, a view only for the sub-interval [begin, end) is returned.

Parameters
beginThe beginning of the array view sub-interval. It is 0 by default.
endThe end of the array view sub-interval. The default value is 0 which is, however, replaced with the array size.

◆ load()

template<typename Value , typename Device , typename Index >
void TNL::Containers::ArrayView< Value, Device, Index >::load ( const std::string & fileName)

Method for loading the data from a binary file fileName.

Parameters
fileNameThe input file name.

◆ operator!=()

template<typename Value , typename Device , typename Index >
template<typename ArrayT >
bool TNL::Containers::ArrayView< Value, Device, Index >::operator!= ( const ArrayT & array) const

Compares the array view with another array-like container.

Template Parameters
ArrayTThe type of the parameter can be any array-like container, e.g. Array, ArrayView, Vector, VectorView, etc.
Parameters
arrayReference to the array-like container.
Returns
The negated result of operator==.

◆ operator()() [1/2]

template<typename Value , typename Device , typename Index >
__cuda_callable__ Value & TNL::Containers::ArrayView< Value, Device, Index >::operator() ( IndexType i)

Accesses the i-th element of the array.

Equivalent to operator[], with the same notes and caveats.

◆ operator()() [2/2]

template<typename Value , typename Device , typename Index >
__cuda_callable__ const Value & TNL::Containers::ArrayView< Value, Device, Index >::operator() ( IndexType i) const

Accesses the i-th element of the array.

Equivalent to operator[], with the same notes and caveats.

◆ operator=() [1/2]

template<typename Value , typename Device , typename Index >
ArrayView< Value, Device, Index > & TNL::Containers::ArrayView< Value, Device, Index >::operator= ( const ArrayView< Value, Device, Index > & view)

Deep copy assignment operator for copying data from another array view.

Parameters
viewReference to the source array view.
Returns
Reference to this array view.

◆ operator=() [2/2]

template<typename Value , typename Device = Devices::Host, typename Index = int>
template<typename T , typename... , typename = std::enable_if_t< std::is_convertible_v< T, ValueType > || IsArrayType< T >::value >>
ArrayView & TNL::Containers::ArrayView< Value, Device, Index >::operator= ( const T & data)

Assigns either array-like container or a single value.

If T is an array type, e.g. Array, ArrayView, StaticArray, Vector, VectorView, or StaticVector, the elements from data are copied into this array view. Otherwise, if it is a type convertible to ValueType, all array elements are set to the value data.

Template Parameters
TThe type of the source array or value.
Parameters
dataReference to the source array or value.
Returns
Reference to this array view.

◆ operator==()

template<typename Value , typename Device , typename Index >
template<typename ArrayT >
bool TNL::Containers::ArrayView< Value, Device, Index >::operator== ( const ArrayT & array) const

Compares the array view with another array-like container.

Template Parameters
ArrayTThe type of the parameter can be any array-like container, e.g. Array, ArrayView, Vector, VectorView, etc.
Parameters
arrayReference to the array-like container.
Returns
true if the array view is element-wise equal to the array-like container and false otherwise.

◆ operator[]() [1/2]

template<typename Value , typename Device , typename Index >
__cuda_callable__ Value & TNL::Containers::ArrayView< Value, Device, Index >::operator[] ( IndexType i)

Accesses the i-th element of the array view.

This method can be called only from the device which has direct access to the memory space where the data was allocated. For example, if the data was allocated in the host memory, it can be called only from host, and if the data was allocated in the device memory, it can be called only from device kernels. If NDEBUG is not defined, assertions inside this methods performs runtime checks for cross-device memory accesses which lead to segmentation fault. If you need to do just a pointer arithmetics use getData instead.

Parameters
iThe index of the element to be accessed.
Returns
Reference to the i-th element.

◆ operator[]() [2/2]

template<typename Value , typename Device , typename Index >
__cuda_callable__ const Value & TNL::Containers::ArrayView< Value, Device, Index >::operator[] ( IndexType i) const

Accesses the i-th element of the array view.

This method can be called only from the device which has direct access to the memory space where the data was allocated. For example, if the data was allocated in the host memory, it can be called only from host, and if the data was allocated in the device memory, it can be called only from device kernels. If NDEBUG is not defined, assertions inside this methods performs runtime checks for cross-device memory accesses which lead to segmentation fault. If you need to do just a pointer arithmetics use getData instead.

Parameters
iThe index of the element to be accessed.
Returns
Constant reference to the i-th element.

◆ save()

template<typename Value , typename Device , typename Index >
void TNL::Containers::ArrayView< Value, Device, Index >::save ( const std::string & fileName) const

Method for saving the data to a binary file fileName.

Parameters
fileNameThe output file name.

◆ setElement()

template<typename Value , typename Device , typename Index >
__cuda_callable__ void TNL::Containers::ArrayView< Value, Device, Index >::setElement ( IndexType i,
ValueType value )

Sets the value of the i-th element to v.

This method can be called from both the host system and the device where the array is allocated.

Parameters
iThe index of the element to be set.
valueThe new value of the element.

◆ setValue()

template<typename Value , typename Device , typename Index >
void TNL::Containers::ArrayView< Value, Device, Index >::setValue ( ValueType value,
IndexType begin = 0,
IndexType end = 0 )

Sets elements of the array view to given value.

By default, all array view elements are set to the given value. If begin or end is set to a non-zero value, only elements in the sub-interval [begin, end) are set.

Parameters
valueThe new value for the array view elements.
beginThe beginning of the array view sub-interval. It is 0 by default.
endThe end of the array view sub-interval. The default value is 0 which is, however, replaced with the array view size.

◆ swap()

template<typename Value , typename Device , typename Index >
__cuda_callable__ void TNL::Containers::ArrayView< Value, Device, Index >::swap ( ArrayView< Value, Device, Index > & view)

Swaps this array view with another.

Swapping is done in a shallow way, i.e. only pointers and sizes are swapped.

Parameters
viewThe array view to be swapped with this array view.

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