![]() |
Functions | |
template<size_t I, size_t... Is, typename VT , bool TF, typename... REAs> | |
decltype(auto) | blaze::elements (Vector< VT, TF > &vector, REAs... args) |
Creating a view on a selection of elements of the given vector. More... | |
template<size_t I, size_t... Is, typename VT , bool TF, typename... REAs> | |
decltype(auto) | blaze::elements (const Vector< VT, TF > &vector, REAs... args) |
Creating a view on a selection of elements of the given constant vector. More... | |
template<size_t I, size_t... Is, typename VT , bool TF, typename... REAs> | |
decltype(auto) | blaze::elements (Vector< VT, TF > &&vector, REAs... args) |
Creating a view on a selection of elements of the given temporary vector. More... | |
template<typename VT , bool TF, typename T , typename... REAs> | |
decltype(auto) | blaze::elements (Vector< VT, TF > &vector, const T *indices, size_t n, REAs... args) |
Creating a view on a selection of elements of the given vector. More... | |
template<typename VT , bool TF, typename T , typename... REAs> | |
decltype(auto) | blaze::elements (const Vector< VT, TF > &vector, const T *indices, size_t n, REAs... args) |
Creating a view on a selection of elements of the given constant vector. More... | |
template<typename VT , bool TF, typename T , typename... REAs> | |
decltype(auto) | blaze::elements (Vector< VT, TF > &&vector, const T *indices, size_t n, REAs... args) |
Creating a view on a selection of elements of the given temporary vector. More... | |
template<typename VT , bool TF, typename P , typename... REAs, EnableIf_t< !IsPointer_v< P > > * = nullptr> | |
decltype(auto) | blaze::elements (Vector< VT, TF > &vector, P p, size_t n, REAs... args) |
Creating a view on a selection of elements of the given vector. More... | |
template<typename VT , bool TF, typename P , typename... REAs, EnableIf_t< !IsPointer_v< P > > * = nullptr> | |
decltype(auto) | blaze::elements (const Vector< VT, TF > &vector, P p, size_t n, REAs... args) |
Creating a view on a selection of elements of the given constant vector. More... | |
template<typename VT , bool TF, typename P , typename... REAs, EnableIf_t< !IsPointer_v< P > > * = nullptr> | |
decltype(auto) | blaze::elements (Vector< VT, TF > &&vector, P p, size_t n, REAs... args) |
Creating a view on a selection of elements of the given temporary vector. More... | |
template<typename VT , typename T , typename... REAs> | |
decltype(auto) | blaze::elements (VT &&vector, initializer_list< T > indices, REAs... args) |
Creating a view on a selection of elements of the given vector. More... | |
template<typename VT , typename T , size_t N, typename... REAs> | |
decltype(auto) | blaze::elements (VT &&vector, const std::array< T, N > &indices, REAs... args) |
Creating a view on a selection of elements of the given vector. More... | |
template<typename VT , typename T , typename... REAs> | |
decltype(auto) | blaze::elements (VT &&vector, const std::vector< T > &indices, REAs... args) |
Creating a view on a selection of elements of the given vector. More... | |
template<typename VT , typename T , size_t N, typename... REAs> | |
decltype(auto) | blaze::elements (VT &&vector, const SmallArray< T, N > &indices, REAs... args) |
Creating a view on a selection of elements of the given vector. More... | |
Element selections provide views on arbitrary compositions of elements of dense and sparse vectors. These views act as a reference to the selected elements and represent them as another dense or sparse vector. This reference is valid and can be used in every way any other dense or sparse vector can be used as long as the vector containing the elements is not resized or entirely destroyed. The element selection also acts as an alias to the vector elements in the specified range: Changes made to the elements (e.g. modifying values, inserting or erasing elements) are immediately visible in the vector and changes made via the vector are immediately visible in the elements.
An element selection can be created very conveniently via the elements()
function. It can be included via the header file
The indices of the elements to be selected can be specified either at compile time or at runtime (by means of an initializer list, array or vector):
Note that it is possible to alias the elements of the underlying vector in any order. Also note that it is possible to use the same index multiple times.
Alternatively it is possible to pass a callable such as a lambda or functor that produces the indices:
The elements()
function returns an expression representing the view on the selected elements. The type of this expression depends on the given arguments, primarily the type of the vector and the compile time arguments. If the type is required, it can be determined via decltype
specifier:
The resulting view can be treated as any other dense or sparse vector, i.e. it can be assigned to, it can be copied from, and it can be used in arithmetic operations. An element selection created from a row vector can be used as any other row vector, an element selection created from a column vector can be used as any other column vector. The view can also be used on both sides of an assignment: It can either be used as an alias to grant write access to specific elements of a vector primitive on the left-hand side of an assignment or to grant read-access to specific elements of a vector primitive or expression on the right-hand side of an assignment. The following example demonstrates this in detail:
Please note that using an element selection, which refers to an index multiple times, on the left-hand side of an assignment leads to undefined behavior:
In this example both vectors have the same size, which results in a correct vector assignment, but the final value of the element at index 1 is unspecified.
The elements of an element selection can be directly accessed via the subscript operator:
The numbering of the selected elements is
where N is the number of selected elements. Alternatively, the elements of an element selection can be traversed via iterators. Just as with vectors, in case of non-const element selections, begin()
and end()
return an iterator, which allows to manipulate the elements, in case of constant element selections an iterator to immutable elements is returned:
Inserting/accessing elements in a sparse element selection can be done by several alternative functions. The following example demonstrates all options:
An element selection can be used like any other dense or sparse vector. For instance, the number of selected elements can be obtained via the size()
function, the current capacity via the capacity()
function, and the number of non-zero elements via the nonZeros()
function. However, since element selections are references to a specific range of a vector, several operations are not possible, such as resizing and swapping. The following example shows this by means of an element selection on a dense vector:
Both dense and sparse element selections can be used in all arithmetic operations that any other dense or sparse vector can be used in. The following example gives an impression of the use of dense element selections within arithmetic operations. All operations (addition, subtraction, multiplication, scaling, ...) can be performed on all possible combinations of dense and sparse element selections with fitting element types:
|
inline |
Creating a view on a selection of elements of the given vector.
vector | The vector containing the elements. |
args | Optional arguments. |
std::invalid_argument | Invalid element access index. |
This function returns an expression representing a selection of elements of the given vector.
By default, the provided element indices are checked at runtime. In case any element is not properly specified (i.e. if any specified index is greater than or equal to the total number of elements in the given vector) a std::invalid_argument exception is thrown. The checks can be skipped by providing the optional blaze::unchecked argument.
|
inline |
Creating a view on a selection of elements of the given constant vector.
vector | The constant vector containing the elements. |
args | Optional arguments. |
std::invalid_argument | Invalid element access index. |
This function returns an expression representing a selection of elements of the given constant vector.
By default, the provided element indices are checked at runtime. In case any element is not properly specified (i.e. if any specified index is greater than or equal to the total number of elements in the given vector) a std::invalid_argument exception is thrown. The checks can be skipped by providing the optional blaze::unchecked argument.
|
inline |
Creating a view on a selection of elements of the given temporary vector.
vector | The temporary vector containing the elements. |
args | Optional arguments. |
std::invalid_argument | Invalid element access index. |
This function returns an expression representing an selection of elements of the given temporary vector. In case any element is not properly specified (i.e. if any specified index is greater than or equal to the total number of the elements in the given vector) a std::invalid_argument exception is thrown.
|
inline |
Creating a view on a selection of elements of the given vector.
vector | The vector containing the elements. |
indices | Pointer to the first index of the selected elements. |
n | The total number of indices. |
args | Optional arguments. |
std::invalid_argument | Invalid element access index. |
This function returns an expression representing a selection of elements of the given vector.
By default, the provided element indices are checked at runtime. In case any element is not properly specified (i.e. if any specified index is greater than or equal to the total number of elements in the given vector) a std::invalid_argument exception is thrown. The checks can be skipped by providing the optional blaze::unchecked argument.
|
inline |
Creating a view on a selection of elements of the given constant vector.
vector | The constant vector containing the elements. |
indices | Pointer to the first index of the selected elements. |
n | The total number of indices. |
args | Optional arguments. |
std::invalid_argument | Invalid element access index. |
This function returns an expression representing a selection of elements of the given constant vector.
By default, the provided element indices are checked at runtime. In case any element is not properly specified (i.e. if any specified index is greater than or equal to the total number of elements in the given vector) a std::invalid_argument exception is thrown. The checks can be skipped by providing the optional blaze::unchecked argument.
|
inline |
Creating a view on a selection of elements of the given temporary vector.
vector | The temporary vector containing the elements. |
indices | Pointer to the first index of the selected elements. |
n | The total number of indices. |
args | Optional arguments. |
std::invalid_argument | Invalid element access index. |
This function returns an expression representing a selection of elements of the given temporary vector. In case any element is not properly specified (i.e. if any specified index is greater than or equal to the total number of elements in the given vector) a std::invalid_argument exception is thrown.
|
inline |
Creating a view on a selection of elements of the given vector.
vector | The vector containing the elements. |
p | Callable producing the indices. |
n | The total number of indices. |
args | Optional arguments. |
std::invalid_argument | Invalid element access index. |
This function returns an expression representing a selection of elements of the given vector.
By default, the provided element indices are checked at runtime. In case any element is not properly specified (i.e. if any specified index is greater than or equal to the total number of elements in the given vector) a std::invalid_argument exception is thrown. The checks can be skipped by providing the optional blaze::unchecked argument.
|
inline |
Creating a view on a selection of elements of the given constant vector.
vector | The constant vector containing the elements. |
p | Callable producing the indices. |
n | The total number of indices. |
args | Optional arguments. |
std::invalid_argument | Invalid element access index. |
This function returns an expression representing a selection of elements of the given constant vector.
By default, the provided element indices are checked at runtime. In case any element is not properly specified (i.e. if any specified index is greater than or equal to the total number of elements in the given vector) a std::invalid_argument exception is thrown. The checks can be skipped by providing the optional blaze::unchecked argument.
|
inline |
Creating a view on a selection of elements of the given temporary vector.
vector | The temporary vector containing the elements. |
p | Callable producing the indices. |
n | The total number of indices. |
args | Optional arguments. |
std::invalid_argument | Invalid element access index. |
This function returns an expression representing a selection of elements of the given temporary vector. In case any element is not properly specified (i.e. if any specified index is greater than or equal to the total number of elements in the given vector) a std::invalid_argument exception is thrown.
|
inline |
Creating a view on a selection of elements of the given vector.
vector | The vector containing the elements. |
indices | The list of element indices. |
args | Optional arguments. |
std::invalid_argument | Invalid element access index. |
This function returns an expression representing a selection of elements of the given vector.
By default, the provided element indices are checked at runtime. In case any element is not properly specified (i.e. if any specified index is greater than or equal to the total number of elements in the given vector) a std::invalid_argument exception is thrown. The checks can be skipped by providing the optional blaze::unchecked argument.
|
inline |
Creating a view on a selection of elements of the given vector.
vector | The vector containing the elements. |
indices | The array of element indices. |
args | Optional arguments. |
std::invalid_argument | Invalid element access index. |
This function returns an expression representing a selection of elements of the given vector.
By default, the provided element indices are checked at runtime. In case any element is not properly specified (i.e. if any specified index is greater than or equal to the total number of elements in the given vector) a std::invalid_argument exception is thrown. The checks can be skipped by providing the optional blaze::unchecked argument.
|
inline |
Creating a view on a selection of elements of the given vector.
vector | The vector containing the elements. |
indices | The vector of element indices. |
args | Optional arguments. |
std::invalid_argument | Invalid element access index. |
This function returns an expression representing a selection of elements of the given vector.
By default, the provided element indices are checked at runtime. In case any element is not properly specified (i.e. if any specified index is greater than or equal to the total number of elements in the given vector) a std::invalid_argument exception is thrown. The checks can be skipped by providing the optional blaze::unchecked argument.
|
inline |
Creating a view on a selection of elements of the given vector.
vector | The vector containing the elements. |
indices | The vector of element indices. |
args | Optional arguments. |
std::invalid_argument | Invalid element access index. |
This function returns an expression representing a selection of elements of the given vector.
By default, the provided element indices are checked at runtime. In case any element is not properly specified (i.e. if any specified index is greater than or equal to the total number of elements in the given vector) a std::invalid_argument exception is thrown. The checks can be skipped by providing the optional blaze::unchecked argument.