Template Numerical Library version main:1655e92
Public Types | Public Member Functions | List of all members
TNL::Containers::VectorView< Real, Device, Index > Class Template Reference

VectorView extends ArrayView with algebraic operations. More...

#include <TNL/Containers/VectorView.h>

Inheritance diagram for TNL::Containers::VectorView< Real, Device, Index >:
Inheritance graph
[legend]
Collaboration diagram for TNL::Containers::VectorView< Real, Device, Index >:
Collaboration graph
[legend]

Public Types

using ConstViewType = VectorView< std::add_const_t< Real >, Device, Index >
 Compatible constant VectorView type.
 
using DeviceType = Device
 Device used to run operations on the vector. More...
 
using IndexType = Index
 Type being used for the vector elements indexing.
 
using RealType = Real
 Type of elements stored in this vector.
 
template<typename _Real , typename _Device = Device, typename _Index = Index>
using Self = VectorView< _Real, _Device, _Index >
 A template which allows to quickly obtain a VectorView type with changed template parameters.
 
using ViewType = VectorView< Real, Device, Index >
 Compatible VectorView type.
 
- Public Types inherited from TNL::Containers::ArrayView< double, Devices::Host, int >
using ConstViewType = ArrayView< std::add_const_t< double >, Devices::Host, int >
 Compatible constant ArrayView type.
 
using DeviceType = Devices::Host
 Device used to run operations on the array. More...
 
using IndexType = int
 Type being used for the array elements indexing.
 
using Self = ArrayView< _Value, _Device, _Index >
 A template which allows to quickly obtain an ArrayView type with changed template parameters.
 
using ValueType = double
 Type of elements stored in this array.
 
using ViewType = ArrayView< double, Devices::Host, int >
 Compatible ArrayView type.
 

Public Member Functions

__cuda_callable__ VectorView ()=default
 Constructs an empty array view with zero size.
 
template<typename Real_ >
__cuda_callable__ VectorView (const ArrayView< Real_, Device, Index > &view)
 Constructor for the initialization by a base class object.
 
__cuda_callable__ ConstViewType getConstView (IndexType begin=0, IndexType end=0) const
 Returns a non-modifiable view of the vector view. More...
 
__cuda_callable__ ViewType getView (IndexType begin=0, IndexType end=0)
 Returns a modifiable view of the vector view. More...
 
template<typename VectorExpression >
VectorViewoperator%= (const VectorExpression &expression)
 Modulo assignment operator for vector view and a vector expression. More...
 
template<typename VectorExpression >
VectorView< Real, Device, Index > & operator%= (const VectorExpression &expression)
 
template<typename VectorExpression >
VectorViewoperator*= (const VectorExpression &expression)
 Multiplies elements of this vector view and a vector expression and stores the result in this vector view. More...
 
template<typename VectorExpression >
VectorView< Real, Device, Index > & operator*= (const VectorExpression &expression)
 
template<typename VectorExpression >
VectorViewoperator+= (const VectorExpression &expression)
 Adds elements of this vector view and a vector expression and stores the result in this vector view. More...
 
template<typename VectorExpression >
VectorView< Real, Device, Index > & operator+= (const VectorExpression &expression)
 
template<typename VectorExpression >
VectorViewoperator-= (const VectorExpression &expression)
 Subtracts elements of this vector view and a vector expression and stores the result in this vector view. More...
 
template<typename VectorExpression >
VectorView< Real, Device, Index > & operator-= (const VectorExpression &expression)
 
template<typename VectorExpression >
VectorViewoperator/= (const VectorExpression &expression)
 Divides elements of this vector view and a vector expression and stores the result in this vector view. More...
 
template<typename VectorExpression >
VectorView< Real, Device, Index > & operator/= (const VectorExpression &expression)
 
template<typename T , typename... , typename = std::enable_if_t< std::is_convertible< T, Real >::value || IsArrayType< T >::value >>
ArrayView< Real, Device, Index > & operator= (const T &data)
 Assigns a value or an array - same as ArrayView::operator=. More...
 
template<typename VectorExpression , typename... , typename = std::enable_if_t< Expressions::HasEnabledExpressionTemplates< VectorExpression >::value && ! IsArrayType< VectorExpression >::value >>
VectorViewoperator= (const VectorExpression &expression)
 Assigns a vector expression to this vector view. More...
 
template<typename VectorExpression , typename... , typename >
VectorView< Real, Device, Index > & operator= (const VectorExpression &expression)
 
