Blaze 3.9
IdentityMatrix.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_SPARSE_IDENTITYMATRIX_H_
36#define _BLAZE_MATH_SPARSE_IDENTITYMATRIX_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <iterator>
44#include <blaze/math/Aliases.h>
53#include <blaze/math/Forward.h>
89#include <blaze/util/Assert.h>
94#include <blaze/util/EnableIf.h>
99#include <blaze/util/Types.h>
101
102
103namespace blaze {
104
105//=================================================================================================
106//
107// CLASS DEFINITION
108//
109//=================================================================================================
110
111//*************************************************************************************************
192template< typename Type // Data type of the matrix
193 , bool SO // Storage order
194 , typename Tag > // Tag type
196 : public Expression< SparseMatrix< IdentityMatrix<Type,SO,Tag>, SO > >
197{
198 public:
199 //**Type definitions****************************************************************************
202
204 using ResultType = This;
205
208
211
212 using ElementType = Type;
213 using TagType = Tag;
214 using ReturnType = const Type;
215 using CompositeType = const This&;
216 using Reference = const Type;
217 using ConstReference = const Type;
218 //**********************************************************************************************
219
220 //**Rebind struct definition********************************************************************
223 template< typename NewType > // Data type of the other matrix
224 struct Rebind {
226 };
227 //**********************************************************************************************
228
229 //**Resize struct definition********************************************************************
232 template< size_t NewM // Number of rows of the other matrix
233 , size_t NewN > // Number of columns of the other matrix
234 struct Resize {
236 };
237 //**********************************************************************************************
238
239 //**ConstIterator class definition**************************************************************
243 {
244 public:
245 //**Type definitions*************************************************************************
248
249 using IteratorCategory = std::forward_iterator_tag;
253 using DifferenceType = ptrdiff_t;
254
255 // STL iterator requirements
261 //*******************************************************************************************
262
263 //**Default constructor**********************************************************************
266 constexpr ConstIterator() noexcept
267 : index_() // Index to the current identity matrix element
268 {}
269 //*******************************************************************************************
270
271 //**Constructor******************************************************************************
276 constexpr ConstIterator( size_t index ) noexcept
277 : index_( index ) // Index to the current identity matrix element
278 {}
279 //*******************************************************************************************
280
281 //**Prefix increment operator****************************************************************
286 constexpr ConstIterator& operator++() noexcept {
287 ++index_;
288 return *this;
289 }
290 //*******************************************************************************************
291
292 //**Postfix increment operator***************************************************************
297 constexpr ConstIterator operator++( int ) noexcept {
298 ConstIterator tmp( *this );
299 ++index_;
300 return tmp;
301 }
302 //*******************************************************************************************
303
304 //**Element access operator******************************************************************
309 constexpr const Element operator*() const noexcept {
310 return Element( Type(1), index_ );
311 }
312 //*******************************************************************************************
313
314 //**Element access operator******************************************************************
319 constexpr const ConstIterator* operator->() const noexcept {
320 return this;
321 }
322 //*******************************************************************************************
323
324 //**Value function***************************************************************************
329 constexpr Type value() const noexcept {
330 return Type(1);
331 }
332 //*******************************************************************************************
333
334 //**Index function***************************************************************************
339 constexpr size_t index() const noexcept {
340 return index_;
341 }
342 //*******************************************************************************************
343
344 //**Equality operator************************************************************************
350 constexpr bool operator==( const ConstIterator& rhs ) const noexcept {
351 return index_ == rhs.index_;
352 }
353 //*******************************************************************************************
354
355 //**Inequality operator**********************************************************************
361 constexpr bool operator!=( const ConstIterator& rhs ) const noexcept {
362 return index_ != rhs.index_;
363 }
364 //*******************************************************************************************
365
366 //**Subtraction operator*********************************************************************
372 constexpr DifferenceType operator-( const ConstIterator& rhs ) const noexcept {
373 return index_ - rhs.index_;
374 }
375 //*******************************************************************************************
376
377 private:
378 //**Member variables*************************************************************************
379 size_t index_;
380 //*******************************************************************************************
381 };
382 //**********************************************************************************************
383
384 //**Type definitions****************************************************************************
386 //**********************************************************************************************
387
388 //**Compilation flags***************************************************************************
390
393 static constexpr bool smpAssignable = !IsSMPAssignable_v<Type>;
394 //**********************************************************************************************
395
396 //**Constructors********************************************************************************
399 constexpr IdentityMatrix() noexcept;
400 explicit constexpr IdentityMatrix( size_t n ) noexcept;
401
402 template< typename MT, bool SO2 >
403 inline IdentityMatrix( const Matrix<MT,SO2>& m );
404
405 IdentityMatrix( const IdentityMatrix& ) = default;
406 IdentityMatrix( IdentityMatrix&& ) = default;
408 //**********************************************************************************************
409
410 //**Destructor**********************************************************************************
413 ~IdentityMatrix() = default;
415 //**********************************************************************************************
416
417 //**Data access functions***********************************************************************
420 constexpr ConstReference operator()( size_t i, size_t j ) const noexcept;
421 inline ConstReference at( size_t i, size_t j ) const;
422 constexpr ConstIterator begin ( size_t i ) const noexcept;
423 constexpr ConstIterator cbegin( size_t i ) const noexcept;
424 constexpr ConstIterator end ( size_t i ) const noexcept;
425 constexpr ConstIterator cend ( size_t i ) const noexcept;
427 //**********************************************************************************************
428
429 //**Assignment operators************************************************************************
432 template< typename MT, bool SO2 >
433 inline IdentityMatrix& operator=( const Matrix<MT,SO2>& rhs ) &;
434
435 IdentityMatrix& operator=( const IdentityMatrix& ) & = default;
436 IdentityMatrix& operator=( IdentityMatrix&& ) & = default;
438 //**********************************************************************************************
439
440 //**Utility functions***************************************************************************
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;
451 constexpr void swap( IdentityMatrix& m ) noexcept;
453 //**********************************************************************************************
454
455 //**Lookup functions****************************************************************************
458 inline ConstIterator find ( size_t i, size_t j ) const;
459 inline ConstIterator lowerBound( size_t i, size_t j ) const;
460 inline ConstIterator upperBound( size_t i, size_t j ) const;
462 //**********************************************************************************************
463
464 //**Numeric functions***************************************************************************
467 constexpr IdentityMatrix& transpose() noexcept;
468 constexpr IdentityMatrix& ctranspose() noexcept;
470 //**********************************************************************************************
471
472 //**Expression template evaluation functions****************************************************
475 template< typename Other > inline bool canAlias ( const Other* alias ) const noexcept;
476 template< typename Other > inline bool isAliased( const Other* alias ) const noexcept;
477
478 inline bool canSMPAssign() const noexcept;
480 //**********************************************************************************************
481
482 private:
483 //**Member variables****************************************************************************
486 size_t n_;
488 //**********************************************************************************************
489
490 //**Compile time checks*************************************************************************
498 //**********************************************************************************************
499};
500//*************************************************************************************************
501
502
503
504
505//=================================================================================================
506//
507// CONSTRUCTORS
508//
509//=================================================================================================
510
511//*************************************************************************************************
514template< typename Type // Data type of the matrix
515 , bool SO // Storage order
516 , typename Tag > // Tag type
517constexpr IdentityMatrix<Type,SO,Tag>::IdentityMatrix() noexcept
518 : n_( 0UL ) // The current number of rows and columns of the identity matrix
519{}
520//*************************************************************************************************
521
522
523//*************************************************************************************************
528template< typename Type // Data type of the matrix
529 , bool SO // Storage order
530 , typename Tag > // Tag type
532 : n_( n ) // The current number of rows and columns of the identity matrix
533{}
534//*************************************************************************************************
535
536
537//*************************************************************************************************
546template< typename Type // Data type of the matrix
547 , bool SO // Storage order
548 , typename Tag > // Tag type
549template< typename MT // Type of the foreign identity matrix
550 , bool SO2 > // Storage order of the foreign identity matrix
552 : n_( (*m).rows() ) // The current number of rows and columns of the identity matrix
553{
555
556 if( !IsIdentity_v<MT> && !isIdentity( *m ) ) {
557 BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of identity matrix" );
558 }
559}
560//*************************************************************************************************
561
562
563
564
565//=================================================================================================
566//
567// DATA ACCESS FUNCTIONS
568//
569//=================================================================================================
570
571//*************************************************************************************************
581template< typename Type // Data type of the matrix
582 , bool SO // Storage order
583 , typename Tag > // Tag type
585 IdentityMatrix<Type,SO,Tag>::operator()( size_t i, size_t j ) const noexcept
586{
587 BLAZE_USER_ASSERT( i < rows() , "Invalid identity matrix row access index" );
588 BLAZE_USER_ASSERT( j < columns(), "Invalid identity matrix column access index" );
589
590 if( i == j )
591 return Type( 1 );
592 else
593 return Type( 0 );
594}
595//*************************************************************************************************
596
597
598//*************************************************************************************************
609template< typename Type // Data type of the matrix
610 , bool SO // Storage order
611 , typename Tag > // Tag type
613 IdentityMatrix<Type,SO,Tag>::at( size_t i, size_t j ) const
614{
615 if( i >= n_ ) {
616 BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
617 }
618 if( j >= n_ ) {
619 BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
620 }
621 return (*this)(i,j);
622}
623//*************************************************************************************************
624
625
626//*************************************************************************************************
637template< typename Type // Data type of the matrix
638 , bool SO // Storage order
639 , typename Tag > // Tag type
641 IdentityMatrix<Type,SO,Tag>::begin( size_t i ) const noexcept
642{
643 BLAZE_USER_ASSERT( i < n_, "Invalid identity matrix row/column access index" );
644
645 return ConstIterator( i );
646}
647//*************************************************************************************************
648
649
650//*************************************************************************************************
661template< typename Type // Data type of the matrix
662 , bool SO // Storage order
663 , typename Tag > // Tag type
665 IdentityMatrix<Type,SO,Tag>::cbegin( size_t i ) const noexcept
666{
667 BLAZE_USER_ASSERT( i < n_, "Invalid identity matrix row/column access index" );
668
669 return ConstIterator( i );
670}
671//*************************************************************************************************
672
673
674//*************************************************************************************************
685template< typename Type // Data type of the matrix
686 , bool SO // Storage order
687 , typename Tag > // Tag type
689 IdentityMatrix<Type,SO,Tag>::end( size_t i ) const noexcept
690{
691 BLAZE_USER_ASSERT( i < n_, "Invalid identity matrix row/column access index" );
692
693 return ConstIterator( i+1UL );
694}
695//*************************************************************************************************
696
697
698//*************************************************************************************************
709template< typename Type // Data type of the matrix
710 , bool SO // Storage order
711 , typename Tag > // Tag type
713 IdentityMatrix<Type,SO,Tag>::cend( size_t i ) const noexcept
714{
715 BLAZE_USER_ASSERT( i < n_, "Invalid identity matrix row/column access index" );
716
717 return ConstIterator( i+1UL );
718}
719//*************************************************************************************************
720
721
722
723
724//=================================================================================================
725//
726// ASSIGNMENT OPERATORS
727//
728//=================================================================================================
729
730//*************************************************************************************************
740template< typename Type // Data type of the matrix
741 , bool SO // Storage order
742 , typename Tag > // Tag type
743template< typename MT // Type of the right-hand side identity matrix
744 , bool SO2 > // Storage order of the right-hand side identity matrix
747{
749
750 if( !IsIdentity_v<MT> && !isIdentity( *rhs ) ) {
751 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment of identity matrix" );
752 }
753
754 n_ = (*rhs).rows();
755
756 return *this;
757}
758//*************************************************************************************************
759
760
761
762
763//=================================================================================================
764//
765// UTILITY FUNCTIONS
766//
767//=================================================================================================
768
769//*************************************************************************************************
774template< typename Type // Data type of the matrix
775 , bool SO // Storage order
776 , typename Tag > // Tag type
777constexpr size_t IdentityMatrix<Type,SO,Tag>::rows() const noexcept
778{
779 return n_;
780}
781//*************************************************************************************************
782
783
784//*************************************************************************************************
789template< typename Type // Data type of the matrix
790 , bool SO // Storage order
791 , typename Tag > // Tag type
792constexpr size_t IdentityMatrix<Type,SO,Tag>::columns() const noexcept
793{
794 return n_;
795}
796//*************************************************************************************************
797
798
799//*************************************************************************************************
804template< typename Type // Data type of the matrix
805 , bool SO // Storage order
806 , typename Tag > // Tag type
807constexpr size_t IdentityMatrix<Type,SO,Tag>::capacity() const noexcept
808{
809 return n_;
810}
811//*************************************************************************************************
812
813
814//*************************************************************************************************
825template< typename Type // Data type of the matrix
826 , bool SO // Storage order
827 , typename Tag > // Tag type
828constexpr size_t IdentityMatrix<Type,SO,Tag>::capacity( size_t i ) const noexcept
829{
830 MAYBE_UNUSED( i );
831
832 BLAZE_USER_ASSERT( i < n_, "Invalid identity matrix row/column access index" );
833
834 return 1UL;
835}
836//*************************************************************************************************
837
838
839//*************************************************************************************************
844template< typename Type // Data type of the matrix
845 , bool SO // Storage order
846 , typename Tag > // Tag type
847constexpr size_t IdentityMatrix<Type,SO,Tag>::nonZeros() const noexcept
848{
849 return n_;
850}
851//*************************************************************************************************
852
853
854//*************************************************************************************************
865template< typename Type // Data type of the matrix
866 , bool SO // Storage order
867 , typename Tag > // Tag type
868constexpr size_t IdentityMatrix<Type,SO,Tag>::nonZeros( size_t i ) const noexcept
869{
870 MAYBE_UNUSED( i );
871
872 BLAZE_USER_ASSERT( i < n_, "Invalid identity matrix row/column access index" );
873
874 return 1UL;
875}
876//*************************************************************************************************
877
878
879//*************************************************************************************************
886template< typename Type // Data type of the matrix
887 , bool SO // Storage order
888 , typename Tag > // Tag type
889constexpr void IdentityMatrix<Type,SO,Tag>::clear() noexcept
890{
891 n_ = 0UL;
892}
893//*************************************************************************************************
894
895
896//*************************************************************************************************
906template< typename Type // Data type of the matrix
907 , bool SO // Storage order
908 , typename Tag > // Tag type
909void constexpr IdentityMatrix<Type,SO,Tag>::resize( size_t n ) noexcept
910{
911 n_ = n;
912}
913//*************************************************************************************************
914
915
916//*************************************************************************************************
922template< typename Type // Data type of the matrix
923 , bool SO // Storage order
924 , typename Tag > // Tag type
926{
927 const size_t tmp( n_ );
928 n_ = m.n_;
929 m.n_ = tmp;
930}
931//*************************************************************************************************
932
933
934
935
936//=================================================================================================
937//
938// LOOKUP FUNCTIONS
939//
940//=================================================================================================
941
942//*************************************************************************************************
955template< typename Type // Data type of the matrix
956 , bool SO // Storage order
957 , typename Tag > // Tag type
959 IdentityMatrix<Type,SO,Tag>::find( size_t i, size_t j ) const
960{
961 BLAZE_USER_ASSERT( SO || i < rows() , "Invalid identity matrix row access index" );
962 BLAZE_USER_ASSERT( !SO || j < columns(), "Invalid identity matrix column access index" );
963
964 if( i == j )
965 return begin( i );
966 else
967 return end( SO ? j : i );
968}
969//*************************************************************************************************
970
971
972//*************************************************************************************************
985template< typename Type // Data type of the matrix
986 , bool SO // Storage order
987 , typename Tag > // Tag type
989 IdentityMatrix<Type,SO,Tag>::lowerBound( size_t i, size_t j ) const
990{
991 BLAZE_USER_ASSERT( SO || i < rows() , "Invalid identity matrix row access index" );
992 BLAZE_USER_ASSERT( !SO || j < columns(), "Invalid identity matrix column access index" );
993
994 if( ( !SO && j <= i ) || ( SO && i <= j ) )
995 return begin( SO ? j : i );
996 else
997 return end( SO ? j : i );
998}
999//*************************************************************************************************
1000
1001
1002//*************************************************************************************************
1015template< typename Type // Data type of the matrix
1016 , bool SO // Storage order
1017 , typename Tag > // Tag type
1020{
1021 BLAZE_USER_ASSERT( SO || i < rows() , "Invalid identity matrix row access index" );
1022 BLAZE_USER_ASSERT( !SO || j < columns(), "Invalid identity matrix column access index" );
1023
1024 if( ( !SO && j < i ) || ( SO && i < j ) )
1025 return begin( SO ? j : i );
1026 else
1027 return end( SO ? j : i );
1028}
1029//*************************************************************************************************
1030
1031
1032
1033
1034//=================================================================================================
1035//
1036// NUMERIC FUNCTIONS
1037//
1038//=================================================================================================
1039
1040//*************************************************************************************************
1045template< typename Type // Data type of the matrix
1046 , bool SO // Storage order
1047 , typename Tag > // Tag type
1049{
1050 return *this;
1051}
1052//*************************************************************************************************
1053
1054
1055//*************************************************************************************************
1060template< typename Type // Data type of the matrix
1061 , bool SO // Storage order
1062 , typename Tag > // Tag type
1064{
1065 return *this;
1066}
1067//*************************************************************************************************
1068
1069
1070
1071
1072//=================================================================================================
1073//
1074// EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1075//
1076//=================================================================================================
1077
1078//*************************************************************************************************
1088template< typename Type // Data type of the matrix
1089 , bool SO // Storage order
1090 , typename Tag > // Type tag
1091template< typename Other > // Data type of the foreign expression
1092inline bool IdentityMatrix<Type,SO,Tag>::canAlias( const Other* alias ) const noexcept
1093{
1094 MAYBE_UNUSED( alias );
1095
1096 return false;
1097}
1098//*************************************************************************************************
1099
1100
1101//*************************************************************************************************
1111template< typename Type // Data type of the matrix
1112 , bool SO // Storage order
1113 , typename Tag > // Type tag
1114template< typename Other > // Data type of the foreign expression
1115inline bool IdentityMatrix<Type,SO,Tag>::isAliased( const Other* alias ) const noexcept
1116{
1117 MAYBE_UNUSED( alias );
1118
1119 return false;
1120}
1121//*************************************************************************************************
1122
1123
1124//*************************************************************************************************
1134template< typename Type // Data type of the matrix
1135 , bool SO // Storage order
1136 , typename Tag > // Tag type
1138{
1139 return false;
1140}
1141//*************************************************************************************************
1142
1143
1144
1145
1146
1147
1148
1149
1150//=================================================================================================
1151//
1152// IDENTITYMATRIX OPERATORS
1153//
1154//=================================================================================================
1155
1156//*************************************************************************************************
1159template< RelaxationFlag RF, typename Type, bool SO, typename Tag >
1160constexpr bool isDefault( const IdentityMatrix<Type,SO,Tag>& m ) noexcept;
1161
1162template< typename Type, bool SO, typename Tag >
1163constexpr bool isIntact( const IdentityMatrix<Type,SO,Tag>& m ) noexcept;
1164
1165template< typename Type, bool SO, typename Tag >
1166constexpr void swap( IdentityMatrix<Type,SO,Tag>& a, IdentityMatrix<Type,SO,Tag>& b ) noexcept;
1168//*************************************************************************************************
1169
1170
1171//*************************************************************************************************
1196template< RelaxationFlag RF // Relaxation flag
1197 , typename Type // Data type of the matrix
1198 , bool SO // Storage order
1199 , typename Tag > // Tag type
1200constexpr bool isDefault( const IdentityMatrix<Type,SO,Tag>& m ) noexcept
1201{
1202 return ( m.rows() == 0UL );
1203}
1204//*************************************************************************************************
1205
1206
1207//*************************************************************************************************
1225template< typename Type // Data type of the matrix
1226 , bool SO // Storage order
1227 , typename Tag > // Tag type
1228constexpr bool isIntact( const IdentityMatrix<Type,SO,Tag>& m ) noexcept
1229{
1230 MAYBE_UNUSED( m );
1231
1232 return true;
1233}
1234//*************************************************************************************************
1235
1236
1237//*************************************************************************************************
1245template< typename Type // Data type of the matrix
1246 , bool SO // Storage order
1247 , typename Tag > // Tag type
1249{
1250 a.swap( b );
1251}
1252//*************************************************************************************************
1253
1254
1255
1256
1257//=================================================================================================
1258//
1259// GLOBAL FUNCTIONS
1260//
1261//=================================================================================================
1262
1263//*************************************************************************************************
1282template< typename MT // Type of the sparse matrix
1283 , bool SO > // Storage order
1284inline IdentityMatrix<ElementType_t<MT>,SO>
1286{
1288
1289 if( !isSquare( *m ) ) {
1290 BLAZE_THROW_INVALID_ARGUMENT( "Invalid identity matrix specification" );
1291 }
1292
1293 return IdentityMatrix<ElementType_t<MT>,SO>( (*m).rows() );
1294}
1295//*************************************************************************************************
1296
1297
1298
1299
1300//=================================================================================================
1301//
1302// ISSQUARE SPECIALIZATIONS
1303//
1304//=================================================================================================
1305
1306//*************************************************************************************************
1308template< typename MT, bool SO, typename Tag >
1309struct IsSquare< IdentityMatrix<MT,SO,Tag> >
1310 : public TrueType
1311{};
1313//*************************************************************************************************
1314
1315
1316
1317
1318//=================================================================================================
1319//
1320// ISSYMMETRIC SPECIALIZATIONS
1321//
1322//=================================================================================================
1323
1324//*************************************************************************************************
1326template< typename MT, bool SO, typename Tag >
1327struct IsSymmetric< IdentityMatrix<MT,SO,Tag> >
1328 : public TrueType
1329{};
1331//*************************************************************************************************
1332
1333
1334
1335
1336//=================================================================================================
1337//
1338// ISHERMITIAN SPECIALIZATIONS
1339//
1340//=================================================================================================
1341
1342//*************************************************************************************************
1344template< typename MT, bool SO, typename Tag >
1345struct IsHermitian< IdentityMatrix<MT,SO,Tag> >
1346 : public TrueType
1347{};
1349//*************************************************************************************************
1350
1351
1352
1353
1354//=================================================================================================
1355//
1356// ISUNILOWER SPECIALIZATIONS
1357//
1358//=================================================================================================
1359
1360//*************************************************************************************************
1362template< typename MT, bool SO, typename Tag >
1363struct IsUniLower< IdentityMatrix<MT,SO,Tag> >
1364 : public TrueType
1365{};
1367//*************************************************************************************************
1368
1369
1370
1371
1372//=================================================================================================
1373//
1374// ISUNIUPPER SPECIALIZATIONS
1375//
1376//=================================================================================================
1377
1378//*************************************************************************************************
1380template< typename MT, bool SO, typename Tag >
1381struct IsUniUpper< IdentityMatrix<MT,SO,Tag> >
1382 : public TrueType
1383{};
1385//*************************************************************************************************
1386
1387
1388
1389
1390//=================================================================================================
1391//
1392// SCHURTRAIT SPECIALIZATIONS
1393//
1394//=================================================================================================
1395
1396//*************************************************************************************************
1398template< typename T1, typename T2 >
1399struct SchurTraitEval1< T1, T2
1400 , EnableIf_t< IsMatrix_v<T1> &&
1401 IsMatrix_v<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> ) > >
1408{
1409 static constexpr bool SO1 = StorageOrder_v<T1>;
1410 static constexpr bool SO2 = StorageOrder_v<T2>;
1411
1412 static constexpr bool SO = ( ( IsDenseMatrix_v<T1> && IsDenseMatrix_v<T2> ) ||
1413 ( IsSparseMatrix_v<T1> && IsSparseMatrix_v<T2> )
1414 ? SO1 && SO2
1415 : ( IsSparseMatrix_v<T1>
1416 ? SO1
1417 : SO2 ) );
1418
1419 using Type = IdentityMatrix< MultTrait_t< ElementType_t<T1>, ElementType_t<T2> >
1420 , SO
1421 , MultTrait_t< TagType_t<T1>, TagType_t<T2> > >;
1422};
1424//*************************************************************************************************
1425
1426
1427
1428
1429//=================================================================================================
1430//
1431// MULTTRAIT SPECIALIZATIONS
1432//
1433//=================================================================================================
1434
1435//*************************************************************************************************
1437template< typename T1, typename T2 >
1438struct MultTraitEval1< T1, T2
1439 , EnableIf_t< IsMatrix_v<T1> &&
1440 IsMatrix_v<T2> &&
1441 !IsIdentity_v<T1> && !IsZero_v<T1> && IsIdentity_v<T2> > >
1442{
1443 using Type = Rebind_t< ResultType_t<T1>, MultTrait_t< ElementType_t<T1>, ElementType_t<T2> > >;
1444};
1445
1446template< typename T1, typename T2 >
1447struct MultTraitEval1< T1, T2
1448 , EnableIf_t< IsMatrix_v<T1> &&
1449 IsMatrix_v<T2> &&
1450 IsIdentity_v<T1> && !IsIdentity_v<T2> && !IsZero_v<T2> > >
1451{
1452 using Type = Rebind_t< ResultType_t<T2>, MultTrait_t< ElementType_t<T1>, ElementType_t<T2> > >;
1453};
1454
1455template< typename T1, typename T2 >
1456struct MultTraitEval1< T1, T2
1457 , EnableIf_t< IsMatrix_v<T1> &&
1458 IsMatrix_v<T2> &&
1459 IsIdentity_v<T1> && IsIdentity_v<T2> > >
1460{
1461 using MultType = MultTrait_t< ElementType_t<T1>, ElementType_t<T2> >;
1462 using MultTag = MultTrait_t< TagType_t<T1>, TagType_t<T2> >;
1463
1464 using Type = IdentityMatrix< AddTrait_t<MultType,MultType>
1465 , StorageOrder_v<T1>
1466 , AddTrait_t<MultTag,MultTag> >;
1467};
1469//*************************************************************************************************
1470
1471
1472
1473
1474//=================================================================================================
1475//
1476// KRONTRAIT SPECIALIZATIONS
1477//
1478//=================================================================================================
1479
1480//*************************************************************************************************
1482template< typename T1, typename T2 >
1483struct KronTraitEval1< T1, T2
1484 , EnableIf_t< IsMatrix_v<T1> &&
1485 IsMatrix_v<T2> &&
1486 IsIdentity_v<T1> && IsIdentity_v<T2> > >
1487{
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> > >;
1491};
1493//*************************************************************************************************
1494
1495
1496
1497
1498//=================================================================================================
1499//
1500// MAPTRAIT SPECIALIZATIONS
1501//
1502//=================================================================================================
1503
1504//*************************************************************************************************
1506template< typename T, typename OP >
1507struct UnaryMapTraitEval1< T, OP
1508 , EnableIf_t< IsMatrix_v<T> &&
1509 YieldsIdentity_v<OP,T> > >
1510{
1511 using ElementType = decltype( std::declval<OP>()( std::declval< ElementType_t<T> >() ) );
1512
1513 using Type = IdentityMatrix< EvaluateTrait_t<ElementType>
1514 , StorageOrder_v<T>
1515 , MapTrait_t< TagType_t<T>, OP > >;
1516};
1518//*************************************************************************************************
1519
1520
1521//*************************************************************************************************
1523template< typename T1, typename T2, typename OP >
1524struct BinaryMapTraitEval1< T1, T2, OP
1525 , EnableIf_t< IsMatrix_v<T1> &&
1526 IsMatrix_v<T2> &&
1527 YieldsIdentity_v<OP,T1,T2> > >
1528{
1529 using ElementType = decltype( std::declval<OP>()( std::declval< ElementType_t<T1> >()
1530 , std::declval< ElementType_t<T2> >() ) );
1531
1532 using Type = IdentityMatrix< EvaluateTrait_t<ElementType>
1533 , ( StorageOrder_v<T1> && StorageOrder_v<T2> )
1534 , MapTrait_t< TagType_t<T1>, TagType_t<T2>, OP > >;
1535};
1537//*************************************************************************************************
1538
1539
1540
1541
1542//=================================================================================================
1543//
1544// DECLSYMTRAIT SPECIALIZATIONS
1545//
1546//=================================================================================================
1547
1548//*************************************************************************************************
1550template< typename T, bool SO, typename Tag >
1551struct DeclSymTrait< IdentityMatrix<T,SO,Tag> >
1552{
1553 using Type = IdentityMatrix<T,SO,Tag>;
1554};
1556//*************************************************************************************************
1557
1558
1559
1560
1561//=================================================================================================
1562//
1563// DECLHERMTRAIT SPECIALIZATIONS
1564//
1565//=================================================================================================
1566
1567//*************************************************************************************************
1569template< typename T, bool SO, typename Tag >
1570struct DeclHermTrait< IdentityMatrix<T,SO,Tag> >
1571{
1572 using Type = IdentityMatrix<T,SO,Tag>;
1573};
1575//*************************************************************************************************
1576
1577
1578
1579
1580//=================================================================================================
1581//
1582// DECLLOWTRAIT SPECIALIZATIONS
1583//
1584//=================================================================================================
1585
1586//*************************************************************************************************
1588template< typename T, bool SO, typename Tag >
1589struct DeclLowTrait< IdentityMatrix<T,SO,Tag> >
1590{
1591 using Type = IdentityMatrix<T,SO,Tag>;
1592};
1594//*************************************************************************************************
1595
1596
1597
1598
1599//=================================================================================================
1600//
1601// DECLUNILOWTRAIT SPECIALIZATIONS
1602//
1603//=================================================================================================
1604
1605//*************************************************************************************************
1607template< typename T, bool SO, typename Tag >
1608struct DeclUniLowTrait< IdentityMatrix<T,SO,Tag> >
1609{
1610 using Type = IdentityMatrix<T,SO,Tag>;
1611};
1613//*************************************************************************************************
1614
1615
1616
1617
1618//=================================================================================================
1619//
1620// DECLSTRLOWTRAIT SPECIALIZATIONS
1621//
1622//=================================================================================================
1623
1624//*************************************************************************************************
1626template< typename T, bool SO, typename Tag >
1627struct DeclStrLowTrait< IdentityMatrix<T,SO,Tag> >
1628{
1629 using Type = INVALID_TYPE;
1630};
1632//*************************************************************************************************
1633
1634
1635
1636
1637//=================================================================================================
1638//
1639// DECLUPPTRAIT SPECIALIZATIONS
1640//
1641//=================================================================================================
1642
1643//*************************************************************************************************
1645template< typename T, bool SO, typename Tag >
1646struct DeclUppTrait< IdentityMatrix<T,SO,Tag> >
1647{
1648 using Type = IdentityMatrix<T,SO,Tag>;
1649};
1651//*************************************************************************************************
1652
1653
1654
1655
1656//=================================================================================================
1657//
1658// DECLUNIUPPTRAIT SPECIALIZATIONS
1659//
1660//=================================================================================================
1661
1662//*************************************************************************************************
1664template< typename T, bool SO, typename Tag >
1665struct DeclUniUppTrait< IdentityMatrix<T,SO,Tag> >
1666{
1667 using Type = IdentityMatrix<T,SO,Tag>;
1668};
1670//*************************************************************************************************
1671
1672
1673
1674
1675//=================================================================================================
1676//
1677// DECLSTRUPPTRAIT SPECIALIZATIONS
1678//
1679//=================================================================================================
1680
1681//*************************************************************************************************
1683template< typename T, bool SO, typename Tag >
1684struct DeclStrUppTrait< IdentityMatrix<T,SO,Tag> >
1685{
1686 using Type = INVALID_TYPE;
1687};
1689//*************************************************************************************************
1690
1691
1692
1693
1694//=================================================================================================
1695//
1696// DECLDIAGTRAIT SPECIALIZATIONS
1697//
1698//=================================================================================================
1699
1700//*************************************************************************************************
1702template< typename T, bool SO, typename Tag >
1703struct DeclDiagTrait< IdentityMatrix<T,SO,Tag> >
1704{
1705 using Type = IdentityMatrix<T,SO,Tag>;
1706};
1708//*************************************************************************************************
1709
1710
1711
1712
1713//=================================================================================================
1714//
1715// HIGHTYPE SPECIALIZATIONS
1716//
1717//=================================================================================================
1718
1719//*************************************************************************************************
1721template< typename T1, bool SO, typename Tag, typename T2 >
1722struct HighType< IdentityMatrix<T1,SO,Tag>, IdentityMatrix<T2,SO,Tag> >
1723{
1724 using Type = IdentityMatrix< typename HighType<T1,T2>::Type, SO, Tag >;
1725};
1727//*************************************************************************************************
1728
1729
1730
1731
1732//=================================================================================================
1733//
1734// LOWTYPE SPECIALIZATIONS
1735//
1736//=================================================================================================
1737
1738//*************************************************************************************************
1740template< typename T1, bool SO, typename Tag, typename T2 >
1741struct LowType< IdentityMatrix<T1,SO,Tag>, IdentityMatrix<T2,SO,Tag> >
1742{
1743 using Type = IdentityMatrix< typename LowType<T1,T2>::Type, SO, Tag >;
1744};
1746//*************************************************************************************************
1747
1748} // namespace blaze
1749
1750#endif
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.
Data type constraint.
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.