![]() |
Blaze
3.6
|
Classes | |
class | blaze::SubvectorData< CSAs > |
Auxiliary class template for the data members of the Subvector class.The auxiliary SubvectorData class template represents an abstraction of the data members of the Subvector class template. The necessary set of data members is selected depending on the number of compile time subvector arguments. More... | |
Functions | |
template<size_t I, size_t N, typename VT , bool TF, typename... RSAs> | |
decltype(auto) | blaze::subvector (Vector< VT, TF > &vector, RSAs... args) |
Creating a view on a specific subvector of the given vector. More... | |
template<size_t I, size_t N, typename VT , bool TF, typename... RSAs> | |
decltype(auto) | blaze::subvector (const Vector< VT, TF > &vector, RSAs... args) |
Creating a view on a specific subvector of the given constant vector. More... | |
template<size_t I, size_t N, typename VT , bool TF, typename... RSAs> | |
decltype(auto) | blaze::subvector (Vector< VT, TF > &&vector, RSAs... args) |
Creating a view on a specific subvector of the given temporary vector. More... | |
template<AlignmentFlag AF, size_t I, size_t N, typename VT , bool TF, typename... RSAs> | |
decltype(auto) | blaze::subvector (Vector< VT, TF > &vector, RSAs... args) |
Creating a view on a specific subvector of the given vector. More... | |
template<AlignmentFlag AF, size_t I, size_t N, typename VT , bool TF, typename... RSAs> | |
decltype(auto) | blaze::subvector (const Vector< VT, TF > &vector, RSAs... args) |
Creating a view on a specific subvector of the given constant vector. More... | |
template<AlignmentFlag AF, size_t I, size_t N, typename VT , bool TF, typename... RSAs> | |
decltype(auto) | blaze::subvector (Vector< VT, TF > &&vector, RSAs... args) |
Creating a view on a specific subvector of the given temporary vector. More... | |
template<typename VT , bool TF, typename... RSAs> | |
decltype(auto) | blaze::subvector (Vector< VT, TF > &vector, size_t index, size_t size, RSAs... args) |
Creating a view on a specific subvector of the given vector. More... | |
template<typename VT , bool TF, typename... RSAs> | |
decltype(auto) | blaze::subvector (const Vector< VT, TF > &vector, size_t index, size_t size, RSAs... args) |
Creating a view on a specific subvector of the given constant vector. More... | |
template<typename VT , bool TF, typename... RSAs> | |
decltype(auto) | blaze::subvector (Vector< VT, TF > &&vector, size_t index, size_t size, RSAs... args) |
Creating a view on a specific subvector of the given temporary vector. More... | |
template<AlignmentFlag AF, typename VT , bool TF, typename... RSAs> | |
decltype(auto) | blaze::subvector (Vector< VT, TF > &vector, size_t index, size_t size, RSAs... args) |
Creating a view on a specific subvector of the given vector. More... | |
template<AlignmentFlag AF, typename VT , bool TF, typename... RSAs> | |
decltype(auto) | blaze::subvector (const Vector< VT, TF > &vector, size_t index, size_t size, RSAs... args) |
Creating a view on a specific subvector of the given constant vector. More... | |
template<AlignmentFlag AF, typename VT , bool TF, typename... RSAs> | |
decltype(auto) | blaze::subvector (Vector< VT, TF > &&vector, size_t index, size_t size, RSAs... args) |
Creating a view on a specific subvector of the given temporary vector. More... | |
Subvectors provide views on a specific part of a dense or sparse vector. As such, subvectors act as a reference to a specific range within a 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 subvector is not resized or entirely destroyed. The subvector 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 subvector.
A view on a dense or sparse subvector can be created very conveniently via the subvector()
function. It can be included via the header file
The first parameter specifies the offset of the subvector within the underlying dense or sparse vector, the second parameter specifies the size of the subvector. The two parameters can be specified either at compile time or at runtime:
The subvector()
function returns an expression representing the subvector view. The type of this expression depends on the given subvector 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. A subvector created from a row vector can be used as any other row vector, a subvector 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: The subvector can either be used as an alias to grant write access to a specific subvector of a vector primitive on the left-hand side of an assignment or to grant read-access to a specific subvector of a vector primitive or expression on the right-hand side of an assignment. The following example demonstrates this in detail:
The elements of a subvector can be directly accessed via the subscript operator:
The numbering of the subvector elements is
where N is the specified size of the subvector. Alternatively, the elements of a subvector can be traversed via iterators. Just as with vectors, in case of non-const subvectors, begin()
and end()
return an iterator, which allows to manipulate the elements, in case of constant subvectors an iterator to immutable elements is returned:
Inserting/accessing elements in a sparse subvector can be done by several alternative functions. The following example demonstrates all options:
A subvector view can be used like any other dense or sparse vector. For instance, the current number of 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 subvectors 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 a dense subvector view:
Both dense and sparse subvectors 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 subvectors within arithmetic operations. All operations (addition, subtraction, multiplication, scaling, ...) can be performed on all possible combinations of dense and sparse subvectors with fitting element types:
Usually subvectors can be defined anywhere within a vector. They may start at any position and may have an arbitrary size (only restricted by the size of the underlying vector). However, in contrast to vectors themselves, which are always properly aligned in memory and therefore can provide maximum performance, this means that subvectors in general have to be considered to be unaligned. This can be made explicit by the blaze::unaligned flag:
All of these calls to the subvector()
function are identical. Whether the alignment flag is explicitly specified or not, it always returns an unaligned subvector. Whereas this may provide full flexibility in the creation of subvectors, this might result in performance disadvantages in comparison to vector primitives (even in case the specified subvector could be aligned). Whereas vector primitives are guaranteed to be properly aligned and therefore provide maximum performance in all operations, a general view on a vector might not be properly aligned. This may cause a performance penalty on some platforms and/or for some operations.
However, it is also possible to create aligned subvectors. Aligned subvectors are identical to unaligned subvectors in all aspects, except that they may pose additional alignment restrictions and therefore have less flexibility during creation, but don't suffer from performance penalties and provide the same performance as the underlying vector. Aligned subvectors are created by explicitly specifying the blaze::aligned flag:
The alignment restrictions refer to system dependent address restrictions for the used element type and the available vectorization mode (SSE, AVX, ...). In order to be properly aligned the first element of the subvector must be aligned. The following source code gives some examples for a double precision dynamic vector, assuming that AVX is available, which packs 4 double
values into a SIMD vector:
Note that the discussed alignment restrictions are only valid for aligned dense subvectors. In contrast, aligned sparse subvectors at this time don't pose any additional restrictions. Therefore aligned and unaligned sparse subvectors are truly fully identical. Still, in case the blaze::aligned flag is specified during setup, an aligned subvector is created:
decltype(auto) blaze::subvector | ( | Vector< VT, TF > & | vector, |
RSAs... | args | ||
) |
Creating a view on a specific subvector of the given vector.
vector | The vector containing the subvector. |
args | Optional subvector arguments. |
std::invalid_argument | Invalid subvector specification. |
This function returns an expression representing the specified subvector of the given vector. The following example demonstrates the creation of a dense and sparse subvector:
By default, the provided subvector arguments are checked at runtime. In case the subvector is not properly specified (i.e. if the specified first index is greater than the total size of the given vector or the subvector is specified beyond the size of the vector) a std::invalid_argument exception is thrown. The checks can be skipped by providing the optional blaze::unchecked argument.
Please note that this function creates an unaligned dense or sparse subvector. For instance, the creation of the dense subvector is equivalent to the following function call:
In contrast to unaligned subvectors, which provide full flexibility, aligned subvectors pose additional alignment restrictions. However, especially in case of dense subvectors this may result in considerable performance improvements. In order to create an aligned subvector the following function call has to be used:
Note however that in this case the given compile time arguments I and N are subject to additional checks to guarantee proper alignment.
decltype(auto) blaze::subvector | ( | const Vector< VT, TF > & | vector, |
RSAs... | args | ||
) |
Creating a view on a specific subvector of the given constant vector.
vector | The constant vector containing the subvector. |
args | Optional subvector arguments. |
std::invalid_argument | Invalid subvector specification. |
This function returns an expression representing the specified subvector of the given constant vector. The following example demonstrates the creation of a dense and sparse subvector:
By default, the provided subvector arguments are checked at runtime. In case the subvector is not properly specified (i.e. if the specified first index is greater than the total size of the given vector or the subvector is specified beyond the size of the vector) a std::invalid_argument exception is thrown. The checks can be skipped by providing the optional blaze::unchecked argument.
Please note that this function creates an unaligned dense or sparse subvector. For instance, the creation of the dense subvector is equivalent to the following function call:
In contrast to unaligned subvectors, which provide full flexibility, aligned subvectors pose additional alignment restrictions. However, especially in case of dense subvectors this may result in considerable performance improvements. In order to create an aligned subvector the following function call has to be used:
Note however that in this case the given compile time arguments I and N are subject to additional checks to guarantee proper alignment.
decltype(auto) blaze::subvector | ( | Vector< VT, TF > && | vector, |
RSAs... | args | ||
) |
Creating a view on a specific subvector of the given temporary vector.
vector | The temporary vector containing the subvector. |
args | Optional subvector arguments. |
std::invalid_argument | Invalid subvector specification. |
This function returns an expression representing the specified subvector of the given temporary vector. In case the subvector is not properly specified (i.e. if the specified first index is greater than the total size of the given vector or the subvector is specified beyond the size of the vector) a std::invalid_argument exception is thrown.
decltype(auto) blaze::subvector | ( | Vector< VT, TF > & | vector, |
RSAs... | args | ||
) |
Creating a view on a specific subvector of the given vector.
vector | The vector containing the subvector. |
args | Optional subvector arguments. |
std::invalid_argument | Invalid subvector specification. |
This function returns an expression representing an aligned or unaligned subvector of the given dense or sparse vector, based on the specified alignment flag AF. The following example demonstrates the creation of both an aligned and unaligned subvector:
By default, the provided subvector arguments are checked at runtime. In case the subvector is not properly specified (i.e. if the specified first index is greater than the total size of the given vector or the subvector is specified beyond the size of the vector) a std::invalid_argument exception is thrown. The checks can be skipped by providing the optional blaze::unchecked argument.
In contrast to unaligned subvectors, which provide full flexibility, aligned subvectors pose additional alignment restrictions and the given index I is subject to additional checks to guarantee proper alignment. However, especially in case of dense subvectors this may result in considerable performance improvements.
The alignment restrictions refer to system dependent address restrictions for the used element type and the available vectorization mode (SSE, AVX, ...). In order to be properly aligned the first element of the subvector must be aligned. The following source code gives some examples for a double precision dynamic vector, assuming that AVX is available, which packs 4 double
values into a SIMD vector:
In case any alignment restrictions are violated, a std::invalid_argument exception is thrown.
decltype(auto) blaze::subvector | ( | const Vector< VT, TF > & | vector, |
RSAs... | args | ||
) |
Creating a view on a specific subvector of the given constant vector.
vector | The constant vector containing the subvector. |
args | Optional subvector arguments. |
std::invalid_argument | Invalid subvector specification. |
This function returns an expression representing an aligned or unaligned subvector of the given constant dense or sparse vector, based on the specified alignment flag AF. The following example demonstrates the creation of both an aligned and unaligned subvector:
By default, the provided subvector arguments are checked at runtime. In case the subvector is not properly specified (i.e. if the specified first index is greater than the total size of the given vector or the subvector is specified beyond the size of the vector) a std::invalid_argument exception is thrown. The checks can be skipped by providing the optional blaze::unchecked argument.
In contrast to unaligned subvectors, which provide full flexibility, aligned subvectors pose additional alignment restrictions and the given index I is subject to additional checks to guarantee proper alignment. However, especially in case of dense subvectors this may result in considerable performance improvements.
The alignment restrictions refer to system dependent address restrictions for the used element type and the available vectorization mode (SSE, AVX, ...). In order to be properly aligned the first element of the subvector must be aligned. The following source code gives some examples for a double precision dynamic vector, assuming that AVX is available, which packs 4 double
values into a SIMD vector:
In case any alignment restrictions are violated, a std::invalid_argument exception is thrown.
decltype(auto) blaze::subvector | ( | Vector< VT, TF > && | vector, |
RSAs... | args | ||
) |
Creating a view on a specific subvector of the given temporary vector.
vector | The temporary vector containing the subvector. |
args | Optional subvector arguments. |
std::invalid_argument | Invalid subvector specification. |
This function returns an expression representing an aligned or unaligned subvector of the given temporary dense or sparse vector, based on the specified alignment flag AF. In case the subvector is not properly specified (i.e. if the specified first index is greater than the total size of the given vector or the subvector is specified beyond the size of the vector) or any alignment restrictions are violated, a std::invalid_argument exception is thrown.
decltype(auto) blaze::subvector | ( | Vector< VT, TF > & | vector, |
size_t | index, | ||
size_t | size, | ||
RSAs... | args | ||
) |
Creating a view on a specific subvector of the given vector.
vector | The vector containing the subvector. |
index | The index of the first element of the subvector. |
size | The size of the subvector. |
args | Optional subvector arguments. |
std::invalid_argument | Invalid subvector specification. |
This function returns an expression representing the specified subvector of the given vector. The following example demonstrates the creation of a dense and sparse subvector:
By default, the provided subvector arguments are checked at runtime. In case the subvector is not properly specified (i.e. if the specified first index is greater than the total size of the given vector or the subvector is specified beyond the size of the vector) a std::invalid_argument exception is thrown. The checks can be skipped by providing the optional blaze::unchecked argument.
Please note that this function creates an unaligned dense or sparse subvector. For instance, the creation of the dense subvector is equivalent to the following function call:
In contrast to unaligned subvectors, which provide full flexibility, aligned subvectors pose additional alignment restrictions. However, especially in case of dense subvectors this may result in considerable performance improvements. In order to create an aligned subvector the following function call has to be used:
Note however that in this case the given index and size are subject to additional checks to guarantee proper alignment.
decltype(auto) blaze::subvector | ( | const Vector< VT, TF > & | vector, |
size_t | index, | ||
size_t | size, | ||
RSAs... | args | ||
) |
Creating a view on a specific subvector of the given constant vector.
vector | The constant vector containing the subvector. |
index | The index of the first element of the subvector. |
size | The size of the subvector. |
args | Optional subvector arguments. |
std::invalid_argument | Invalid subvector specification. |
This function returns an expression representing the specified subvector of the given constant vector. The following example demonstrates the creation of a dense and sparse subvector:
By default, the provided subvector arguments are checked at runtime. In case the subvector is not properly specified (i.e. if the specified first index is greater than the total size of the given vector or the subvector is specified beyond the size of the vector) a std::invalid_argument exception is thrown. The checks can be skipped by providing the optional blaze::unchecked argument.
Please note that this function creates an unaligned dense or sparse subvector. For instance, the creation of the dense subvector is equivalent to the following function call:
In contrast to unaligned subvectors, which provide full flexibility, aligned subvectors pose additional alignment restrictions. However, especially in case of dense subvectors this may result in considerable performance improvements. In order to create an aligned subvector the following function call has to be used:
Note however that in this case the given index and size are subject to additional checks to guarantee proper alignment.
decltype(auto) blaze::subvector | ( | Vector< VT, TF > && | vector, |
size_t | index, | ||
size_t | size, | ||
RSAs... | args | ||
) |
Creating a view on a specific subvector of the given temporary vector.
vector | The temporary vector containing the subvector. |
index | The index of the first element of the subvector. |
size | The size of the subvector. |
args | Optional subvector arguments. |
std::invalid_argument | Invalid subvector specification. |
This function returns an expression representing the specified subvector of the given temporary vector. In case the subvector is not properly specified (i.e. if the specified first index is greater than the total size of the given vector or the subvector is specified beyond the size of the vector) a std::invalid_argument exception is thrown.
decltype(auto) blaze::subvector | ( | Vector< VT, TF > & | vector, |
size_t | index, | ||
size_t | size, | ||
RSAs... | args | ||
) |
Creating a view on a specific subvector of the given vector.
vector | The vector containing the subvector. |
index | The index of the first element of the subvector. |
size | The size of the subvector. |
args | Optional subvector arguments. |
std::invalid_argument | Invalid subvector specification. |
This function returns an expression representing an aligned or unaligned subvector of the given dense or sparse vector, based on the specified alignment flag AF. The following example demonstrates the creation of both an aligned and unaligned subvector:
By default, the provided subvector arguments are checked at runtime. In case the subvector is not properly specified (i.e. if the specified first index is greater than the total size of the given vector or the subvector is specified beyond the size of the vector) a std::invalid_argument exception is thrown. The checks can be skipped by providing the optional blaze::unchecked argument.
In contrast to unaligned subvectors, which provide full flexibility, aligned subvectors pose additional alignment restrictions and the given index is subject to additional checks to guarantee proper alignment. However, especially in case of dense subvectors this may result in considerable performance improvements.
The alignment restrictions refer to system dependent address restrictions for the used element type and the available vectorization mode (SSE, AVX, ...). In order to be properly aligned the first element of the subvector must be aligned. The following source code gives some examples for a double precision dynamic vector, assuming that AVX is available, which packs 4 double
values into a SIMD vector:
In case any alignment restrictions are violated, a std::invalid_argument exception is thrown.
decltype(auto) blaze::subvector | ( | const Vector< VT, TF > & | vector, |
size_t | index, | ||
size_t | size, | ||
RSAs... | args | ||
) |
Creating a view on a specific subvector of the given constant vector.
vector | The constant vector containing the subvector. |
index | The index of the first element of the subvector. |
size | The size of the subvector. |
args | Optional subvector arguments. |
std::invalid_argument | Invalid subvector specification. |
This function returns an expression representing an aligned or unaligned subvector of the given constant dense or sparse vector, based on the specified alignment flag AF. The following example demonstrates the creation of both an aligned and unaligned subvector:
By default, the provided subvector arguments are checked at runtime. In case the subvector is not properly specified (i.e. if the specified first index is greater than the total size of the given vector or the subvector is specified beyond the size of the vector) a std::invalid_argument exception is thrown. The checks can be skipped by providing the optional blaze::unchecked argument.
In contrast to unaligned subvectors, which provide full flexibility, aligned subvectors pose additional alignment restrictions and the given index is subject to additional checks to guarantee proper alignment. However, especially in case of dense subvectors this may result in considerable performance improvements.
The alignment restrictions refer to system dependent address restrictions for the used element type and the available vectorization mode (SSE, AVX, ...). In order to be properly aligned the first element of the subvector must be aligned. The following source code gives some examples for a double precision dynamic vector, assuming that AVX is available, which packs 4 double
values into a SIMD vector:
In case any alignment restrictions are violated, a std::invalid_argument exception is thrown.
decltype(auto) blaze::subvector | ( | Vector< VT, TF > && | vector, |
size_t | index, | ||
size_t | size, | ||
RSAs... | args | ||
) |
Creating a view on a specific subvector of the given temporary vector.
vector | The temporary vector containing the subvector. |
index | The index of the first element of the subvector. |
size | The size of the subvector. |
args | Optional subvector arguments. |
std::invalid_argument | Invalid subvector specification. |
This function returns an expression representing an aligned or unaligned subvector of the given temporary dense or sparse vector, based on the specified alignment flag AF. In case the subvector is not properly specified (i.e. if the specified first index is greater than the total size of the given vector or the subvector is specified beyond the size of the vector) or any alignment restrictions are violated, a std::invalid_argument exception is thrown.