- Public Member Functions inherited from TNL::Containers::ArrayView< double, Devices::Host, int >
__cuda_callable__ ArrayView ()=default
 Constructs an empty array view. More...
 
__cuda_callable__ ArrayView (ArrayView &&view) noexcept=default
 Move constructor for initialization from rvalues. More...
 
__cuda_callable__ ArrayView (const ArrayView &view)=default
 Shallow copy constructor. More...
 
__cuda_callable__ ArrayView (const ArrayView< Value_, Devices::Host, int > &view)
 "Templated" shallow copy constructor. More...
 
__cuda_callable__ ArrayView (ValueType *data, IndexType size)
 Constructs an array view by binding to the given data pointer and size. More...
 
__cuda_callable__ void bind (ArrayView view)
 Method for rebinding (reinitialization) using another array view. More...
 
__cuda_callable__ void bind (ValueType *data, IndexType size)
 Method for rebinding (reinitialization) using a raw pointer and size. More...
 
__cuda_callable__ bool empty () const
 Returns true if the current array view size is zero. More...
 
void forAllElements (Function &&f)
 Process the lambda function f for each array element. More...
 
void forAllElements (Function &&f) const
 Process the lambda function f for each array element for constant instances. More...
 
void forElements (IndexType begin, IndexType end, Function &&f)
 Process the lambda function f for each array element in interval [ begin, end). More...
 
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. More...
 
__cuda_callable__ ValueTypegetArrayData ()
 Returns a raw pointer to the data. More...
 
__cuda_callable__ const ValueTypegetArrayData () const
 Returns a const-qualified raw pointer to the data. More...
 
__cuda_callable__ ConstViewType getConstView (IndexType begin=0, IndexType end=0) const
 Returns a non-modifiable view of the array view. More...
 
__cuda_callable__ ValueTypegetData ()
 Returns a raw pointer to the data. More...
 
__cuda_callable__ const ValueTypegetData () const
 Returns a const-qualified raw pointer to the data. More...
 
__cuda_callable__ ValueType getElement (IndexType i) const
 Returns the value of the i-th element. More...
 
__cuda_callable__ IndexType getSize () const
 Returns the current size of the array view. More...
 
__cuda_callable__ ViewType getView (IndexType begin=0, IndexType end=0)
 Returns a modifiable view of the array view. More...
 
void load (const String &fileName)
 Method for loading the data from a binary file fileName. More...
 
bool operator!= (const ArrayT &array) const
 Compares the array view with another array-like container. More...
 
__cuda_callable__ double & operator() (IndexType i)
 Accesses the i-th element of the array. More...
 
__cuda_callable__ const double & operator() (IndexType i) const
 Accesses the i-th element of the array. More...
 
ArrayViewoperator= (const ArrayView &view)
 Deep copy assignment operator for copying data from another array view. More...
 
ArrayViewoperator= (const T &data)
 Assigns either array-like container or a single value. More...
 
ArrayView< double, Devices::Host, int > & operator= (const T &data)
 
bool operator== (const ArrayT &array) const
 Compares the array view with another array-like container. More...
 
__cuda_callable__ double & operator[] (IndexType i)
 Accesses the i-th element of the array view. More...
 
__cuda_callable__ const double & operator[] (IndexType i) const
 Accesses the i-th element of the array view. More...
 
__cuda_callable__ void reset ()
 
void save (const String &fileName) const
 Method for saving the data to a binary file fileName. More...
 
__cuda_callable__ void setElement (IndexType i, ValueType value)
 Sets the value of the i-th element to v. More...
 
void setValue (ValueType value, IndexType begin=0, IndexType end=0)
 Sets elements of the array view to given value. More...
 
__cuda_callable__ void swap (ArrayView &view)
 Swaps this array view with another. More...
 

Additional Inherited Members

- Protected Attributes inherited from TNL::Containers::ArrayView< double, Devices::Host, int >
ValueTypedata
 Pointer to the data.
 
IndexType size
 Array view size.
 

Detailed Description

template<typename Real = double, typename Device = Devices::Host, typename Index = int>
class TNL::Containers::VectorView< Real, Device, Index >

VectorView extends ArrayView with algebraic operations.

The template parameters have the same meaning as in ArrayView, with Real corresponding to ArrayView's Value parameter.

Template Parameters
RealAn arithmetic type for the vector values, e.g. float or double.
DeviceThe device to be used for the execution of vector operations.
IndexThe indexing type.

