Modules | Classes
Matrices

Modules

 Dense Matrices
 
 Sparse Matrices
 

Classes

struct  blaze::Matrix< MT, SO >
 Base class for matrices.The Matrix class is a base class for all dense and sparse matrix classes within the Blaze library. It provides an abstraction from the actual type of the matrix, but enables a conversion back to this type via the 'Curiously Recurring Template Pattern' (CRTP). More...
 

Matrix global functions

template<typename MT , bool SO>
BLAZE_ALWAYS_INLINE MT::Iterator blaze::begin (Matrix< MT, SO > &matrix, size_t i)
 Returns an iterator to the first element of row/column i. More...
 
template<typename MT , bool SO>
BLAZE_ALWAYS_INLINE MT::ConstIterator blaze::begin (const Matrix< MT, SO > &matrix, size_t i)
 Returns an iterator to the first element of row/column i. More...
 
template<typename MT , bool SO>
BLAZE_ALWAYS_INLINE MT::ConstIterator blaze::cbegin (const Matrix< MT, SO > &matrix, size_t i)
 Returns an iterator to the first element of row/column i. More...
 
template<typename MT , bool SO>
BLAZE_ALWAYS_INLINE MT::Iterator blaze::end (Matrix< MT, SO > &matrix, size_t i)
 Returns an iterator just past the last element of row/column i. More...
 
template<typename MT , bool SO>
BLAZE_ALWAYS_INLINE MT::ConstIterator blaze::end (const Matrix< MT, SO > &matrix, size_t i)
 Returns an iterator just past the last element of row/column i. More...
 
template<typename MT , bool SO>
BLAZE_ALWAYS_INLINE MT::ConstIterator blaze::cend (const Matrix< MT, SO > &matrix, size_t i)
 Returns an iterator just past the last element of row/column i. More...
 
template<typename MT , bool SO>
BLAZE_ALWAYS_INLINE size_t blaze::rows (const Matrix< MT, SO > &matrix) noexcept
 Returns the current number of rows of the matrix. More...
 
template<typename MT , bool SO>
BLAZE_ALWAYS_INLINE size_t blaze::columns (const Matrix< MT, SO > &matrix) noexcept
 Returns the current number of columns of the matrix. More...
 
template<typename MT , bool SO>
BLAZE_ALWAYS_INLINE size_t blaze::capacity (const Matrix< MT, SO > &matrix) noexcept
 Returns the maximum capacity of the matrix. More...
 
template<typename MT , bool SO>
BLAZE_ALWAYS_INLINE size_t blaze::capacity (const Matrix< MT, SO > &matrix, size_t i) noexcept
 Returns the current capacity of the specified row/column. More...
 
template<typename MT , bool SO>
BLAZE_ALWAYS_INLINE size_t blaze::nonZeros (const Matrix< MT, SO > &matrix)
 Returns the total number of non-zero elements in the matrix. More...
 
template<typename MT , bool SO>
BLAZE_ALWAYS_INLINE size_t blaze::nonZeros (const Matrix< MT, SO > &matrix, size_t i)
 Returns the number of non-zero elements in the specified row/column. More...
 
template<typename MT , bool SO>
BLAZE_ALWAYS_INLINE void blaze::resize (Matrix< MT, SO > &matrix, size_t m, size_t n, bool preserve)
 Changing the size of the matrix. More...
 
template<typename MT , bool SO>
BLAZE_ALWAYS_INLINE void blaze::shrinkToFit (Matrix< MT, SO > &matrix)
 Requesting the removal of unused capacity. More...
 
template<typename MT , bool SO>
BLAZE_ALWAYS_INLINE void blaze::transpose (Matrix< MT, SO > &matrix)
 In-place transpose of the given matrix. More...
 
template<typename MT , bool SO>
BLAZE_ALWAYS_INLINE void blaze::ctranspose (Matrix< MT, SO > &matrix)
 In-place conjugate transpose of the given matrix. More...
 
template<typename MT , bool SO>
const MT::ResultType blaze::evaluate (const Matrix< MT, SO > &matrix)
 Evaluates the given matrix expression. More...
 
template<typename MT , bool SO>
BLAZE_ALWAYS_INLINE bool blaze::isSquare (const Matrix< MT, SO > &matrix) noexcept
 Checks if the given matrix is a square matrix. More...
 
template<typename MT1 , bool SO1, typename MT2 , bool SO2>
BLAZE_ALWAYS_INLINE bool blaze::isSame (const Matrix< MT1, SO1 > &a, const Matrix< MT2, SO2 > &b) noexcept
 Returns whether the two given matrices represent the same observable state. More...
 

