Blaze  3.6
Classes | Public Types | Public Member Functions | Static Public Attributes | Private Types | List of all members
blaze::ZeroMatrix< Type, SO > Class Template Reference

Efficient implementation of an $ M \times N $ zero matrix.The ZeroMatrix class template is the representation of an immutable, arbitrary sized zero matrix with $ M \cdot N $ elements of arbitrary type. The type of the elements and the storage order of the matrix can be specified via the two template parameters: More...

#include <ZeroMatrix.h>

Inherits blaze::Expression< SparseMatrix< ZeroMatrix< Type, SO >, SO > >.

Classes

struct  Rebind
 Rebind mechanism to obtain a ZeroMatrix with different data/element type. More...
 
struct  Resize
 Resize mechanism to obtain a ZeroMatrix with different fixed dimensions. More...
 

Public Types

using This = ZeroMatrix< Type, SO >
 Type of this ZeroMatrix instance.
 
using BaseType = SparseMatrix< This, SO >
 Base type of this ZeroMatrix instance.
 
using ResultType = This
 Result type for expression template evaluations.
 
using OppositeType = ZeroMatrix< Type,!SO >
 Result type with opposite storage order for expression template evaluations.
 
using TransposeType = ZeroMatrix< Type,!SO >
 Transpose type for expression template evaluations.
 
using ElementType = Type
 Type of the zero matrix elements.
 
using ReturnType = const Type &
 Return type for expression template evaluations.
 
using CompositeType = const This &
 Data type for composite expression templates.
 
using Reference = const Type &
 Reference to a zero matrix element.
 
using ConstReference = const Type &
 Reference to a constant zero matrix element.
 
using Iterator = Element *
 Iterator over non-constant elements.
 
using ConstIterator = const Element *
 Iterator over constant elements.
 
using MatrixType = ZeroMatrix< Type, SO >
 Type of the matrix.
 

Public Member Functions

template<typename MT , bool SO2>
ZeroMatrix< Type, SO > & operator= (const Matrix< MT, SO2 > &rhs)
 Assignment operator for different zero matrices. More...
 
BLAZE_ALWAYS_INLINE constexpr MatrixTypeoperator~ () noexcept
 Conversion operator for non-constant matrices. More...
 
BLAZE_ALWAYS_INLINE constexpr const MatrixTypeoperator~ () const noexcept
 Conversion operator for constant matrices. More...
 
Constructors
constexpr ZeroMatrix () noexcept
 The default constructor for ZeroMatrix.
 
constexpr ZeroMatrix (size_t m, size_t n) noexcept
 Constructor for a zero matrix of size $ M \times N $. More...
 
template<typename MT , bool SO2>
 ZeroMatrix (const Matrix< MT, SO2 > &m)
 Conversion constructor for different zero matrices. More...
 
 ZeroMatrix (const ZeroMatrix &)=default
 
 ZeroMatrix (ZeroMatrix &&)=default
 
Destructor
 ~ZeroMatrix ()=default
 
Data access functions
constexpr ConstReference operator() (size_t i, size_t j) const noexcept
 2D-access to the zero matrix elements. More...
 
ConstReference at (size_t i, size_t j) const
 Checked access to the matrix elements. More...
 
constexpr ConstIterator begin (size_t i) const noexcept
 Returns an iterator to the first non-zero element of row/column i. More...
 
constexpr ConstIterator cbegin (size_t i) const noexcept
 Returns an iterator to the first non-zero element of row/column i. More...
 
constexpr ConstIterator end (size_t i) const noexcept
 Returns an iterator just past the last non-zero element of row/column i. More...
 
constexpr ConstIterator cend (size_t i) const noexcept
 Returns an iterator just past the last non-zero element of row/column i. More...
 
Assignment operators
template<typename MT , bool SO2>
ZeroMatrixoperator= (const Matrix< MT, SO2 > &rhs)
 
ZeroMatrixoperator= (const ZeroMatrix &)=default
 
ZeroMatrixoperator= (ZeroMatrix &&)=default
 
Utility functions
constexpr size_t rows () const noexcept
 Returns the current number of rows of the zero matrix. More...
 
constexpr size_t columns () const noexcept
 Returns the current number of columns of the zero matrix. More...
 
constexpr size_t capacity () const noexcept
 Returns the maximum capacity of the zero matrix. More...
 
