![]() |
Blaze 3.9
|
The blaze::StaticMatrix class template is the representation of a fixed size matrix with statically allocated elements of arbitrary type. It can be included via the header files
and forward declared via the header file
The type of the elements, the number of rows and columns, the storage order of the matrix, the alignment, the padding, and the group tag of the matrix can be specified via the seven template parameters:
Type:
specifies the type of the matrix elements. StaticMatrix can be used with any non-cv-qualified, non-reference element type.M
: specifies the total number of rows of the matrix.N
: specifies the total number of columns of the matrix. Note that it is expected that StaticMatrix is only used for tiny and small matrices.SO
: specifies the storage order (blaze::rowMajor
, blaze::columnMajor
) of the matrix. The default value is blaze::defaultStorageOrder
.AF
: specifies whether the first element of every row/column is properly aligned with respect to the available instruction set (SSE, AVX, ...). Possible values are blaze::aligned
and blaze::unaligned
. The default value is blaze::defaultAlignmentFlag
.PF
: specifies whether every row/column of the matrix should be padded to maximize the efficiency of vectorized operations. Possible values are blaze::padded
and blaze::unpadded
. The default value is blaze::defaultPaddingFlag
.Tag
: optional type parameter to tag the matrix. The default type is blaze::Group0
. See Grouping/Tagging for details.The blaze::StaticMatrix is perfectly suited for small to medium matrices whose dimensions are known at compile time:
In case AF
is set to blaze::aligned
, the elements of a blaze::StaticMatrix are possibly over-aligned to meet the alignment requirements of the available instruction set (SSE, AVX, AVX-512, ...). The alignment for fundamental types (short
, int
, float
, double
, ...) and complex types (complex<float>
, complex<double>
, ...) is 16 bytes for SSE, 32 bytes for AVX, and 64 bytes for AVX-512. All other types are aligned according to their intrinsic alignment:
Note that an aligned blaze::StaticMatrix instance may be bigger than the sum of its data elements:
Please note that for this reason a blaze::StaticMatrix cannot be used in containers using dynamic memory such as std::vector
without additionally providing an allocator that can provide over-aligned memory:
Adding padding elements to the end of every row or column of a blaze::StaticMatrix can have a significant impact on the performance. For instance, assuming that AVX is available, then two padded 3x3 matrices of double precision values can be added with three SIMD addition operations:
Due to padding, the first addition will run at maximum performance. On the flip side, the size of each matrix instance is increased due to the padding elements. The total size of an instance depends on the number of elements and width of the available instruction set (16 bytes for SSE, 32 bytes for AVX, and 64 bytes for AVX-512).
The second addition will be limited in performance since due to the number of elements some of the elements need to be handled in a scalar operation. However, the size of an unaligned
, unpadded
blaze::StaticMatrix instance is guaranteed to be the sum of its elements.
Please also note that Blaze will zero initialize the padding elements in order to achieve maximum performance!
The blaze::DynamicMatrix class template is the representation of an arbitrary sized matrix with dynamically allocated elements of arbitrary type. It can be included via the header files
and forward declared via the header file
The type of the elements, the storage order, the type of the allocator, and the group tag of the matrix can be specified via the three template parameters:
Type
: specifies the type of the matrix elements. DynamicMatrix can be used with any non-cv-qualified, non-reference element type.SO
: specifies the storage order (blaze::rowMajor
, blaze::columnMajor
) of the matrix. The default value is blaze::defaultStorageOrder
.Alloc:
specifies the type of allocator used to allocate dynamic memory. The default type of allocator is blaze::AlignedAllocator
.Tag
: optional type parameter to tag the matrix. The default type is blaze::Group0
. See Grouping/Tagging for details.The blaze::DynamicMatrix is the default choice for all kinds of dense matrices and the best choice for medium to large matrices. The number of rows and columns can be modified at runtime:
Via the third template parameter it is possible to customize the memory allocation of a blaze::DynamicMatrix
. The provided allocator is expected to represent an implementation of the allocator concept of the standard library (see for instance std::vector and std::allocator). In addition, the provided allocator is also required to provide properly (over-)aligned memory for fundamental and complex numbers. For instance, in case SSE vectorization is possible, the returned memory must be at least 16-byte aligned. In case AVX is active, the memory must be at least 32-byte aligned, and in case of AVX-512 the memory must be even 64-byte aligned.
The HybridMatrix class template combines the flexibility of a dynamically sized matrix with the efficiency and performance of a fixed size matrix. It is implemented as a crossing between the blaze::StaticMatrix and the blaze::DynamicMatrix class templates: Similar to the static matrix it uses static stack memory instead of dynamically allocated memory and similar to the dynamic matrix it can be resized (within the extend of the static memory). It can be included via the header files
and forward declared via the header file
The type of the elements, the maximum number of rows and columns, the storage order of the matrix, the alignment, the padding, and the group tag of the matrix can be specified via the seven template parameters:
Type:
specifies the type of the matrix elements. HybridMatrix can be used with any non-cv-qualified, non-reference, non-pointer element type.M
: specifies the maximum number of rows of the matrix.N
: specifies the maximum number of columns of the matrix. Note that it is expected that HybridMatrix is only used for tiny and small matrices.SO
: specifies the storage order (blaze::rowMajor
, blaze::columnMajor
) of the matrix. The default value is blaze::defaultStorageOrder
.AF
: specifies whether the first element of every row/column is properly aligned with respect to the available instruction set (SSE, AVX, ...). Possible values are blaze::aligned
and blaze::unaligned
. The default value is blaze::defaultAlignmentFlag
.PF
: specifies whether every row/column of the matrix should be padded to maximize the efficiency of vectorized operations. Possible values are blaze::padded
and blaze::unpadded
. The default value is blaze::defaultPaddingFlag
.Tag
: optional type parameter to tag the matrix. The default type is blaze::Group0
. See Grouping/Tagging for details.The blaze::HybridMatrix is a suitable choice for small to medium matrices, whose dimensions are not known at compile time or not fixed at runtime, but whose maximum dimensions are known at compile time:
In case AF
is set to blaze::aligned
, the elements of a blaze::HybridMatrix are possibly over-aligned to meet the alignment requirements of the available instruction set (SSE, AVX, AVX-512, ...). The alignment for fundamental types (short
, int
, float
, double
, ...) and complex types (complex<float>
, complex<double>
, ...) is 16 bytes for SSE, 32 bytes for AVX, and 64 bytes for AVX-512. All other types are aligned according to their intrinsic alignment:
Note that an aligned blaze::HybridMatrix instance may be bigger than an according unaligned blaze::HybridMatrix:
Please note that for this reason a blaze::HybridMatrix cannot be used in containers using dynamic memory such as std::vector
without additionally providing an allocator that can provide over-aligned memory:
Adding padding elements to the end of every row or column of a blaze::HybridMatrix can have a significant impact on the performance. For instance, assuming that AVX is available, then two padded 3x3 matrices of double precision values can be added with three SIMD addition operations:
Due to padding, the first addition will run at maximum performance. On the flip side, the size of each matrix instance is increased due to the padding elements. The total size of an instance depends on the number of elements and width of the available instruction set (16 bytes for SSE, 32 bytes for AVX, and 64 bytes for AVX-512).
The second addition will be limited in performance since due to the number of elements some of the elements need to be handled in a scalar operation. However, the size of an unaligned
, unpadded
blaze::HybridMatrix instance is guaranteed to be the sum of its elements plus the. necessary data members to store the current number of rows and columns.
Please also note that Blaze will zero initialize the padding elements in order to achieve maximum performance!
The blaze::CustomMatrix class template provides the functionality to represent an external array of elements of arbitrary type and a fixed size as a native Blaze dense matrix data structure. Thus in contrast to all other dense matrix types a custom matrix does not perform any kind of memory allocation by itself, but it is provided with an existing array of element during construction. A custom matrix can therefore be considered an alias to the existing array. It can be included via the header files
and forward declared via the header file
The type of the elements, the properties of the given array of elements, the storage order, and the group tag of the matrix can be specified via the following five template parameters:
Type:
specifies the type of the matrix elements. blaze::CustomMatrix can be used with any possibly cv-qualified, non-reference, non-pointer element type.AF
: specifies whether the represented, external arrays are properly aligned with respect to the available instruction set (SSE, AVX, ...) or not (blaze::aligned
or blaze::unaligned
).PF
: specified whether the represented, external arrays are properly padded with respect to the available instruction set (SSE, AVX, ...) or not (blaze::padded
or blaze::unpadded
).SO
: specifies the storage order (blaze::rowMajor
, blaze::columnMajor
) of the matrix. The default value is blaze::defaultStorageOrder
.Tag
: optional type parameter to tag the matrix. The default type is blaze::Group0
. See Grouping/Tagging for details.The blaze::CustomMatrix is the right choice if any external array needs to be represented as a Blaze dense matrix data structure or if a custom memory allocation strategy needs to be realized:
In comparison with the remaining Blaze dense matrix types blaze::CustomMatrix has several special characteristics. All of these result from the fact that a custom matrix 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::CustomMatrix 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 matrix data structure. However, this flexibility comes with the price that the user of a custom matrix is responsible for the resource management.
The following examples give an impression of several possible types of custom matrices:
As with all dense matrices it is possible to copy construct a custom matrix:
It is important to note that a custom matrix acts as a reference to the specified array. Thus the result of the copy constructor is a new custom matrix that is referencing and representing the same array as the original custom matrix.
In contrast to copy construction, just as with references, copy assignment does not change which array is referenced by the custom matrices, but modifies the values of the array:
In case the custom matrix is specified as aligned
the passed array must adhere to some alignment restrictions based on the alignment requirements of the used data type and the used instruction set (SSE, AVX, ...). The restriction applies to the first element of each row/column: In case of a row-major matrix the first element of each row must be properly aligned, in case of a column-major matrix the first element of each column must be properly aligned. For instance, if a row-major matrix is used and AVX is active the first element of each row must be 32-bit aligned:
In the example, the row-major matrix has six columns. However, since with AVX eight integer values are loaded together the matrix is padded with two additional elements. This guarantees that the first element of each row is 32-bit aligned. In case the alignment requirements are violated, a std::invalid_argument
exception is thrown.
Adding padding elements to the end of each row/column can have a significant impact on the performance. For instance, assuming that AVX is available, then two aligned, padded, 3x3 double precision matrices can be added via three SIMD addition operations:
In this example, maximum performance is possible. However, in case no padding elements are inserted a scalar addition has to be used:
Note that the construction of padded and unpadded aligned matrices looks identical. However, in case of padded matrices, Blaze will zero initialize the padding element and use them in all computations in order to achieve maximum performance. In case of an unpadded matrix Blaze will ignore the elements with the downside that it is not possible to load a complete row to an AVX register, which makes it necessary to fall back to a scalar addition.
The number of padding elements is required to be sufficient with respect to the available instruction set: In case of an aligned padded custom matrix the added padding elements must guarantee that the total number of elements in each row/column is a multiple of the SIMD vector width. In case of an unaligned padded matrix the number of padding elements can be greater or equal the number of padding elements of an aligned padded custom matrix. In case the padding is insufficient with respect to the available instruction set, a std::invalid_argument
exception is thrown.
The blaze::UniformMatrix class template is the representation of an arbitrary sized uniform matrix with elements of arbitrary type. It can be included via the header files
and forward declared via the header file
The type of the elements, the storage order, and the group tag of the matrix can be specified via the three template parameters:
Type:
specifies the type of the matrix elements. UniformMatrix can be used with any non-cv-qualified, non-reference element type.SO
: specifies the storage order (blaze::rowMajor
, blaze::columnMajor
) of the matrix. The default value is blaze::defaultStorageOrder
.Tag
: optional type parameter to tag the matrix. The default type is blaze::Group0
. See Grouping/Tagging for details.The blaze::UniformVector is the best choice for uniform matrices of any size. The number of rows and columns can be modified at runtime:
The blaze::CompressedMatrix class template is the representation of an arbitrary sized sparse matrix with dynamically allocated elements of arbitrary type. It can be included via the header files
and forward declared via the header file
The type of the elements, the storage order, and the group tag of the matrix can be specified via the three template parameters:
Type:
specifies the type of the matrix elements. CompressedMatrix can be used with any non-cv-qualified, non-reference, non-pointer element type.SO
: specifies the storage order (blaze::rowMajor
, blaze::columnMajor
) of the matrix. The default value is blaze::defaultStorageOrder
.Tag
: optional type parameter to tag the matrix. The default type is blaze::Group0
. See Grouping/Tagging for details.The blaze::CompressedMatrix is the right choice for all kinds of sparse matrices:
The blaze::IdentityMatrix class template is the representation of an immutable, arbitrary sized identity matrix with elements of arbitrary type. It can be included via the header files
and forward declared via the header file
The type of the elements and the storage order of the matrix can be specified via the three template parameters:
Type:
specifies the type of the matrix elements. IdentityMatrix can be used with any non-cv-qualified, non-reference, non-pointer element type.SO
: specifies the storage order (blaze::rowMajor
, blaze::columnMajor
) of the matrix. The default value is blaze::defaultStorageOrder
.Tag
: optional type parameter to tag the matrix. The default type is blaze::Group0
. See Grouping/Tagging for details.The blaze::IdentityMatrix is the perfect choice to represent an identity matrix:
The blaze::ZeroMatrix class template is the representation of an immutable, arbitrary sized zero matrix with elements of arbitrary type. It can be included via the header files
and forward declared via the header file
The type of the elements, the storage order, and the group tag of the matrix can be specified via the three template parameters:
Type:
specifies the type of the matrix elements. ZeroMatrix can be used with any non-cv-qualified, non-reference, non-pointer element type.SO
: specifies the storage order (blaze::rowMajor
, blaze::columnMajor
) of the matrix. The default value is blaze::defaultStorageOrder
.Tag
: optional type parameter to tag the matrix. The default type is blaze::Group0
. See Grouping/Tagging for details.The blaze::ZeroMatrix is the perfect choice to represent a zero matrix:
Previous: Matrices Next: Matrix Operations