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

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

#include <IdentityMatrix.h>

Inherits blaze::Expression< SparseMatrix< IdentityMatrix< Type, SO, Tag >, 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

using This = IdentityMatrix< Type, SO, Tag >
 Type of this IdentityMatrix instance.
 
using BaseType = Expression< SparseMatrix< This, SO > >
 Result type for expression template evaluations.
 
using ResultType = This
 
using OppositeType = IdentityMatrix< Type,!SO, Tag >
 Result type with opposite storage order for expression template evaluations.
 
using TransposeType = IdentityMatrix< Type,!SO, Tag >
 Transpose type for expression template evaluations.
 
using ElementType = Type
 Type of the identity matrix elements.
 
using TagType = Tag
 Tag type of this IdentityMatrix instance.
 
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, Tag >
 Type of the matrix.
 

Public Member Functions

template<typename MT , bool SO2>
IdentityMatrix< Type, SO, Tag > & operator= (const Matrix< MT, SO2 > &rhs) &
 Assignment operator for different identity matrices. More...
 
Constructors
constexpr IdentityMatrix () noexcept
 The default constructor for IdentityMatrix.
 
constexpr 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...
 
 IdentityMatrix (const IdentityMatrix &)=default
 
 IdentityMatrix (IdentityMatrix &&)=default
 
Destructor
 ~IdentityMatrix ()=default
 
Data access functions
constexpr 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...
 
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>
IdentityMatrixoperator= (const Matrix< MT, SO2 > &rhs) &
 
IdentityMatrixoperator= (const IdentityMatrix &) &=default
 
IdentityMatrixoperator= (IdentityMatrix &&) &=default
 
Utility functions
constexpr size_t rows () const noexcept
 Returns the current number of rows of the identity matrix. More...
 
constexpr size_t columns () const noexcept
 Returns the current number of columns of the identity matrix. More...
 
constexpr size_t capacity () const noexcept
 Returns the maximum capacity of the identity 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 identity 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 identity matrix. More...
 
constexpr void resize (size_t n) noexcept
 Changing the size of the identity matrix. More...
 
constexpr 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
constexpr IdentityMatrixtranspose () noexcept
 In-place transpose of the matrix. More...
 
constexpr IdentityMatrixctranspose () 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...
 
Conversion operators
BLAZE_ALWAYS_INLINE constexpr IdentityMatrix< Type, SO, Tag > & operator~ () noexcept
 CRTP-based conversion operation for non-constant matrices. More...
 
BLAZE_ALWAYS_INLINE constexpr const IdentityMatrix< Type, SO, Tag > & operator~ () const noexcept
 CRTP-based conversion operation for constant matrices. More...
 
constexpr IdentityMatrix< Type, SO, Tag > & operator* () noexcept
 CRTP-based conversion operation for non-constant matrices. More...
 
constexpr const IdentityMatrix< Type, SO, Tag > & operator* () const noexcept
 CRTP-based conversion operation for constant matrices. 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 Attributes

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

Detailed Description

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

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, 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 >
} // namespace blaze
constexpr IdentityMatrix() noexcept
The default constructor for IdentityMatrix.
Definition: IdentityMatrix.h:517

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 identity 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
}
ConstIterator Iterator
Iterator over non-constant elements.
Definition: IdentityMatrix.h:385
constexpr bool rowMajor
Storage order flag for row-major matrices.
Definition: StorageOrder.h:71

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
Efficient implementation of a compressed matrix.
Definition: CompressedMatrix.h:239
Efficient implementation of a dynamic matrix.
Definition: DynamicMatrix.h:242
Efficient implementation of an identity matrix.
Definition: IdentityMatrix.h:197
constexpr bool columnMajor
Storage order flag for column-major matrices.
Definition: StorageOrder.h:99

Constructor & Destructor Documentation

◆ IdentityMatrix() [1/2]

template<typename Type , bool SO, typename Tag >
constexpr blaze::IdentityMatrix< Type, SO, Tag >::IdentityMatrix ( size_t  n)
explicitconstexprnoexcept

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, typename Tag >
template<typename MT , bool SO2>
blaze::IdentityMatrix< Type, SO, Tag >::IdentityMatrix ( const Matrix< MT, SO2 > &  m)
inline

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, typename Tag >
IdentityMatrix< Type, SO, Tag >::ConstReference blaze::IdentityMatrix< Type, SO, Tag >::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, typename Tag >
constexpr IdentityMatrix< Type, SO, Tag >::ConstIterator blaze::IdentityMatrix< Type, SO, Tag >::begin ( size_t  i) const
constexprnoexcept

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, typename Tag >
template<typename Other >
bool blaze::IdentityMatrix< Type, SO, Tag >::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, typename Tag >
bool blaze::IdentityMatrix< Type, SO, Tag >::canSMPAssign
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, typename Tag >
constexpr size_t blaze::IdentityMatrix< Type, SO, Tag >::capacity
constexprnoexcept

Returns the maximum capacity of the identity matrix.

Returns
The capacity of the identity matrix.

◆ capacity() [2/2]