Matrix functions

template<typename MT , bool SO>
bool blaze::isSymmetric (const Matrix< MT, SO > &m)
 Checks if the given matrix is symmetric. More...
 
template<typename MT , bool SO>
bool blaze::isHermitian (const Matrix< MT, SO > &m)
 Checks if the given matrix is Hermitian. More...
 
template<typename MT , bool SO>
bool blaze::isUniform (const Matrix< MT, SO > &m)
 Checks if the given matrix is a uniform matrix. More...
 
template<typename MT , bool SO>
bool blaze::isLower (const Matrix< MT, SO > &m)
 Checks if the given matrix is a lower triangular matrix. More...
 
template<typename MT , bool SO>
bool blaze::isUniLower (const Matrix< MT, SO > &m)
 Checks if the given matrix is a lower unitriangular matrix. More...
 
template<typename MT , bool SO>
bool blaze::isStrictlyLower (const Matrix< MT, SO > &m)
 Checks if the given matrix is a strictly lower triangular matrix. More...
 
template<typename MT , bool SO>
bool blaze::isUpper (const Matrix< MT, SO > &m)
 Checks if the given matrix is an upper triangular matrix. More...
 
template<typename MT , bool SO>
bool blaze::isUniUpper (const Matrix< MT, SO > &m)
 Checks if the given matrix is an upper unitriangular matrix. More...
 
template<typename MT , bool SO>
bool blaze::isStrictlyUpper (const Matrix< MT, SO > &m)
 Checks if the given matrix is a strictly upper triangular matrix. More...
 
template<typename MT , bool SO>
bool blaze::isDiagonal (const Matrix< MT, SO > &m)
 Checks if the give matrix is diagonal. More...
 
template<typename MT , bool SO>
bool blaze::isIdentity (const Matrix< MT, SO > &m)
 Checks if the give matrix is an identity matrix. More...
 
template<typename MT , bool SO>
auto blaze::trace (const Matrix< MT, SO > &m)
 Computes the trace of the given square matrix. More...
 

Matrix operators

template<typename MT , bool SO>
std::ostream & blaze::operator<< (std::ostream &os, const Matrix< MT, SO > &m)
 Global output operator for dense and sparse matrices. More...
 

Detailed Description

Function Documentation

◆ begin() [1/2]

template<typename MT , bool SO>
BLAZE_ALWAYS_INLINE MT::Iterator blaze::begin ( Matrix< MT, SO > &  matrix,
size_t  i 
)

Returns an iterator to the first element of row/column i.

Parameters
matrixThe given dense or sparse matrix.
iThe row/column index.
Returns
Iterator to the first element of row/column i.

This function returns a row/column iterator to the first element of row/column i. In case the given matrix is a row-major matrix the function returns an iterator to the first element of row i, in case it is a column-major matrix the function returns an iterator to the first element of column i.

◆ begin() [2/2]

template<typename MT , bool SO>
BLAZE_ALWAYS_INLINE MT::ConstIterator blaze::begin ( const Matrix< MT, SO > &  matrix,
size_t  i 
)

Returns an iterator to the first element of row/column i.

Parameters
matrixThe given dense or sparse matrix.
iThe row/column index.
Returns
Iterator to the first element of row/column i.

This function returns a row/column iterator to the first element of row/column i. In case the given matrix is a row-major matrix the function returns an iterator to the first element of row i, in case it is a column-major matrix the function returns an iterator to the first element of column i.

◆ capacity() [1/2]

template<typename MT , bool SO>
BLAZE_ALWAYS_INLINE size_t blaze::capacity ( const Matrix< MT, SO > &  matrix)
noexcept

Returns the maximum capacity of the matrix.

Parameters
matrixThe given matrix.
Returns
The capacity of the matrix.

◆ capacity() [2/2]

template<typename MT , bool SO>
BLAZE_ALWAYS_INLINE size_t blaze::capacity ( const Matrix< MT, SO > &  matrix,
size_t  i 
)
noexcept

Returns the current capacity of the specified row/column.

Parameters
matrixThe given matrix.
iThe index of the row/column.
Returns
The current capacity of row/column i.

This function returns the current capacity of the specified row/column. In case the storage order is set to rowMajor the function returns the capacity of row i, in case the storage flag is set to columnMajor the function returns the capacity of column i.

◆ cbegin()