constexpr size_t capacity (size_t i) const noexcept
 Returns the current capacity of the specified row/column. More...
 
constexpr size_t nonZeros () const noexcept
 Returns the number of non-zero elements in the zero matrix. More...
 
constexpr size_t nonZeros (size_t i) const noexcept
 Returns the number of non-zero elements in the specified row/column. More...
 
constexpr void clear () noexcept
 Clearing the zero matrix. More...
 
constexpr void resize (size_t m, size_t n) noexcept
 Changing the size of the zero matrix. More...
 
constexpr void swap (ZeroMatrix &m) noexcept
 Swapping the contents of two zero matrices. More...
 
Lookup functions
ConstIterator find (size_t i, size_t j) const
 Searches for a specific matrix element. More...
 
ConstIterator lowerBound (size_t i, size_t j) const
 Returns an iterator to the first index not less then the given index. More...
 
ConstIterator upperBound (size_t i, size_t j) const
 Returns an iterator to the first index greater then the given index. More...
 
Numeric functions
constexpr ZeroMatrixtranspose () noexcept
 In-place transpose of the matrix. More...
 
constexpr ZeroMatrixctranspose () noexcept
 In-place conjugate transpose of the matrix. More...
 
Expression template evaluation functions
template<typename Other >
bool canAlias (const Other *alias) const noexcept
 Returns whether the matrix can alias with the given address alias. More...
 
template<typename Other >
bool isAliased (const Other *alias) const noexcept
 Returns whether the matrix is aliased with the given address alias. More...
 
bool canSMPAssign () const noexcept
 Returns whether the matrix can be used in SMP assignments. More...
 

Static Public Attributes

static constexpr bool smpAssignable = !IsSMPAssignable_v<Type>
 Compilation flag for SMP assignments. More...
 
static constexpr bool storageOrder
 Storage order of the matrix.
 

Private Types

using Element = ValueIndexPair< Type >
 Value-index-pair for the ZeroMatrix class.
 

Member variables

size_t m_
 The current number of rows of the zero matrix.
 
size_t n_
 The current number of columns of the zero matrix.
 
static const Type zero_ {}
 The zero element.
 

Detailed Description

template<typename Type, bool SO = defaultStorageOrder>
class blaze::ZeroMatrix< Type, SO >

Efficient implementation of an $ M \times N $ zero matrix.

The ZeroMatrix class template is the representation of an immutable, arbitrary sized zero matrix with $ M \cdot N $ elements of arbitrary type. The type of the elements and the storage order of the matrix can be specified via the two template parameters:

template< typename Type, bool SO >
class ZeroMatrix;

It is not possible to insert, erase or modify the elements of a zero matrix. It is only possible to read from the elements:

// Creating a row-major 4x6 zero matrix with 4 rows and 6 columns
ZeroMatrix<double,rowMajor> Z( 4, 6 );
// The function call operator provides access to all possible elements of the zero matrix,
// including the zero elements.
Z(1,2) = 2.0; // Compilation error: It is not possible to write to a zero matrix
double d = Z(2,1); // Access to the element (2,1)
// In order to traverse all non-zero elements currently stored in the matrix, the begin()
// and end() functions can be used. In the example, all non-zero elements of the 2nd row
// of Z are traversed.
for( ZeroMatrix<double,rowMajor>::Iterator i=Z.begin(1); i!=Z.end(1); ++i ) {
... = i->value(); // Access to the value of the non-zero element
... = i->index(); // Access to the index of the non-zero element
}

The use of ZeroMatrix is very natural and intuitive. All operations (addition, subtraction, multiplication, ...) can be performed on all possible combinations of row-major and column-major dense and sparse matrices with fitting element types. The following example gives an impression of the use of ZeroMatrix:

ZeroMatrix<double,rowMajor> Z( 3, 3 ); // Row-major 3x3 zero matrix
DynamicMatrix<double,columnMajor> A( 3, 3 ); // Column-major 3x3 dynamic dense matrix
CompressedMatrix<double,rowMajor> B( 3, 3 ); // Row-major 3x3 compressed sparse matrix
CompressedMatrix<float,rowMajor> C( 3, 5 ); // Row-major 3x5 compressed sparse matrix
// ... Initialization of A, B, and C
DynamicMatrix<double,rowMajor> D( Z ); // Creation of a new row-major matrix as a copy of Z
CompressedMatrix<double,columnMajor> E; // Creation of a default column-major matrix
D = Z + A; // Addition of a zero matrix and a dense matrix
D = B - Z; // Subtraction of a sparse matrix and a zero matrix
E = Z * C; // Matrix multiplication between two matrices of different element types
D = 2.0 * Z; // Scaling of a zero matrix
E = Z * 2.0; // Scaling of a zero matrix

