35 #ifndef _BLAZE_MATH_SPARSE_IDENTITYMATRIX_H_ 36 #define _BLAZE_MATH_SPARSE_IDENTITYMATRIX_H_ 179 template<
typename Type
180 ,
bool SO = defaultStorageOrder >
182 :
public Expression< SparseMatrix< IdentityMatrix<Type,SO>, SO > >
201 template<
typename NewType >
210 template<
size_t NewM
307 inline constexpr Type
value() const noexcept {
317 inline constexpr
size_t index() const noexcept {
329 return index_ == rhs.index_;
340 return index_ != rhs.index_;
351 return index_ - rhs.index_;
380 template< typename MT,
bool SO2 >
398 inline constexpr
ConstReference operator()(
size_t i,
size_t j ) const noexcept;
410 template< typename MT,
bool SO2 >
421 inline constexpr
size_t rows() const noexcept;
422 inline constexpr
size_t columns() const noexcept;
423 inline constexpr
size_t capacity() const noexcept;
424 inline constexpr
size_t capacity(
size_t i ) const noexcept;
425 inline constexpr
size_t nonZeros() const noexcept;
426 inline constexpr
size_t nonZeros(
size_t i ) const noexcept;
427 inline constexpr
void clear() noexcept;
428 constexpr
void resize(
size_t n ) noexcept;
453 template< typename Other > inline
bool canAlias ( const Other* alias ) const noexcept;
454 template< typename Other > inline
bool isAliased( const Other* alias ) const noexcept;
492 template< typename Type
505 template<
typename Type
522 template<
typename Type
524 template<
typename MT
529 if( !IsIdentity_v<MT> && !
isIdentity( ~m ) ) {
554 template<
typename Type
581 template<
typename Type
608 template<
typename Type
631 template<
typename Type
654 template<
typename Type
677 template<
typename Type
707 template<
typename Type
709 template<
typename MT
714 if( !IsIdentity_v<MT> && !
isIdentity( ~rhs ) ) {
738 template<
typename Type
752 template<
typename Type
766 template<
typename Type
786 template<
typename Type
804 template<
typename Type
824 template<
typename Type
844 template<
typename Type
863 template<
typename Type
878 template<
typename Type
882 const size_t tmp( n_ );
910 template<
typename Type
921 return end( SO ? j : i );
939 template<
typename Type
947 if( ( !SO && j <= i ) || ( SO && i <= j ) )
948 return begin( SO ? j : i );
950 return end( SO ? j : i );
968 template<
typename Type
976 if( ( !SO && j < i ) || ( SO && i < j ) )
977 return begin( SO ? j : i );
979 return end( SO ? j : i );
997 template<
typename Type
1011 template<
typename Type
1038 template<
typename Type
1040 template<
typename Other >
1060 template<
typename Type
1062 template<
typename Other >
1082 template<
typename Type
1106 template<
typename Type,
bool SO >
1109 template<
typename Type,
bool SO >
1112 template<
typename Type,
bool SO >
1115 template<
bool RF,
typename Type,
bool SO >
1118 template<
typename Type,
bool SO >
1121 template<
typename Type,
bool SO >
1134 template<
typename Type
1156 template<
typename Type
1172 template<
typename Type
1211 return ( m.rows() == 0UL );
1234 template<
typename Type
1253 template<
typename Type
1289 template<
typename MT
1291 inline IdentityMatrix<ElementType_t<MT>,SO>
1315 template<
typename MT,
bool SO >
1316 struct IsSquare< IdentityMatrix<MT,SO> >
1333 template<
typename MT,
bool SO >
1334 struct IsSymmetric< IdentityMatrix<MT,SO> >
1351 template<
typename MT,
bool SO >
1352 struct IsHermitian< IdentityMatrix<MT,SO> >
1369 template<
typename MT,
bool SO >
1370 struct IsUniLower< IdentityMatrix<MT,SO> >
1387 template<
typename MT,
bool SO >
1388 struct IsUniUpper< IdentityMatrix<MT,SO> >
1405 template<
typename T,
bool SO >
1406 struct IsResizable< IdentityMatrix<T,SO> >
1423 template<
typename T1,
typename T2 >
1424 struct SchurTraitEval1< T1, T2
1427 ( ( IsIdentity_v<T1> && IsIdentity_v<T2> ) ||
1428 ( IsIdentity_v<T1> && IsUniTriangular_v<T2> ) ||
1429 ( IsUniTriangular_v<T1> && IsIdentity_v<T2> ) ||
1430 ( IsUniLower_v<T1> && IsUniUpper_v<T2> ) ||
1431 ( IsUniUpper_v<T1> && IsUniLower_v<T2> ) ) &&
1432 !( IsZero_v<T1> || IsZero_v<T2> ) > >
1434 using ET1 = ElementType_t<T1>;
1435 using ET2 = ElementType_t<T2>;
1437 static constexpr
bool SO1 = StorageOrder_v<T1>;
1438 static constexpr
bool SO2 = StorageOrder_v<T2>;
1440 static constexpr
bool SO = ( ( IsDenseMatrix_v<T1> && IsDenseMatrix_v<T2> ) ||
1441 ( IsSparseMatrix_v<T1> && IsSparseMatrix_v<T2> )
1443 : ( IsSparseMatrix_v<T1>
1447 using Type = IdentityMatrix< MultTrait_t<ET1,ET2>, SO >;
1463 template<
typename T1,
typename T2 >
1464 struct MultTraitEval1< T1, T2
1467 !IsIdentity_v<T1> && !IsZero_v<T1> && IsIdentity_v<T2> > >
1469 using Type = Rebind_t< ResultType_t<T1>, MultTrait_t< ElementType_t<T1>, ElementType_t<T2> > >;
1472 template<
typename T1,
typename T2 >
1473 struct MultTraitEval1< T1, T2
1476 IsIdentity_v<T1> && !IsIdentity_v<T2> && !IsZero_v<T2> > >
1478 using Type = Rebind_t< ResultType_t<T2>, MultTrait_t< ElementType_t<T1>, ElementType_t<T2> > >;
1481 template<
typename T1,
typename T2 >
1482 struct MultTraitEval1< T1, T2
1485 IsIdentity_v<T1> && IsIdentity_v<T2> > >
1487 using ET1 = ElementType_t<T1>;
1488 using ET2 = ElementType_t<T2>;
1490 using Type = IdentityMatrix< MultTrait_t<ET1,ET2>, StorageOrder_v<T1> >;
1506 template<
typename T1,
typename T2 >
1507 struct KronTraitEval1< T1, T2
1510 IsIdentity_v<T1> && IsIdentity_v<T2> > >
1512 using ET1 = ElementType_t<T1>;
1513 using ET2 = ElementType_t<T2>;
1515 using Type = IdentityMatrix< MultTrait_t<ET1,ET2>, StorageOrder_v<T2> >;
1531 template<
typename T,
typename OP >
1532 struct UnaryMapTraitEval1< T, OP
1534 YieldsIdentity_v<OP,T> > >
1536 using ET = ElementType_t<T>;
1538 using Type = IdentityMatrix< MapTrait_t<ET,OP>, StorageOrder_v<T> >;
1546 template<
typename T1,
typename T2,
typename OP >
1547 struct BinaryMapTraitEval1< T1, T2, OP
1550 YieldsIdentity_v<OP,T1,T2> > >
1552 using ET1 = ElementType_t<T1>;
1553 using ET2 = ElementType_t<T2>;
1555 static constexpr
bool SO = StorageOrder_v<T1> && StorageOrder_v<T2>;
1557 using Type = IdentityMatrix< MapTrait_t<ET1,ET2,OP>, SO >;
1573 template<
typename T,
bool SO >
1574 struct DeclSymTrait< IdentityMatrix<T,SO> >
1576 using Type = IdentityMatrix<T,SO>;
1592 template<
typename T,
bool SO >
1593 struct DeclHermTrait< IdentityMatrix<T,SO> >
1595 using Type = IdentityMatrix<T,SO>;
1611 template<
typename T,
bool SO >
1612 struct DeclLowTrait< IdentityMatrix<T,SO> >
1614 using Type = IdentityMatrix<T,SO>;
1630 template<
typename T,
bool SO >
1631 struct DeclUppTrait< IdentityMatrix<T,SO> >
1633 using Type = IdentityMatrix<T,SO>;
1649 template<
typename T,
bool SO >
1650 struct DeclDiagTrait< IdentityMatrix<T,SO> >
1652 using Type = IdentityMatrix<T,SO>;
1668 template<
typename T1,
bool SO,
typename T2 >
1669 struct HighType< IdentityMatrix<T1,SO>, IdentityMatrix<T2,SO> >
1671 using Type = IdentityMatrix< typename HighType<T1,T2>::Type, SO >;
1687 template<
typename T1,
bool SO,
typename T2 >
1688 struct LowType< IdentityMatrix<T1,SO>, IdentityMatrix<T2,SO> >
1690 using Type = IdentityMatrix< typename LowType<T1,T2>::Type, SO >;
constexpr ConstIterator() noexcept
Default constructor for the ConstIterator class.
Definition: IdentityMatrix.h:244
#define BLAZE_CONSTRAINT_MUST_NOT_BE_CONST(T)
Constraint on the data type.In case the given data type is a const-qualified type,...
Definition: Const.h:79
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.This macro encapsulates the default way o...
Definition: Exception.h:235
Pointer difference type of the Blaze library.
Header file for auxiliary alias declarations.
Header file for the decldiag trait.
Iterator over the elements of the identity matrix.
Definition: IdentityMatrix.h:220
Constraint on the data type.
Header file for the Schur product trait.
bool isAliased(const Other *alias) const noexcept
Returns whether the matrix is aliased with the given address alias.
Definition: IdentityMatrix.h:1063
constexpr bool IsMatrix_v
Auxiliary variable template for the IsMatrix type trait.The IsMatrix_v variable template provides a c...
Definition: IsMatrix.h:138
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.In case of an invalid run time expression,...
Definition: Assert.h:117
ValueIndexPair< Type > Element
Element type of the identity matrix.
Definition: IdentityMatrix.h:225
constexpr void swap(IdentityMatrix &m) noexcept
Swapping the contents of two sparse matrices.
Definition: IdentityMatrix.h:880
Header file for the IsUniUpper type trait.
const Type ReturnType
Return type for expression template evaluations.
Definition: IdentityMatrix.h:192
Header file for basic type definitions.
Header file for the SparseVector base class.
constexpr DifferenceType operator-(const ConstIterator &rhs) const noexcept
Calculating the number of elements between two ConstIterator objects.
Definition: IdentityMatrix.h:350
Header file for the declherm trait.
constexpr ConstIterator end(size_t i) const noexcept
Returns an iterator just past the last non-zero element of row/column i.
Definition: IdentityMatrix.h:657
Resize mechanism to obtain a IdentityMatrix with different fixed dimensions.
Definition: IdentityMatrix.h:212
Header file for the IsSparseMatrix type trait.
const Type ConstReference
Reference to a constant identity matrix element.
Definition: IdentityMatrix.h:195
Header file for the IsSame and IsStrictlySame type traits.
constexpr Type value() const noexcept
Access to the current value of the sparse element.
Definition: IdentityMatrix.h:307
MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:372
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:595
Header file for the YieldsIdentity type trait.
constexpr IdentityMatrix() noexcept
The default constructor for IdentityMatrix.
Definition: IdentityMatrix.h:494
Header file for the DenseVector base class.
Header file for the MAYBE_UNUSED function template.
Header file for the IsIdentity type trait.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE(T)
Constraint on the data type.In case the given data type is a volatile-qualified type,...
Definition: Volatile.h:79
std::forward_iterator_tag IteratorCategory
The iterator category.
Definition: IdentityMatrix.h:227
BoolConstant< true > TrueType
Type traits base class.The TrueType class is used as base class for type traits and value traits that...
Definition: IntegralConstant.h:132
Header file for all forward declarations of the math module.
ConstIterator lowerBound(size_t i, size_t j) const
Returns an iterator to the first index not less then the given index.
Definition: IdentityMatrix.h:942
constexpr ConstIterator operator++(int) noexcept
Post-increment operator.
Definition: IdentityMatrix.h:275
Header file for the IsUniLower type trait.
constexpr size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:514
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes....
Definition: Forward.h:145
constexpr void clear() noexcept
Clearing the identity matrix.
Definition: IdentityMatrix.h:846
Constraint on the data type.
bool isIdentity(const DenseMatrix< MT, SO > &dm)
Checks if the give dense matrix is an identity matrix.
Definition: DenseMatrix.h:2433
constexpr const Element operator *() const noexcept
Direct access to the sparse matrix element at the current iterator position.
Definition: IdentityMatrix.h:287
Header file for the IsMatrix type trait.
Header file for the SparseMatrix base class.
Header file for the IsSquare type trait.
typename EnableIf< Condition, T >::Type EnableIf_t
Auxiliary type for the EnableIf class template.The EnableIf_t alias declaration provides a convenient...
Definition: EnableIf.h:138
Header file for the ValueIndexPair class.
Efficient implementation of an identity matrix.The IdentityMatrix class template is the representati...
Definition: Forward.h:49
Header file for the LowType type trait.
Header file for the multiplication trait.
Header file for the IsSymmetric type trait.
constexpr size_t rows() const noexcept
Returns the current number of rows of the identity matrix.
Definition: IdentityMatrix.h:740
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
#define BLAZE_CONSTRAINT_MUST_NOT_BE_POINTER_TYPE(T)
Constraint on the data type.In case the given data type T is not a pointer type, a compilation error ...
Definition: Pointer.h:79
Header file for the IsSMPAssignable type trait.
Header file for the decllow trait.
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.This macro encapsulates the default way of Bl...
Definition: Exception.h:331
constexpr ConstIterator cbegin(size_t i) const noexcept
Returns an iterator to the first non-zero element of row/column i.
Definition: IdentityMatrix.h:634
Header file for the DenseMatrix base class.
Type ElementType
Type of the identity matrix elements.
Definition: IdentityMatrix.h:191
constexpr size_t capacity() const noexcept
Returns the maximum capacity of the identity matrix.
Definition: IdentityMatrix.h:768
constexpr ConstIterator(size_t index) noexcept
Constructor for the ConstIterator class.
Definition: IdentityMatrix.h:254
Constraint on the data type.
ConstIterator find(size_t i, size_t j) const
Searches for a specific matrix element.
Definition: IdentityMatrix.h:913
constexpr size_t nonZeros() const noexcept
Returns the number of non-zero elements in the identity matrix.
Definition: IdentityMatrix.h:806
constexpr void MAYBE_UNUSED(const Args &...)
Suppression of unused parameter warnings.
Definition: MaybeUnused.h:81
Header file for the default storage order for all vectors of the Blaze library.
Header file for the IsUniTriangular type trait.
Header file for the Kron product trait.
Header file for the exception macros of the math module.
MT::Iterator end(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:438
Rebind mechanism to obtain an IdentityMatrix with different data/element type.
Definition: IdentityMatrix.h:202
size_t index_
Index to the current identity matrix element.
Definition: IdentityMatrix.h:357
Header file for the IsDenseMatrix type trait.
Header file for the EnableIf class template.
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:615
constexpr IdentityMatrix & transpose() noexcept
In-place transpose of the matrix.
Definition: IdentityMatrix.h:999
bool canSMPAssign() const noexcept
Returns whether the matrix can be used in SMP assignments.
Definition: IdentityMatrix.h:1084
constexpr void resize(size_t n) noexcept
Changing the size of the identity matrix.
Definition: IdentityMatrix.h:865
constexpr size_t index() const noexcept
Access to the current index of the sparse element.
Definition: IdentityMatrix.h:317
const Type Reference
Reference to a identity matrix element.
Definition: IdentityMatrix.h:194
IdentityMatrix< ElementType_t< MT >, SO > declid(const Matrix< MT, SO > &m)
Declares the given matrix expression m as identity matrix.
Definition: IdentityMatrix.h:1292
constexpr ConstIterator cend(size_t i) const noexcept
Returns an iterator just past the last non-zero element of row/column i.
Definition: IdentityMatrix.h:680
Header file for the IsNumeric type trait.
size_t n_
The current number of rows and columns of the identity matrix.
Definition: IdentityMatrix.h:464
IdentityMatrix< Type, SO > This
Type of this IdentityMatrix instance.
Definition: IdentityMatrix.h:186
Header file for the declupp trait.
constexpr bool operator==(const ConstIterator &rhs) const noexcept
Equality comparison between two ConstIterator objects.
Definition: IdentityMatrix.h:328
constexpr bool operator!=(const ConstIterator &rhs) const noexcept
Inequality comparison between two ConstIterator objects.
Definition: IdentityMatrix.h:339
constexpr const ConstIterator * operator->() const noexcept
Direct access to the sparse matrix element at the current iterator position.
Definition: IdentityMatrix.h:297
Header file for run time assertion macros.
Constraint on the data type.
#define BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE(T)
Constraint on the data type.In case the given data type T is not a numeric (integral or floating poin...
Definition: Numeric.h:61
Header file for the IsZero type trait.
constexpr ConstReference operator()(size_t i, size_t j) const noexcept
2D-access to the identity matrix elements.
Definition: IdentityMatrix.h:557
Header file for the declsym trait.
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:94
ValueType & ReferenceType
Reference return type.
Definition: IdentityMatrix.h:230
#define BLAZE_CONSTRAINT_MUST_NOT_BE_REFERENCE_TYPE(T)
Constraint on the data type.In case the given data type T is not a reference type,...
Definition: Reference.h:79
Header file for the isDefault shim.
void swap(DiagonalMatrix< MT, SO, DF > &a, DiagonalMatrix< MT, SO, DF > &b) noexcept
Swapping the contents of two matrices.
Definition: DiagonalMatrix.h:282
Base class for matrices.The Matrix class is a base class for all dense and sparse matrix classes with...
Definition: Forward.h:114
Constraint on the data type.
bool canAlias(const Other *alias) const noexcept
Returns whether the matrix can alias with the given address alias.
Definition: IdentityMatrix.h:1041
constexpr IdentityMatrix & ctranspose() noexcept
In-place conjugate transpose of the matrix.
Definition: IdentityMatrix.h:1013
constexpr size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:498
constexpr ConstIterator begin(size_t i) const noexcept
Returns an iterator to the first non-zero element of row/column i.
Definition: IdentityMatrix.h:611
ConstReference at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: IdentityMatrix.h:584
static constexpr bool smpAssignable
Compilation flag for SMP assignments.
Definition: IdentityMatrix.h:371
constexpr size_t columns() const noexcept
Returns the current number of columns of the identity matrix.
Definition: IdentityMatrix.h:754
Index-value-pair for sparse vectors and matrices.The ValueIndexPair class represents a single index-v...
Definition: ValueIndexPair.h:73
Header file for the default transpose flag for all vectors of the Blaze library.
Header file for the StorageOrder type trait.
IteratorCategory iterator_category
The iterator category.
Definition: IdentityMatrix.h:234
Header file for the IntegralConstant class template.
Header file for the map trait.
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:264
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:635
Header file for the IsHermitian type trait.
bool isSquare(const Matrix< MT, SO > &matrix) noexcept
Checks if the given matrix is a square matrix.
Definition: Matrix.h:951
Header file for the IsResizable type trait.
ValueType * PointerType
Pointer return type.
Definition: IdentityMatrix.h:229
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: IdentityMatrix.h:231
constexpr ConstIterator & operator++() noexcept
Pre-increment operator.
Definition: IdentityMatrix.h:264
Header file for the Expression base class.
Header file for the HighType type trait.
Header file for the function trace functionality.
Element ValueType
Type of the underlying pointers.
Definition: IdentityMatrix.h:228
ConstIterator upperBound(size_t i, size_t j) const
Returns an iterator to the first index greater then the given index.
Definition: IdentityMatrix.h:971