template<typename MT , bool SO>
BLAZE_ALWAYS_INLINE MT::ConstIterator blaze::cbegin ( const Matrix< MT, SO > &  matrix,
size_t  i 
)

Returns an iterator to the first element of row/column i.

Parameters
matrixThe given dense or sparse matrix.
iThe row/column index.
Returns
Iterator to the first element of row/column i.

This function returns a row/column iterator to the first element of row/column i. In case the given matrix is a row-major matrix the function returns an iterator to the first element of row i, in case it is a column-major matrix the function returns an iterator to the first element of column i.

◆ cend()

template<typename MT , bool SO>
BLAZE_ALWAYS_INLINE MT::ConstIterator blaze::cend ( const Matrix< MT, SO > &  matrix,
size_t  i 
)

Returns an iterator just past the last element of row/column i.

Parameters
matrixThe given dense or sparse matrix.
iThe row/column index.
Returns
Iterator just past the last element of row/column i.

This function returns an row/column iterator just past the last element of row/column i. In case the given matrix is a row-major matrix the function returns an iterator just past the last element of row i, in case it is a column-major matrix the function returns an iterator just past the last element of column i.

◆ columns()

template<typename MT , bool SO>
BLAZE_ALWAYS_INLINE size_t blaze::columns ( const Matrix< MT, SO > &  matrix)
noexcept

Returns the current number of columns of the matrix.

Parameters
matrixThe given matrix.
Returns
The number of columns of the matrix.

◆ ctranspose()

template<typename MT , bool SO>
BLAZE_ALWAYS_INLINE void blaze::ctranspose ( Matrix< MT, SO > &  matrix)

In-place conjugate transpose of the given matrix.

Parameters
matrixThe given matrix to be transposed.
Returns
void
Exceptions
std::logic_errorMatrix cannot be transposed.

This function transposes the given matrix in-place. The function fails if ...

  • ... the given matrix has a fixed size and is non-square;
  • ... the given matrix is a triangular matrix;
  • ... the given submatrix affects the restricted parts of a triangular matrix;
  • ... the given submatrix would cause non-deterministic results in a symmetric/Hermitian matrix.

In all failure cases a std::logic_error exception is thrown.

◆ end() [1/2]

template<typename MT , bool SO>
BLAZE_ALWAYS_INLINE MT::Iterator blaze::end ( Matrix< MT, SO > &  matrix,
size_t  i 
)

Returns an iterator just past the last element of row/column i.

Parameters
matrixThe given dense or sparse matrix.
iThe row/column index.
Returns
Iterator just past the last element of row/column i.

This function returns an row/column iterator just past the last element of row/column i. In case the given matrix is a row-major matrix the function returns an iterator just past the last element of row i, in case it is a column-major matrix the function returns an iterator just past the last element of column i.

◆ end() [2/2]

template<typename MT , bool SO>
BLAZE_ALWAYS_INLINE MT::ConstIterator blaze::end ( const Matrix< MT, SO > &  matrix,
size_t  i 
)

Returns an iterator just past the last element of row/column i.

Parameters
matrixThe given dense or sparse matrix.
iThe row/column index.
Returns
Iterator just past the last element of row/column i.

This function returns an row/column iterator just past the last element of row/column i. In case the given matrix is a row-major matrix the function returns an iterator just past the last element of row i, in case it is a column-major matrix the function returns an iterator just past the last element of column i.

◆ evaluate()

template<typename MT , bool SO>
const MT::ResultType blaze::evaluate ( const Matrix< MT, SO > &  matrix)
inline

Evaluates the given matrix expression.

Parameters
matrixThe matrix to be evaluated.
Returns
The result of the evaluated matrix expression.

This function forces an evaluation of the given matrix expression and enables an automatic deduction of the correct result type of an operation. The following code example demonstrates its intended use for the multiplication of a lower and a strictly lower dense matrix:

LowerMatrix< DynamicMatrix<double> > A;
StrictlyLowerMatrix< DynamicMatrix<double> > B;
// ... Resizing and initialization
auto C = evaluate( A * B );

In this scenario, the evaluate() function assists in deducing the exact result type of the operation via the 'auto' keyword. Please note that if evaluate() is used in this way, no temporary matrix is created and no copy operation is performed. Instead, the result is directly written to the target matrix due to the return value optimization (RVO). However, if evaluate() is used in combination with an explicit target type, a temporary will be created and a copy operation will be performed if the used type differs from the type returned from the function:

