Classes | Public Types | Public Member Functions | List of all members
blaze::IdentityMatrix< Type, SO > Class Template Reference

Efficient implementation of an $ N \times N $ identity matrix.The IdentityMatrix class template is the representation of an immutable, arbitrary sized identity matrix with $ N \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 <IdentityMatrix.h>

Inherits blaze::SparseMatrix< IdentityMatrix< Type, SO >, SO >.

Classes

class  ConstIterator
 Iterator over the elements of the identity matrix. More...
 
struct  Rebind
 Rebind mechanism to obtain an IdentityMatrix with different data/element type. More...
 
struct  Resize
 Resize mechanism to obtain a IdentityMatrix with different fixed dimensions. More...
 

Public Types

enum  : bool { smpAssignable = !IsSMPAssignable<Type>::value }
 Compilation flag for SMP assignments. More...
 
using This = IdentityMatrix< Type, SO >
 Type of this IdentityMatrix instance.
 
using BaseType = SparseMatrix< This, SO >
 Base type of this IdentityMatrix instance.
 
using ResultType = This
 Result type for expression template evaluations.
 
using OppositeType = IdentityMatrix< Type,!SO >
 Result type with opposite storage order for expression template evaluations.
 
using TransposeType = IdentityMatrix< Type,!SO >
 Transpose type for expression template evaluations.
 
using ElementType = Type
 Type of the identity 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 identity matrix element.
 
using ConstReference = const Type
 Reference to a constant identity matrix element.
 
using Iterator = ConstIterator
 Iterator over non-constant elements.
 
using MatrixType = IdentityMatrix< Type, SO >
 Type of the matrix.
 

Public Member Functions

template<typename MT , bool SO2>
IdentityMatrix< Type, SO > & operator= (const Matrix< MT, SO2 > &rhs)
 Assignment operator for different identity matrices. More...
 
BLAZE_ALWAYS_INLINE MatrixTypeoperator~ () noexcept
 Conversion operator for non-constant matrices. More...
 
BLAZE_ALWAYS_INLINE const MatrixTypeoperator~ () const noexcept
 Conversion operator for constant matrices. More...
 
Constructors
 IdentityMatrix () noexcept
 The default constructor for IdentityMatrix.
 
 IdentityMatrix (size_t n) noexcept
 Constructor for an identity matrix of size $ N \times N $. More...
 
template<typename MT , bool SO2>
 IdentityMatrix (const Matrix< MT, SO2 > &m)
 Conversion constructor for different identity matrices. More...
 
Data access functions
ConstReference operator() (size_t i, size_t j) const noexcept
 2D-access to the identity matrix elements. More...
 
ConstReference at (size_t i, size_t j) const
 Checked access to the matrix elements. More...
 
ConstIterator begin (size_t i) const noexcept
 Returns an iterator to the first non-zero element of row/column i. More...
 
ConstIterator cbegin (size_t i) const noexcept
 Returns an iterator to the first non-zero element of row/column i. More...
 
ConstIterator end (size_t i) const noexcept
 Returns an iterator just past the last non-zero element of row/column i. More...
 
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>
IdentityMatrixoperator= (const Matrix< MT, SO2 > &rhs)
 
Utility functions
size_t rows () const noexcept
 Returns the current number of rows of the identity matrix. More...
 
size_t columns () const noexcept
 Returns the current number of columns of the identity matrix. More...
 
size_t capacity () const noexcept
 Returns the maximum capacity of the identity matrix. More...
 
size_t capacity (size_t i) const noexcept
 Returns the current capacity of the specified row/column. More...
 
size_t nonZeros () const
 Returns the number of non-zero elements in the identity matrix. More...
 
size_t nonZeros (size_t i) const
 Returns the number of non-zero elements in the specified row/column. More...
 
void clear ()
 Clearing the identity matrix. More...
 
void resize (size_t n)
 Changing the size of the identity matrix. More...
 
void swap (IdentityMatrix &m) noexcept
 Swapping the contents of two sparse 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
IdentityMatrixtranspose ()
 In-place transpose of the matrix. More...
 
IdentityMatrixctranspose ()
 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...
 

Private Attributes

Member variables
size_t n_
 The current number of rows and columns of the identity matrix.
 

Detailed Description

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

Efficient implementation of an $ N \times N $ identity matrix.

The IdentityMatrix class template is the representation of an immutable, arbitrary sized identity matrix with $ N \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 >

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

