Wiki

Clone wiki

blaze / Matrix Types


Dense Matrices

StaticMatrix

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

#include <blaze/Blaze.h>
// or
#include <blaze/Math.h>
// or
#include <blaze/math/StaticMatrix.h>

and forward declared via the header file

#include <blaze/Forward.h>

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:

namespace blaze {

template< typename Type, size_t M, size_t N, bool SO, AlignmentFlag AF, PaddingFlag PF, typename Tag >
class StaticMatrix;

} // namespace blaze
  • Type : specifies the type of the matrix elements. StaticMatrix can be used with any non-cv-qualified element type, including vector and other matrix types.
  • 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:

// Definition of a 3x4 integral row-major matrix
blaze::StaticMatrix<int,3UL,4UL> A;

// Definition of a 4x6 single precision row-major matrix
blaze::StaticMatrix<float,4UL,6UL,blaze::rowMajor> B;

// Definition of an unaligned, unpadded 6x4 double precision column-major matrix
blaze::StaticMatrix<double,6UL,4UL,blaze::columnMajor,blaze::unaligned,blaze::unpadded> C;
Alignment

In case AF is set to blaze::aligned, the elements of a 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:

struct Int { int i; };

using MT1 = blaze::StaticMatrix<double,3UL,5UL>;
using MT2 = blaze::StaticMatrix<complex<float>,2UL,3UL>;
using MT3 = blaze::StaticMatrix<Int,5UL,4UL>;

alignof( MT1 );  // Evaluates to 16 for SSE, 32 for AVX, and 64 for AVX-512
alignof( MT2 );  // Evaluates to 16 for SSE, 32 for AVX, and 64 for AVX-512
alignof( MT3 );  // Evaluates to 'alignof( Int )'

Note that an aligned StaticMatrix instance may be bigger than the sum of its data elements:

sizeof( MT1 );  // Evaluates to 160 for SSE, and 192 for AVX and AVX-512
sizeof( MT2 );  // Evaluates to 64 for SSE and AVX and 128 for AVX-512
sizeof( MT3 );  // Evaluates to 80; no special alignment requirements

Please note that for this reason a StaticMatrix cannot be used in containers using dynamic memory such as std::vector without additionally providing an allocator that can provide over-aligned memory:

using Type = blaze::StaticMatrix<double,3UL,5UL>;
using Allocator = blaze::AlignedAllocator<Type>;

std::vector<Type> v1;  // Might be misaligned for AVX or AVX-512
std::vector<Type,Allocator> v2;  // Properly aligned for AVX or AVX-512
Padding

Adding padding elements to the end of every row or column of a 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:

using blaze::StaticMatrix;
using blaze::rowMajor;
using blaze::aligned;
using blaze::unaligned;
using blaze::padded;
using blaze::unpadded;

StaticMatrix<double,3UL,3UL,rowMajor,aligned,padded> A1, B1, C1;
StaticMatrix<double,3UL,3UL,rowMajor,unaligned,unpadded> A2, B2, C2;

// ... Initialization

C1 = A1 + B1;  // AVX-based matrix addition; maximum performance
C2 = A2 + B2;  // Scalar matrix addition; limited performance

sizeof( A1 );  // Evaluates to 96 for SSE and AVX, and 192 for AVX-512
sizeof( A2 );  // Evaluates to 72 for SSE, AVX, and AVX-512 (minimum size)

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 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!

DynamicMatrix

The blaze::DynamicMatrix class template is the representation of an arbitrary sized matrix with MxN dynamically allocated elements of arbitrary type. It can be included via the header files

#include <blaze/Blaze.h>
// or
#include <blaze/Math.h>
// or
#include <blaze/math/DynamicMatrix.h>

and forward declared via the header file

#include <blaze/Forward.h>

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:

namespace blaze {

template< typename Type, bool SO, typename Alloc, typename Tag >
class DynamicMatrix;

} // namespace blaze
  • Type : specifies the type of the matrix elements. DynamicMatrix can be used with any non-cv-qualified element type (even with vector and other matrix types).
  • 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:

// Definition of a 3x4 integral row-major matrix
blaze::DynamicMatrix<int> A( 3UL, 4UL );

// Definition of a 4x6 single precision row-major matrix
blaze::DynamicMatrix<float,blaze::rowMajor> B( 4UL, 6UL );

// Definition of a double precision column-major matrix with 0 rows and columns
blaze::DynamicMatrix<double,blaze::columnMajor> C;
Allocators

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.

HybridMatrix

The blaze::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

#include <blaze/Blaze.h>
// or
#include <blaze/Math.h>
// or
#include <blaze/math/HybridMatrix.h>

and forward declared via the header file

#include <blaze/Forward.h>

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:

namespace blaze {

template< typename Type, size_t M, size_t N, bool SO, AlignmentFlag AF, PaddingFlag PF, typename Tag >
class HybridMatrix;

} // namespace blaze
  • 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:

// Definition of a 3x4 integral row-major matrix with maximum dimensions of 6x8
blaze::HybridMatrix<int,6UL,8UL> A( 3UL, 4UL );

// Definition of a 4x6 single precision row-major matrix with maximum dimensions of 12x16
blaze::HybridMatrix<float,12UL,16UL,blaze::rowMajor> B( 4UL, 6UL );

// Definition of an unaligned, unpadded 0x0 double precision column-major matrix and maximum dimensions of 6x6
blaze::HybridMatrix<double,6UL,6UL,blaze::columnMajor,blaze::unaligned,blaze::unpadded> C;

In case \c 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:

struct Int { int i; };

using MT1 = blaze::HybridMatrix<double,3UL>;
using MT2 = blaze::HybridMatrix<complex<float>,2UL>;
using MT3 = blaze::HybridMatrix<Int,5UL>;

alignof( MT1 );  // Evaluates to 16 for SSE, 32 for AVX, and 64 for AVX-512
alignof( MT2 );  // Evaluates to 16 for SSE, 32 for AVX, and 64 for AVX-512
alignof( MT3 );  // Evaluates to 'alignof( Int )'

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:

using Type = blaze::HybridMatrix<double,3UL,5UL>;
using Allocator = blaze::AlignedAllocator<Type>;

std::vector<Type> v1;  // Might be misaligned for AVX or AVX-512
std::vector<Type,Allocator> v2;  // Properly aligned for AVX or AVX-512

CustomMatrix

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

#include <blaze/Blaze.h>
// or
#include <blaze/Math.h>
// or
#include <blaze/math/CustomMatrix.h>

and forward declared via the header file

#include <blaze/Forward.h>

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:

namespace blaze {

template< typename Type, bool AF, bool PF, bool SO, typename Tag >
class CustomMatrix;

} // namespace blaze
  • Type : specifies the type of the matrix elements. 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:

using blaze::CustomMatrix;
using blaze::Deallocate;
using blaze::aligned;
using blaze::unaligned;
using blaze::padded;
using blaze::unpadded;

// Definition of an unmanaged 3x4 custom matrix for unaligned, unpadded integer arrays
using UnalignedUnpadded = CustomMatrix<int,unaligned,unpadded,rowMajor>;
std::vector<int> vec( 12UL )
UnalignedUnpadded A( &vec[0], 3UL, 4UL );

// Definition of a managed 5x6 custom matrix for unaligned but padded 'float' arrays
using UnalignedPadded = CustomMatrix<float,unaligned,padded,columnMajor>;
std::unique_ptr<float[]> memory1( new float[40] );
UnalignedPadded B( memory1.get(), 5UL, 6UL, 8UL );

// Definition of a managed 12x13 custom matrix for aligned, unpadded 'double' arrays
using AlignedUnpadded = CustomMatrix<double,aligned,unpadded,rowMajor>;
std::unique_ptr<double[],Deallocate> memory2( blaze::allocate<double>( 192UL ) );
AlignedUnpadded C( memory2.get(), 12UL, 13UL, 16UL );

// Definition of a 7x14 custom matrix for aligned, padded 'complex<double>' arrays
using cplx = complex<double>;
using AlignedPadded = CustomMatrix<cplx,aligned,padded,columnMajor>;
std::unique_ptr<cplx[],Deallocate> memory3( blaze::allocate<cplx>( 112UL ) );
AlignedPadded D( memory3.get(), 7UL, 14UL, 16UL );