StrictlyLowerMatrix< DynamicMatrix<double> > D( A * B ); // No temporary & no copy operation
LowerMatrix< DynamicMatrix<double> > E( A * B ); // Temporary & copy operation
DynamicMatrix<double> F( A * B ); // Temporary & copy operation
D = evaluate( A * B ); // Temporary & copy operation

Sometimes it might be desirable to explicitly evaluate a sub-expression within a larger expression. However, please note that evaluate() is not intended to be used for this purpose. This task is more elegantly and efficiently handled by the eval() function:

D = A + evaluate( B * C ); // Unnecessary creation of a temporary matrix
D = A + eval( B * C ); // No creation of a temporary matrix

In contrast to the evaluate() function, eval() can take the complete expression into account and therefore can guarantee the most efficient way to evaluate it.

◆ isDiagonal()

template<typename MT , bool SO>
bool blaze::isDiagonal ( const Matrix< MT, SO > &  m)
inline

Checks if the give matrix is diagonal.

Parameters
mThe matrix to be checked.
Returns
true if the matrix is diagonal, false if not.

This function checks if the given dense or sparse matrix is diagonal, i.e. if the non-diagonal elements are default elements. In case of integral or floating point data types, a diagonal matrix has the form

\[\left(\begin{array}{*{5}{c}} aa & 0 & 0 & \cdots & 0 \\ 0 & bb & 0 & \cdots & 0 \\ 0 & 0 & cc & \cdots & 0 \\ \vdots & \vdots & \vdots & \ddots & 0 \\ 0 & 0 & 0 & 0 & xx \\ \end{array}\right)\]

$ 0 \times 0 $ or $ 1 \times 1 $ matrices are considered as trivially diagonal. The following example demonstrates the use of the function:

// ... Initialization
if( isDiagonal( A ) ) { ... }

Optionally, it is possible to switch between strict semantics (blaze::strict) and relaxed semantics (blaze::relaxed):

if( isDiagonal<relaxed>( A ) ) { ... }

It is also possible to check if a matrix expression results in a diagonal matrix:

if( isDiagonal( A * B ) ) { ... }

However, note that this might require the complete evaluation of the expression, including the generation of a temporary matrix.

◆ isHermitian()

template<typename MT , bool SO>
bool blaze::isHermitian ( const Matrix< MT, SO > &  m)
inline

Checks if the given matrix is Hermitian.

Parameters
mThe matrix to be checked.
Returns
true if the matrix is Hermitian, false if not.

This function checks if the given dense or sparse matrix is an Hermitian matrix. The matrix is considered to be an Hermitian matrix if it is a square matrix whose conjugate transpose is equal to itself ( $ A = \overline{A^T} $), i.e. each matrix element $ a_{ij} $ is equal to the complex conjugate of the element $ a_{ji} $. The following code example demonstrates the use of the function:

// ... Initialization
if( isHermitian( A ) ) { ... }

Optionally, it is possible to switch between strict semantics (blaze::strict) and relaxed semantics (blaze::relaxed):

if( isHermitian<relaxed>( A ) ) { ... }

It is also possible to check if a matrix expression results in an Hermitian matrix:

if( isHermitian( A * B ) ) { ... }

However, note that this might require the complete evaluation of the expression, including the generation of a temporary matrix.

◆ isIdentity()

template<typename MT , bool SO>
bool blaze::isIdentity ( const Matrix< MT, SO > &  m)
inline

Checks if the give matrix is an identity matrix.

Parameters
mThe matrix to be checked.
Returns
true if the matrix is an identity matrix, false if not.

This function checks if the given dense or sparse matrix is an identity matrix, i.e. if the diagonal elements are 1 and the non-diagonal elements are 0. In case of integral or floating point data types, an identity matrix has the form

\[\left(\begin{array}{*{5}{c}} 1 & 0 & 0 & \cdots & 0 \\ 0 & 1 & 0 & \cdots & 0 \\ 0 & 0 & 1 & \cdots & 0 \\ \vdots & \vdots & \vdots & \ddots & 0 \\ 0 & 0 & 0 & 0 & 1 \\ \end{array}\right)\]

The following example demonstrates the use of the function:

// ... Initialization
if( isIdentity( A ) ) { ... }

Optionally, it is possible to switch between strict semantics (blaze::strict) and relaxed semantics (blaze::relaxed):

if( isIdentity<relaxed>( A ) ) { ... }

It is also possible to check if a matrix expression results in an identity matrix:

if( isIdentity( A * B ) ) { ... }

However, note that this might require the complete evaluation of the expression, including the generation of a temporary matrix.

