35#ifndef _BLAZE_MATH_SPARSE_IDENTITYMATRIX_H_
36#define _BLAZE_MATH_SPARSE_IDENTITYMATRIX_H_
192template<
typename Type
196 :
public Expression< SparseMatrix< IdentityMatrix<Type,SO,Tag>, SO > >
223 template<
typename NewType >
232 template<
size_t NewM
329 constexpr Type
value() const noexcept {
339 constexpr size_t index() const noexcept {
351 return index_ == rhs.index_;
362 return index_ != rhs.index_;
373 return index_ - rhs.index_;
402 template< typename MT,
bool SO2 >
420 constexpr
ConstReference operator()(
size_t i,
size_t j ) const noexcept;
432 template< typename MT,
bool SO2 >
443 constexpr
size_t rows() const noexcept;
444 constexpr
size_t columns() const noexcept;
445 constexpr
size_t capacity() const noexcept;
446 constexpr
size_t capacity(
size_t i ) const noexcept;
447 constexpr
size_t nonZeros() const noexcept;
448 constexpr
size_t nonZeros(
size_t i ) const noexcept;
449 constexpr
void clear() noexcept;
450 constexpr
void resize(
size_t n ) noexcept;
475 template< typename Other > inline
bool canAlias ( const Other* alias ) const noexcept;
476 template< typename Other > inline
bool isAliased( const Other* alias ) const noexcept;
514template< typename Type
528template<
typename Type
546template<
typename Type
556 if( !IsIdentity_v<MT> && !
isIdentity( *m ) ) {
581template<
typename Type
609template<
typename Type
637template<
typename Type
661template<
typename Type
685template<
typename Type
709template<
typename Type
740template<
typename Type
750 if( !IsIdentity_v<MT> && !
isIdentity( *rhs ) ) {
774template<
typename Type
789template<
typename Type
804template<
typename Type
825template<
typename Type
844template<
typename Type
865template<
typename Type
886template<
typename Type
906template<
typename Type
922template<
typename Type
927 const size_t tmp( n_ );
955template<
typename Type
967 return end( SO ? j : i );
985template<
typename Type
994 if( ( !SO && j <= i ) || ( SO && i <= j ) )
995 return begin( SO ? j : i );
997 return end( SO ? j : i );
1015template<
typename Type
1024 if( ( !SO && j < i ) || ( SO && i < j ) )
1025 return begin( SO ? j : i );
1027 return end( SO ? j : i );
1045template<
typename Type
1060template<
typename Type
1088template<
typename Type
1091template<
typename Other >
1111template<
typename Type
1114template<
typename Other >
1134template<
typename Type
1159template< RelaxationFlag RF,
typename Type,
bool SO,
typename Tag >
1162template<
typename Type,
bool SO,
typename Tag >
1165template<
typename Type,
bool SO,
typename Tag >
1202 return ( m.rows() == 0UL );
1225template<
typename Type
1245template<
typename Type
1282template<
typename MT
1284inline IdentityMatrix<ElementType_t<MT>,SO>
1308template<
typename MT,
bool SO,
typename Tag >
1309struct IsSquare< IdentityMatrix<MT,SO,Tag> >
1326template<
typename MT,
bool SO,
typename Tag >
1327struct IsSymmetric< IdentityMatrix<MT,SO,Tag> >
1344template<
typename MT,
bool SO,
typename Tag >
1345struct IsHermitian< IdentityMatrix<MT,SO,Tag> >
1362template<
typename MT,
bool SO,
typename Tag >
1363struct IsUniLower< IdentityMatrix<MT,SO,Tag> >
1380template<
typename MT,
bool SO,
typename Tag >
1381struct IsUniUpper< IdentityMatrix<MT,SO,Tag> >
1398template<
typename T1,
typename T2 >
1399struct SchurTraitEval1< T1, T2
1402 ( ( IsIdentity_v<T1> && IsIdentity_v<T2> ) ||
1403 ( IsIdentity_v<T1> && IsUniTriangular_v<T2> ) ||
1404 ( IsUniTriangular_v<T1> && IsIdentity_v<T2> ) ||
1405 ( IsUniLower_v<T1> && IsUniUpper_v<T2> ) ||
1406 ( IsUniUpper_v<T1> && IsUniLower_v<T2> ) ) &&
1407 !( IsZero_v<T1> || IsZero_v<T2> ) > >
1409 static constexpr bool SO1 = StorageOrder_v<T1>;
1410 static constexpr bool SO2 = StorageOrder_v<T2>;
1412 static constexpr bool SO = ( ( IsDenseMatrix_v<T1> && IsDenseMatrix_v<T2> ) ||
1413 ( IsSparseMatrix_v<T1> && IsSparseMatrix_v<T2> )
1415 : ( IsSparseMatrix_v<T1>
1419 using Type = IdentityMatrix< MultTrait_t< ElementType_t<T1>, ElementType_t<T2> >
1421 , MultTrait_t< TagType_t<T1>, TagType_t<T2> > >;
1437template<
typename T1,
typename T2 >
1438struct MultTraitEval1< T1, T2
1441 !IsIdentity_v<T1> && !IsZero_v<T1> && IsIdentity_v<T2> > >
1443 using Type = Rebind_t< ResultType_t<T1>, MultTrait_t< ElementType_t<T1>, ElementType_t<T2> > >;
1446template<
typename T1,
typename T2 >
1447struct MultTraitEval1< T1, T2
1450 IsIdentity_v<T1> && !IsIdentity_v<T2> && !IsZero_v<T2> > >
1452 using Type = Rebind_t< ResultType_t<T2>, MultTrait_t< ElementType_t<T1>, ElementType_t<T2> > >;
1455template<
typename T1,
typename T2 >
1456struct MultTraitEval1< T1, T2
1459 IsIdentity_v<T1> && IsIdentity_v<T2> > >
1461 using MultType = MultTrait_t< ElementType_t<T1>, ElementType_t<T2> >;
1462 using MultTag = MultTrait_t< TagType_t<T1>, TagType_t<T2> >;
1464 using Type = IdentityMatrix< AddTrait_t<MultType,MultType>
1465 , StorageOrder_v<T1>
1466 , AddTrait_t<MultTag,MultTag> >;
1482template<
typename T1,
typename T2 >
1483struct KronTraitEval1< T1, T2
1486 IsIdentity_v<T1> && IsIdentity_v<T2> > >
1488 using Type = IdentityMatrix< MultTrait_t< ElementType_t<T1>, ElementType_t<T2> >
1489 , StorageOrder_v<T2>
1490 , MultTrait_t< TagType_t<T1>, TagType_t<T2> > >;
1506template<
typename T,
typename OP >
1507struct UnaryMapTraitEval1< T, OP
1509 YieldsIdentity_v<OP,T> > >
1511 using ElementType =
decltype( std::declval<OP>()( std::declval< ElementType_t<T> >() ) );
1513 using Type = IdentityMatrix< EvaluateTrait_t<ElementType>
1515 , MapTrait_t< TagType_t<T>, OP > >;
1523template<
typename T1,
typename T2,
typename OP >
1524struct BinaryMapTraitEval1< T1, T2, OP
1527 YieldsIdentity_v<OP,T1,T2> > >
1529 using ElementType =
decltype( std::declval<OP>()( std::declval< ElementType_t<T1> >()
1530 , std::declval< ElementType_t<T2> >() ) );
1532 using Type = IdentityMatrix< EvaluateTrait_t<ElementType>
1533 , ( StorageOrder_v<T1> && StorageOrder_v<T2> )
1534 ,
MapTrait_t< TagType_t<T1>, TagType_t<T2>, OP > >;
1550template<
typename T,
bool SO,
typename Tag >
1551struct DeclSymTrait< IdentityMatrix<T,SO,Tag> >
1553 using Type = IdentityMatrix<T,SO,Tag>;
1569template<
typename T,
bool SO,
typename Tag >
1570struct DeclHermTrait< IdentityMatrix<T,SO,Tag> >
1572 using Type = IdentityMatrix<T,SO,Tag>;
1588template<
typename T,
bool SO,
typename Tag >
1589struct DeclLowTrait< IdentityMatrix<T,SO,Tag> >
1591 using Type = IdentityMatrix<T,SO,Tag>;
1607template<
typename T,
bool SO,
typename Tag >
1608struct DeclUniLowTrait< IdentityMatrix<T,SO,Tag> >
1610 using Type = IdentityMatrix<T,SO,Tag>;
1626template<
typename T,
bool SO,
typename Tag >
1627struct DeclStrLowTrait< IdentityMatrix<T,SO,Tag> >
1629 using Type = INVALID_TYPE;
1645template<
typename T,
bool SO,
typename Tag >
1646struct DeclUppTrait< IdentityMatrix<T,SO,Tag> >
1648 using Type = IdentityMatrix<T,SO,Tag>;
1664template<
typename T,
bool SO,
typename Tag >
1665struct DeclUniUppTrait< IdentityMatrix<T,SO,Tag> >
1667 using Type = IdentityMatrix<T,SO,Tag>;
1683template<
typename T,
bool SO,
typename Tag >
1684struct DeclStrUppTrait< IdentityMatrix<T,SO,Tag> >
1686 using Type = INVALID_TYPE;
1702template<
typename T,
bool SO,
typename Tag >
1703struct DeclDiagTrait< IdentityMatrix<T,SO,Tag> >
1705 using Type = IdentityMatrix<T,SO,Tag>;
1721template<
typename T1,
bool SO,
typename Tag,
typename T2 >
1722struct HighType< IdentityMatrix<T1,SO,Tag>, IdentityMatrix<T2,SO,Tag> >
1724 using Type = IdentityMatrix< typename HighType<T1,T2>::Type, SO, Tag >;
1740template<
typename T1,
bool SO,
typename Tag,
typename T2 >
1741struct LowType< IdentityMatrix<T1,SO,Tag>, IdentityMatrix<T2,SO,Tag> >
1743 using Type = IdentityMatrix< typename LowType<T1,T2>::Type, SO, Tag >;
Header file for the addition trait.
Header file for auxiliary alias declarations.
typename ResultType_t< T >::TagType TagType_t
Alias declaration for nested TagType type definitions.
Definition: Aliases.h:530
Header file for run time assertion macros.
Constraint on the data type.
Header file for the decldiag trait.
Header file for the declherm trait.
Header file for the decllow trait.
Header file for the declstrlow trait.
Header file for the declstrupp trait.
Header file for the declsym trait.
Header file for the declunilow trait.
Header file for the decluniupp trait.
Header file for the declupp trait.
Header file for the EnableIf class template.
Header file for the EvaluateTrait class template.
Header file for the function trace functionality.
Header file for the HighType type trait.
Header file for the IntegralConstant class template.
Utility type for generic codes.
Header file for the isDefault shim.
Header file for the IsDenseMatrix type trait.
Header file for the IsHermitian type trait.
Header file for the IsIdentity type trait.
Header file for the IsMatrix type trait.
Header file for the IsSMPAssignable type trait.
Header file for the IsSame and IsStrictlySame type traits.
Header file for the IsSparseMatrix type trait.
Header file for the IsSquare type trait.
Header file for the IsSymmetric type trait.
Header file for the IsUniLower type trait.
Header file for the IsUniTriangular type trait.
Header file for the IsUniUpper type trait.
Header file for the Kron product trait.
Header file for the LowType type trait.
Header file for the map trait.
Header file for the MAYBE_UNUSED function template.
Header file for the multiplication trait.
Constraint on the data type.
Constraint on the data type.
Header file for the relaxation flag enumeration.
Constraint on the data type.
Header file for the Schur product trait.
Header file for the ValueIndexPair class.
Constraint on the data type.
Header file for the YieldsIdentity type trait.
Iterator over the elements of the identity matrix.
Definition: IdentityMatrix.h:243
Element ValueType
Type of the underlying pointers.
Definition: IdentityMatrix.h:250
ValueIndexPair< Type > Element
Element type of the identity matrix.
Definition: IdentityMatrix.h:247
IteratorCategory iterator_category
The iterator category.
Definition: IdentityMatrix.h:256
constexpr size_t index() const noexcept
Access to the current index of the sparse element.
Definition: IdentityMatrix.h:339
constexpr ConstIterator() noexcept
Default constructor for the ConstIterator class.
Definition: IdentityMatrix.h:266
constexpr DifferenceType operator-(const ConstIterator &rhs) const noexcept
Calculating the number of elements between two ConstIterator objects.
Definition: IdentityMatrix.h:372
constexpr ConstIterator(size_t index) noexcept
Constructor for the ConstIterator class.
Definition: IdentityMatrix.h:276
constexpr const Element operator*() const noexcept
Direct access to the sparse matrix element at the current iterator position.
Definition: IdentityMatrix.h:309
constexpr ConstIterator operator++(int) noexcept
Post-increment operator.
Definition: IdentityMatrix.h:297
constexpr ConstIterator & operator++() noexcept
Pre-increment operator.
Definition: IdentityMatrix.h:286
std::forward_iterator_tag IteratorCategory
The iterator category.
Definition: IdentityMatrix.h:249
ValueType * PointerType
Pointer return type.
Definition: IdentityMatrix.h:251
constexpr bool operator!=(const ConstIterator &rhs) const noexcept
Inequality comparison between two ConstIterator objects.
Definition: IdentityMatrix.h:361
constexpr const ConstIterator * operator->() const noexcept
Direct access to the sparse matrix element at the current iterator position.
Definition: IdentityMatrix.h:319
DifferenceType difference_type
Difference between two iterators.
Definition: IdentityMatrix.h:260
ValueType & ReferenceType
Reference return type.
Definition: IdentityMatrix.h:252
constexpr Type value() const noexcept
Access to the current value of the sparse element.
Definition: IdentityMatrix.h:329
size_t index_
Index to the current identity matrix element.
Definition: IdentityMatrix.h:379
constexpr bool operator==(const ConstIterator &rhs) const noexcept
Equality comparison between two ConstIterator objects.
Definition: IdentityMatrix.h:350
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: IdentityMatrix.h:253
Efficient implementation of an identity matrix.
Definition: IdentityMatrix.h:197
constexpr IdentityMatrix & transpose() noexcept
In-place transpose of the matrix.
Definition: IdentityMatrix.h:1048
bool isAliased(const Other *alias) const noexcept
Returns whether the matrix is aliased with the given address alias.
Definition: IdentityMatrix.h:1115
ConstIterator find(size_t i, size_t j) const
Searches for a specific matrix element.
Definition: IdentityMatrix.h:959
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:713
constexpr ConstIterator begin(size_t i) const noexcept
Returns an iterator to the first non-zero element of row/column i.
Definition: IdentityMatrix.h:641
constexpr size_t capacity() const noexcept
Returns the maximum capacity of the identity matrix.
Definition: IdentityMatrix.h:807
const Type ReturnType
Return type for expression template evaluations.
Definition: IdentityMatrix.h:214
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:989
bool canAlias(const Other *alias) const noexcept
Returns whether the matrix can alias with the given address alias.
Definition: IdentityMatrix.h:1092
constexpr size_t columns() const noexcept
Returns the current number of columns of the identity matrix.
Definition: IdentityMatrix.h:792
constexpr ConstIterator cbegin(size_t i) const noexcept
Returns an iterator to the first non-zero element of row/column i.
Definition: IdentityMatrix.h:665
constexpr void swap(IdentityMatrix &m) noexcept
Swapping the contents of two sparse matrices.
Definition: IdentityMatrix.h:925
ConstReference at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: IdentityMatrix.h:613
const Type ConstReference
Reference to a constant identity matrix element.
Definition: IdentityMatrix.h:217
const Type Reference
Reference to a identity matrix element.
Definition: IdentityMatrix.h:216
static constexpr bool smpAssignable
Compilation flag for SMP assignments.
Definition: IdentityMatrix.h:393
size_t n_
The current number of rows and columns of the identity matrix.
Definition: IdentityMatrix.h:486
constexpr void resize(size_t n) noexcept
Changing the size of the identity matrix.
Definition: IdentityMatrix.h:909
IdentityMatrix< Type, SO, Tag > This
Type of this IdentityMatrix instance.
Definition: IdentityMatrix.h:200
Type ElementType
Type of the identity matrix elements.
Definition: IdentityMatrix.h:212
constexpr IdentityMatrix & ctranspose() noexcept
In-place conjugate transpose of the matrix.
Definition: IdentityMatrix.h:1063
Tag TagType
Tag type of this IdentityMatrix instance.
Definition: IdentityMatrix.h:213
constexpr size_t nonZeros() const noexcept
Returns the number of non-zero elements in the identity matrix.
Definition: IdentityMatrix.h:847
constexpr ConstReference operator()(size_t i, size_t j) const noexcept
2D-access to the identity matrix elements.
Definition: IdentityMatrix.h:585
ConstIterator upperBound(size_t i, size_t j) const
Returns an iterator to the first index greater then the given index.
Definition: IdentityMatrix.h:1019
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:689
constexpr size_t rows() const noexcept
Returns the current number of rows of the identity matrix.
Definition: IdentityMatrix.h:777
bool canSMPAssign() const noexcept
Returns whether the matrix can be used in SMP assignments.
Definition: IdentityMatrix.h:1137
constexpr void clear() noexcept
Clearing the identity matrix.
Definition: IdentityMatrix.h:889
constexpr IdentityMatrix() noexcept
The default constructor for IdentityMatrix.
Definition: IdentityMatrix.h:517
Base class for matrices.
Definition: Matrix.h:85
Index-value-pair for sparse vectors and matrices.
Definition: ValueIndexPair.h:75
Header file for the DenseMatrix base class.
Header file for the DenseVector base class.
Header file for the Expression base class.
Header file for the SparseMatrix base class.
Header file for the SparseVector base class.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE(T)
Constraint on the data type.
Definition: Volatile.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_POINTER_TYPE(T)
Constraint on the data type.
Definition: Pointer.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_CONST(T)
Constraint on the data type.
Definition: Const.h:79
#define BLAZE_CONSTRAINT_MUST_BE_SAME_TAG(A, B)
Data type constraint.
Definition: SameTag.h:68
#define BLAZE_CONSTRAINT_MUST_NOT_BE_REFERENCE_TYPE(T)
Constraint on the data type.
Definition: Reference.h:79
bool isIdentity(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is an identity matrix.
Definition: DenseMatrix.h:2561
IdentityMatrix< ElementType_t< MT >, SO > declid(const Matrix< MT, SO > &m)
Declares the given matrix expression m as identity matrix.
Definition: IdentityMatrix.h:1285
constexpr bool isIntact(const IdentityMatrix< Type, SO, Tag > &m) noexcept
Returns whether the invariants of the given identity matrix are intact.
Definition: IdentityMatrix.h:1228
constexpr void swap(IdentityMatrix< Type, SO, Tag > &a, IdentityMatrix< Type, SO, Tag > &b) noexcept
Swapping the contents of two identity matrices.
Definition: IdentityMatrix.h:1248
constexpr bool isDefault(const IdentityMatrix< Type, SO, Tag > &m) noexcept
Returns whether the given identity matrix is in default state.
Definition: IdentityMatrix.h:1200
#define BLAZE_CONSTRAINT_MUST_BE_SCALAR_TYPE(T)
Constraint on the data type.
Definition: Scalar.h:61
typename MapTrait< Args... >::Type MapTrait_t
Auxiliary alias declaration for the MapTrait class template.
Definition: MapTrait.h:131
constexpr bool IsMatrix_v
Auxiliary variable template for the IsMatrix type trait.
Definition: IsMatrix.h:124
RelaxationFlag
Relaxation flag for strict or relaxed semantics.
Definition: RelaxationFlag.h:66
constexpr size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:644
constexpr size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:660
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:584
MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:518
bool isSquare(const Matrix< MT, SO > &matrix) noexcept
Checks if the given matrix is a square matrix.
Definition: Matrix.h:1383
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.
Definition: Assert.h:117
BoolConstant< true > TrueType
Type traits base class.
Definition: IntegralConstant.h:132
typename EnableIf< Condition, T >::Type EnableIf_t
Auxiliary type for the EnableIf class template.
Definition: EnableIf.h:138
constexpr void MAYBE_UNUSED(const Args &...)
Suppression of unused parameter warnings.
Definition: MaybeUnused.h:81
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.
Definition: Exception.h:331
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.
Definition: Exception.h:235
#define BLAZE_FUNCTION_TRACE
Function trace macro.
Definition: FunctionTrace.h:94
Header file for the exception macros of the math module.
Header file for all forward declarations of the math module.
Header file for all forward declarations for sparse vectors and matrices.
Header file for the StorageOrder type trait.
Base class for all expression templates.
Definition: Expression.h:60
Rebind mechanism to obtain an IdentityMatrix with different data/element type.
Definition: IdentityMatrix.h:224
Resize mechanism to obtain a IdentityMatrix with different fixed dimensions.
Definition: IdentityMatrix.h:234
Header file for the IsZero type trait.
Header file for basic type definitions.