Blaze  3.6
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>
51 #include <blaze/math/Forward.h>
82 #include <blaze/util/Assert.h>
88 #include <blaze/util/EnableIf.h>
91 #include <blaze/util/MaybeUnused.h>
92 #include <blaze/util/Types.h>
95 
96 
97 namespace blaze {
98 
99 //=================================================================================================
100 //
101 // CLASS DEFINITION
102 //
103 //=================================================================================================
104 
105 //*************************************************************************************************
179 template< typename Type // Data type of the matrix
180  , bool SO = defaultStorageOrder > // Storage order
181 class IdentityMatrix
182  : public Expression< SparseMatrix< IdentityMatrix<Type,SO>, SO > >
183 {
184  public:
185  //**Type definitions****************************************************************************
188  using ResultType = This;
191  using ElementType = Type;
192  using ReturnType = const Type;
193  using CompositeType = const This&;
194  using Reference = const Type;
195  using ConstReference = const Type;
196  //**********************************************************************************************
197 
198  //**Rebind struct definition********************************************************************
201  template< typename NewType > // Data type of the other matrix
202  struct Rebind {
204  };
205  //**********************************************************************************************
206 
207  //**Resize struct definition********************************************************************
210  template< size_t NewM // Number of rows of the other matrix
211  , size_t NewN > // Number of columns of the other matrix
212  struct Resize {
214  };
215  //**********************************************************************************************
216 
217  //**ConstIterator class definition**************************************************************
221  {
222  public:
223  //**Type definitions*************************************************************************
226 
227  using IteratorCategory = std::forward_iterator_tag;
228  using ValueType = Element;
232 
233  // STL iterator requirements
239  //*******************************************************************************************
240 
241  //**Default constructor**********************************************************************
244  inline constexpr ConstIterator() noexcept
245  : index_() // Index to the current identity matrix element
246  {}
247  //*******************************************************************************************
248 
249  //**Constructor******************************************************************************
254  inline constexpr ConstIterator( size_t index ) noexcept
255  : index_( index ) // Index to the current identity matrix element
256  {}
257  //*******************************************************************************************
258 
259  //**Prefix increment operator****************************************************************
264  inline constexpr ConstIterator& operator++() noexcept {
265  ++index_;
266  return *this;
267  }
268  //*******************************************************************************************
269 
270  //**Postfix increment operator***************************************************************
275  inline constexpr ConstIterator operator++( int ) noexcept {
276  ConstIterator tmp( *this );
277  ++index_;
278  return tmp;
279  }
280  //*******************************************************************************************
281 
282  //**Element access operator******************************************************************
287  inline constexpr const Element operator*() const noexcept {
288  return Element( Type(1), index_ );
289  }
290  //*******************************************************************************************
291 
292  //**Element access operator******************************************************************
297  inline constexpr const ConstIterator* operator->() const noexcept {
298  return this;
299  }
300  //*******************************************************************************************
301 
302  //**Value function***************************************************************************
307  inline constexpr Type value() const noexcept {
308  return Type(1);
309  }
310  //*******************************************************************************************
311 
312  //**Index function***************************************************************************
317  inline constexpr size_t index() const noexcept {
318  return index_;
319  }
320  //*******************************************************************************************
321 
322  //**Equality operator************************************************************************
328  inline constexpr bool operator==( const ConstIterator& rhs ) const noexcept {
329  return index_ == rhs.index_;
330  }
331  //*******************************************************************************************
332 
333  //**Inequality operator**********************************************************************
339  inline constexpr bool operator!=( const ConstIterator& rhs ) const noexcept {
340  return index_ != rhs.index_;
341  }
342  //*******************************************************************************************
343 
344  //**Subtraction operator*********************************************************************
350  inline constexpr DifferenceType operator-( const ConstIterator& rhs ) const noexcept {
351  return index_ - rhs.index_;
352  }
353  //*******************************************************************************************
354 
355  private:
356  //**Member variables*************************************************************************
357  size_t index_;
358  //*******************************************************************************************
359  };
360  //**********************************************************************************************
361 
362  //**Type definitions****************************************************************************
364  //**********************************************************************************************
365 
366  //**Compilation flags***************************************************************************
368 
371  static constexpr bool smpAssignable = !IsSMPAssignable_v<Type>;
372  //**********************************************************************************************
373 
374  //**Constructors********************************************************************************
377  explicit inline constexpr IdentityMatrix() noexcept;
378  explicit inline constexpr IdentityMatrix( size_t n ) noexcept;
379 
380  template< typename MT, bool SO2 >
381  explicit inline IdentityMatrix( const Matrix<MT,SO2>& m );
382 
383  IdentityMatrix( const IdentityMatrix& ) = default;
384  IdentityMatrix( IdentityMatrix&& ) = default;
386  //**********************************************************************************************
387 
388  //**Destructor**********************************************************************************
391  ~IdentityMatrix() = default;
393  //**********************************************************************************************
394 
395  //**Data access functions***********************************************************************
398  inline constexpr ConstReference operator()( size_t i, size_t j ) const noexcept;
399  inline ConstReference at( size_t i, size_t j ) const;
400  inline constexpr ConstIterator begin ( size_t i ) const noexcept;
401  inline constexpr ConstIterator cbegin( size_t i ) const noexcept;
402  inline constexpr ConstIterator end ( size_t i ) const noexcept;
403  inline constexpr ConstIterator cend ( size_t i ) const noexcept;
405  //**********************************************************************************************
406 
407  //**Assignment operators************************************************************************
410  template< typename MT, bool SO2 >
411  inline IdentityMatrix& operator=( const Matrix<MT,SO2>& rhs );
412 
413  IdentityMatrix& operator=( const IdentityMatrix& ) = default;
414  IdentityMatrix& operator=( IdentityMatrix&& ) = default;
416  //**********************************************************************************************
417 
418  //**Utility functions***************************************************************************
421  inline constexpr size_t rows() const noexcept;
422  inline constexpr size_t columns() const noexcept;
423  inline constexpr size_t capacity() const noexcept;
424  inline constexpr size_t capacity( size_t i ) const noexcept;
425  inline constexpr size_t nonZeros() const noexcept;
426  inline constexpr size_t nonZeros( size_t i ) const noexcept;
427  inline constexpr void clear() noexcept;
428  constexpr void resize( size_t n ) noexcept;
429  inline constexpr void swap( IdentityMatrix& m ) noexcept;
431  //**********************************************************************************************
432 
433  //**Lookup functions****************************************************************************
436  inline ConstIterator find ( size_t i, size_t j ) const;
437  inline ConstIterator lowerBound( size_t i, size_t j ) const;
438  inline ConstIterator upperBound( size_t i, size_t j ) const;
440  //**********************************************************************************************
441 
442  //**Numeric functions***************************************************************************
445  inline constexpr IdentityMatrix& transpose() noexcept;
446  inline constexpr IdentityMatrix& ctranspose() noexcept;
448  //**********************************************************************************************
449 
450  //**Expression template evaluation functions****************************************************
453  template< typename Other > inline bool canAlias ( const Other* alias ) const noexcept;
454  template< typename Other > inline bool isAliased( const Other* alias ) const noexcept;
455 
456  inline bool canSMPAssign() const noexcept;
458  //**********************************************************************************************
459 
460  private:
461  //**Member variables****************************************************************************
464  size_t n_;
465 
466  //**********************************************************************************************
467 
468  //**Compile time checks*************************************************************************
476  //**********************************************************************************************
477 };
478 //*************************************************************************************************
479 
480 
481 
482 
483 //=================================================================================================
484 //
485 // CONSTRUCTORS
486 //
487 //=================================================================================================
488 
489 //*************************************************************************************************
492 template< typename Type // Data type of the matrix
493  , bool SO > // Storage order
494 inline constexpr IdentityMatrix<Type,SO>::IdentityMatrix() noexcept
495  : n_( 0UL ) // The current number of rows and columns of the identity matrix
496 {}
497 //*************************************************************************************************
498 
499 
500 //*************************************************************************************************
505 template< typename Type // Data type of the matrix
506  , bool SO > // Storage order
507 inline constexpr IdentityMatrix<Type,SO>::IdentityMatrix( size_t n ) noexcept
508  : n_( n ) // The current number of rows and columns of the identity matrix
509 {}
510 //*************************************************************************************************
511 
512 
513 //*************************************************************************************************
522 template< typename Type // Data type of the matrix
523  , bool SO > // Storage order
524 template< typename MT // Type of the foreign identity matrix
525  , bool SO2 > // Storage order of the foreign identity matrix
527  : n_( (~m).rows() ) // The current number of rows and columns of the identity matrix
528 {
529  if( !IsIdentity_v<MT> && !isIdentity( ~m ) ) {
530  BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of identity matrix" );
531  }
532 }
533 //*************************************************************************************************
534 
535 
536 
537 
538 //=================================================================================================
539 //
540 // DATA ACCESS FUNCTIONS
541 //
542 //=================================================================================================
543 
544 //*************************************************************************************************
554 template< typename Type // Data type of the matrix
555  , bool SO > // Storage order
556 inline constexpr typename IdentityMatrix<Type,SO>::ConstReference
557  IdentityMatrix<Type,SO>::operator()( size_t i, size_t j ) const noexcept
558 {
559  BLAZE_USER_ASSERT( i < rows() , "Invalid identity matrix row access index" );
560  BLAZE_USER_ASSERT( j < columns(), "Invalid identity matrix column access index" );
561 
562  if( i == j )
563  return Type( 1 );
564  else
565  return Type( 0 );
566 }
567 //*************************************************************************************************
568 
569 
570 //*************************************************************************************************
581 template< typename Type // Data type of the matrix
582  , bool SO > // Storage order
584  IdentityMatrix<Type,SO>::at( size_t i, size_t j ) const
585 {
586  if( i >= n_ ) {
587  BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
588  }
589  if( j >= n_ ) {
590  BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
591  }
592  return (*this)(i,j);
593 }
594 //*************************************************************************************************
595 
596 
597 //*************************************************************************************************
608 template< typename Type // Data type of the matrix
609  , bool SO > // Storage order
610 inline constexpr typename IdentityMatrix<Type,SO>::ConstIterator
611  IdentityMatrix<Type,SO>::begin( size_t i ) const noexcept
612 {
613  BLAZE_USER_ASSERT( i < n_, "Invalid identity matrix row/column access index" );
614 
615  return ConstIterator( i );
616 }
617 //*************************************************************************************************
618 
619 
620 //*************************************************************************************************
631 template< typename Type // Data type of the matrix
632  , bool SO > // Storage order
633 inline constexpr typename IdentityMatrix<Type,SO>::ConstIterator
634  IdentityMatrix<Type,SO>::cbegin( size_t i ) const noexcept
635 {
636  BLAZE_USER_ASSERT( i < n_, "Invalid identity matrix row/column access index" );
637 
638  return ConstIterator( i );
639 }
640 //*************************************************************************************************
641 
642 
643 //*************************************************************************************************
654 template< typename Type // Data type of the matrix
655  , bool SO > // Storage order
656 inline constexpr typename IdentityMatrix<Type,SO>::ConstIterator
657  IdentityMatrix<Type,SO>::end( size_t i ) const noexcept
658 {
659  BLAZE_USER_ASSERT( i < n_, "Invalid identity matrix row/column access index" );
660 
661  return ConstIterator( i+1UL );
662 }
663 //*************************************************************************************************
664 
665 
666 //*************************************************************************************************
677 template< typename Type // Data type of the matrix
678  , bool SO > // Storage order
679 inline constexpr typename IdentityMatrix<Type,SO>::ConstIterator
680  IdentityMatrix<Type,SO>::cend( size_t i ) const noexcept
681 {
682  BLAZE_USER_ASSERT( i < n_, "Invalid identity matrix row/column access index" );
683 
684  return ConstIterator( i+1UL );
685 }
686 //*************************************************************************************************
687 
688 
689 
690 
691 //=================================================================================================
692 //
693 // ASSIGNMENT OPERATORS
694 //
695 //=================================================================================================
696 
697 //*************************************************************************************************
707 template< typename Type // Data type of the matrix
708  , bool SO > // Storage order
709 template< typename MT // Type of the right-hand side identity matrix
710  , bool SO2 > // Storage order of the right-hand side identity matrix
713 {
714  if( !IsIdentity_v<MT> && !isIdentity( ~rhs ) ) {
715  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment of identity matrix" );
716  }
717 
718  n_ = (~rhs).rows();
719 
720  return *this;
721 }
722 //*************************************************************************************************
723 
724 
725 
726 
727 //=================================================================================================
728 //
729 // UTILITY FUNCTIONS
730 //
731 //=================================================================================================
732 
733 //*************************************************************************************************
738 template< typename Type // Data type of the matrix
739  , bool SO > // Storage order
740 inline constexpr size_t IdentityMatrix<Type,SO>::rows() const noexcept
741 {
742  return n_;
743 }
744 //*************************************************************************************************
745 
746 
747 //*************************************************************************************************
752 template< typename Type // Data type of the matrix
753  , bool SO > // Storage order
754 inline constexpr size_t IdentityMatrix<Type,SO>::columns() const noexcept
755 {
756  return n_;
757 }
758 //*************************************************************************************************
759 
760 
761 //*************************************************************************************************
766 template< typename Type // Data type of the matrix
767  , bool SO > // Storage order
768 inline constexpr size_t IdentityMatrix<Type,SO>::capacity() const noexcept
769 {
770  return n_;
771 }
772 //*************************************************************************************************
773 
774 
775 //*************************************************************************************************
786 template< typename Type // Data type of the matrix
787  , bool SO > // Storage order
788 inline constexpr size_t IdentityMatrix<Type,SO>::capacity( size_t i ) const noexcept
789 {
790  MAYBE_UNUSED( i );
791 
792  BLAZE_USER_ASSERT( i < n_, "Invalid identity matrix row/column access index" );
793 
794  return 1UL;
795 }
796 //*************************************************************************************************
797 
798 
799 //*************************************************************************************************
804 template< typename Type // Data type of the matrix
805  , bool SO > // Storage order
806 inline constexpr size_t IdentityMatrix<Type,SO>::nonZeros() const noexcept
807 {
808  return n_;
809 }
810 //*************************************************************************************************
811 
812 
813 //*************************************************************************************************
824 template< typename Type // Data type of the matrix
825  , bool SO > // Storage order
826 inline constexpr size_t IdentityMatrix<Type,SO>::nonZeros( size_t i ) const noexcept
827 {
828  MAYBE_UNUSED( i );
829 
830  BLAZE_USER_ASSERT( i < n_, "Invalid identity matrix row/column access index" );
831 
832  return 1UL;
833 }
834 //*************************************************************************************************
835 
836 
837 //*************************************************************************************************
844 template< typename Type // Data type of the matrix
845  , bool SO > // Storage order
846 inline constexpr void IdentityMatrix<Type,SO>::clear() noexcept
847 {
848  n_ = 0UL;
849 }
850 //*************************************************************************************************
851 
852 
853 //*************************************************************************************************
863 template< typename Type // Data type of the matrix
864  , bool SO > // Storage order
865 void constexpr IdentityMatrix<Type,SO>::resize( size_t n ) noexcept
866 {
867  n_ = n;
868 }
869 //*************************************************************************************************
870 
871 
872 //*************************************************************************************************
878 template< typename Type // Data type of the matrix
879  , bool SO > // Storage order
880 inline constexpr void IdentityMatrix<Type,SO>::swap( IdentityMatrix& m ) noexcept
881 {
882  const size_t tmp( n_ );
883  n_ = m.n_;
884  m.n_ = tmp;
885 }
886 //*************************************************************************************************
887 
888 
889 
890 
891 //=================================================================================================
892 //
893 // LOOKUP FUNCTIONS
894 //
895 //=================================================================================================
896 
897 //*************************************************************************************************
910 template< typename Type // Data type of the matrix
911  , bool SO > // Storage order
913  IdentityMatrix<Type,SO>::find( size_t i, size_t j ) const
914 {
915  BLAZE_USER_ASSERT( SO || i < rows() , "Invalid identity matrix row access index" );
916  BLAZE_USER_ASSERT( !SO || j < columns(), "Invalid identity matrix column access index" );
917 
918  if( i == j )
919  return begin( i );
920  else
921  return end( SO ? j : i );
922 }
923 //*************************************************************************************************
924 
925 
926 //*************************************************************************************************
939 template< typename Type // Data type of the matrix
940  , bool SO > // Storage order
942  IdentityMatrix<Type,SO>::lowerBound( size_t i, size_t j ) const
943 {
944  BLAZE_USER_ASSERT( SO || i < rows() , "Invalid identity matrix row access index" );
945  BLAZE_USER_ASSERT( !SO || j < columns(), "Invalid identity matrix column access index" );
946 
947  if( ( !SO && j <= i ) || ( SO && i <= j ) )
948  return begin( SO ? j : i );
949  else
950  return end( SO ? j : i );
951 }
952 //*************************************************************************************************
953 
954 
955 //*************************************************************************************************
968 template< typename Type // Data type of the matrix
969  , bool SO > // Storage order
971  IdentityMatrix<Type,SO>::upperBound( size_t i, size_t j ) const
972 {
973  BLAZE_USER_ASSERT( SO || i < rows() , "Invalid identity matrix row access index" );
974  BLAZE_USER_ASSERT( !SO || j < columns(), "Invalid identity matrix column access index" );
975 
976  if( ( !SO && j < i ) || ( SO && i < j ) )
977  return begin( SO ? j : i );
978  else
979  return end( SO ? j : i );
980 }
981 //*************************************************************************************************
982 
983 
984 
985 
986 //=================================================================================================
987 //
988 // NUMERIC FUNCTIONS
989 //
990 //=================================================================================================
991 
992 //*************************************************************************************************
997 template< typename Type // Data type of the matrix
998  , bool SO > // Storage order
1000 {
1001  return *this;
1002 }
1003 //*************************************************************************************************
1004 
1005 
1006 //*************************************************************************************************
1011 template< typename Type // Data type of the matrix
1012  , bool SO > // Storage order
1014 {
1015  return *this;
1016 }
1017 //*************************************************************************************************
1018 
1019 
1020 
1021 
1022 //=================================================================================================
1023 //
1024 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1025 //
1026 //=================================================================================================
1027 
1028 //*************************************************************************************************
1038 template< typename Type // Data type of the matrix
1039  , bool SO > // Storage order
1040 template< typename Other > // Data type of the foreign expression
1041 inline bool IdentityMatrix<Type,SO>::canAlias( const Other* alias ) const noexcept
1042 {
1043  MAYBE_UNUSED( alias );
1044 
1045  return false;
1046 }
1047 //*************************************************************************************************
1048 
1049 
1050 //*************************************************************************************************
1060 template< typename Type // Data type of the matrix
1061  , bool SO > // Storage order
1062 template< typename Other > // Data type of the foreign expression
1063 inline bool IdentityMatrix<Type,SO>::isAliased( const Other* alias ) const noexcept
1064 {
1065  MAYBE_UNUSED( alias );
1066 
1067  return false;
1068 }
1069 //*************************************************************************************************
1070 
1071 
1072 //*************************************************************************************************
1082 template< typename Type // Data type of the matrix
1083  , bool SO > // Storage order
1084 inline bool IdentityMatrix<Type,SO>::canSMPAssign() const noexcept
1085 {
1086  return false;
1087 }
1088 //*************************************************************************************************
1089 
1090 
1091 
1092 
1093 
1094 
1095 
1096 
1097 //=================================================================================================
1098 //
1099 // IDENTITYMATRIX OPERATORS
1100 //
1101 //=================================================================================================
1102 
1103 //*************************************************************************************************
1106 template< typename Type, bool SO >
1107 constexpr void reset( IdentityMatrix<Type,SO>& m ) noexcept;
1108 
1109 template< typename Type, bool SO >
1110 constexpr void reset( IdentityMatrix<Type,SO>& m, size_t i ) noexcept;
1111 
1112 template< typename Type, bool SO >
1113 constexpr void clear( IdentityMatrix<Type,SO>& m ) noexcept;
1114 
1115 template< bool RF, typename Type, bool SO >
1116 constexpr bool isDefault( const IdentityMatrix<Type,SO>& m ) noexcept;
1117 
1118 template< typename Type, bool SO >
1119 constexpr bool isIntact( const IdentityMatrix<Type,SO>& m ) noexcept;
1120 
1121 template< typename Type, bool SO >
1122 constexpr void swap( IdentityMatrix<Type,SO>& a, IdentityMatrix<Type,SO>& b ) noexcept;
1124 //*************************************************************************************************
1125 
1126 
1127 //*************************************************************************************************
1134 template< typename Type // Data type of the matrix
1135  , bool SO > // Storage order
1136 inline constexpr void reset( IdentityMatrix<Type,SO>& m ) noexcept
1137 {
1138  MAYBE_UNUSED( m );
1139 }
1140 //*************************************************************************************************
1141 
1142 
1143 //*************************************************************************************************
1156 template< typename Type // Data type of the matrix
1157  , bool SO > // Storage order
1158 inline constexpr void reset( IdentityMatrix<Type,SO>& m, size_t i ) noexcept
1159 {
1160  MAYBE_UNUSED( m, i );
1161 }
1162 //*************************************************************************************************
1163 
1164 
1165 //*************************************************************************************************
1172 template< typename Type // Data type of the matrix
1173  , bool SO > // Storage order
1174 inline constexpr void clear( IdentityMatrix<Type,SO>& m ) noexcept
1175 {
1176  m.clear();
1177 }
1178 //*************************************************************************************************
1179 
1180 
1181 //*************************************************************************************************
1206 template< bool RF // Relaxation flag
1207  , typename Type // Data type of the matrix
1208  , bool SO > // Storage order
1209 inline constexpr bool isDefault( const IdentityMatrix<Type,SO>& m ) noexcept
1210 {
1211  return ( m.rows() == 0UL );
1212 }
1213 //*************************************************************************************************
1214 
1215 
1216 //*************************************************************************************************
1234 template< typename Type // Data type of the matrix
1235  , bool SO > // Storage order
1236 inline constexpr bool isIntact( const IdentityMatrix<Type,SO>& m ) noexcept
1237 {
1238  MAYBE_UNUSED( m );
1239 
1240  return true;
1241 }
1242 //*************************************************************************************************
1243 
1244 
1245 //*************************************************************************************************
1253 template< typename Type // Data type of the matrix
1254  , bool SO > // Storage order
1255 inline constexpr void swap( IdentityMatrix<Type,SO>& a, IdentityMatrix<Type,SO>& b ) noexcept
1256 {
1257  a.swap( b );
1258 }
1259 //*************************************************************************************************
1260 
1261 
1262 
1263 
1264 //=================================================================================================
1265 //
1266 // GLOBAL FUNCTIONS
1267 //
1268 //=================================================================================================
1269 
1270 //*************************************************************************************************
1289 template< typename MT // Type of the sparse matrix
1290  , bool SO > // Storage order
1291 inline IdentityMatrix<ElementType_t<MT>,SO>
1292  declid( const Matrix<MT,SO>& m )
1293 {
1295 
1296  if( !isSquare( ~m ) ) {
1297  BLAZE_THROW_INVALID_ARGUMENT( "Invalid identity matrix specification" );
1298  }
1299 
1300  return IdentityMatrix<ElementType_t<MT>,SO>( (~m).rows() );
1301 }
1302 //*************************************************************************************************
1303 
1304 
1305 
1306 
1307 //=================================================================================================
1308 //
1309 // ISSQUARE SPECIALIZATIONS
1310 //
1311 //=================================================================================================
1312 
1313 //*************************************************************************************************
1315 template< typename MT, bool SO >
1316 struct IsSquare< IdentityMatrix<MT,SO> >
1317  : public TrueType
1318 {};
1320 //*************************************************************************************************
1321 
1322 
1323 
1324 
1325 //=================================================================================================
1326 //
1327 // ISSYMMETRIC SPECIALIZATIONS
1328 //
1329 //=================================================================================================
1330 
1331 //*************************************************************************************************
1333 template< typename MT, bool SO >
1334 struct IsSymmetric< IdentityMatrix<MT,SO> >
1335  : public TrueType
1336 {};
1338 //*************************************************************************************************
1339 
1340 
1341 
1342 
1343 //=================================================================================================
1344 //
1345 // ISHERMITIAN SPECIALIZATIONS
1346 //
1347 //=================================================================================================
1348 
1349 //*************************************************************************************************
1351 template< typename MT, bool SO >
1352 struct IsHermitian< IdentityMatrix<MT,SO> >
1353  : public TrueType
1354 {};
1356 //*************************************************************************************************
1357 
1358 
1359 
1360 
1361 //=================================================================================================
1362 //
1363 // ISUNILOWER SPECIALIZATIONS
1364 //
1365 //=================================================================================================
1366 
1367 //*************************************************************************************************
1369 template< typename MT, bool SO >
1370 struct IsUniLower< IdentityMatrix<MT,SO> >
1371  : public TrueType
1372 {};
1374 //*************************************************************************************************
1375 
1376 
1377 
1378 
1379 //=================================================================================================
1380 //
1381 // ISUNIUPPER SPECIALIZATIONS
1382 //
1383 //=================================================================================================
1384 
1385 //*************************************************************************************************
1387 template< typename MT, bool SO >
1388 struct IsUniUpper< IdentityMatrix<MT,SO> >
1389  : public TrueType
1390 {};
1392 //*************************************************************************************************
1393 
1394 
1395 
1396 
1397 //=================================================================================================
1398 //
1399 // ISRESIZABLE SPECIALIZATIONS
1400 //
1401 //=================================================================================================
1402 
1403 //*************************************************************************************************
1405 template< typename T, bool SO >
1406 struct IsResizable< IdentityMatrix<T,SO> >
1407  : public TrueType
1408 {};
1410 //*************************************************************************************************
1411 
1412 
1413 
1414 
1415 //=================================================================================================
1416 //
1417 // SCHURTRAIT SPECIALIZATIONS
1418 //
1419 //=================================================================================================
1420 
1421 //*************************************************************************************************
1423 template< typename T1, typename T2 >
1424 struct SchurTraitEval1< T1, T2
1425  , EnableIf_t< IsMatrix_v<T1> &&
1426  IsMatrix_v<T2> &&
1427  ( ( IsIdentity_v<T1> && IsIdentity_v<T2> ) ||
1428  ( IsIdentity_v<T1> && IsUniTriangular_v<T2> ) ||
1429  ( IsUniTriangular_v<T1> && IsIdentity_v<T2> ) ||
1430  ( IsUniLower_v<T1> && IsUniUpper_v<T2> ) ||
1431  ( IsUniUpper_v<T1> && IsUniLower_v<T2> ) ) &&
1432  !( IsZero_v<T1> || IsZero_v<T2> ) > >
1433 {
1434  using ET1 = ElementType_t<T1>;
1435  using ET2 = ElementType_t<T2>;
1436 
1437  static constexpr bool SO1 = StorageOrder_v<T1>;
1438  static constexpr bool SO2 = StorageOrder_v<T2>;
1439 
1440  static constexpr bool SO = ( ( IsDenseMatrix_v<T1> && IsDenseMatrix_v<T2> ) ||
1441  ( IsSparseMatrix_v<T1> && IsSparseMatrix_v<T2> )
1442  ? SO1 && SO2
1443  : ( IsSparseMatrix_v<T1>
1444  ? SO1
1445  : SO2 ) );
1446 
1447  using Type = IdentityMatrix< MultTrait_t<ET1,ET2>, SO >;
1448 };
1450 //*************************************************************************************************
1451 
1452 
1453 
1454 
1455 //=================================================================================================
1456 //
1457 // MULTTRAIT SPECIALIZATIONS
1458 //
1459 //=================================================================================================
1460 
1461 //*************************************************************************************************
1463 template< typename T1, typename T2 >
1464 struct MultTraitEval1< T1, T2
1465  , EnableIf_t< IsMatrix_v<T1> &&
1466  IsMatrix_v<T2> &&
1467  !IsIdentity_v<T1> && !IsZero_v<T1> && IsIdentity_v<T2> > >
1468 {
1469  using Type = Rebind_t< ResultType_t<T1>, MultTrait_t< ElementType_t<T1>, ElementType_t<T2> > >;
1470 };
1471 
1472 template< typename T1, typename T2 >
1473 struct MultTraitEval1< T1, T2
1474  , EnableIf_t< IsMatrix_v<T1> &&
1475  IsMatrix_v<T2> &&
1476  IsIdentity_v<T1> && !IsIdentity_v<T2> && !IsZero_v<T2> > >
1477 {
1478  using Type = Rebind_t< ResultType_t<T2>, MultTrait_t< ElementType_t<T1>, ElementType_t<T2> > >;
1479 };
1480 
1481 template< typename T1, typename T2 >
1482 struct MultTraitEval1< T1, T2
1483  , EnableIf_t< IsMatrix_v<T1> &&
1484  IsMatrix_v<T2> &&
1485  IsIdentity_v<T1> && IsIdentity_v<T2> > >
1486 {
1487  using ET1 = ElementType_t<T1>;
1488  using ET2 = ElementType_t<T2>;
1489 
1490  using Type = IdentityMatrix< MultTrait_t<ET1,ET2>, StorageOrder_v<T1> >;
1491 };
1493 //*************************************************************************************************
1494 
1495 
1496 
1497 
1498 //=================================================================================================
1499 //
1500 // KRONTRAIT SPECIALIZATIONS
1501 //
1502 //=================================================================================================
1503 
1504 //*************************************************************************************************
1506 template< typename T1, typename T2 >
1507 struct KronTraitEval1< T1, T2
1508  , EnableIf_t< IsMatrix_v<T1> &&
1509  IsMatrix_v<T2> &&
1510  IsIdentity_v<T1> && IsIdentity_v<T2> > >
1511 {
1512  using ET1 = ElementType_t<T1>;
1513  using ET2 = ElementType_t<T2>;
1514 
1515  using Type = IdentityMatrix< MultTrait_t<ET1,ET2>, StorageOrder_v<T2> >;
1516 };
1518 //*************************************************************************************************
1519 
1520 
1521 
1522 
1523 //=================================================================================================
1524 //
1525 // MAPTRAIT SPECIALIZATIONS
1526 //
1527 //=================================================================================================
1528 
1529 //*************************************************************************************************
1531 template< typename T, typename OP >
1532 struct UnaryMapTraitEval1< T, OP
1533  , EnableIf_t< IsMatrix_v<T> &&
1534  YieldsIdentity_v<OP,T> > >
1535 {
1536  using ET = ElementType_t<T>;
1537 
1538  using Type = IdentityMatrix< MapTrait_t<ET,OP>, StorageOrder_v<T> >;
1539 };
1541 //*************************************************************************************************
1542 
1543 
1544 //*************************************************************************************************
1546 template< typename T1, typename T2, typename OP >
1547 struct BinaryMapTraitEval1< T1, T2, OP
1548  , EnableIf_t< IsMatrix_v<T1> &&
1549  IsMatrix_v<T2> &&
1550  YieldsIdentity_v<OP,T1,T2> > >
1551 {
1552  using ET1 = ElementType_t<T1>;
1553  using ET2 = ElementType_t<T2>;
1554 
1555  static constexpr bool SO = StorageOrder_v<T1> && StorageOrder_v<T2>;
1556 
1557  using Type = IdentityMatrix< MapTrait_t<ET1,ET2,OP>, SO >;
1558 };
1560 //*************************************************************************************************
1561 
1562 
1563 
1564 
1565 //=================================================================================================
1566 //
1567 // DECLSYMTRAIT SPECIALIZATIONS
1568 //
1569 //=================================================================================================
1570 
1571 //*************************************************************************************************
1573 template< typename T, bool SO >
1574 struct DeclSymTrait< IdentityMatrix<T,SO> >
1575 {
1576  using Type = IdentityMatrix<T,SO>;
1577 };
1579 //*************************************************************************************************
1580 
1581 
1582 
1583 
1584 //=================================================================================================
1585 //
1586 // DECLHERMTRAIT SPECIALIZATIONS
1587 //
1588 //=================================================================================================
1589 
1590 //*************************************************************************************************
1592 template< typename T, bool SO >
1593 struct DeclHermTrait< IdentityMatrix<T,SO> >
1594 {
1595  using Type = IdentityMatrix<T,SO>;
1596 };
1598 //*************************************************************************************************
1599 
1600 
1601 
1602 
1603 //=================================================================================================
1604 //
1605 // DECLLOWTRAIT SPECIALIZATIONS
1606 //
1607 //=================================================================================================
1608 
1609 //*************************************************************************************************
1611 template< typename T, bool SO >
1612 struct DeclLowTrait< IdentityMatrix<T,SO> >
1613 {
1614  using Type = IdentityMatrix<T,SO>;
1615 };
1617 //*************************************************************************************************
1618 
1619 
1620 
1621 
1622 //=================================================================================================
1623 //
1624 // DECLUPPTRAIT SPECIALIZATIONS
1625 //
1626 //=================================================================================================
1627 
1628 //*************************************************************************************************
1630 template< typename T, bool SO >
1631 struct DeclUppTrait< IdentityMatrix<T,SO> >
1632 {
1633  using Type = IdentityMatrix<T,SO>;
1634 };
1636 //*************************************************************************************************
1637 
1638 
1639 
1640 
1641 //=================================================================================================
1642 //
1643 // DECLDIAGTRAIT SPECIALIZATIONS
1644 //
1645 //=================================================================================================
1646 
1647 //*************************************************************************************************
1649 template< typename T, bool SO >
1650 struct DeclDiagTrait< IdentityMatrix<T,SO> >
1651 {
1652  using Type = IdentityMatrix<T,SO>;
1653 };
1655 //*************************************************************************************************
1656 
1657 
1658 
1659 
1660 //=================================================================================================
1661 //
1662 // HIGHTYPE SPECIALIZATIONS
1663 //
1664 //=================================================================================================
1665 
1666 //*************************************************************************************************
1668 template< typename T1, bool SO, typename T2 >
1669 struct HighType< IdentityMatrix<T1,SO>, IdentityMatrix<T2,SO> >
1670 {
1671  using Type = IdentityMatrix< typename HighType<T1,T2>::Type, SO >;
1672 };
1674 //*************************************************************************************************
1675 
1676 
1677 
1678 
1679 //=================================================================================================
1680 //
1681 // LOWTYPE SPECIALIZATIONS
1682 //
1683 //=================================================================================================
1684 
1685 //*************************************************************************************************
1687 template< typename T1, bool SO, typename T2 >
1688 struct LowType< IdentityMatrix<T1,SO>, IdentityMatrix<T2,SO> >
1689 {
1690  using Type = IdentityMatrix< typename LowType<T1,T2>::Type, SO >;
1691 };
1693 //*************************************************************************************************
1694 
1695 } // namespace blaze
1696 
1697 #endif
constexpr ConstIterator() noexcept
Default constructor for the ConstIterator class.
Definition: IdentityMatrix.h:244
#define BLAZE_CONSTRAINT_MUST_NOT_BE_CONST(T)
Constraint on the data type.In case the given data type is a const-qualified type,...
Definition: Const.h:79
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.This macro encapsulates the default way o...
Definition: Exception.h:235
Pointer difference type of the Blaze library.
Header file for auxiliary alias declarations.
Header file for the decldiag trait.
Iterator over the elements of the identity matrix.
Definition: IdentityMatrix.h:220
Constraint on the data type.
Header file for the Schur product trait.
bool isAliased(const Other *alias) const noexcept
Returns whether the matrix is aliased with the given address alias.
Definition: IdentityMatrix.h:1063
constexpr bool IsMatrix_v
Auxiliary variable template for the IsMatrix type trait.The IsMatrix_v variable template provides a c...
Definition: IsMatrix.h:138
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.In case of an invalid run time expression,...
Definition: Assert.h:117
ValueIndexPair< Type > Element
Element type of the identity matrix.
Definition: IdentityMatrix.h:225
constexpr void swap(IdentityMatrix &m) noexcept
Swapping the contents of two sparse matrices.
Definition: IdentityMatrix.h:880
Header file for the IsUniUpper type trait.
const Type ReturnType
Return type for expression template evaluations.
Definition: IdentityMatrix.h:192
Header file for basic type definitions.
Header file for the SparseVector base class.
constexpr DifferenceType operator-(const ConstIterator &rhs) const noexcept
Calculating the number of elements between two ConstIterator objects.
Definition: IdentityMatrix.h:350
Header file for the declherm trait.
constexpr ConstIterator end(size_t i) const noexcept
Returns an iterator just past the last non-zero element of row/column i.
Definition: IdentityMatrix.h:657
Resize mechanism to obtain a IdentityMatrix with different fixed dimensions.
Definition: IdentityMatrix.h:212
Header file for the IsSparseMatrix type trait.
const Type ConstReference
Reference to a constant identity matrix element.
Definition: IdentityMatrix.h:195
Header file for the IsSame and IsStrictlySame type traits.
constexpr Type value() const noexcept
Access to the current value of the sparse element.
Definition: IdentityMatrix.h:307
MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:372
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:595
Header file for the YieldsIdentity type trait.
constexpr IdentityMatrix() noexcept
The default constructor for IdentityMatrix.
Definition: IdentityMatrix.h:494
Header file for the DenseVector base class.
Header file for the MAYBE_UNUSED function template.
Header file for the IsIdentity type trait.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE(T)
Constraint on the data type.In case the given data type is a volatile-qualified type,...
Definition: Volatile.h:79
std::forward_iterator_tag IteratorCategory
The iterator category.
Definition: IdentityMatrix.h:227
BoolConstant< true > TrueType
Type traits base class.The TrueType class is used as base class for type traits and value traits that...
Definition: IntegralConstant.h:132
Header file for all forward declarations of the math module.
ConstIterator lowerBound(size_t i, size_t j) const
Returns an iterator to the first index not less then the given index.
Definition: IdentityMatrix.h:942
constexpr ConstIterator operator++(int) noexcept
Post-increment operator.
Definition: IdentityMatrix.h:275
Header file for the IsUniLower type trait.
constexpr size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:514
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes....
Definition: Forward.h:145
constexpr void clear() noexcept
Clearing the identity matrix.
Definition: IdentityMatrix.h:846
Constraint on the data type.
bool isIdentity(const DenseMatrix< MT, SO > &dm)
Checks if the give dense matrix is an identity matrix.
Definition: DenseMatrix.h:2433
constexpr const Element operator *() const noexcept
Direct access to the sparse matrix element at the current iterator position.
Definition: IdentityMatrix.h:287
Header file for the IsMatrix type trait.
Header file for the SparseMatrix base class.
Header file for the IsSquare type trait.
typename EnableIf< Condition, T >::Type EnableIf_t
Auxiliary type for the EnableIf class template.The EnableIf_t alias declaration provides a convenient...
Definition: EnableIf.h:138
Header file for the ValueIndexPair class.
Efficient implementation of an identity matrix.The IdentityMatrix class template is the representati...
Definition: Forward.h:49
Header file for the LowType type trait.
Header file for the multiplication trait.
Header file for the IsSymmetric type trait.
constexpr size_t rows() const noexcept
Returns the current number of rows of the identity matrix.
Definition: IdentityMatrix.h:740
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
#define BLAZE_CONSTRAINT_MUST_NOT_BE_POINTER_TYPE(T)
Constraint on the data type.In case the given data type T is not a pointer type, a compilation error ...
Definition: Pointer.h:79
Header file for the IsSMPAssignable type trait.
Header file for the decllow trait.
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.This macro encapsulates the default way of Bl...
Definition: Exception.h:331
constexpr ConstIterator cbegin(size_t i) const noexcept
Returns an iterator to the first non-zero element of row/column i.
Definition: IdentityMatrix.h:634
Header file for the DenseMatrix base class.
Type ElementType
Type of the identity matrix elements.
Definition: IdentityMatrix.h:191
constexpr size_t capacity() const noexcept
Returns the maximum capacity of the identity matrix.
Definition: IdentityMatrix.h:768
constexpr ConstIterator(size_t index) noexcept
Constructor for the ConstIterator class.
Definition: IdentityMatrix.h:254
Constraint on the data type.
ConstIterator find(size_t i, size_t j) const
Searches for a specific matrix element.
Definition: IdentityMatrix.h:913
constexpr size_t nonZeros() const noexcept
Returns the number of non-zero elements in the identity matrix.
Definition: IdentityMatrix.h:806
constexpr void MAYBE_UNUSED(const Args &...)
Suppression of unused parameter warnings.
Definition: MaybeUnused.h:81
Header file for the default storage order for all vectors of the Blaze library.
Header file for the IsUniTriangular type trait.
Header file for the Kron product trait.
Header file for the exception macros of the math module.
MT::Iterator end(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:438
Rebind mechanism to obtain an IdentityMatrix with different data/element type.
Definition: IdentityMatrix.h:202
size_t index_
Index to the current identity matrix element.
Definition: IdentityMatrix.h:357
Header file for the IsDenseMatrix type trait.
Header file for the EnableIf class template.
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:615
constexpr IdentityMatrix & transpose() noexcept
In-place transpose of the matrix.
Definition: IdentityMatrix.h:999
bool canSMPAssign() const noexcept
Returns whether the matrix can be used in SMP assignments.
Definition: IdentityMatrix.h:1084
constexpr void resize(size_t n) noexcept
Changing the size of the identity matrix.
Definition: IdentityMatrix.h:865
constexpr size_t index() const noexcept
Access to the current index of the sparse element.
Definition: IdentityMatrix.h:317
const Type Reference
Reference to a identity matrix element.
Definition: IdentityMatrix.h:194
IdentityMatrix< ElementType_t< MT >, SO > declid(const Matrix< MT, SO > &m)
Declares the given matrix expression m as identity matrix.
Definition: IdentityMatrix.h:1292
constexpr ConstIterator cend(size_t i) const noexcept
Returns an iterator just past the last non-zero element of row/column i.
Definition: IdentityMatrix.h:680
Header file for the IsNumeric type trait.
size_t n_
The current number of rows and columns of the identity matrix.
Definition: IdentityMatrix.h:464
IdentityMatrix< Type, SO > This
Type of this IdentityMatrix instance.
Definition: IdentityMatrix.h:186
Header file for the declupp trait.
constexpr bool operator==(const ConstIterator &rhs) const noexcept
Equality comparison between two ConstIterator objects.
Definition: IdentityMatrix.h:328
constexpr bool operator!=(const ConstIterator &rhs) const noexcept
Inequality comparison between two ConstIterator objects.
Definition: IdentityMatrix.h:339
constexpr const ConstIterator * operator->() const noexcept
Direct access to the sparse matrix element at the current iterator position.
Definition: IdentityMatrix.h:297
Header file for run time assertion macros.
Constraint on the data type.
#define BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE(T)
Constraint on the data type.In case the given data type T is not a numeric (integral or floating poin...
Definition: Numeric.h:61
Header file for the IsZero type trait.
constexpr ConstReference operator()(size_t i, size_t j) const noexcept
2D-access to the identity matrix elements.
Definition: IdentityMatrix.h:557
Header file for the declsym trait.
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:94
ValueType & ReferenceType
Reference return type.
Definition: IdentityMatrix.h:230
#define BLAZE_CONSTRAINT_MUST_NOT_BE_REFERENCE_TYPE(T)
Constraint on the data type.In case the given data type T is not a reference type,...
Definition: Reference.h:79
Header file for the isDefault shim.
void swap(DiagonalMatrix< MT, SO, DF > &a, DiagonalMatrix< MT, SO, DF > &b) noexcept
Swapping the contents of two matrices.
Definition: DiagonalMatrix.h:282
Base class for matrices.The Matrix class is a base class for all dense and sparse matrix classes with...
Definition: Forward.h:114
Constraint on the data type.
bool canAlias(const Other *alias) const noexcept
Returns whether the matrix can alias with the given address alias.
Definition: IdentityMatrix.h:1041
constexpr IdentityMatrix & ctranspose() noexcept
In-place conjugate transpose of the matrix.
Definition: IdentityMatrix.h:1013
constexpr size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:498
constexpr ConstIterator begin(size_t i) const noexcept
Returns an iterator to the first non-zero element of row/column i.
Definition: IdentityMatrix.h:611
ConstReference at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: IdentityMatrix.h:584
static constexpr bool smpAssignable
Compilation flag for SMP assignments.
Definition: IdentityMatrix.h:371
constexpr size_t columns() const noexcept
Returns the current number of columns of the identity matrix.
Definition: IdentityMatrix.h:754
Index-value-pair for sparse vectors and matrices.The ValueIndexPair class represents a single index-v...
Definition: ValueIndexPair.h:73
Header file for the default transpose flag for all vectors of the Blaze library.
Header file for the StorageOrder type trait.
IteratorCategory iterator_category
The iterator category.
Definition: IdentityMatrix.h:234
Header file for the IntegralConstant class template.
Header file for the map trait.
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:264
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:635
Header file for the IsHermitian type trait.
bool isSquare(const Matrix< MT, SO > &matrix) noexcept
Checks if the given matrix is a square matrix.
Definition: Matrix.h:951
Header file for the IsResizable type trait.
ValueType * PointerType
Pointer return type.
Definition: IdentityMatrix.h:229
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: IdentityMatrix.h:231
constexpr ConstIterator & operator++() noexcept
Pre-increment operator.
Definition: IdentityMatrix.h:264
Header file for the Expression base class.
Header file for the HighType type trait.
Header file for the function trace functionality.
Element ValueType
Type of the underlying pointers.
Definition: IdentityMatrix.h:228
ConstIterator upperBound(size_t i, size_t j) const
Returns an iterator to the first index greater then the given index.
Definition: IdentityMatrix.h:971