◆ isLower()

template<typename MT , bool SO>
bool blaze::isLower ( const Matrix< MT, SO > &  m)
inline

Checks if the given matrix is a lower triangular matrix.

Parameters
mThe matrix to be checked.
Returns
true if the matrix is a lower triangular matrix, false if not.

This function checks if the given dense or sparse matrix is a lower triangular matrix. The matrix is considered to be lower triangular if it is a square matrix of the form

\[\left(\begin{array}{*{5}{c}} l_{0,0} & 0 & 0 & \cdots & 0 \\ l_{1,0} & l_{1,1} & 0 & \cdots & 0 \\ l_{2,0} & l_{2,1} & l_{2,2} & \cdots & 0 \\ \vdots & \vdots & \vdots & \ddots & \vdots \\ l_{N,0} & l_{N,1} & l_{N,2} & \cdots & l_{N,N} \\ \end{array}\right).\]

$ 0 \times 0 $ or $ 1 \times 1 $ matrices are considered as trivially lower triangular. The following code example demonstrates the use of the function:

// ... Initialization
if( isLower( A ) ) { ... }

Optionally, it is possible to switch between strict semantics (blaze::strict) and relaxed semantics (blaze::relaxed):

if( isLower<relaxed>( A ) ) { ... }

It is also possible to check if a matrix expression results in a lower triangular matrix:

if( isLower( A * B ) ) { ... }

However, note that this might require the complete evaluation of the expression, including the generation of a temporary matrix.

◆ isSame()

template<typename MT1 , bool SO1, typename MT2 , bool SO2>
BLAZE_ALWAYS_INLINE bool blaze::isSame ( const Matrix< MT1, SO1 > &  a,
const Matrix< MT2, SO2 > &  b 
)
noexcept

Returns whether the two given matrices represent the same observable state.

Parameters
aThe first matrix to be tested for its state.
bThe second matrix to be tested for its state.
Returns
true in case the two matrices share a state, false otherwise.

The isSame function provides an abstract interface for testing if the two given matrices represent the same observable state. This happens for instance in case a and b refer to the same matrix or in case a and b are aliases for the same matrix. In case both matrices represent the same observable state, the function returns true, other it returns false.

using MatrixType = blaze::DynamicMatrix<int>;
using SubmatrixType = blaze::Submatrix<MatrixType>;
MatrixType mat1( 4UL, 5UL ); // Setup of a 4x5 dynamic matrix
MatrixType mat2( 4UL, 5UL ); // Setup of a second 4x5 dynamic matrix
SubmatrixType sub1 = submatrix( mat1, 0UL, 0UL, 4UL, 5UL ); // Submatrix fully covering mat1
SubmatrixType sub2 = submatrix( mat1, 1UL, 1UL, 2UL, 3UL ); // Submatrix partially covering mat1
SubmatrixType sub3 = submatrix( mat1, 1UL, 1UL, 2UL, 3UL ); // Submatrix partially covering mat1
isSame( mat1, mat1 ); // returns true since both objects refer to the same matrix
isSame( mat1, mat2 ); // returns false since mat1 and mat2 are two different matrices
isSame( mat1, sub1 ); // returns true since sub1 represents the same observable state as mat1
isSame( mat1, sub3 ); // returns false since sub3 only covers part of mat1
isSame( sub2, sub3 ); // returns true since sub1 and sub2 refer to exactly the same part of mat1
isSame( sub1, sub3 ); // returns false since sub1 and sub3 refer to different parts of mat1

◆ isSquare()

template<typename MT , bool SO>
BLAZE_ALWAYS_INLINE bool blaze::isSquare ( const Matrix< MT, SO > &  matrix)
noexcept

Checks if the given matrix is a square matrix.

Parameters
matrixThe matrix to be checked.
Returns
true if the matrix is a square matrix, false if not.

This function checks if the number of rows and columns of the given matrix are equal. If they are, the function returns true, otherwise it returns false.

◆ isStrictlyLower()

template<typename MT , bool SO>
bool blaze::isStrictlyLower ( const Matrix< MT, SO > &  m)
inline

Checks if the given matrix is a strictly lower triangular matrix.

Parameters
mThe matrix to be checked.
Returns
true if the matrix is a strictly lower triangular matrix, false if not.

This function checks if the given dense or sparse matrix is a strictly lower triangular matrix. The matrix is considered to be strictly lower triangular if it is a square matrix of the form

\[\left(\begin{array}{*{5}{c}} 0 & 0 & 0 & \cdots & 0 \\ l_{1,0} & 0 & 0 & \cdots & 0 \\ l_{2,0} & l_{2,1} & 0 & \cdots & 0 \\ \vdots & \vdots & \vdots & \ddots & \vdots \\ l_{N,0} & l_{N,1} & l_{N,2} & \cdots & 0 \\ \end{array}\right).\]

The following code example demonstrates the use of the function:

// ... Initialization
if( isStrictlyLower( A ) ) { ... }

Optionally, it is possible to switch between strict semantics (blaze::strict) and relaxed semantics (blaze::relaxed):

if( isStrictlyLower<relaxed>( A ) ) { ... }

It is also possible to check if a matrix expression results in a strictly lower triangular matrix:

if( isStrictlyLower( A * B ) ) { ... }

However, note that this might require the complete evaluation of the expression, including the generation of a temporary matrix.

◆ isStrictlyUpper()

template<typename MT , bool SO>
bool blaze::isStrictlyUpper ( const Matrix< MT, SO > &  m)
inline

Checks if the given matrix is a strictly upper triangular matrix.

Parameters
mThe matrix to be checked.
Returns
true if the matrix is a strictly upper triangular matrix, false if not.

This function checks if the given dense or sparse matrix is a strictly upper triangular matrix. The matrix is considered to be strictly upper triangular if it is a square matrix of the form

\[\left(\begin{array}{*{5}{c}} 0 & u_{0,1} & u_{0,2} & \cdots & u_{0,N} \\ 0 & 0 & u_{1,2} & \cdots & u_{1,N} \\ 0 & 0 & 0 & \cdots & u_{2,N} \\ \vdots & \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & 0 & \cdots & 0 \\ \end{array}\right).\]

The following code example demonstrates the use of the function:

// ... Initialization
if( isStrictlyUpper( A ) ) { ... }

Optionally, it is possible to switch between strict semantics (blaze::strict) and relaxed semantics (blaze::relaxed):

if( isStrictlyUpper<relaxed>( A ) ) { ... }

It is also possible to check if a matrix expression results in a strictly upper triangular matrix:

if( isStrictlyUpper( A * B ) ) { ... }

However, note that this might require the complete evaluation of the expression, including the generation of a temporary matrix.

◆ isSymmetric()

template<typename MT , bool SO>
bool blaze::isSymmetric ( const Matrix< MT, SO > &  m)
inline

Checks if the given matrix is symmetric.

Parameters
mThe matrix to be checked.
Returns
true if the matrix is symmetric, false if not.

This function checks if the given dense or sparse matrix is symmetric. The matrix is considered to be symmetric if it is a square matrix whose transpose is equal to itself ( $ A = A^T $). The following code example demonstrates the use of the function:

// ... Initialization
if( isSymmetric( A ) ) { ... }

Optionally, it is possible to switch between strict semantics (blaze::strict) and relaxed semantics (blaze::relaxed):

if( isSymmetric<relaxed>( A ) ) { ... }

It is also possible to check if a matrix expression results in a symmetric matrix:

if( isSymmetric( A * B ) ) { ... }

However, note that this might require the complete evaluation of the expression, including the generation of a temporary matrix.

◆ isUniform()

template<typename MT , bool SO>
bool blaze::isUniform ( const Matrix< MT, SO > &  m)
inline

Checks if the given matrix is a uniform matrix.

Parameters
mThe matrix to be checked.
Returns
true if the matrix is a uniform matrix, false if not.

This function checks if the given dense or sparse matrix is a uniform matrix. The matrix is considered to be uniform if all its elements are identical. The following code example demonstrates the use of the function:

// ... Initialization
if( isUniform( A ) ) { ... }

Optionally, it is possible to switch between strict semantics (blaze::strict) and relaxed semantics (blaze::relaxed):

if( isUniform<relaxed>( A ) ) { ... }

It is also possible to check if a matrix expression results in a uniform matrix:

if( isUniform( A * B ) ) { ... }

However, note that this might require the complete evaluation of the expression, including the generation of a temporary matrix.

◆ isUniLower()

template<typename MT , bool SO>
bool blaze::isUniLower ( const Matrix< MT, SO > &  m)
inline

Checks if the given matrix is a lower unitriangular matrix.

Parameters
mThe matrix to be checked.
Returns
true if the matrix is a lower unitriangular matrix, false if not.

This function checks if the given dense or sparse matrix is a lower unitriangular matrix. The matrix is considered to be lower unitriangular if it is a square matrix of the form

\[\left(\begin{array}{*{5}{c}} 1 & 0 & 0 & \cdots & 0 \\ l_{1,0} & 1 & 0 & \cdots & 0 \\ l_{2,0} & l_{2,1} & 1 & \cdots & 0 \\ \vdots & \vdots & \vdots & \ddots & \vdots \\ l_{N,0} & l_{N,1} & l_{N,2} & \cdots & 1 \\ \end{array}\right).\]

The following code example demonstrates the use of the function:

// ... Initialization
if( isUniLower( A ) ) { ... }

Optionally, it is possible to switch between strict semantics (blaze::strict) and relaxed semantics (blaze::relaxed):

if( isUniLower<relaxed>( A ) ) { ... }

It is also possible to check if a matrix expression results in a lower unitriangular matrix:

if( isUniLower( A * B ) ) { ... }

However, note that this might require the complete evaluation of the expression, including the generation of a temporary matrix.

◆ isUniUpper()

template<typename MT , bool SO>
bool blaze::isUniUpper ( const Matrix< MT, SO > &  m)
inline

Checks if the given matrix is an upper unitriangular matrix.

Parameters
mThe matrix to be checked.
Returns
true if the matrix is an upper unitriangular matrix, false if not.

This function checks if the given dense or sparse matrix is an upper unitriangular matrix. The matrix is considered to be upper unitriangular if it is a square matrix of the form

\[\left(\begin{array}{*{5}{c}} 1 & u_{0,1} & u_{0,2} & \cdots & u_{0,N} \\ 0 & 1 & u_{1,2} & \cdots & u_{1,N} \\ 0 & 0 & 1 & \cdots & u_{2,N} \\ \vdots & \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & 0 & \cdots & 1 \\ \end{array}\right).\]

The following code example demonstrates the use of the function:

// ... Initialization
if( isUniUpper( A ) ) { ... }

Optionally, it is possible to switch between strict semantics (blaze::strict) and relaxed semantics (blaze::relaxed):

if( isUniUpper<relaxed>( A ) ) { ... }

It is also possible to check if a matrix expression results in an upper unitriangular matrix:

if( isUniUpper( A * B ) ) { ... }

However, note that this might require the complete evaluation of the expression, including the generation of a temporary matrix.

◆ isUpper()

template<typename MT , bool SO>
bool blaze::isUpper ( const Matrix< MT, SO > &  m)
inline

Checks if the given matrix is an upper triangular matrix.

Parameters
mThe matrix to be checked.
Returns
true if the matrix is an upper triangular matrix, false if not.

This function checks if the given dense or sparse matrix is an upper triangular matrix. The matrix is considered to be upper triangular if it is a square matrix of the form

\[\left(\begin{array}{*{5}{c}} u_{0,0} & u_{0,1} & u_{0,2} & \cdots & u_{0,N} \\ 0 & u_{1,1} & u_{1,2} & \cdots & u_{1,N} \\ 0 & 0 & u_{2,2} & \cdots & u_{2,N} \\ \vdots & \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & 0 & \cdots & u_{N,N} \\ \end{array}\right).\]

$ 0 \times 0 $ or $ 1 \times 1 $ matrices are considered as trivially upper triangular. The following code example demonstrates the use of the function:

// ... Initialization
if( isUpper( A ) ) { ... }

Optionally, it is possible to switch between strict semantics (blaze::strict) and relaxed semantics (blaze::relaxed):

if( isUpper<relaxed>( A ) ) { ... }

It is also possible to check if a matrix expression results in an upper triangular matrix:

if( isUpper( A * B ) ) { ... }

However, note that this might require the complete evaluation of the expression, including the generation of a temporary matrix.

◆ nonZeros() [1/2]

template<typename MT , bool SO>
BLAZE_ALWAYS_INLINE size_t blaze::nonZeros ( const Matrix< MT, SO > &  matrix)

Returns the total number of non-zero elements in the matrix.

Parameters
matrixThe given matrix.
Returns
The number of non-zero elements in the dense matrix.

◆ nonZeros() [2/2]

template<typename MT , bool SO>
BLAZE_ALWAYS_INLINE size_t blaze::nonZeros ( const Matrix< MT, SO > &  matrix,
size_t  i 
)

Returns the number of non-zero elements in the specified row/column.

Parameters
matrixThe given matrix.
iThe index of the row/column.
Returns
The number of non-zero elements of row/column i.

This function returns the current number of non-zero elements in the specified row/column. In case the storage order is set to rowMajor the function returns the number of non-zero elements in row i, in case the storage flag is set to columnMajor the function returns the number of non-zero elements in column i.

◆ operator<<()

template<typename MT , bool SO>
std::ostream & blaze::operator<< ( std::ostream &  os,
const Matrix< MT, SO > &  m 
)
inline

Global output operator for dense and sparse matrices.

Parameters
osReference to the output stream.
mReference to a constant matrix object.
Returns
Reference to the output stream.

◆ resize()

template<typename MT , bool SO>
BLAZE_ALWAYS_INLINE void blaze::resize ( Matrix< MT, SO > &  matrix,
size_t  m,
size_t  n,
bool  preserve 
)

Changing the size of the matrix.

Parameters
matrixThe given matrix to be resized.
mThe new number of rows of the matrix.
nThe new number of columns of the matrix.
preservetrue if the old values of the matrix should be preserved, false if not.
Returns
void
Exceptions
std::invalid_argumentInvalid resize arguments for square matrix.
std::invalid_argumentMatrix cannot be resized.

This function provides a unified interface to resize dense and sparse matrices. In contrast to the resize() member function, which is only available on resizable matrix types, this function can be used on both resizable and non-resizable matrices. In case the given matrix of type MT is resizable (i.e. provides a resize function) the type-specific resize() member function is called. Depending on the type MT, this may result in the allocation of new dynamic memory and the invalidation of existing views (submatrices, rows, columns, ...). Note that in case the matrix is a compile time square matrix (as for instance the blaze::SymmetricMatrix adaptor, ...) the specified number of rows must be identical to the number of columns. Otherwise a std::invalid_argument exception is thrown. If the matrix type MT is non-resizable (i.e. does not provide a resize() function) and if the specified number of rows and columns is not identical to the current number of rows and columns of the matrix, a std::invalid_argument exception is thrown.

resize( A, 5UL, 2UL ); // OK: regular resize operation
resize( B, 4UL, 4UL ); // OK: Number of rows and columns is identical
resize( B, 3UL, 5UL ); // Error: Invalid arguments for square matrix!
resize( C, 3UL, 3UL ); // OK: No resize necessary
resize( C, 5UL, 2UL ); // Error: Matrix cannot be resized!

◆ rows()

template<typename MT , bool SO>
BLAZE_ALWAYS_INLINE size_t blaze::rows ( const Matrix< MT, SO > &  matrix)
noexcept

Returns the current number of rows of the matrix.

Parameters
matrixThe given matrix.
Returns
The number of rows of the matrix.

◆ shrinkToFit()

template<typename MT , bool SO>
BLAZE_ALWAYS_INLINE void blaze::shrinkToFit ( Matrix< MT, SO > &  matrix)

Requesting the removal of unused capacity.

Parameters
matrixThe given matrix to be shrunk.
Returns
void

This function tries to minimize the capacity of the matrix by removing unused capacity. Please note that in case of a shrinkable matrix, due to padding the capacity might not be reduced exactly to the number of rows times the number of columns. Please also note that in case a reallocation occurs, all iterators (including end() iterators), all pointers and references to elements of this matrix are invalidated. In case of an unshrinkable matrix the function has no effect.

◆ trace()

template<typename MT , bool SO>
auto blaze::trace ( const Matrix< MT, SO > &  m)
inline

Computes the trace of the given square matrix.

Parameters
mReference to a constant matrix object.
Returns
The trace of the matrix.
Exceptions
std::invalid_argumentInvalid input matrix for trace computation.

This function computes the trace of the given square matrix, i.e. sums the elements on its diagonal:

\[ trace(A) = a_{11} + a_{22} + ... + a_{nn} = \sum_{i=1}^{n} a_{ii} \]

In case the given matrix is not a square matrix a std::invalid_argument exception is thrown.

◆ transpose()

template<typename MT , bool SO>
BLAZE_ALWAYS_INLINE void blaze::transpose ( Matrix< MT, SO > &  matrix)

In-place transpose of the given matrix.

Parameters
matrixThe given matrix to be transposed.
Returns
void
Exceptions
std::logic_errorMatrix cannot be transposed.

This function transposes the given matrix in-place. The function fails if ...

  • ... the given matrix has a fixed size and is non-square;
  • ... the given matrix is a triangular matrix;
  • ... the given submatrix affects the restricted parts of a triangular matrix;
  • ... the given submatrix would cause non-deterministic results in a symmetric/Hermitian matrix.

In all failure cases a std::logic_error exception is thrown.