35 #ifndef _BLAZE_MATH_SPARSE_IDENTITYMATRIX_H_ 36 #define _BLAZE_MATH_SPARSE_IDENTITYMATRIX_H_ 177 template<
typename Type
178 ,
bool SO = defaultStorageOrder >
180 :
public SparseMatrix< IdentityMatrix<Type,SO>, SO >
199 template<
typename NewType >
208 template<
size_t NewM
305 inline constexpr Type
value() const noexcept {
315 inline constexpr
size_t index() const noexcept {
327 return index_ == rhs.index_;
338 return index_ != rhs.index_;
349 return index_ - rhs.index_;
378 template< typename MT,
bool SO2 >
396 inline constexpr
ConstReference operator()(
size_t i,
size_t j ) const noexcept;
408 template< typename MT,
bool SO2 >
419 inline constexpr
size_t rows() const noexcept;
420 inline constexpr
size_t columns() const noexcept;
421 inline constexpr
size_t capacity() const noexcept;
422 inline constexpr
size_t capacity(
size_t i ) const noexcept;
423 inline constexpr
size_t nonZeros() const noexcept;
424 inline constexpr
size_t nonZeros(
size_t i ) const noexcept;
425 inline constexpr
void clear() noexcept;
426 constexpr
void resize(
size_t n ) noexcept;
451 template< typename Other > inline
bool canAlias ( const Other* alias ) const noexcept;
452 template< typename Other > inline
bool isAliased( const Other* alias ) const noexcept;
490 template< typename Type
503 template<
typename Type
520 template<
typename Type
522 template<
typename MT
527 if( !IsIdentity_v<MT> && !
isIdentity( ~m ) ) {
552 template<
typename Type
579 template<
typename Type
606 template<
typename Type
629 template<
typename Type
652 template<
typename Type
675 template<
typename Type
705 template<
typename Type
707 template<
typename MT
712 if( !IsIdentity_v<MT> && !
isIdentity( ~rhs ) ) {
736 template<
typename Type
750 template<
typename Type
764 template<
typename Type
784 template<
typename Type
802 template<
typename Type
822 template<
typename Type
842 template<
typename Type
861 template<
typename Type
876 template<
typename Type
880 const size_t tmp(
n_ );
908 template<
typename Type
919 return end( SO ? j : i );
937 template<
typename Type
945 if( ( !SO && j <= i ) || ( SO && i <= j ) )
946 return begin( SO ? j : i );
948 return end( SO ? j : i );
966 template<
typename Type
974 if( ( !SO && j < i ) || ( SO && i < j ) )
975 return begin( SO ? j : i );
977 return end( SO ? j : i );
995 template<
typename Type
1009 template<
typename Type
1036 template<
typename Type
1038 template<
typename Other >
1058 template<
typename Type
1060 template<
typename Other >
1080 template<
typename Type
1104 template<
typename Type,
bool SO >
1107 template<
typename Type,
bool SO >
1110 template<
typename Type,
bool SO >
1113 template<
bool RF,
typename Type,
bool SO >
1116 template<
typename Type,
bool SO >
1119 template<
typename Type,
bool SO >
1132 template<
typename Type
1154 template<
typename Type
1170 template<
typename Type
1209 return ( m.rows() == 0UL );
1232 template<
typename Type
1251 template<
typename Type
1287 template<
typename MT
1289 inline IdentityMatrix<ElementType_t<MT>,SO>
1313 template<
typename MT,
bool SO >
1314 struct IsSquare< IdentityMatrix<MT,SO> >
1331 template<
typename MT,
bool SO >
1332 struct IsSymmetric< IdentityMatrix<MT,SO> >
1349 template<
typename MT,
bool SO >
1350 struct IsHermitian< IdentityMatrix<MT,SO> >
1367 template<
typename MT,
bool SO >
1368 struct IsUniLower< IdentityMatrix<MT,SO> >
1385 template<
typename MT,
bool SO >
1386 struct IsUniUpper< IdentityMatrix<MT,SO> >
1403 template<
typename T,
bool SO >
1404 struct IsResizable< IdentityMatrix<T,SO> >
1421 template<
typename T1,
typename T2 >
1422 struct SchurTraitEval1< T1, T2
1425 ( ( IsIdentity_v<T1> && IsIdentity_v<T2> ) ||
1426 ( IsIdentity_v<T1> && IsUniTriangular_v<T2> ) ||
1427 ( IsUniTriangular_v<T1> && IsIdentity_v<T2> ) ||
1428 ( IsUniLower_v<T1> && IsUniUpper_v<T2> ) ||
1429 ( IsUniUpper_v<T1> && IsUniLower_v<T2> ) ) &&
1430 !( IsZero_v<T1> || IsZero_v<T2> ) > >
1432 using ET1 = ElementType_t<T1>;
1433 using ET2 = ElementType_t<T2>;
1435 static constexpr
bool SO1 = StorageOrder_v<T1>;
1436 static constexpr
bool SO2 = StorageOrder_v<T2>;
1438 static constexpr
bool SO = ( ( IsDenseMatrix_v<T1> && IsDenseMatrix_v<T2> ) ||
1439 ( IsSparseMatrix_v<T1> && IsSparseMatrix_v<T2> )
1441 : ( IsSparseMatrix_v<T1>
1445 using Type = IdentityMatrix< MultTrait_t<ET1,ET2>, SO >;
1461 template<
typename T1,
typename T2 >
1462 struct MultTraitEval1< T1, T2
1465 !IsIdentity_v<T1> && !IsZero_v<T1> && IsIdentity_v<T2> > >
1467 using Type = Rebind_t< ResultType_t<T1>, MultTrait_t< ElementType_t<T1>, ElementType_t<T2> > >;
1470 template<
typename T1,
typename T2 >
1471 struct MultTraitEval1< T1, T2
1474 IsIdentity_v<T1> && !IsIdentity_v<T2> && !IsZero_v<T2> > >
1476 using Type = Rebind_t< ResultType_t<T2>, MultTrait_t< ElementType_t<T1>, ElementType_t<T2> > >;
1479 template<
typename T1,
typename T2 >
1480 struct MultTraitEval1< T1, T2
1483 IsIdentity_v<T1> && IsIdentity_v<T2> > >
1485 using ET1 = ElementType_t<T1>;
1486 using ET2 = ElementType_t<T2>;
1488 using Type = IdentityMatrix< MultTrait_t<ET1,ET2>, StorageOrder_v<T1> >;
1504 template<
typename T,
typename OP >
1505 struct UnaryMapTraitEval1< T, OP
1507 YieldsIdentity_v<OP,T> > >
1509 using ET = ElementType_t<T>;
1511 using Type = IdentityMatrix< MapTrait_t<ET,OP>, StorageOrder_v<T> >;
1519 template<
typename T1,
typename T2,
typename OP >
1520 struct BinaryMapTraitEval1< T1, T2, OP
1523 YieldsIdentity_v<OP,T1,T2> > >
1525 using ET1 = ElementType_t<T1>;
1526 using ET2 = ElementType_t<T2>;
1528 static constexpr
bool SO = StorageOrder_v<T1> && StorageOrder_v<T2>;
1530 using Type = IdentityMatrix< MapTrait_t<ET1,ET2,OP>, SO >;
1546 template<
typename T,
bool SO >
1547 struct DeclSymTrait< IdentityMatrix<T,SO> >
1549 using Type = IdentityMatrix<T,SO>;
1565 template<
typename T,
bool SO >
1566 struct DeclHermTrait< IdentityMatrix<T,SO> >
1568 using Type = IdentityMatrix<T,SO>;
1584 template<
typename T,
bool SO >
1585 struct DeclLowTrait< IdentityMatrix<T,SO> >
1587 using Type = IdentityMatrix<T,SO>;
1603 template<
typename T,
bool SO >
1604 struct DeclUppTrait< IdentityMatrix<T,SO> >
1606 using Type = IdentityMatrix<T,SO>;
1622 template<
typename T,
bool SO >
1623 struct DeclDiagTrait< IdentityMatrix<T,SO> >
1625 using Type = IdentityMatrix<T,SO>;
1641 template<
typename T1,
bool SO,
typename T2 >
1642 struct HighType< IdentityMatrix<T1,SO>, IdentityMatrix<T2,SO> >
1644 using Type = IdentityMatrix< typename HighType<T1,T2>::Type, SO >;
1660 template<
typename T1,
bool SO,
typename T2 >
1661 struct LowType< IdentityMatrix<T1,SO>, IdentityMatrix<T2,SO> >
1663 using Type = IdentityMatrix< typename LowType<T1,T2>::Type, SO >;
constexpr ConstIterator() noexcept
Default constructor for the ConstIterator class.
Definition: IdentityMatrix.h:242
#define BLAZE_CONSTRAINT_MUST_NOT_BE_CONST(T)
Constraint on the data type.In case the given data type is a const-qualified type, a compilation error is created.
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:218
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:1061
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_USER_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERT flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:117
ValueIndexPair< Type > Element
Element type of the identity matrix.
Definition: IdentityMatrix.h:223
constexpr void swap(IdentityMatrix &m) noexcept
Swapping the contents of two sparse matrices.
Definition: IdentityMatrix.h:878
Header file for the UNUSED_PARAMETER function template.
Header file for the IsUniUpper type trait.
const Type ReturnType
Return type for expression template evaluations.
Definition: IdentityMatrix.h:190
Header file for basic type definitions.
Header file for the SparseVector base class.
constexpr bool IsMatrix_v
Auxiliary variable template for the IsMatrix type trait.The IsMatrix_v variable template provides a c...
Definition: IsMatrix.h:139
constexpr DifferenceType operator-(const ConstIterator &rhs) const noexcept
Calculating the number of elements between two ConstIterator objects.
Definition: IdentityMatrix.h:348
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:655
Resize mechanism to obtain a IdentityMatrix with different fixed dimensions.
Definition: IdentityMatrix.h:210
Header file for the IsSparseMatrix type trait.
const Type ConstReference
Reference to a constant identity matrix element.
Definition: IdentityMatrix.h:193
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:305
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:591
Header file for the YieldsIdentity type trait.
constexpr IdentityMatrix() noexcept
The default constructor for IdentityMatrix.
Definition: IdentityMatrix.h:492
Header file for the DenseVector base class.
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, a compilation error is created.
Definition: Volatile.h:79
std::forward_iterator_tag IteratorCategory
The iterator category.
Definition: IdentityMatrix.h:225
BoolConstant< true > TrueType
Type traits base class.The TrueType class is used as base class for type traits and value traits that...
Definition: TrueType.h:61
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:940
constexpr ConstIterator operator++(int) noexcept
Post-increment operator.
Definition: IdentityMatrix.h:273
constexpr void UNUSED_PARAMETER(const Args &...)
Suppression of unused parameter warnings.
Definition: Unused.h:81
Header file for the IsUniLower type trait.
constexpr const Element operator*() const noexcept
Direct access to the sparse matrix element at the current iterator position.
Definition: IdentityMatrix.h:285
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:137
constexpr void clear() noexcept
Clearing the identity matrix.
Definition: IdentityMatrix.h:844
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:1644
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:738
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for all forward declarations of the math module.
#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:632
Header file for the DenseMatrix base class.
Type ElementType
Type of the identity matrix elements.
Definition: IdentityMatrix.h:189
constexpr size_t capacity() const noexcept
Returns the maximum capacity of the identity matrix.
Definition: IdentityMatrix.h:766
constexpr ConstIterator(size_t index) noexcept
Constructor for the ConstIterator class.
Definition: IdentityMatrix.h:252
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:3086
Constraint on the data type.
ConstIterator find(size_t i, size_t j) const
Searches for a specific matrix element.
Definition: IdentityMatrix.h:911
constexpr size_t nonZeros() const noexcept
Returns the number of non-zero elements in the identity matrix.
Definition: IdentityMatrix.h:804
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 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:200
size_t index_
Index to the current identity matrix element.
Definition: IdentityMatrix.h:355
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:611
constexpr IdentityMatrix & transpose() noexcept
In-place transpose of the matrix.
Definition: IdentityMatrix.h:997
bool canSMPAssign() const noexcept
Returns whether the matrix can be used in SMP assignments.
Definition: IdentityMatrix.h:1082
constexpr void resize(size_t n) noexcept
Changing the size of the identity matrix.
Definition: IdentityMatrix.h:863
constexpr size_t index() const noexcept
Access to the current index of the sparse element.
Definition: IdentityMatrix.h:315
const Type Reference
Reference to a identity matrix element.
Definition: IdentityMatrix.h:192
IdentityMatrix< ElementType_t< MT >, SO > declid(const Matrix< MT, SO > &m)
Declares the given matrix expression m as identity matrix.
Definition: IdentityMatrix.h:1290
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:678
Header file for the IsNumeric type trait.
size_t n_
The current number of rows and columns of the identity matrix.
Definition: IdentityMatrix.h:462
IdentityMatrix< Type, SO > This
Type of this IdentityMatrix instance.
Definition: IdentityMatrix.h:184
Header file for the declupp trait.
constexpr bool operator==(const ConstIterator &rhs) const noexcept
Equality comparison between two ConstIterator objects.
Definition: IdentityMatrix.h:326
constexpr bool operator!=(const ConstIterator &rhs) const noexcept
Inequality comparison between two ConstIterator objects.
Definition: IdentityMatrix.h:337
constexpr const ConstIterator * operator->() const noexcept
Direct access to the sparse matrix element at the current iterator position.
Definition: IdentityMatrix.h:295
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:555
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:228
#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, a compilation error is created.
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:281
Base class for matrices.The Matrix class is a base class for all dense and sparse matrix classes with...
Definition: Forward.h:109
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:1039
constexpr IdentityMatrix & ctranspose() noexcept
In-place conjugate transpose of the matrix.
Definition: IdentityMatrix.h:1011
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:609
ConstReference at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: IdentityMatrix.h:582
static constexpr bool smpAssignable
Compilation flag for SMP assignments.
Definition: IdentityMatrix.h:369
size_t n_
The current number of columns of the compressed matrix.
Definition: CompressedMatrix.h:3290
constexpr size_t columns() const noexcept
Returns the current number of columns of the identity matrix.
Definition: IdentityMatrix.h:752
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:232
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:263
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:631
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:227
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: IdentityMatrix.h:229
constexpr ConstIterator & operator++() noexcept
Pre-increment operator.
Definition: IdentityMatrix.h:262
Header file for the HighType type trait.
Header file for the TrueType type/value trait base class.
Header file for the function trace functionality.
Element ValueType
Type of the underlying pointers.
Definition: IdentityMatrix.h:226
ConstIterator upperBound(size_t i, size_t j) const
Returns an iterator to the first index greater then the given index.
Definition: IdentityMatrix.h:969