Member Typedef Documentation

◆ DeviceType

template<typename Real = double, typename Device = Devices::Host, typename Index = int>
using TNL::Containers::VectorView< Real, Device, Index >::DeviceType = Device

Device used to run operations on the vector.

See TNL::Devices for the available options.

Member Function Documentation

◆ getConstView()

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

Returns a non-modifiable view of the vector view.

By default, a view for the whole vector 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 vector view sub-interval. It is 0 by default.
endThe end of the vector view sub-interval. The default value is 0 which is, however, replaced with the array size.

◆ getView()

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

Returns a modifiable view of the vector view.

By default, a view for the whole vector 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 vector view sub-interval. It is 0 by default.
endThe end of the vector view sub-interval. The default value is 0 which is, however, replaced with the array size.

◆ operator%=()

template<typename Real = double, typename Device = Devices::Host, typename Index = int>
template<typename VectorExpression >
VectorView & TNL::Containers::VectorView< Real, Device, Index >::operator%= ( const VectorExpression &  expression)

Modulo assignment operator for vector view and a vector expression.

The division is evaluated element-wise. The vector expression must either evaluate to a scalar or a vector of the same size as this vector view.

Parameters
expressionReference to a vector expression.
Returns
Reference to this vector.

◆ operator*=()

template<typename Real = double, typename Device = Devices::Host, typename Index = int>
template<typename VectorExpression >
VectorView & TNL::Containers::VectorView< Real, Device, Index >::operator*= ( const VectorExpression &  expression)

Multiplies elements of this vector view and a vector expression and stores the result in this vector view.

The multiplication is evaluated element-wise. The vector expression must either evaluate to a scalar or a vector of the same size as this vector view.

Parameters
expressionReference to a vector expression.
Returns
Reference to this vector view.

◆ operator+=()

template<typename Real = double, typename Device = Devices::Host, typename Index = int>
template<typename VectorExpression >
VectorView & TNL::Containers::VectorView< Real, Device, Index >::operator+= ( const VectorExpression &  expression)

Adds elements of this vector view and a vector expression and stores the result in this vector view.

The addition is evaluated element-wise. The vector expression must either evaluate to a scalar or a vector of the same size as this vector view.

Parameters
expressionReference to a vector expression.
Returns
Reference to this vector view.

◆ operator-=()

template<typename Real = double, typename Device = Devices::Host, typename Index = int>
template<typename VectorExpression >
VectorView & TNL::Containers::VectorView< Real, Device, Index >::operator-= ( const VectorExpression &  expression)

Subtracts elements of this vector view and a vector expression and stores the result in this vector view.

The subtraction is evaluated element-wise. The vector expression must either evaluate to a scalar or a vector of the same size as this vector view.

Parameters
expressionReference to a vector expression.
Returns
Reference to this vector view.

◆ operator/=()

template<typename Real = double, typename Device = Devices::Host, typename Index = int>
template<typename VectorExpression >
VectorView & TNL::Containers::VectorView< Real, Device, Index >::operator/= ( const VectorExpression &  expression)

Divides elements of this vector view and a vector expression and stores the result in this vector view.

The division is evaluated element-wise. The vector expression must either evaluate to a scalar or a vector of the same size as this vector view.

Parameters
expressionReference to a vector expression.
Returns
Reference to this vector view.

◆ operator=() [1/2]

template<typename Real = double, typename Device = Devices::Host, typename Index = int>
template<typename T , typename... , typename = std::enable_if_t< std::is_convertible< T, Real >::value || IsArrayType< T >::value >>
ArrayView< Real, Device, Index > & TNL::Containers::VectorView< Real, Device, Index >::operator= ( const T &  data)
inline

Assigns a value or an array - same as ArrayView::operator=.

Returns
Reference to this vector view.

◆ operator=() [2/2]

template<typename Real = double, typename Device = Devices::Host, typename Index = int>
template<typename VectorExpression , typename... , typename = std::enable_if_t< Expressions::HasEnabledExpressionTemplates< VectorExpression >::value && ! IsArrayType< VectorExpression >::value >>
VectorView & TNL::Containers::VectorView< Real, Device, Index >::operator= ( const VectorExpression &  expression)

Assigns a vector expression to this vector view.

The assignment is evaluated element-wise. The vector expression must either evaluate to a scalar or a vector of the same size as this vector view.

Parameters
expressionThe vector expression to be evaluated and assigned to this vector view.
Returns
Reference to this vector view.

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