template<typename Type , bool SO, typename Tag >
constexpr size_t blaze::IdentityMatrix< Type, SO, Tag >::capacity ( size_t  i) const
constexprnoexcept

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, typename Tag >
constexpr IdentityMatrix< Type, SO, Tag >::ConstIterator blaze::IdentityMatrix< Type, SO, Tag >::cbegin ( size_t  i) const
constexprnoexcept

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, typename Tag >
constexpr IdentityMatrix< Type, SO, Tag >::ConstIterator blaze::IdentityMatrix< Type, SO, Tag >::cend ( size_t  i) const
constexprnoexcept

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, typename Tag >
constexpr void blaze::IdentityMatrix< Type, SO, Tag >::clear
constexprnoexcept

Clearing the identity matrix.

Returns
void

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

◆ columns()

template<typename Type , bool SO, typename Tag >
constexpr size_t blaze::IdentityMatrix< Type, SO, Tag >::columns
constexprnoexcept

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, typename Tag >
constexpr IdentityMatrix< Type, SO, Tag > & blaze::IdentityMatrix< Type, SO, Tag >::ctranspose
constexprnoexcept

In-place conjugate transpose of the matrix.

Returns
Reference to the transposed matrix.

◆ end()

template<typename Type , bool SO, typename Tag >
constexpr IdentityMatrix< Type, SO, Tag >::ConstIterator blaze::IdentityMatrix< Type, SO, Tag >::end ( size_t  i) const
constexprnoexcept

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, typename Tag >
IdentityMatrix< Type, SO, Tag >::ConstIterator blaze::IdentityMatrix< Type, SO, Tag >::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, typename Tag >
template<typename Other >
bool blaze::IdentityMatrix< Type, SO, Tag >::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, typename Tag >
IdentityMatrix< Type, SO, Tag >::ConstIterator blaze::IdentityMatrix< Type, SO, Tag >::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, typename Tag >
constexpr size_t blaze::IdentityMatrix< Type, SO, Tag >::nonZeros
constexprnoexcept

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, typename Tag >
constexpr size_t blaze::IdentityMatrix< Type, SO, Tag >::nonZeros ( size_t  i) const
constexprnoexcept

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

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*() [1/2]

BLAZE_ALWAYS_INLINE constexpr const IdentityMatrix< Type, SO, Tag > & blaze::Matrix< IdentityMatrix< Type, SO, Tag > , SO >::operator*
constexprnoexceptinherited

CRTP-based conversion operation for constant matrices.

Returns
Constant reference of the actual type of the matrix.

This operator performs the CRTP-based type-safe downcast to the actual type MT of the matrix. It will return a constant reference to the actual type MT.

◆ operator*() [2/2]

BLAZE_ALWAYS_INLINE constexpr IdentityMatrix< Type, SO, Tag > & blaze::Matrix< IdentityMatrix< Type, SO, Tag > , SO >::operator*
constexprnoexceptinherited

CRTP-based conversion operation for non-constant matrices.

Returns
Mutable reference of the actual type of the matrix.

This operator performs the CRTP-based type-safe downcast to the actual type MT of the matrix. It will return a mutable reference to the actual type MT.

◆ operator=()

template<typename Type , bool SO, typename Tag >
template<typename MT , bool SO2>
IdentityMatrix< Type, SO, Tag > & blaze::IdentityMatrix< Type, SO, Tag >::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 constexpr const IdentityMatrix< Type, SO, Tag > & blaze::Matrix< IdentityMatrix< Type, SO, Tag > , SO >::operator~
constexprnoexceptinherited

CRTP-based conversion operation for constant matrices.

Parameters
matrixThe matrix to be downcast.
Returns
Constant reference of the actual type of the matrix.

This operator performs the CRTP-based type-safe downcast to the actual type MT of the matrix. It will return a constant reference to the actual type MT.

◆ operator~() [2/2]

BLAZE_ALWAYS_INLINE constexpr IdentityMatrix< Type, SO, Tag > & blaze::Matrix< IdentityMatrix< Type, SO, Tag > , SO >::operator~
constexprnoexceptinherited

CRTP-based conversion operation for non-constant matrices.

Parameters
matrixThe matrix to be downcast.
Returns
Mutable reference of the actual type of the matrix.

This operator performs the CRTP-based type-safe downcast to the actual type MT of the matrix. It will return a mutable reference to the actual type MT.

◆ resize()

template<typename Type , bool SO, typename Tag >
void constexpr blaze::IdentityMatrix< Type, SO, Tag >::resize ( size_t  n)
constexprnoexcept

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, typename Tag >
constexpr size_t blaze::IdentityMatrix< Type, SO, Tag >::rows
constexprnoexcept

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, typename Tag >
constexpr void blaze::IdentityMatrix< Type, SO, Tag >::swap ( IdentityMatrix< Type, SO, Tag > &  m)
constexprnoexcept

Swapping the contents of two sparse matrices.

Parameters
mThe identity matrix to be swapped.
Returns
void

◆ transpose()

template<typename Type , bool SO, typename Tag >
constexpr IdentityMatrix< Type, SO, Tag > & blaze::IdentityMatrix< Type, SO, Tag >::transpose
constexprnoexcept

In-place transpose of the matrix.

Returns
Reference to the transposed matrix.

◆ upperBound()

template<typename Type , bool SO, typename Tag >
IdentityMatrix< Type, SO, Tag >::ConstIterator blaze::IdentityMatrix< Type, SO, Tag >::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, typename Tag >
constexpr bool blaze::IdentityMatrix< Type, SO, Tag >::smpAssignable = !IsSMPAssignable_v<Type>
staticconstexpr

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: