![]() |
The blaze::StaticVector class template is the representation of a fixed size vector with statically allocated elements of arbitrary type. It can be included via the header file
The type of the elements, the number of elements, and the transpose flag of the vector can be specified via the three template parameters:
Type:
specifies the type of the vector elements. StaticVector can be used with any non-cv-qualified, non-reference, non-pointer element type.N
: specifies the total number of vector elements. It is expected that StaticVector is only used for tiny and small vectors.TF
: specifies whether the vector is a row vector (blaze::rowVector
) or a column vector (blaze::columnVector
). The default value is blaze::columnVector
.The blaze::StaticVector is perfectly suited for small to medium vectors whose size is known at compile time:
The blaze::DynamicVector class template is the representation of an arbitrary sized vector with dynamically allocated elements of arbitrary type. It can be included via the header file
The type of the elements and the transpose flag of the vector can be specified via the two template parameters:
Type:
specifies the type of the vector elements. DynamicVector can be used with any non-cv-qualified, non-reference, non-pointer element type.TF
: specifies whether the vector is a row vector (blaze::rowVector
) or a column vector (blaze::columnVector
). The default value is blaze::columnVector
.The blaze::DynamicVector is the default choice for all kinds of dense vectors and the best choice for medium to large vectors. Its size can be modified at runtime:
The blaze::HybridVector class template combines the advantages of the blaze::StaticVector and the blaze::DynamicVector class templates. It represents a fixed size vector with statically allocated elements, but still can be dynamically resized (within the bounds of the available memory). It can be included via the header file
The type of the elements, the number of elements, and the transpose flag of the vector can be specified via the three template parameters:
Type:
specifies the type of the vector elements. HybridVector can be used with any non-cv-qualified, non-reference, non-pointer element type.N
: specifies the maximum number of vector elements. It is expected that HybridVector is only used for tiny and small vectors.TF
: specifies whether the vector is a row vector (blaze::rowVector
) or a column vector (blaze::columnVector
). The default value is blaze::columnVector
.The blaze::HybridVector is a suitable choice for small to medium vectors, whose size is not known at compile time or not fixed at runtime, but whose maximum size is known at compile time:
The blaze::CustomVector class template provides the functionality to represent an external array of elements of arbitrary type and a fixed size as a native Blaze dense vector data structure. Thus in contrast to all other dense vector types a custom vector does not perform any kind of memory allocation by itself, but it is provided with an existing array of element during construction. A custom vector can therefore be considered an alias to the existing array. It can be included via the header file
The type of the elements, the properties of the given array of elements and the transpose flag of the vector can be specified via the following four template parameters:
blaze::rowVector
) or a column vector (blaze::columnVector
). The default value is blaze::columnVector
.The blaze::CustomVector is the right choice if any external array needs to be represented as a Blaze dense vector data structure or if a custom memory allocation strategy needs to be realized:
In comparison with the remaining Blaze dense vector types blaze::CustomVector has several special characteristics. All of these result from the fact that a custom vector is not performing any kind of memory allocation, but instead is given an existing array of elements. The following sections discuss all of these characteristics:
The blaze::CustomVector class template acts as an adaptor for an existing array of elements. As such it provides everything that is required to use the array just like a native Blaze dense vector data structure. However, this flexibility comes with the price that the user of a custom vector is responsible for the resource management.
When constructing a custom vector there are two choices: Either a user manually manages the array of elements outside the custom vector, or alternatively passes the responsibility for the memory management to an instance of CustomVector. In the second case the CustomVector class employs shared ownership between all copies of the custom vector, which reference the same array.
The following examples give an impression of several possible types of custom vectors:
It is possible to pass any type of deleter to the constructor. The deleter is only required to provide a function call operator that can be passed the pointer to the managed array. As an example the following code snipped shows the implementation of two native Blaze deleters blaze::ArrayDelete and blaze::Deallocate:
As with all dense vectors it is possible to copy construct a custom vector:
It is important to note that a custom vector acts as a reference to the specified array. Thus the result of the copy constructor is a new custom vector that is referencing and representing the same array as the original custom vector. In case a deleter has been provided to the first custom vector, both vectors share the responsibility to destroy the array when the last vector goes out of scope.
In contrast to copy construction, just as with references, copy assignment does not change which array is referenced by the custom vector, but modifies the values of the array:
In case the custom vector is specified as aligned
the passed array must be guaranteed to be aligned according to the requirements of the used instruction set (SSE, AVX, ...). For instance, if AVX is active an array of integers must be 32-bit aligned:
In case the alignment requirements are violated, a std::invalid_argument
exception is thrown.
Adding padding elements to the end of an array can have a significant impact on the performance. For instance, assuming that AVX is available, then two aligned, padded, 3-dimensional vectors of double precision values can be added via a single SIMD addition operation:
In this example, maximum performance is possible. However, in case no padding elements are inserted, a scalar addition has to be used:
Note the different number of constructor parameters for unpadded and padded custom vectors: In contrast to unpadded vectors, where during the construction only the size of the array has to be specified, during the construction of a padded custom vector it is additionally necessary to explicitly specify the capacity of the array.
The number of padding elements is required to be sufficient with respect to the available instruction set: In case of an aligned padded custom vector the added padding elements must guarantee that the capacity is a multiple of the SIMD vector width. In case of unaligned padded vectors additional padding elements are required, where
is the SIMD vector width. In case the padding is insufficient with respect to the available instruction set, a
std::invalid_argument
exception is thrown.
Please also note that Blaze will zero initialize the padding elements in order to achieve maximum performance!
The blaze::CompressedVector class is the representation of an arbitrarily sized sparse vector, which stores only non-zero elements of arbitrary type. It can be included via the header file
The type of the elements and the transpose flag of the vector can be specified via the two template parameters:
Type:
specifies the type of the vector elements. CompressedVector can be used with any non-cv-qualified, non-reference, non-pointer element type.TF
: specifies whether the vector is a row vector (blaze::rowVector
) or a column vector (blaze::columnVector
). The default value is blaze::columnVector
.The blaze::CompressedVector is the right choice for all kinds of sparse vectors:
Previous: Vectors Next: Vector Operations