In comparison with the remaining Blaze dense matrix types 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:

Memory Management

The 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:

using blaze::CustomMatrix;
using blaze::Deallocate;
using blaze::allocate;
using blaze::aligned;
using blaze::unaligned;
using blaze::padded;
using blaze::unpadded;

// Definition of a 3x4 custom row-major matrix with unaligned, unpadded and externally
// managed integer array. Note that the std::vector must be guaranteed to outlive the
// custom matrix!
std::vector<int> vec( 12UL );
CustomMatrix<int,unaligned,unpadded> A( &vec[0], 3UL, 4UL );

// Definition of a custom 8x12 matrix for an aligned and padded integer array of
// capacity 128 (including 8 padding elements per row). Note that the std::unique_ptr
// must be guaranteed to outlive the custom matrix!
std::unique_ptr<int[],Deallocate> memory( allocate<int>( 128UL ) );
CustomMatrix<int,aligned,padded> B( memory.get(), 8UL, 12UL, 16UL );
Copy Operations

As with all dense matrices it is possible to copy construct a custom matrix:

using blaze::CustomMatrix;
using blaze::unaligned;
using blaze::unpadded;

using CustomType = CustomMatrix<int,unaligned,unpadded>;

std::vector<int> vec( 6UL, 10 );    // Vector of 6 integers of the value 10
CustomType A( &vec[0], 2UL, 3UL );  // Represent the std::vector as Blaze dense matrix
a[1] = 20;                          // Also modifies the std::vector

CustomType B( a );  // Creating a copy of vector a
b[2] = 20;          // Also affects matrix A and the std::vector

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:

std::vector<int> vec2( 6UL, 4 );     // Vector of 6 integers of the value 4
CustomType C( &vec2[0], 2UL, 3UL );  // Represent the std::vector as Blaze dense matrix

A = C;  // Copy assignment: Set all values of matrix A and B to 4.
Alignment

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:

using blaze::CustomMatrix;
using blaze::Deallocate;
using blaze::allocate;
using blaze::aligned;
using blaze::padded;
using blaze::rowMajor;

// Allocation of 32-bit aligned memory
std::unique_ptr<int[],Deallocate> memory( allocate<int>( 40UL ) );

CustomMatrix<int,aligned,padded,rowMajor> A( memory.get(), 5UL, 6UL, 8UL );

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.

Padding

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 instruction:

using blaze::CustomMatrix;
using blaze::Deallocate;
using blaze::allocate;
using blaze::aligned;
using blaze::padded;

using CustomType = CustomMatrix<double,aligned,padded>;

std::unique_ptr<double[],Deallocate> memory1( allocate<double>( 12UL ) );
std::unique_ptr<double[],Deallocate> memory2( allocate<double>( 12UL ) );
std::unique_ptr<double[],Deallocate> memory3( allocate<double>( 12UL ) );

// Creating padded custom 3x3 matrix with an additional padding element in each row
CustomType A( memory1.get(), 3UL, 3UL, 4UL );
CustomType B( memory2.get(), 3UL, 3UL, 4UL );
CustomType C( memory3.get(), 3UL, 3UL, 4UL );

// ... Initialization

C = A + B;  // AVX-based matrix addition

In this example, maximum performance is possible. However, in case no padding elements are inserted a scalar addition has to be used:

using blaze::CustomMatrix;
using blaze::Deallocate;
using blaze::allocate;
using blaze::aligned;
using blaze::unpadded;

using CustomType = CustomMatrix<double,aligned,unpadded>;

std::unique_ptr<double[],Deallocate> memory1( allocate<double>( 9UL ) );
std::unique_ptr<double[],Deallocate> memory2( allocate<double>( 9UL ) );
std::unique_ptr<double[],Deallocate> memory3( allocate<double>( 9UL ) );

// Creating unpadded custom 3x3 matrix
CustomType A( memory1.get(), 3UL, 3UL );
CustomType B( memory2.get(), 3UL, 3UL );
CustomType C( memory3.get(), 3UL, 3UL );

// ... Initialization

C = A + B;  // Scalar matrix addition

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.

UniformMatrix

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

#include <blaze/Blaze.h>
// or
#include <blaze/Math.h>
// or
#include <blaze/math/UniformMatrix.h>

and forward declared via the header file

#include <blaze/Forward.h>

The type of the elements, the storage order, and the group tag of the matrix can be specified via the three template parameters:

namespace blaze {

template< typename Type, bool SO, typename Tag >
class UniformMatrix;

} // namespace blaze
  • 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:

// Definition of a 3x4 integral row-major matrix
blaze::UniformMatrix<int> A( 3UL, 4UL );

// Definition of a 4x6 single precision row-major matrix
blaze::UniformMatrix<float,blaze::rowMajor> B( 4UL, 6UL );

// Definition of a double precision column-major matrix with 0 rows and columns
blaze::UniformMatrix<double,blaze::columnMajor> C;

Sparse Matrices

CompressedMatrix

The blaze::CompressedMatrix class template is the representation of an arbitrary sized sparse matrix with MxN dynamically allocated elements of arbitrary type. It can be included via the header files

#include <blaze/Blaze.h>
// or
#include <blaze/Math.h>
// or
#include <blaze/math/CompressedMatrix.h>

and forward declared via the header file

#include <blaze/Forward.h>

The type of the elements, the storage order, and the group tag of the matrix can be specified via the three template parameters:

namespace blaze {

template< typename Type, bool SO, typename Tag >
class CompressedMatrix;

} // namespace blaze
  • Type : specifies the type of the matrix elements. CompressedMatrix can be used with any non-cv-qualified element type (including vector and other matrix types).
  • 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:

// Definition of a 3x4 integral row-major matrix
blaze::CompressedMatrix<int> A( 3UL, 4UL );

// Definition of a 4x6 single precision row-major matrix
blaze::CompressedMatrix<float,blaze::rowMajor> B( 4UL, 6UL );

// Definition of a double precision column-major matrix with 0 rows and columns
blaze::CompressedMatrix<double,blaze::columnMajor> C;

IdentityMatrix

The blaze::IdentityMatrix class template is the representation of an immutable, arbitrary sized identity matrix with NxN elements of arbitrary type. It can be included via the header files

#include <blaze/Blaze.h>
// or
#include <blaze/Math.h>
// or
#include <blaze/math/IdentityMatrix.h>

and forward declared via the header file

#include <blaze/Forward.h>

The type of the elements, the storage order, and the group tag of the matrix can be specified via the three template parameters:

namespace blaze {

template< typename Type, bool SO, typename Tag >
class IdentityMatrix;

} // namespace blaze
  • 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:

// Definition of a 3x3 integral row-major identity matrix
blaze::IdentityMatrix<int> A( 3UL );

// Definition of a 6x6 single precision row-major identity matrix
blaze::IdentityMatrix<float,blaze::rowMajor> B( 6UL );

// Definition of a double precision column-major identity matrix with 0 rows and columns
blaze::IdentityMatrix<double,blaze::columnMajor> C;

ZeroMatrix

The blaze::ZeroMatrix class template is the representation of an immutable, arbitrary sized zero matrix with MxN elements of arbitrary type. It can be included via the header files

#include <blaze/Blaze.h>
// or
#include <blaze/Math.h>
// or
#include <blaze/math/ZeroMatrix.h>

and forward declared via the header file

#include <blaze/Forward.h>

The type of the elements, the storage order, and the group tag of the matrix can be specified via the three template parameters:

namespace blaze {

template< typename Type, bool SO, typename Tag >
class ZeroMatrix;

} // namespace blaze
  • 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:

// Definition of a 3x5 integral row-major zero matrix
blaze::ZeroMatrix<int> A( 3UL, 5UL );

// Definition of a 6x4 single precision row-major zero matrix
blaze::ZeroMatrix<float,blaze::rowMajor> B( 6UL, 4UL );

// Definition of a double precision column-major zero matrix with 0 rows and columns
blaze::ZeroMatrix<double,blaze::columnMajor> C;

Previous: Matrices ---- Next: Matrix Operations

Updated