// Creating a row-major 4x4 identity matrix with 4 rows and 4 columns
IdentityMatrix<double,rowMajor> A( 4 );
// The function call operator provides access to all possible elements of the identity matrix,
// including the zero elements.
A(1,2) = 2.0; // Compilation error: It is not possible to write to an indentity matrix
double d = A(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 A are traversed.
for( IdentityMatrix<double,rowMajor>::Iterator i=A.begin(1); i!=A.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 IdentityMatrix 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 IdentityMatrix:

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

Member Enumeration Documentation

◆ anonymous enum

template<typename Type, bool SO = defaultStorageOrder>
anonymous enum : bool

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).

Constructor & Destructor Documentation

◆ IdentityMatrix() [1/2]

template<typename Type , bool SO>
blaze::IdentityMatrix< Type, SO >::IdentityMatrix ( size_t  n)
inlineexplicitnoexcept

Constructor for an identity matrix of size $ N \times N $.

Parameters
nThe number of rows and columns of the matrix.

◆ IdentityMatrix() [2/2]

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

Conversion constructor for different identity matrices.

Parameters
mIdentity matrix to be copied.
Exceptions
std::invalid_argumentInvalid setup of identity matrix.

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

Member Function Documentation

◆ at()

template<typename Type , bool SO>
IdentityMatrix< Type, SO >::ConstReference blaze::IdentityMatrix< 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>
IdentityMatrix< Type, SO >::ConstIterator blaze::IdentityMatrix< 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::IdentityMatrix< 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::IdentityMatrix< 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>
size_t blaze::IdentityMatrix< Type, SO >::capacity ( ) const
inlinenoexcept

Returns the maximum capacity of the identity matrix.

Returns
The capacity of the identity matrix.

◆ capacity() [2/2]

template<typename Type , bool SO>
size_t blaze::IdentityMatrix< 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>
IdentityMatrix< Type, SO >::ConstIterator blaze::IdentityMatrix< 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>
IdentityMatrix< Type, SO >::ConstIterator blaze::IdentityMatrix< 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>
void blaze::IdentityMatrix< Type, SO >::clear ( )
inline

Clearing the identity matrix.

Returns
void

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

◆ columns()

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

Returns the current number of columns of the identity matrix.

Returns
The number of columns of the identity matrix.

◆ ctranspose()

template<typename Type , bool SO>
IdentityMatrix< Type, SO > & blaze::IdentityMatrix< Type, SO >::ctranspose ( )
inline

In-place conjugate transpose of the matrix.

Returns
Reference to the transposed matrix.

◆ end()

template<typename Type , bool SO>
IdentityMatrix< Type, SO >::ConstIterator blaze::IdentityMatrix< 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>
IdentityMatrix< Type, SO >::ConstIterator blaze::IdentityMatrix< 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::IdentityMatrix< 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>
IdentityMatrix< Type, SO >::ConstIterator blaze::IdentityMatrix< 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>
size_t blaze::IdentityMatrix< Type, SO >::nonZeros ( ) const
inline

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

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

◆ nonZeros() [2/2]

template<typename Type , bool SO>
size_t blaze::IdentityMatrix< Type, SO >::nonZeros ( size_t  i) const
inline

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

2D-access to the identity 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>
IdentityMatrix<Type,SO>& blaze::IdentityMatrix< Type, SO >::operator= ( const Matrix< MT, SO2 > &  rhs)
inline

Assignment operator for different identity matrices.

Parameters
rhsIdentity matrix to be copied.
Returns
Reference to the assigned matrix.
Exceptions
std::invalid_argumentInvalid assignment to identity matrix.

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

◆ operator~() [1/2]

BLAZE_ALWAYS_INLINE MatrixType& blaze::Matrix< IdentityMatrix< 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 const MatrixType& blaze::Matrix< IdentityMatrix< 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 blaze::IdentityMatrix< Type, SO >::resize ( size_t  n)

Changing the size of the identity matrix.

Parameters
nThe new number of rows and columns of the identity matrix.
Returns
void

This function resizes the matrix using the given size to $ n \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>
size_t blaze::IdentityMatrix< Type, SO >::rows ( ) const
inlinenoexcept

Returns the current number of rows of the identity matrix.

Returns
The number of rows of the identity matrix.

◆ swap()

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

Swapping the contents of two sparse matrices.

Parameters
mThe identity matrix to be swapped.
Returns
void

◆ transpose()

template<typename Type , bool SO>
IdentityMatrix< Type, SO > & blaze::IdentityMatrix< Type, SO >::transpose ( )
inline

In-place transpose of the matrix.

Returns
Reference to the transposed matrix.

◆ upperBound()

template<typename Type , bool SO>
IdentityMatrix< Type, SO >::ConstIterator blaze::IdentityMatrix< 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.


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