|
| Vector ()=default |
| Constructs an empty array with zero size.
|
|
| Vector (const Vector &)=default |
| Copy constructor (makes a deep copy).
|
|
| Vector (const Vector &vector, const AllocatorType &allocator) |
| Copy constructor with a specific allocator (makes a deep copy).
|
|
template<typename VectorExpression , typename... , typename = std::enable_if_t< Expressions::HasEnabledExpressionTemplates< VectorExpression >::value && ! IsArrayType< VectorExpression >::value >> |
| Vector (const VectorExpression &expression) |
| Constructor from expression template. More...
|
|
| Vector (Vector &&) noexcept=default |
| Default move constructor.
|
|
ConstViewType | getConstView (IndexType begin=0, IndexType end=0) const |
| Returns a non-modifiable view of the vector. More...
|
|
ViewType | getView (IndexType begin=0, IndexType end=0) |
| Returns a modifiable view of the vector. More...
|
|
| operator ConstViewType () const |
| Conversion operator to a non-modifiable view of the vector.
|
|
| operator ViewType () |
| Conversion operator to a modifiable view of the vector.
|
|
template<typename VectorExpression > |
Vector & | operator%= (const VectorExpression &expression) |
| Modulo assignment operator for vector and a vector expression. More...
|
|
template<typename VectorExpression > |
Vector< Real, Device, Index, Allocator > & | operator%= (const VectorExpression &expression) |
|
template<typename VectorExpression > |
Vector & | operator*= (const VectorExpression &expression) |
| Multiplies elements of this vector and a vector expression and stores the result in this vector. More...
|
|
template<typename VectorExpression > |
Vector< Real, Device, Index, Allocator > & | operator*= (const VectorExpression &expression) |
|
template<typename VectorExpression > |
Vector & | operator+= (const VectorExpression &expression) |
| Adds elements of this vector and a vector expression and stores the result in this vector. More...
|
|
template<typename VectorExpression > |
Vector< Real, Device, Index, Allocator > & | operator+= (const VectorExpression &expression) |
|
template<typename VectorExpression > |
Vector & | operator-= (const VectorExpression &expression) |
| Subtracts elements of this vector and a vector expression and stores the result in this vector. More...
|
|
template<typename VectorExpression > |
Vector< Real, Device, Index, Allocator > & | operator-= (const VectorExpression &expression) |
|
template<typename VectorExpression > |
Vector & | operator/= (const VectorExpression &expression) |
| Divides elements of this vector and a vector expression and stores the result in this vector. More...
|
|
template<typename VectorExpression > |
Vector< Real, Device, Index, Allocator > & | operator/= (const VectorExpression &expression) |
|
template<typename T , typename... , typename = std::enable_if_t< std::is_convertible< T, Real >::value || IsArrayType< T >::value >> |
Array< Real, Device, Index, Allocator > & | operator= (const T &data) |
| Assigns a value or an array - same as Array::operator=. More...
|
|
Vector & | operator= (const Vector &)=default |
| Copy-assignment operator for copying data from another vector.
|
|
template<typename VectorExpression , typename... , typename = std::enable_if_t< Expressions::HasEnabledExpressionTemplates< VectorExpression >::value && ! IsArrayType< VectorExpression >::value >> |
Vector & | operator= (const VectorExpression &expression) |
| Assigns a vector expression to this vector. More...
|
|
template<typename VectorExpression , typename... , typename > |
Vector< Real, Device, Index, Allocator > & | operator= (const VectorExpression &expression) |
|
Vector & | operator= (Vector &&) noexcept(false)=default |
| Move-assignment operator for acquiring data from rvalues.
|
|
| Array ()=default |
| Constructs an empty array with zero size.
|
|
| Array (Array &&array) noexcept |
| Move constructor for initialization from rvalues. More...
|
|
| Array (const AllocatorType &allocator) |
| Constructs an empty array and sets the provided allocator. More...
|
|
| Array (const Array &array) |
| Copy constructor (makes a deep copy). More...
|
|
| Array (const Array &array, const AllocatorType &allocator) |
| Copy constructor with a specific allocator (makes a deep copy). More...
|
|
| Array (const Array &array, IndexType begin, IndexType size=0, const AllocatorType &allocator=AllocatorType()) |
| Copy constructor (makes a deep copy). More...
|
|
| Array (const Array< Value_, Device_, Index_, Allocator_ > &a) |
| Copy constructor from array with different template parameters. More...
|
|
| Array (const std::initializer_list< InValue > &list, const AllocatorType &allocator=AllocatorType()) |
| Constructor which initializes the array by copying elements from std::initializer_list, e.g. {...} . More...
|
|
| Array (const std::list< InValue > &list, const AllocatorType &allocator=AllocatorType()) |
| Constructor which initializes the array by copying elements from std::list. More...
|
|
| Array (const std::vector< InValue > &vector, const AllocatorType &allocator=AllocatorType()) |
| Constructor which initializes the array by copying elements from std::vector. More...
|
|
| Array (IndexType size, const AllocatorType &allocator=AllocatorType()) |
| Constructs an array with given size. More...
|
|
| Array (IndexType size, ValueType value, const AllocatorType &allocator=AllocatorType()) |
| Constructs an array with given size and value. More...
|
|
| Array (ValueType *data, IndexType size, const AllocatorType &allocator=AllocatorType()) |
| Constructs an array with given size and copies data from given pointer. More...
|
|
virtual | ~Array () |
| Destructor.
|
|
__cuda_callable__ bool | empty () const |
| Returns true if the current array 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...
|
|
AllocatorType | getAllocator () const |
| Returns the allocator associated with the array.
|
|
__cuda_callable__ double * | getArrayData () |
| Returns a raw pointer to the data. More...
|
|
__cuda_callable__ const double * | getArrayData () const |
| Returns a const-qualified raw pointer to the data. More...
|
|
ConstViewType | getConstView (IndexType begin=0, IndexType end=0) const |
| Returns a non-modifiable view of the array. More...
|
|
__cuda_callable__ double * | getData () |
| Returns a raw pointer to the data. More...
|
|
__cuda_callable__ const double * | getData () 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...
|
|
virtual std::string | getSerializationTypeVirtual () const |
| Returns a string representation of the array type in C++ style, with a placeholder in place of Device and Allocator.
|
|
__cuda_callable__ IndexType | getSize () const |
| Returns the current array size. More...
|
|
ViewType | getView (IndexType begin=0, IndexType end=0) |
| Returns a modifiable view of the array. More...
|
|
void | load (const String &fileName) |
| Method for loading the array from a binary file fileName. More...
|
|
| operator ConstViewType () const |
| Conversion operator to a non-modifiable view of the array.
|
|
| operator ViewType () |
| Conversion operator to a modifiable view of the array.
|
|
bool | operator!= (const ArrayT &array) const |
| Compares the array 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...
|
|
Array & | operator= (Array &&array) noexcept(false) |
| Move-assignment operator for acquiring data from rvalues. More...
|
|
Array & | operator= (const Array &array) |
| Copy-assignment operator for copying data from another array. More...
|
|
Array & | operator= (const std::list< InValue > &list) |
| Copies elements from std::list to this array. More...
|
|
Array< double, Devices::Host, int, typename Allocators::Default< Devices::Host >::template Allocator< double > > & | operator= (const std::list< InValue > &list) |
|
Array & | operator= (const std::vector< InValue > &vector) |
| Copies elements from std::vector to this array. More...
|
|
Array< double, Devices::Host, int, typename Allocators::Default< Devices::Host >::template Allocator< double > > & | operator= (const std::vector< InValue > &vector) |
|
Array & | operator= (const T &data) |
| Assigns either array-like container or a single value. More...
|
|
Array< double, Devices::Host, int, typename Allocators::Default< Devices::Host >::template Allocator< double > > & | operator= (const T &data) |
|
bool | operator== (const ArrayT &array) const |
| Compares the array 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...
|
|
void | reset () |
| Resets the array to the empty state. More...
|
|
void | resize (IndexType size) |
| Method for resizing the array. More...
|
|
void | resize (IndexType size, ValueType value) |
| Method for resizing the array with an initial value. More...
|
|
void | save (const String &fileName) const |
| Method for saving the array 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 | setLike (const ArrayT &array) |
| Sets the same size as the size of an existing array. More...
|
|
void | setSize (IndexType size) |
| Method for setting the array size. More...
|
|
void | setValue (ValueType value, IndexType begin=0, IndexType end=0) |
| Sets elements of the array to given value. More...
|
|
void | swap (Array &array) |
| Swaps this array with another. More...
|
|
template<typename
Real = double, typename Device = Devices::Host, typename Index = int, typename Allocator = typename Allocators::Default< Device >::template Allocator< Real >>
class TNL::Containers::Vector< Real, Device, Index, Allocator >
Vector extends Array with algebraic operations.
The template parameters have the same meaning as in Array, with Real corresponding to Array's Value parameter.
- Template Parameters
-
Real | An arithmetic type for the vector values, e.g. float or double . |
Device | The device to be used for the execution of vector operations. |
Index | The indexing type. |
Allocator | The type of the allocator used for the allocation and deallocation of memory used by the array. By default, an appropriate allocator for the specified Device is selected with Allocators::Default. |
- Example
#include <iostream>
#include <TNL/Containers/Vector.h>
#include <TNL/Containers/Array.h>
#include <TNL/Devices/Host.h>
#include <TNL/Devices/Cuda.h>
template< typename Device >
void VectorExample()
{
Containers::Vector< int, Device > vector1( 5 );
vector1 = 0;
Containers::Vector< int, Device > vector2( 3 );
vector2 = 1;
vector2.swap( vector1 );
vector2.setElement( 2, 4 );
cout <<
"First vector:" << vector1.getData() <<
endl;
cout <<
"Second vector:" << vector2.getData() <<
endl;
vector2.reset();
cout <<
"Second vector after reset:" << vector2.getData() <<
endl;
Containers::Vector< int, Device > vect = { 1, 2, -3, 3 };
cout <<
"The smallest element is:" <<
min( vect ) <<
endl;
cout <<
"The absolute biggest element is:" <<
max(
abs( vect ) ) <<
endl;
cout <<
"Sum of all vector elements:" << sum( vect ) <<
endl;
vect *= 2.0;
cout <<
"Vector multiplied by 2:" << vect <<
endl;
}
int main()
{
VectorExample< Devices::Host >();
#ifdef HAVE_CUDA
VectorExample< Devices::Cuda >();
#endif
}
The main TNL namespace.
Definition: AtomicOperations.h:13
__cuda_callable__ T abs(const T &n)
This function returns absolute value of given number n.
Definition: Math.h:87
constexpr ResultType min(const T1 &a, const T2 &b)
This function returns minimum of two numbers.
Definition: Math.h:30
constexpr ResultType max(const T1 &a, const T2 &b)
This function returns maximum of two numbers.
Definition: Math.h:61
- Output
Running vector example on the host system:
First vector:0x55721acf06a0
Second vector:0x55721acf0680
Second vector after reset:0
The smallest element is:-3
The absolute biggest element is:3
Sum of all vector elements:3
Vector multiplied by 2:[ 2, 4, -6, 6 ]
Running vector example on the CUDA device:
First vector:0x7fb82ba00200
Second vector:0x7fb82ba00000
Second vector after reset:0
The smallest element is:-3
The absolute biggest element is:3
Sum of all vector elements:3
Vector multiplied by 2:[ 2, 4, -6, 6 ]