Constructor & Destructor Documentation

◆ ZeroMatrix() [1/2]

template<typename Type , bool SO>
constexpr blaze::ZeroMatrix< Type, SO >::ZeroMatrix ( size_t  m,
size_t  n 
)
inlineexplicitnoexcept

Constructor for a zero matrix of size $ M \times N $.

Parameters
mThe number of rows of the matrix.
nThe number of columns of the matrix.

◆ ZeroMatrix() [2/2]

template<typename Type , bool SO>
template<typename MT , bool SO2>
blaze::ZeroMatrix< Type, SO >::ZeroMatrix ( const Matrix< MT, SO2 > &  m)
inlineexplicit

Conversion constructor for different zero matrices.

Parameters
mZero matrix to be copied.
Exceptions
std::invalid_argumentInvalid setup of zero matrix.

The matrix is sized according to the given $ M \times N $ zero matrix and initialized as a copy of this matrix.

Member Function Documentation

◆ at()

template<typename Type , bool SO>
ZeroMatrix< Type, SO >::ConstReference blaze::ZeroMatrix< Type, SO >::at ( size_t  i,
size_t  j 
) const
inline

Checked access to the matrix elements.

Parameters
iAccess index for the row. The index has to be in the range $[0..M-1]$.
jAccess index for the column. The index has to be in the range $[0..N-1]$.
Returns
Reference to the accessed value.
Exceptions
std::out_of_rangeInvalid matrix access index.

In contrast to the subscript operator this function always performs a check of the given access indices.

◆ begin()

template<typename Type , bool SO>
constexpr ZeroMatrix< Type, SO >::ConstIterator blaze::ZeroMatrix< Type, SO >::begin ( size_t  i) const
inlinenoexcept

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

Parameters
iThe row/column index.
Returns
Iterator to the first non-zero element of row/column i.

This function returns a row/column iterator to the first non-zero element of row/column i. In case the storage order is set to rowMajor the function returns an iterator to the first non-zero element of row i, in case the storage flag is set to columnMajor the function returns an iterator to the first non-zero element of column i.

◆ canAlias()

template<typename Type , bool SO>
template<typename Other >
bool blaze::ZeroMatrix< Type, SO >::canAlias ( const Other *  alias) const
inlinenoexcept

Returns whether the matrix can alias with the given address alias.

Parameters
aliasThe alias to be checked.
Returns
true in case the alias corresponds to this matrix, false if not.

This function returns whether the given address can alias with the matrix. In contrast to the isAliased() function this function is allowed to use compile time expressions to optimize the evaluation.

◆ canSMPAssign()

template<typename Type , bool SO>
bool blaze::ZeroMatrix< Type, SO >::canSMPAssign ( ) const
inlinenoexcept

Returns whether the matrix can be used in SMP assignments.

Returns
true in case the matrix can be used in SMP assignments, false if not.

This function returns whether the matrix can be used in SMP assignments. In contrast to the smpAssignable member enumeration, which is based solely on compile time information, this function additionally provides runtime information (as for instance the current number of rows and/or columns of the matrix).

◆ capacity() [1/2]

template<typename Type , bool SO>
constexpr size_t blaze::ZeroMatrix< Type, SO >::capacity ( ) const
inlinenoexcept

Returns the maximum capacity of the zero matrix.

Returns
The capacity of the zero matrix.

◆ capacity() [2/2]

template<typename Type , bool SO>
constexpr size_t blaze::ZeroMatrix< Type, SO >::capacity ( size_t  i) const
inlinenoexcept

Returns the current capacity of the specified row/column.

Parameters
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 Type , bool SO>
constexpr ZeroMatrix< Type, SO >::ConstIterator blaze::ZeroMatrix< Type, SO >::cbegin ( size_t  i) const
inlinenoexcept

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

Parameters
iThe row/column index.
Returns
Iterator to the first non-zero element of row/column i.

This function returns a row/column iterator to the first non-zero element of row/column i. In case the storage order is set to rowMajor the function returns an iterator to the first non-zero element of row i, in case the storage flag is set to columnMajor the function returns an iterator to the first non-zero element of column i.

◆ cend()

template<typename Type , bool SO>
constexpr ZeroMatrix< Type, SO >::ConstIterator blaze::ZeroMatrix< Type, SO >::cend ( size_t  i) const
inlinenoexcept

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

Parameters
iThe row/column index.
Returns
Iterator just past the last non-zero element of row/column i.

This function returns an row/column iterator just past the last non-zero element of row/column i. In case the storage order is set to rowMajor the function returns an iterator just past the last non-zero element of row i, in case the storage flag is set to columnMajor the function returns an iterator just past the last non-zero element of column i.

◆ clear()

template<typename Type , bool SO>
constexpr void blaze::ZeroMatrix< Type, SO >::clear ( )
inlinenoexcept

Clearing the zero matrix.

Returns
void

After the clear() function, the size of the zero matrix is 0.

◆ columns()

template<typename Type , bool SO>
constexpr size_t blaze::ZeroMatrix< Type, SO >::columns ( ) const
inlinenoexcept

Returns the current number of columns of the zero matrix.

Returns
The number of columns of the zero matrix.

◆ ctranspose()

template<typename Type , bool SO>
constexpr ZeroMatrix< Type, SO > & blaze::ZeroMatrix< Type, SO >::ctranspose ( )
inlinenoexcept

In-place conjugate transpose of the matrix.

Returns
Reference to the transposed matrix.

◆ end()

template<typename Type , bool SO>
constexpr ZeroMatrix< Type, SO >::ConstIterator blaze::ZeroMatrix< Type, SO >::end ( size_t  i) const
inlinenoexcept

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

Parameters
iThe row/column index.
Returns
Iterator just past the last non-zero element of row/column i.

This function returns an row/column iterator just past the last non-zero element of row/column i. In case the storage order is set to rowMajor the function returns an iterator just past the last non-zero element of row i, in case the storage flag is set to columnMajor the function returns an iterator just past the last non-zero element of column i.

◆ find()

template<typename Type , bool SO>
ZeroMatrix< Type, SO >::ConstIterator blaze::ZeroMatrix< Type, SO >::find ( size_t  i,
size_t  j 
) const
inline

Searches for a specific matrix element.

Parameters
iThe row index of the search element. The index has to be in the range $[0..M-1]$.
jThe column index of the search element. The index has to be in the range $[0..N-1]$.
Returns
Iterator to the element in case the index is found, end() iterator otherwise.

This function can be used to check whether a specific element is contained in the sparse matrix. It specifically searches for the element with row index i and column index j. In case the element is found, the function returns an row/column iterator to the element. Otherwise an iterator just past the last non-zero element of row i or column j (the end() iterator) is returned.

◆ isAliased()

template<typename Type , bool SO>
template<typename Other >
bool blaze::ZeroMatrix< Type, SO >::isAliased ( const Other *  alias) const
inlinenoexcept

Returns whether the matrix is aliased with the given address alias.

Parameters
aliasThe alias to be checked.
Returns
true in case the alias corresponds to this matrix, false if not.

This function returns whether the given address is aliased with the matrix. In contrast to the canAlias() function this function is not allowed to use compile time expressions to optimize the evaluation.

◆ lowerBound()

template<typename Type , bool SO>
ZeroMatrix< Type, SO >::ConstIterator blaze::ZeroMatrix< Type, SO >::lowerBound ( size_t  i,
size_t  j 
) const
inline

Returns an iterator to the first index not less then the given index.

Parameters
iThe row index of the search element. The index has to be in the range $[0..M-1]$.
jThe column index of the search element. The index has to be in the range $[0..N-1]$.
Returns
Iterator to the first index not less then the given index, end() iterator otherwise.

In case of a row-major matrix, this function returns a row iterator to the first element with an index not less then the given column index. In case of a column-major matrix, the function returns a column iterator to the first element with an index not less then the given row index. In combination with the upperBound() function this function can be used to create a pair of iterators specifying a range of indices.

◆ nonZeros() [1/2]

template<typename Type , bool SO>
constexpr size_t blaze::ZeroMatrix< Type, SO >::nonZeros ( ) const
inlinenoexcept

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

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

◆ nonZeros() [2/2]

template<typename Type , bool SO>
constexpr size_t blaze::ZeroMatrix< Type, SO >::nonZeros ( size_t  i) const
inlinenoexcept

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

Parameters
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 Type , bool SO>
constexpr ZeroMatrix< Type, SO >::ConstReference blaze::ZeroMatrix< Type, SO >::operator() ( size_t  i,
size_t  j 
) const
inlinenoexcept

2D-access to the zero matrix elements.

Parameters
iAccess index for the row. The index has to be in the range $[0..M-1]$.
jAccess index for the column. The index has to be in the range $[0..N-1]$.
Returns
Reference to the accessed value.

This function only performs an index check in case BLAZE_USER_ASSERT() is active. In contrast, the at() function is guaranteed to perform a check of the given access indices.

◆ operator=()

template<typename Type, bool SO = defaultStorageOrder>
template<typename MT , bool SO2>
ZeroMatrix<Type,SO>& blaze::ZeroMatrix< Type, SO >::operator= ( const Matrix< MT, SO2 > &  rhs)
inline

Assignment operator for different zero matrices.

Parameters
rhsZero matrix to be copied.
Returns
Reference to the assigned matrix.
Exceptions
std::invalid_argumentInvalid assignment to zero matrix.

The matrix is resized according to the given $ M \times N $ zero matrix and initialized as a copy of this matrix.

◆ operator~() [1/2]

BLAZE_ALWAYS_INLINE constexpr MatrixType& blaze::Matrix< ZeroMatrix< Type, SO > , SO >::operator~ ( )
inlinenoexceptinherited

Conversion operator for non-constant matrices.

Returns
Reference of the actual type of the matrix.

◆ operator~() [2/2]

BLAZE_ALWAYS_INLINE constexpr const MatrixType& blaze::Matrix< ZeroMatrix< Type, SO > , SO >::operator~ ( ) const
inlinenoexceptinherited

Conversion operator for constant matrices.

Returns
Constant reference of the actual type of the matrix.

◆ resize()

template<typename Type , bool SO>
void constexpr blaze::ZeroMatrix< Type, SO >::resize ( size_t  m,
size_t  n 
)
noexcept

Changing the size of the zero matrix.

Parameters
mThe new number of rows of the zero matrix.
nThe new number of columns of the zero matrix.
Returns
void

This function resizes the matrix using the given size to $ m \times n $. Note that this function may invalidate all existing views (submatrices, rows, columns, ...) on the matrix if it is used to shrink the matrix.

◆ rows()

template<typename Type , bool SO>
constexpr size_t blaze::ZeroMatrix< Type, SO >::rows ( ) const
inlinenoexcept

Returns the current number of rows of the zero matrix.

Returns
The number of rows of the zero matrix.

◆ swap()

template<typename Type , bool SO>
constexpr void blaze::ZeroMatrix< Type, SO >::swap ( ZeroMatrix< Type, SO > &  m)
inlinenoexcept

Swapping the contents of two zero matrices.

Parameters
mThe zero matrix to be swapped.
Returns
void

◆ transpose()

template<typename Type , bool SO>
constexpr ZeroMatrix< Type, SO > & blaze::ZeroMatrix< Type, SO >::transpose ( )
inlinenoexcept

In-place transpose of the matrix.

Returns
Reference to the transposed matrix.

◆ upperBound()

template<typename Type , bool SO>
ZeroMatrix< Type, SO >::ConstIterator blaze::ZeroMatrix< Type, SO >::upperBound ( size_t  i,
size_t  j 
) const
inline

Returns an iterator to the first index greater then the given index.

Parameters
iThe row index of the search element. The index has to be in the range $[0..M-1]$.
jThe column index of the search element. The index has to be in the range $[0..N-1]$.
Returns
Iterator to the first index greater then the given index, end() iterator otherwise.

In case of a row-major matrix, this function returns a row iterator to the first element with an index greater then the given column index. In case of a column-major matrix, the function returns a column iterator to the first element with an index greater then the given row index. In combination with the lowerBound() function this function can be used to create a pair of iterators specifying a range of indices.

Member Data Documentation

◆ smpAssignable

template<typename Type, bool SO = defaultStorageOrder>
constexpr bool blaze::ZeroMatrix< Type, SO >::smpAssignable = !IsSMPAssignable_v<Type>
static

Compilation flag for SMP assignments.

The smpAssignable compilation flag indicates whether the matrix can be used in SMP (shared memory parallel) assignments (both on the left-hand and right-hand side of the assignment).


The documentation for this class was generated from the following files: