![]() |
Efficient implementation of an identity matrix.The IdentityMatrix class template is the representation of an immutable, arbitrary sized identity matrix with
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 | |
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 constexpr MatrixType & | operator~ () noexcept |
Conversion operator for non-constant matrices. More... | |
BLAZE_ALWAYS_INLINE constexpr const MatrixType & | operator~ () const noexcept |
Conversion operator for constant matrices. More... | |
Constructors | |
constexpr | IdentityMatrix () noexcept |
The default constructor for IdentityMatrix. | |
constexpr | IdentityMatrix (size_t n) noexcept |
Constructor for an identity matrix of size ![]() | |
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> | |
IdentityMatrix & | operator= (const Matrix< MT, SO2 > &rhs) |
IdentityMatrix & | operator= (const IdentityMatrix &)=default |
IdentityMatrix & | operator= (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 IdentityMatrix & | transpose () noexcept |
In-place transpose of the matrix. More... | |
constexpr IdentityMatrix & | ctranspose () 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 Attributes | |
Member variables | |
size_t | n_ |
The current number of rows and columns of the identity matrix. | |
Efficient implementation of an identity matrix.
The IdentityMatrix class template is the representation of an immutable, arbitrary sized identity matrix with elements of arbitrary type. The type of the elements and the storage order of the matrix can be specified via the two template parameters:
It is not possible to insert, erase or modify the elements of an identity matrix. It is only possible to read from the elements:
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:
|
inlineexplicitnoexcept |
Constructor for an identity matrix of size .
n | The number of rows and columns of the matrix. |
|
inlineexplicit |
Conversion constructor for different identity matrices.
m | Identity matrix to be copied. |
std::invalid_argument | Invalid setup of identity matrix. |
The matrix is sized according to the given identity matrix and initialized as a copy of this matrix.
|
inline |
Checked access to the matrix elements.
i | Access index for the row. The index has to be in the range ![]() |
j | Access index for the column. The index has to be in the range ![]() |
std::out_of_range | Invalid matrix access index. |
In contrast to the subscript operator this function always performs a check of the given access indices.
|
inlinenoexcept |
Returns an iterator to the first non-zero element of row/column i.
i | The row/column index. |
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.
|
inlinenoexcept |
Returns whether the matrix can alias with the given address alias.
alias | The alias to be checked. |
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.
|
inlinenoexcept |
Returns whether the matrix can be used in SMP assignments.
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).
|
inlinenoexcept |
Returns the maximum capacity of the identity matrix.
|
inlinenoexcept |
Returns the current capacity of the specified row/column.
i | The index of the row/column. |
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.
|
inlinenoexcept |
Returns an iterator to the first non-zero element of row/column i.
i | The row/column index. |
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.
|
inlinenoexcept |
Returns an iterator just past the last non-zero element of row/column i.
i | The row/column index. |
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.
|
inlinenoexcept |
Clearing the identity matrix.
After the clear() function, the size of the identity matrix is 0.
|
inlinenoexcept |
Returns the current number of columns of the identity matrix.
|
inlinenoexcept |
In-place conjugate transpose of the matrix.
|
inlinenoexcept |
Returns an iterator just past the last non-zero element of row/column i.
i | The row/column index. |
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.
|
inline |
Searches for a specific matrix element.
i | The row index of the search element. The index has to be in the range ![]() |
j | The column index of the search element. The index has to be in the range ![]() |
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.
|
inlinenoexcept |
Returns whether the matrix is aliased with the given address alias.
alias | The alias to be checked. |
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.
|
inline |
Returns an iterator to the first index not less then the given index.
i | The row index of the search element. The index has to be in the range ![]() |
j | The column index of the search element. The index has to be in the range ![]() |
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.
|
inlinenoexcept |
Returns the number of non-zero elements in the identity matrix.
|
inlinenoexcept |
Returns the number of non-zero elements in the specified row/column.
i | The index of the row/column. |
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.
|
inlinenoexcept |
2D-access to the identity matrix elements.
i | Access index for the row. The index has to be in the range ![]() |
j | Access index for the column. The index has to be in the range ![]() |
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.
|
inline |
Assignment operator for different identity matrices.
rhs | Identity matrix to be copied. |
std::invalid_argument | Invalid assignment to identity matrix. |
The matrix is resized according to the given identity matrix and initialized as a copy of this matrix.
|
inlinenoexceptinherited |
Conversion operator for non-constant matrices.
|
inlinenoexceptinherited |
Conversion operator for constant matrices.
|
noexcept |
Changing the size of the identity matrix.
n | The new number of rows and columns of the identity matrix. |
This function resizes the matrix using the given size to . Note that this function may invalidate all existing views (submatrices, rows, columns, ...) on the matrix if it is used to shrink the matrix.
|
inlinenoexcept |
Returns the current number of rows of the identity matrix.
|
inlinenoexcept |
Swapping the contents of two sparse matrices.
m | The identity matrix to be swapped. |
|
inlinenoexcept |
In-place transpose of the matrix.
|
inline |
Returns an iterator to the first index greater then the given index.
i | The row index of the search element. The index has to be in the range ![]() |
j | The column index of the search element. The index has to be in the range ![]() |
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.
|
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).