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>
45 #include <blaze/math/Exception.h>
50 #include <blaze/math/Forward.h>
80 #include <blaze/util/Assert.h>
86 #include <blaze/util/EnableIf.h>
88 #include <blaze/util/TrueType.h>
89 #include <blaze/util/Types.h>
92 #include <blaze/util/Unused.h>
93 
94 
95 namespace blaze {
96 
97 //=================================================================================================
98 //
99 // CLASS DEFINITION
100 //
101 //=================================================================================================
102 
103 //*************************************************************************************************
177 template< typename Type // Data type of the matrix
178  , bool SO = defaultStorageOrder > // Storage order
179 class IdentityMatrix
180  : public SparseMatrix< IdentityMatrix<Type,SO>, SO >
181 {
182  public:
183  //**Type definitions****************************************************************************
186  using ResultType = This;
189  using ElementType = Type;
190  using ReturnType = const Type;
191  using CompositeType = const This&;
192  using Reference = const Type;
193  using ConstReference = const Type;
194  //**********************************************************************************************
195 
196  //**Rebind struct definition********************************************************************
199  template< typename NewType > // Data type of the other matrix
200  struct Rebind {
202  };
203  //**********************************************************************************************
204 
205  //**Resize struct definition********************************************************************
208  template< size_t NewM // Number of rows of the other matrix
209  , size_t NewN > // Number of columns of the other matrix
210  struct Resize {
212  };
213  //**********************************************************************************************
214 
215  //**ConstIterator class definition**************************************************************
219  {
220  public:
221  //**Type definitions*************************************************************************
224 
225  using IteratorCategory = std::forward_iterator_tag;
226  using ValueType = Element;
230 
231  // STL iterator requirements
237  //*******************************************************************************************
238 
239  //**Default constructor**********************************************************************
242  inline constexpr ConstIterator() noexcept
243  : index_() // Index to the current identity matrix element
244  {}
245  //*******************************************************************************************
246 
247  //**Constructor******************************************************************************
252  inline constexpr ConstIterator( size_t index ) noexcept
253  : index_( index ) // Index to the current identity matrix element
254  {}
255  //*******************************************************************************************
256 
257  //**Prefix increment operator****************************************************************
262  inline constexpr ConstIterator& operator++() noexcept {
263  ++index_;
264  return *this;
265  }
266  //*******************************************************************************************
267 
268  //**Postfix increment operator***************************************************************
273  inline constexpr ConstIterator operator++( int ) noexcept {
274  ConstIterator tmp( *this );
275  ++index_;
276  return tmp;
277  }
278  //*******************************************************************************************
279 
280  //**Element access operator******************************************************************
285  inline constexpr const Element operator*() const noexcept {
286  return Element( Type(1), index_ );
287  }
288  //*******************************************************************************************
289 
290  //**Element access operator******************************************************************
295  inline constexpr const ConstIterator* operator->() const noexcept {
296  return this;
297  }
298  //*******************************************************************************************
299 
300  //**Value function***************************************************************************
305  inline constexpr Type value() const noexcept {
306  return Type(1);
307  }
308  //*******************************************************************************************
309 
310  //**Index function***************************************************************************
315  inline constexpr size_t index() const noexcept {
316  return index_;
317  }
318  //*******************************************************************************************
319 
320  //**Equality operator************************************************************************
326  inline constexpr bool operator==( const ConstIterator& rhs ) const noexcept {
327  return index_ == rhs.index_;
328  }
329  //*******************************************************************************************
330 
331  //**Inequality operator**********************************************************************
337  inline constexpr bool operator!=( const ConstIterator& rhs ) const noexcept {
338  return index_ != rhs.index_;
339  }
340  //*******************************************************************************************
341 
342  //**Subtraction operator*********************************************************************
348  inline constexpr DifferenceType operator-( const ConstIterator& rhs ) const noexcept {
349  return index_ - rhs.index_;
350  }
351  //*******************************************************************************************
352 
353  private:
354  //**Member variables*************************************************************************
355  size_t index_;
356  //*******************************************************************************************
357  };
358  //**********************************************************************************************
359 
360  //**Type definitions****************************************************************************
362  //**********************************************************************************************
363 
364  //**Compilation flags***************************************************************************
366 
369  static constexpr bool smpAssignable = !IsSMPAssignable_v<Type>;
370  //**********************************************************************************************
371 
372  //**Constructors********************************************************************************
375  explicit inline constexpr IdentityMatrix() noexcept;
376  explicit inline constexpr IdentityMatrix( size_t n ) noexcept;
377 
378  template< typename MT, bool SO2 >
379  explicit inline IdentityMatrix( const Matrix<MT,SO2>& m );
380 
381  IdentityMatrix( const IdentityMatrix& ) = default;
382  IdentityMatrix( IdentityMatrix&& ) = default;
384  //**********************************************************************************************
385 
386  //**Destructor**********************************************************************************
389  ~IdentityMatrix() = default;
391  //**********************************************************************************************
392 
393  //**Data access functions***********************************************************************
396  inline constexpr ConstReference operator()( size_t i, size_t j ) const noexcept;
397  inline ConstReference at( size_t i, size_t j ) const;
398  inline constexpr ConstIterator begin ( size_t i ) const noexcept;
399  inline constexpr ConstIterator cbegin( size_t i ) const noexcept;
400  inline constexpr ConstIterator end ( size_t i ) const noexcept;
401  inline constexpr ConstIterator cend ( size_t i ) const noexcept;
403  //**********************************************************************************************
404 
405  //**Assignment operators************************************************************************
408  template< typename MT, bool SO2 >
409  inline IdentityMatrix& operator=( const Matrix<MT,SO2>& rhs );
410 
411  IdentityMatrix& operator=( const IdentityMatrix& ) = default;
412  IdentityMatrix& operator=( IdentityMatrix&& ) = default;
414  //**********************************************************************************************
415 
416  //**Utility functions***************************************************************************
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;
427  inline constexpr void swap( IdentityMatrix& m ) noexcept;
429  //**********************************************************************************************
430 
431  //**Lookup functions****************************************************************************
434  inline ConstIterator find ( size_t i, size_t j ) const;
435  inline ConstIterator lowerBound( size_t i, size_t j ) const;
436  inline ConstIterator upperBound( size_t i, size_t j ) const;
438  //**********************************************************************************************
439 
440  //**Numeric functions***************************************************************************
443  inline constexpr IdentityMatrix& transpose() noexcept;
444  inline constexpr IdentityMatrix& ctranspose() noexcept;
446  //**********************************************************************************************
447 
448  //**Expression template evaluation functions****************************************************
451  template< typename Other > inline bool canAlias ( const Other* alias ) const noexcept;
452  template< typename Other > inline bool isAliased( const Other* alias ) const noexcept;
453 
454  inline bool canSMPAssign() const noexcept;
456  //**********************************************************************************************
457 
458  private:
459  //**Member variables****************************************************************************
462  size_t n_;
463 
464  //**********************************************************************************************
465 
466  //**Compile time checks*************************************************************************
474  //**********************************************************************************************
475 };
476 //*************************************************************************************************
477 
478 
479 
480 
481 //=================================================================================================
482 //
483 // CONSTRUCTORS
484 //
485 //=================================================================================================
486 
487 //*************************************************************************************************
490 template< typename Type // Data type of the matrix
491  , bool SO > // Storage order
492 inline constexpr IdentityMatrix<Type,SO>::IdentityMatrix() noexcept
493  : n_( 0UL ) // The current number of rows and columns of the identity matrix
494 {}
495 //*************************************************************************************************
496 
497 
498 //*************************************************************************************************
503 template< typename Type // Data type of the matrix
504  , bool SO > // Storage order
505 inline constexpr IdentityMatrix<Type,SO>::IdentityMatrix( size_t n ) noexcept
506  : n_( n ) // The current number of rows and columns of the identity matrix
507 {}
508 //*************************************************************************************************
509 
510 
511 //*************************************************************************************************
520 template< typename Type // Data type of the matrix
521  , bool SO > // Storage order
522 template< typename MT // Type of the foreign identity matrix
523  , bool SO2 > // Storage order of the foreign identity matrix
525  : n_( (~m).rows() ) // The current number of rows and columns of the identity matrix
526 {
527  if( !IsIdentity_v<MT> && !isIdentity( ~m ) ) {
528  BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of identity matrix" );
529  }
530 }
531 //*************************************************************************************************
532 
533 
534 
535 
536 //=================================================================================================
537 //
538 // DATA ACCESS FUNCTIONS
539 //
540 //=================================================================================================
541 
542 //*************************************************************************************************
552 template< typename Type // Data type of the matrix
553  , bool SO > // Storage order
554 inline constexpr typename IdentityMatrix<Type,SO>::ConstReference
555  IdentityMatrix<Type,SO>::operator()( size_t i, size_t j ) const noexcept
556 {
557  BLAZE_USER_ASSERT( i < rows() , "Invalid identity matrix row access index" );
558  BLAZE_USER_ASSERT( j < columns(), "Invalid identity matrix column access index" );
559 
560  if( i == j )
561  return Type( 1 );
562  else
563  return Type( 0 );
564 }
565 //*************************************************************************************************
566 
567 
568 //*************************************************************************************************
579 template< typename Type // Data type of the matrix
580  , bool SO > // Storage order
582  IdentityMatrix<Type,SO>::at( size_t i, size_t j ) const
583 {
584  if( i >= n_ ) {
585  BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
586  }
587  if( j >= n_ ) {
588  BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
589  }
590  return (*this)(i,j);
591 }
592 //*************************************************************************************************
593 
594 
595 //*************************************************************************************************
606 template< typename Type // Data type of the matrix
607  , bool SO > // Storage order
608 inline constexpr typename IdentityMatrix<Type,SO>::ConstIterator
609  IdentityMatrix<Type,SO>::begin( size_t i ) const noexcept
610 {
611  BLAZE_USER_ASSERT( i < n_, "Invalid identity matrix row/column access index" );
612 
613  return ConstIterator( i );
614 }
615 //*************************************************************************************************
616 
617 
618 //*************************************************************************************************
629 template< typename Type // Data type of the matrix
630  , bool SO > // Storage order
631 inline constexpr typename IdentityMatrix<Type,SO>::ConstIterator
632  IdentityMatrix<Type,SO>::cbegin( size_t i ) const noexcept
633 {
634  BLAZE_USER_ASSERT( i < n_, "Invalid identity matrix row/column access index" );
635 
636  return ConstIterator( i );
637 }
638 //*************************************************************************************************
639 
640 
641 //*************************************************************************************************
652 template< typename Type // Data type of the matrix
653  , bool SO > // Storage order
654 inline constexpr typename IdentityMatrix<Type,SO>::ConstIterator
655  IdentityMatrix<Type,SO>::end( size_t i ) const noexcept
656 {
657  BLAZE_USER_ASSERT( i < n_, "Invalid identity matrix row/column access index" );
658 
659  return ConstIterator( i+1UL );
660 }
661 //*************************************************************************************************
662 
663 
664 //*************************************************************************************************
675 template< typename Type // Data type of the matrix
676  , bool SO > // Storage order
677 inline constexpr typename IdentityMatrix<Type,SO>::ConstIterator
678  IdentityMatrix<Type,SO>::cend( size_t i ) const noexcept
679 {
680  BLAZE_USER_ASSERT( i < n_, "Invalid identity matrix row/column access index" );
681 
682  return ConstIterator( i+1UL );
683 }
684 //*************************************************************************************************
685 
686 
687 
688 
689 //=================================================================================================
690 //
691 // ASSIGNMENT OPERATORS
692 //
693 //=================================================================================================
694 
695 //*************************************************************************************************
705 template< typename Type // Data type of the matrix
706  , bool SO > // Storage order
707 template< typename MT // Type of the right-hand side identity matrix
708  , bool SO2 > // Storage order of the right-hand side identity matrix
711 {
712  if( !IsIdentity_v<MT> && !isIdentity( ~rhs ) ) {
713  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment of identity matrix" );
714  }
715 
716  n_ = (~rhs).rows();
717 
718  return *this;
719 }
720 //*************************************************************************************************
721 
722 
723 
724 
725 //=================================================================================================
726 //
727 // UTILITY FUNCTIONS
728 //
729 //=================================================================================================
730 
731 //*************************************************************************************************
736 template< typename Type // Data type of the matrix
737  , bool SO > // Storage order
738 inline constexpr size_t IdentityMatrix<Type,SO>::rows() const noexcept
739 {
740  return n_;
741 }
742 //*************************************************************************************************
743 
744 
745 //*************************************************************************************************
750 template< typename Type // Data type of the matrix
751  , bool SO > // Storage order
752 inline constexpr size_t IdentityMatrix<Type,SO>::columns() const noexcept
753 {
754  return n_;
755 }
756 //*************************************************************************************************
757 
758 
759 //*************************************************************************************************
764 template< typename Type // Data type of the matrix
765  , bool SO > // Storage order
766 inline constexpr size_t IdentityMatrix<Type,SO>::capacity() const noexcept
767 {
768  return n_;
769 }
770 //*************************************************************************************************
771 
772 
773 //*************************************************************************************************
784 template< typename Type // Data type of the matrix
785  , bool SO > // Storage order
786 inline constexpr size_t IdentityMatrix<Type,SO>::capacity( size_t i ) const noexcept
787 {
788  UNUSED_PARAMETER( i );
789 
790  BLAZE_USER_ASSERT( i < n_, "Invalid identity matrix row/column access index" );
791 
792  return 1UL;
793 }
794 //*************************************************************************************************
795 
796 
797 //*************************************************************************************************
802 template< typename Type // Data type of the matrix
803  , bool SO > // Storage order
804 inline constexpr size_t IdentityMatrix<Type,SO>::nonZeros() const noexcept
805 {
806  return n_;
807 }
808 //*************************************************************************************************
809 
810 
811 //*************************************************************************************************
822 template< typename Type // Data type of the matrix
823  , bool SO > // Storage order
824 inline constexpr size_t IdentityMatrix<Type,SO>::nonZeros( size_t i ) const noexcept
825 {
826  UNUSED_PARAMETER( i );
827 
828  BLAZE_USER_ASSERT( i < n_, "Invalid identity matrix row/column access index" );
829 
830  return 1UL;
831 }
832 //*************************************************************************************************
833 
834 
835 //*************************************************************************************************
842 template< typename Type // Data type of the matrix
843  , bool SO > // Storage order
844 inline constexpr void IdentityMatrix<Type,SO>::clear() noexcept
845 {
846  n_ = 0UL;
847 }
848 //*************************************************************************************************
849 
850 
851 //*************************************************************************************************
861 template< typename Type // Data type of the matrix
862  , bool SO > // Storage order
863 void constexpr IdentityMatrix<Type,SO>::resize( size_t n ) noexcept
864 {
865  n_ = n;
866 }
867 //*************************************************************************************************
868 
869 
870 //*************************************************************************************************
876 template< typename Type // Data type of the matrix
877  , bool SO > // Storage order
878 inline constexpr void IdentityMatrix<Type,SO>::swap( IdentityMatrix& m ) noexcept
879 {
880  const size_t tmp( n_ );
881  n_ = m.n_;
882  m.n_ = tmp;
883 }
884 //*************************************************************************************************
885 
886 
887 
888 
889 //=================================================================================================
890 //
891 // LOOKUP FUNCTIONS
892 //
893 //=================================================================================================
894 
895 //*************************************************************************************************
908 template< typename Type // Data type of the matrix
909  , bool SO > // Storage order
911  IdentityMatrix<Type,SO>::find( size_t i, size_t j ) const
912 {
913  BLAZE_USER_ASSERT( SO || i < rows() , "Invalid identity matrix row access index" );
914  BLAZE_USER_ASSERT( !SO || j < columns(), "Invalid identity matrix column access index" );
915 
916  if( i == j )
917  return begin( i );
918  else
919  return end( SO ? j : i );
920 }
921 //*************************************************************************************************
922 
923 
924 //*************************************************************************************************
937 template< typename Type // Data type of the matrix
938  , bool SO > // Storage order
940  IdentityMatrix<Type,SO>::lowerBound( size_t i, size_t j ) const
941 {
942  BLAZE_USER_ASSERT( SO || i < rows() , "Invalid identity matrix row access index" );
943  BLAZE_USER_ASSERT( !SO || j < columns(), "Invalid identity matrix column access index" );
944 
945  if( ( !SO && j <= i ) || ( SO && i <= j ) )
946  return begin( SO ? j : i );
947  else
948  return end( SO ? j : i );
949 }
950 //*************************************************************************************************
951 
952 
953 //*************************************************************************************************
966 template< typename Type // Data type of the matrix
967  , bool SO > // Storage order
969  IdentityMatrix<Type,SO>::upperBound( size_t i, size_t j ) const
970 {
971  BLAZE_USER_ASSERT( SO || i < rows() , "Invalid identity matrix row access index" );
972  BLAZE_USER_ASSERT( !SO || j < columns(), "Invalid identity matrix column access index" );
973 
974  if( ( !SO && j < i ) || ( SO && i < j ) )
975  return begin( SO ? j : i );
976  else
977  return end( SO ? j : i );
978 }
979 //*************************************************************************************************
980 
981 
982 
983 
984 //=================================================================================================
985 //
986 // NUMERIC FUNCTIONS
987 //
988 //=================================================================================================
989 
990 //*************************************************************************************************
995 template< typename Type // Data type of the matrix
996  , bool SO > // Storage order
998 {
999  return *this;
1000 }
1001 //*************************************************************************************************
1002 
1003 
1004 //*************************************************************************************************
1009 template< typename Type // Data type of the matrix
1010  , bool SO > // Storage order
1012 {
1013  return *this;
1014 }
1015 //*************************************************************************************************
1016 
1017 
1018 
1019 
1020 //=================================================================================================
1021 //
1022 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1023 //
1024 //=================================================================================================
1025 
1026 //*************************************************************************************************
1036 template< typename Type // Data type of the matrix
1037  , bool SO > // Storage order
1038 template< typename Other > // Data type of the foreign expression
1039 inline bool IdentityMatrix<Type,SO>::canAlias( const Other* alias ) const noexcept
1040 {
1041  UNUSED_PARAMETER( alias );
1042 
1043  return false;
1044 }
1045 //*************************************************************************************************
1046 
1047 
1048 //*************************************************************************************************
1058 template< typename Type // Data type of the matrix
1059  , bool SO > // Storage order
1060 template< typename Other > // Data type of the foreign expression
1061 inline bool IdentityMatrix<Type,SO>::isAliased( const Other* alias ) const noexcept
1062 {
1063  UNUSED_PARAMETER( alias );
1064 
1065  return false;
1066 }
1067 //*************************************************************************************************
1068 
1069 
1070 //*************************************************************************************************
1080 template< typename Type // Data type of the matrix
1081  , bool SO > // Storage order
1082 inline bool IdentityMatrix<Type,SO>::canSMPAssign() const noexcept
1083 {
1084  return false;
1085 }
1086 //*************************************************************************************************
1087 
1088 
1089 
1090 
1091 
1092 
1093 
1094 
1095 //=================================================================================================
1096 //
1097 // IDENTITYMATRIX OPERATORS
1098 //
1099 //=================================================================================================
1100 
1101 //*************************************************************************************************
1104 template< typename Type, bool SO >
1105 constexpr void reset( IdentityMatrix<Type,SO>& m ) noexcept;
1106 
1107 template< typename Type, bool SO >
1108 constexpr void reset( IdentityMatrix<Type,SO>& m, size_t i ) noexcept;
1109 
1110 template< typename Type, bool SO >
1111 constexpr void clear( IdentityMatrix<Type,SO>& m ) noexcept;
1112 
1113 template< bool RF, typename Type, bool SO >
1114 constexpr bool isDefault( const IdentityMatrix<Type,SO>& m ) noexcept;
1115 
1116 template< typename Type, bool SO >
1117 constexpr bool isIntact( const IdentityMatrix<Type,SO>& m ) noexcept;
1118 
1119 template< typename Type, bool SO >
1120 constexpr void swap( IdentityMatrix<Type,SO>& a, IdentityMatrix<Type,SO>& b ) noexcept;
1122 //*************************************************************************************************
1123 
1124 
1125 //*************************************************************************************************
1132 template< typename Type // Data type of the matrix
1133  , bool SO > // Storage order
1134 inline constexpr void reset( IdentityMatrix<Type,SO>& m ) noexcept
1135 {
1136  UNUSED_PARAMETER( m );
1137 }
1138 //*************************************************************************************************
1139 
1140 
1141 //*************************************************************************************************
1154 template< typename Type // Data type of the matrix
1155  , bool SO > // Storage order
1156 inline constexpr void reset( IdentityMatrix<Type,SO>& m, size_t i ) noexcept
1157 {
1158  UNUSED_PARAMETER( m, i );
1159 }
1160 //*************************************************************************************************
1161 
1162 
1163 //*************************************************************************************************
1170 template< typename Type // Data type of the matrix
1171  , bool SO > // Storage order
1172 inline constexpr void clear( IdentityMatrix<Type,SO>& m ) noexcept
1173 {
1174  m.clear();
1175 }
1176 //*************************************************************************************************
1177 
1178 
1179 //*************************************************************************************************
1204 template< bool RF // Relaxation flag
1205  , typename Type // Data type of the matrix
1206  , bool SO > // Storage order
1207 inline constexpr bool isDefault( const IdentityMatrix<Type,SO>& m ) noexcept
1208 {
1209  return ( m.rows() == 0UL );
1210 }
1211 //*************************************************************************************************
1212 
1213 
1214 //*************************************************************************************************
1232 template< typename Type // Data type of the matrix
1233  , bool SO > // Storage order
1234 inline constexpr bool isIntact( const IdentityMatrix<Type,SO>& m ) noexcept
1235 {
1236  UNUSED_PARAMETER( m );
1237 
1238  return true;
1239 }
1240 //*************************************************************************************************
1241 
1242 
1243 //*************************************************************************************************
1251 template< typename Type // Data type of the matrix
1252  , bool SO > // Storage order
1253 inline constexpr void swap( IdentityMatrix<Type,SO>& a, IdentityMatrix<Type,SO>& b ) noexcept
1254 {
1255  a.swap( b );
1256 }
1257 //*************************************************************************************************
1258 
1259 
1260 
1261 
1262 //=================================================================================================
1263 //
1264 // GLOBAL FUNCTIONS
1265 //
1266 //=================================================================================================
1267 
1268 //*************************************************************************************************
1287 template< typename MT // Type of the sparse matrix
1288  , bool SO > // Storage order
1289 inline IdentityMatrix<ElementType_t<MT>,SO>
1290  declid( const Matrix<MT,SO>& m )
1291 {
1293 
1294  if( !isSquare( ~m ) ) {
1295  BLAZE_THROW_INVALID_ARGUMENT( "Invalid identity matrix specification" );
1296  }
1297 
1298  return IdentityMatrix<ElementType_t<MT>,SO>( (~m).rows() );
1299 }
1300 //*************************************************************************************************
1301 
1302 
1303 
1304 
1305 //=================================================================================================
1306 //
1307 // ISSQUARE SPECIALIZATIONS
1308 //
1309 //=================================================================================================
1310 
1311 //*************************************************************************************************
1313 template< typename MT, bool SO >
1314 struct IsSquare< IdentityMatrix<MT,SO> >
1315  : public TrueType
1316 {};
1318 //*************************************************************************************************
1319 
1320 
1321 
1322 
1323 //=================================================================================================
1324 //
1325 // ISSYMMETRIC SPECIALIZATIONS
1326 //
1327 //=================================================================================================
1328 
1329 //*************************************************************************************************
1331 template< typename MT, bool SO >
1332 struct IsSymmetric< IdentityMatrix<MT,SO> >
1333  : public TrueType
1334 {};
1336 //*************************************************************************************************
1337 
1338 
1339 
1340 
1341 //=================================================================================================
1342 //
1343 // ISHERMITIAN SPECIALIZATIONS
1344 //
1345 //=================================================================================================
1346 
1347 //*************************************************************************************************
1349 template< typename MT, bool SO >
1350 struct IsHermitian< IdentityMatrix<MT,SO> >
1351  : public TrueType
1352 {};
1354 //*************************************************************************************************
1355 
1356 
1357 
1358 
1359 //=================================================================================================
1360 //
1361 // ISUNILOWER SPECIALIZATIONS
1362 //
1363 //=================================================================================================
1364 
1365 //*************************************************************************************************
1367 template< typename MT, bool SO >
1368 struct IsUniLower< IdentityMatrix<MT,SO> >
1369  : public TrueType
1370 {};
1372 //*************************************************************************************************
1373 
1374 
1375 
1376 
1377 //=================================================================================================
1378 //
1379 // ISUNIUPPER SPECIALIZATIONS
1380 //
1381 //=================================================================================================
1382 
1383 //*************************************************************************************************
1385 template< typename MT, bool SO >
1386 struct IsUniUpper< IdentityMatrix<MT,SO> >
1387  : public TrueType
1388 {};
1390 //*************************************************************************************************
1391 
1392 
1393 
1394 
1395 //=================================================================================================
1396 //
1397 // ISRESIZABLE SPECIALIZATIONS
1398 //
1399 //=================================================================================================
1400 
1401 //*************************************************************************************************
1403 template< typename T, bool SO >
1404 struct IsResizable< IdentityMatrix<T,SO> >
1405  : public TrueType
1406 {};
1408 //*************************************************************************************************
1409 
1410 
1411 
1412 
1413 //=================================================================================================
1414 //
1415 // SCHURTRAIT SPECIALIZATIONS
1416 //
1417 //=================================================================================================
1418 
1419 //*************************************************************************************************
1421 template< typename T1, typename T2 >
1422 struct SchurTraitEval1< T1, T2
1423  , EnableIf_t< IsMatrix_v<T1> &&
1424  IsMatrix_v<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> ) > >
1431 {
1432  using ET1 = ElementType_t<T1>;
1433  using ET2 = ElementType_t<T2>;
1434 
1435  static constexpr bool SO1 = StorageOrder_v<T1>;
1436  static constexpr bool SO2 = StorageOrder_v<T2>;
1437 
1438  static constexpr bool SO = ( ( IsDenseMatrix_v<T1> && IsDenseMatrix_v<T2> ) ||
1439  ( IsSparseMatrix_v<T1> && IsSparseMatrix_v<T2> )
1440  ? SO1 && SO2
1441  : ( IsSparseMatrix_v<T1>
1442  ? SO1
1443  : SO2 ) );
1444 
1445  using Type = IdentityMatrix< MultTrait_t<ET1,ET2>, SO >;
1446 };
1448 //*************************************************************************************************
1449 
1450 
1451 
1452 
1453 //=================================================================================================
1454 //
1455 // MULTTRAIT SPECIALIZATIONS
1456 //
1457 //=================================================================================================
1458 
1459 //*************************************************************************************************
1461 template< typename T1, typename T2 >
1462 struct MultTraitEval1< T1, T2
1463  , EnableIf_t< IsMatrix_v<T1> &&
1464  IsMatrix_v<T2> &&
1465  !IsIdentity_v<T1> && !IsZero_v<T1> && IsIdentity_v<T2> > >
1466 {
1467  using Type = Rebind_t< ResultType_t<T1>, MultTrait_t< ElementType_t<T1>, ElementType_t<T2> > >;
1468 };
1469 
1470 template< typename T1, typename T2 >
1471 struct MultTraitEval1< T1, T2
1472  , EnableIf_t< IsMatrix_v<T1> &&
1473  IsMatrix_v<T2> &&
1474  IsIdentity_v<T1> && !IsIdentity_v<T2> && !IsZero_v<T2> > >
1475 {
1476  using Type = Rebind_t< ResultType_t<T2>, MultTrait_t< ElementType_t<T1>, ElementType_t<T2> > >;
1477 };
1478 
1479 template< typename T1, typename T2 >
1480 struct MultTraitEval1< T1, T2
1481  , EnableIf_t< IsMatrix_v<T1> &&
1482  IsMatrix_v<T2> &&
1483  IsIdentity_v<T1> && IsIdentity_v<T2> > >
1484 {
1485  using ET1 = ElementType_t<T1>;
1486  using ET2 = ElementType_t<T2>;
1487 
1488  using Type = IdentityMatrix< MultTrait_t<ET1,ET2>, StorageOrder_v<T1> >;
1489 };
1491 //*************************************************************************************************
1492 
1493 
1494 
1495 
1496 //=================================================================================================
1497 //
1498 // MAPTRAIT SPECIALIZATIONS
1499 //
1500 //=================================================================================================
1501 
1502 //*************************************************************************************************
1504 template< typename T, typename OP >
1505 struct UnaryMapTraitEval1< T, OP
1506  , EnableIf_t< IsMatrix_v<T> &&
1507  YieldsIdentity_v<OP,T> > >
1508 {
1509  using ET = ElementType_t<T>;
1510 
1511  using Type = IdentityMatrix< MapTrait_t<ET,OP>, StorageOrder_v<T> >;
1512 };
1514 //*************************************************************************************************
1515 
1516 
1517 //*************************************************************************************************
1519 template< typename T1, typename T2, typename OP >
1520 struct BinaryMapTraitEval1< T1, T2, OP
1521  , EnableIf_t< IsMatrix_v<T1> &&
1522  IsMatrix_v<T2> &&
1523  YieldsIdentity_v<OP,T1,T2> > >
1524 {
1525  using ET1 = ElementType_t<T1>;
1526  using ET2 = ElementType_t<T2>;
1527 
1528  static constexpr bool SO = StorageOrder_v<T1> && StorageOrder_v<T2>;
1529 
1530  using Type = IdentityMatrix< MapTrait_t<ET1,ET2,OP>, SO >;
1531 };
1533 //*************************************************************************************************
1534 
1535 
1536 
1537 
1538 //=================================================================================================
1539 //
1540 // DECLSYMTRAIT SPECIALIZATIONS
1541 //
1542 //=================================================================================================
1543 
1544 //*************************************************************************************************
1546 template< typename T, bool SO >
1547 struct DeclSymTrait< IdentityMatrix<T,SO> >
1548 {
1549  using Type = IdentityMatrix<T,SO>;
1550 };
1552 //*************************************************************************************************
1553 
1554 
1555 
1556 
1557 //=================================================================================================
1558 //
1559 // DECLHERMTRAIT SPECIALIZATIONS
1560 //
1561 //=================================================================================================
1562 
1563 //*************************************************************************************************
1565 template< typename T, bool SO >
1566 struct DeclHermTrait< IdentityMatrix<T,SO> >
1567 {
1568  using Type = IdentityMatrix<T,SO>;
1569 };
1571 //*************************************************************************************************
1572 
1573 
1574 
1575 
1576 //=================================================================================================
1577 //
1578 // DECLLOWTRAIT SPECIALIZATIONS
1579 //
1580 //=================================================================================================
1581 
1582 //*************************************************************************************************
1584 template< typename T, bool SO >
1585 struct DeclLowTrait< IdentityMatrix<T,SO> >
1586 {
1587  using Type = IdentityMatrix<T,SO>;
1588 };
1590 //*************************************************************************************************
1591 
1592 
1593 
1594 
1595 //=================================================================================================
1596 //
1597 // DECLUPPTRAIT SPECIALIZATIONS
1598 //
1599 //=================================================================================================
1600 
1601 //*************************************************************************************************
1603 template< typename T, bool SO >
1604 struct DeclUppTrait< IdentityMatrix<T,SO> >
1605 {
1606  using Type = IdentityMatrix<T,SO>;
1607 };
1609 //*************************************************************************************************
1610 
1611 
1612 
1613 
1614 //=================================================================================================
1615 //
1616 // DECLDIAGTRAIT SPECIALIZATIONS
1617 //
1618 //=================================================================================================
1619 
1620 //*************************************************************************************************
1622 template< typename T, bool SO >
1623 struct DeclDiagTrait< IdentityMatrix<T,SO> >
1624 {
1625  using Type = IdentityMatrix<T,SO>;
1626 };
1628 //*************************************************************************************************
1629 
1630 
1631 
1632 
1633 //=================================================================================================
1634 //
1635 // HIGHTYPE SPECIALIZATIONS
1636 //
1637 //=================================================================================================
1638 
1639 //*************************************************************************************************
1641 template< typename T1, bool SO, typename T2 >
1642 struct HighType< IdentityMatrix<T1,SO>, IdentityMatrix<T2,SO> >
1643 {
1644  using Type = IdentityMatrix< typename HighType<T1,T2>::Type, SO >;
1645 };
1647 //*************************************************************************************************
1648 
1649 
1650 
1651 
1652 //=================================================================================================
1653 //
1654 // LOWTYPE SPECIALIZATIONS
1655 //
1656 //=================================================================================================
1657 
1658 //*************************************************************************************************
1660 template< typename T1, bool SO, typename T2 >
1661 struct LowType< IdentityMatrix<T1,SO>, IdentityMatrix<T2,SO> >
1662 {
1663  using Type = IdentityMatrix< typename LowType<T1,T2>::Type, SO >;
1664 };
1666 //*************************************************************************************************
1667 
1668 } // namespace blaze
1669 
1670 #endif
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