Sparse.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_ADAPTORS_DIAGONALMATRIX_SPARSE_H_
36 #define _BLAZE_MATH_ADAPTORS_DIAGONALMATRIX_SPARSE_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <vector>
44 #include <utility>
47 #include <blaze/math/Aliases.h>
57 #include <blaze/math/Exception.h>
60 #include <blaze/math/shims/Clear.h>
67 #include <blaze/util/Assert.h>
72 #include <blaze/util/DisableIf.h>
73 #include <blaze/util/EnableIf.h>
75 #include <blaze/util/Types.h>
76 
77 
78 namespace blaze {
79 
80 //=================================================================================================
81 //
82 // CLASS TEMPLATE SPECIALIZATION FOR SPARSE MATRICES
83 //
84 //=================================================================================================
85 
86 //*************************************************************************************************
94 template< typename MT // Type of the adapted sparse matrix
95  , bool SO > // Storage order of the adapted sparse matrix
96 class DiagonalMatrix<MT,SO,false>
97  : public SparseMatrix< DiagonalMatrix<MT,SO,false>, SO >
98 {
99  private:
100  //**Type definitions****************************************************************************
101  using OT = OppositeType_<MT>;
102  using TT = TransposeType_<MT>;
103  using ET = ElementType_<MT>;
104  //**********************************************************************************************
105 
106  public:
107  //**Type definitions****************************************************************************
108  using This = DiagonalMatrix<MT,SO,false>;
109  using BaseType = SparseMatrix<This,SO>;
110  using ResultType = This;
111  using OppositeType = DiagonalMatrix<OT,!SO,false>;
112  using TransposeType = DiagonalMatrix<TT,!SO,false>;
113  using ElementType = ET;
114  using ReturnType = ReturnType_<MT>;
115  using CompositeType = const This&;
116  using Reference = DiagonalProxy<MT>;
117  using ConstReference = ConstReference_<MT>;
118  using Iterator = Iterator_<MT>;
119  using ConstIterator = ConstIterator_<MT>;
120  //**********************************************************************************************
121 
122  //**Rebind struct definition********************************************************************
125  template< typename NewType > // Data type of the other matrix
126  struct Rebind {
128  using Other = DiagonalMatrix< typename MT::template Rebind<NewType>::Other >;
129  };
130  //**********************************************************************************************
131 
132  //**Resize struct definition********************************************************************
135  template< size_t NewM // Number of rows of the other matrix
136  , size_t NewN > // Number of columns of the other matrix
137  struct Resize {
139  using Other = DiagonalMatrix< typename MT::template Resize<NewM,NewN>::Other >;
140  };
141  //**********************************************************************************************
142 
143  //**Compilation flags***************************************************************************
145  enum : bool { smpAssignable = false };
146  //**********************************************************************************************
147 
148  //**Constructors********************************************************************************
151  explicit inline DiagonalMatrix();
152  explicit inline DiagonalMatrix( size_t n );
153  explicit inline DiagonalMatrix( size_t n, size_t nonzeros );
154  explicit inline DiagonalMatrix( size_t n, const std::vector<size_t>& nonzeros );
155  explicit inline DiagonalMatrix( initializer_list< initializer_list<ElementType> > list );
156 
157  inline DiagonalMatrix( const DiagonalMatrix& m );
158  inline DiagonalMatrix( DiagonalMatrix&& m ) noexcept;
159 
160  template< typename MT2, bool SO2 >
161  inline DiagonalMatrix( const Matrix<MT2,SO2>& m );
163  //**********************************************************************************************
164 
165  //**Destructor**********************************************************************************
166  // No explicitly declared destructor.
167  //**********************************************************************************************
168 
169  //**Data access functions***********************************************************************
172  inline Reference operator()( size_t i, size_t j );
173  inline ConstReference operator()( size_t i, size_t j ) const;
174  inline Reference at( size_t i, size_t j );
175  inline ConstReference at( size_t i, size_t j ) const;
176  inline Iterator begin ( size_t i );
177  inline ConstIterator begin ( size_t i ) const;
178  inline ConstIterator cbegin( size_t i ) const;
179  inline Iterator end ( size_t i );
180  inline ConstIterator end ( size_t i ) const;
181  inline ConstIterator cend ( size_t i ) const;
183  //**********************************************************************************************
184 
185  //**Assignment operators************************************************************************
188  inline DiagonalMatrix& operator=( initializer_list< initializer_list<ElementType> > list );
189 
190  inline DiagonalMatrix& operator=( const DiagonalMatrix& rhs );
191  inline DiagonalMatrix& operator=( DiagonalMatrix&& rhs ) noexcept;
192 
193  template< typename MT2, bool SO2 >
194  inline DisableIf_< IsComputation<MT2>, DiagonalMatrix& > operator=( const Matrix<MT2,SO2>& rhs );
195 
196  template< typename MT2, bool SO2 >
197  inline EnableIf_< IsComputation<MT2>, DiagonalMatrix& > operator=( const Matrix<MT2,SO2>& rhs );
198 
199  template< typename MT2, bool SO2 >
200  inline DisableIf_< IsComputation<MT2>, DiagonalMatrix& > operator+=( const Matrix<MT2,SO2>& rhs );
201 
202  template< typename MT2, bool SO2 >
203  inline EnableIf_< IsComputation<MT2>, DiagonalMatrix& > operator+=( const Matrix<MT2,SO2>& rhs );
204 
205  template< typename MT2, bool SO2 >
206  inline DisableIf_< IsComputation<MT2>, DiagonalMatrix& > operator-=( const Matrix<MT2,SO2>& rhs );
207 
208  template< typename MT2, bool SO2 >
209  inline EnableIf_< IsComputation<MT2>, DiagonalMatrix& > operator-=( const Matrix<MT2,SO2>& rhs );
210 
211  template< typename MT2, bool SO2 >
212  inline DiagonalMatrix& operator%=( const Matrix<MT2,SO2>& rhs );
214  //**********************************************************************************************
215 
216  //**Utility functions***************************************************************************
219  inline size_t rows() const noexcept;
220  inline size_t columns() const noexcept;
221  inline size_t capacity() const noexcept;
222  inline size_t capacity( size_t i ) const noexcept;
223  inline size_t nonZeros() const;
224  inline size_t nonZeros( size_t i ) const;
225  inline void reset();
226  inline void reset( size_t i );
227  inline void clear();
228  inline void resize ( size_t n, bool preserve=true );
229  inline void reserve( size_t nonzeros );
230  inline void reserve( size_t i, size_t nonzeros );
231  inline void trim();
232  inline void trim( size_t i );
233  inline void shrinkToFit();
234  inline void swap( DiagonalMatrix& m ) noexcept;
236  //**********************************************************************************************
237 
238  //**Insertion functions*************************************************************************
241  inline Iterator set ( size_t i, size_t j, const ElementType& value );
242  inline Iterator insert ( size_t i, size_t j, const ElementType& value );
243  inline void append ( size_t i, size_t j, const ElementType& value, bool check=false );
244  inline void finalize( size_t i );
246  //**********************************************************************************************
247 
248  //**Erase functions*****************************************************************************
251  inline void erase( size_t i, size_t j );
252  inline Iterator erase( size_t i, Iterator pos );
253  inline Iterator erase( size_t i, Iterator first, Iterator last );
254 
255  template< typename Pred >
256  inline void erase( Pred predicate );
257 
258  template< typename Pred >
259  inline void erase( size_t i, Iterator first, Iterator last, Pred predicate );
261  //**********************************************************************************************
262 
263  //**Lookup functions****************************************************************************
266  inline Iterator find ( size_t i, size_t j );
267  inline ConstIterator find ( size_t i, size_t j ) const;
268  inline Iterator lowerBound( size_t i, size_t j );
269  inline ConstIterator lowerBound( size_t i, size_t j ) const;
270  inline Iterator upperBound( size_t i, size_t j );
271  inline ConstIterator upperBound( size_t i, size_t j ) const;
273  //**********************************************************************************************
274 
275  //**Numeric functions***************************************************************************
278  template< typename Other > inline DiagonalMatrix& scale( const Other& scalar );
280  //**********************************************************************************************
281 
282  //**Debugging functions*************************************************************************
285  inline bool isIntact() const noexcept;
287  //**********************************************************************************************
288 
289  //**Expression template evaluation functions****************************************************
292  template< typename Other > inline bool canAlias ( const Other* alias ) const noexcept;
293  template< typename Other > inline bool isAliased( const Other* alias ) const noexcept;
294 
295  inline bool canSMPAssign() const noexcept;
297  //**********************************************************************************************
298 
299  private:
300  //**Utility functions***************************************************************************
303  inline void resetNonDiagonal();
305  //**********************************************************************************************
306 
307  //**Member variables****************************************************************************
310  MT matrix_;
311 
312  //**********************************************************************************************
313 
314  //**Friend declarations*************************************************************************
315  template< bool RF, typename MT2, bool SO2, bool DF2 >
316  friend bool isDefault( const DiagonalMatrix<MT2,SO2,DF2>& m );
317 
318  template< typename MT2, bool SO2, bool DF2 >
319  friend MT2& derestrict( DiagonalMatrix<MT2,SO2,DF2>& m );
320  //**********************************************************************************************
321 
322  //**Compile time checks*************************************************************************
335  BLAZE_STATIC_ASSERT( ( Size<MT,0UL>::value == Size<MT,1UL>::value ) );
336  //**********************************************************************************************
337 };
339 //*************************************************************************************************
340 
341 
342 
343 
344 //=================================================================================================
345 //
346 // CONSTRUCTORS
347 //
348 //=================================================================================================
349 
350 //*************************************************************************************************
354 template< typename MT // Type of the adapted sparse matrix
355  , bool SO > // Storage order of the adapted sparse matrix
356 inline DiagonalMatrix<MT,SO,false>::DiagonalMatrix()
357  : matrix_() // The adapted sparse matrix
358 {
359  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
360 }
362 //*************************************************************************************************
363 
364 
365 //*************************************************************************************************
373 template< typename MT // Type of the adapted sparse matrix
374  , bool SO > // Storage order of the adapted sparse matrix
375 inline DiagonalMatrix<MT,SO,false>::DiagonalMatrix( size_t n )
376  : matrix_( n, n ) // The adapted sparse matrix
377 {
379 
380  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
381 }
383 //*************************************************************************************************
384 
385 
386 //*************************************************************************************************
395 template< typename MT // Type of the adapted sparse matrix
396  , bool SO > // Storage order of the adapted sparse matrix
397 inline DiagonalMatrix<MT,SO,false>::DiagonalMatrix( size_t n, size_t nonzeros )
398  : matrix_( n, n, nonzeros ) // The adapted sparse matrix
399 {
401 
402  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
403 }
405 //*************************************************************************************************
406 
407 
408 //*************************************************************************************************
419 template< typename MT // Type of the adapted sparse matrix
420  , bool SO > // Storage order of the adapted sparse matrix
421 inline DiagonalMatrix<MT,SO,false>::DiagonalMatrix( size_t n, const std::vector<size_t>& nonzeros )
422  : matrix_( n, n, nonzeros ) // The adapted sparse matrix
423 {
425 
426  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
427 }
429 //*************************************************************************************************
430 
431 
432 //*************************************************************************************************
456 template< typename MT // Type of the adapted sparse matrix
457  , bool SO > // Storage order of the adapted sparse matrix
458 inline DiagonalMatrix<MT,SO,false>::DiagonalMatrix( initializer_list< initializer_list<ElementType> > list )
459  : matrix_( list ) // The adapted sparse matrix
460 {
461  if( !isDiagonal( matrix_ ) ) {
462  BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of diagonal matrix" );
463  }
464 
465  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
466 }
468 //*************************************************************************************************
469 
470 
471 //*************************************************************************************************
477 template< typename MT // Type of the adapted sparse matrix
478  , bool SO > // Storage order of the adapted sparse matrix
479 inline DiagonalMatrix<MT,SO,false>::DiagonalMatrix( const DiagonalMatrix& m )
480  : matrix_( m.matrix_ ) // The adapted sparse matrix
481 {
482  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
483  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
484 }
486 //*************************************************************************************************
487 
488 
489 //*************************************************************************************************
495 template< typename MT // Type of the adapted sparse matrix
496  , bool SO > // Storage order of the adapted sparse matrix
497 inline DiagonalMatrix<MT,SO,false>::DiagonalMatrix( DiagonalMatrix&& m ) noexcept
498  : matrix_( std::move( m.matrix_ ) ) // The adapted sparse matrix
499 {
500  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
501  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
502 }
504 //*************************************************************************************************
505 
506 
507 //*************************************************************************************************
517 template< typename MT // Type of the adapted sparse matrix
518  , bool SO > // Storage order of the adapted sparse matrix
519 template< typename MT2 // Type of the foreign matrix
520  , bool SO2 > // Storage order of the foreign matrix
521 inline DiagonalMatrix<MT,SO,false>::DiagonalMatrix( const Matrix<MT2,SO2>& m )
522  : matrix_( ~m ) // The adapted sparse matrix
523 {
524  if( !IsDiagonal<MT2>::value && !isDiagonal( matrix_ ) ) {
525  BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of diagonal matrix" );
526  }
527 
528  if( !IsDiagonal<MT2>::value )
529  resetNonDiagonal();
530 
531  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
532  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
533 }
535 //*************************************************************************************************
536 
537 
538 
539 
540 //=================================================================================================
541 //
542 // DATA ACCESS FUNCTIONS
543 //
544 //=================================================================================================
545 
546 //*************************************************************************************************
562 template< typename MT // Type of the adapted sparse matrix
563  , bool SO > // Storage order of the adapted sparse matrix
565  DiagonalMatrix<MT,SO,false>::operator()( size_t i, size_t j )
566 {
567  BLAZE_USER_ASSERT( i<rows() , "Invalid row access index" );
568  BLAZE_USER_ASSERT( j<columns(), "Invalid column access index" );
569 
570  return Reference( matrix_, i, j );
571 }
573 //*************************************************************************************************
574 
575 
576 //*************************************************************************************************
592 template< typename MT // Type of the adapted sparse matrix
593  , bool SO > // Storage order of the adapted sparse matrix
595  DiagonalMatrix<MT,SO,false>::operator()( size_t i, size_t j ) const
596 {
597  BLAZE_USER_ASSERT( i<rows() , "Invalid row access index" );
598  BLAZE_USER_ASSERT( j<columns(), "Invalid column access index" );
599 
600  return matrix_(i,j);
601 }
603 //*************************************************************************************************
604 
605 
606 //*************************************************************************************************
623 template< typename MT // Type of the adapted sparse matrix
624  , bool SO > // Storage order of the adapted sparse matrix
626  DiagonalMatrix<MT,SO,false>::at( size_t i, size_t j )
627 {
628  if( i >= rows() ) {
629  BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
630  }
631  if( j >= columns() ) {
632  BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
633  }
634  return (*this)(i,j);
635 }
637 //*************************************************************************************************
638 
639 
640 //*************************************************************************************************
657 template< typename MT // Type of the adapted sparse matrix
658  , bool SO > // Storage order of the adapted sparse matrix
660  DiagonalMatrix<MT,SO,false>::at( size_t i, size_t j ) const
661 {
662  if( i >= rows() ) {
663  BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
664  }
665  if( j >= columns() ) {
666  BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
667  }
668  return (*this)(i,j);
669 }
671 //*************************************************************************************************
672 
673 
674 //*************************************************************************************************
686 template< typename MT // Type of the adapted sparse matrix
687  , bool SO > // Storage order of the adapted sparse matrix
690 {
691  return matrix_.begin(i);
692 }
694 //*************************************************************************************************
695 
696 
697 //*************************************************************************************************
709 template< typename MT // Type of the adapted sparse matrix
710  , bool SO > // Storage order of the adapted sparse matrix
712  DiagonalMatrix<MT,SO,false>::begin( size_t i ) const
713 {
714  return matrix_.begin(i);
715 }
717 //*************************************************************************************************
718 
719 
720 //*************************************************************************************************
732 template< typename MT // Type of the adapted sparse matrix
733  , bool SO > // Storage order of the adapted sparse matrix
735  DiagonalMatrix<MT,SO,false>::cbegin( size_t i ) const
736 {
737  return matrix_.cbegin(i);
738 }
740 //*************************************************************************************************
741 
742 
743 //*************************************************************************************************
755 template< typename MT // Type of the adapted sparse matrix
756  , bool SO > // Storage order of the adapted sparse matrix
759 {
760  return matrix_.end(i);
761 }
763 //*************************************************************************************************
764 
765 
766 //*************************************************************************************************
778 template< typename MT // Type of the adapted sparse matrix
779  , bool SO > // Storage order of the adapted sparse matrix
781  DiagonalMatrix<MT,SO,false>::end( size_t i ) const
782 {
783  return matrix_.end(i);
784 }
786 //*************************************************************************************************
787 
788 
789 //*************************************************************************************************
801 template< typename MT // Type of the adapted sparse matrix
802  , bool SO > // Storage order of the adapted sparse matrix
804  DiagonalMatrix<MT,SO,false>::cend( size_t i ) const
805 {
806  return matrix_.cend(i);
807 }
809 //*************************************************************************************************
810 
811 
812 
813 
814 //=================================================================================================
815 //
816 // ASSIGNMENT OPERATORS
817 //
818 //=================================================================================================
819 
820 //*************************************************************************************************
845 template< typename MT // Type of the adapted sparse matrix
846  , bool SO > // Storage order of the adapted sparse matrix
847 inline DiagonalMatrix<MT,SO,false>&
848  DiagonalMatrix<MT,SO,false>::operator=( initializer_list< initializer_list<ElementType> > list )
849 {
850  const InitializerMatrix<ElementType> tmp( list, list.size() );
851 
852  if( !isDiagonal( tmp ) ) {
853  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
854  }
855 
856  matrix_ = list;
857 
858  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
859  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
860 
861  return *this;
862 }
864 //*************************************************************************************************
865 
866 
867 //*************************************************************************************************
877 template< typename MT // Type of the adapted sparse matrix
878  , bool SO > // Storage order of the adapted sparse matrix
879 inline DiagonalMatrix<MT,SO,false>&
880  DiagonalMatrix<MT,SO,false>::operator=( const DiagonalMatrix& rhs )
881 {
882  matrix_ = rhs.matrix_;
883 
884  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
885  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
886 
887  return *this;
888 }
890 //*************************************************************************************************
891 
892 
893 //*************************************************************************************************
900 template< typename MT // Type of the adapted sparse matrix
901  , bool SO > // Storage order of the adapted sparse matrix
902 inline DiagonalMatrix<MT,SO,false>&
903  DiagonalMatrix<MT,SO,false>::operator=( DiagonalMatrix&& rhs ) noexcept
904 {
905  matrix_ = std::move( rhs.matrix_ );
906 
907  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
908  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
909 
910  return *this;
911 }
913 //*************************************************************************************************
914 
915 
916 //*************************************************************************************************
929 template< typename MT // Type of the adapted sparse matrix
930  , bool SO > // Storage order of the adapted sparse matrix
931 template< typename MT2 // Type of the right-hand side matrix
932  , bool SO2 > // Storage order of the right-hand side matrix
933 inline DisableIf_< IsComputation<MT2>, DiagonalMatrix<MT,SO,false>& >
934  DiagonalMatrix<MT,SO,false>::operator=( const Matrix<MT2,SO2>& rhs )
935 {
936  if( !IsDiagonal<MT2>::value && !isDiagonal( ~rhs ) ) {
937  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
938  }
939 
940  matrix_ = decldiag( ~rhs );
941 
942  if( !IsDiagonal<MT2>::value )
943  resetNonDiagonal();
944 
945  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
946  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
947 
948  return *this;
949 }
951 //*************************************************************************************************
952 
953 
954 //*************************************************************************************************
967 template< typename MT // Type of the adapted sparse matrix
968  , bool SO > // Storage order of the adapted sparse matrix
969 template< typename MT2 // Type of the right-hand side matrix
970  , bool SO2 > // Storage order of the right-hand side matrix
971 inline EnableIf_< IsComputation<MT2>, DiagonalMatrix<MT,SO,false>& >
972  DiagonalMatrix<MT,SO,false>::operator=( const Matrix<MT2,SO2>& rhs )
973 {
974  if( !IsSquare<MT2>::value && !isSquare( ~rhs ) ) {
975  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
976  }
977 
978  if( IsDiagonal<MT2>::value ) {
979  matrix_ = ~rhs;
980  }
981  else {
982  MT tmp( ~rhs );
983 
984  if( !isDiagonal( tmp ) ) {
985  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
986  }
987 
988  matrix_ = std::move( tmp );
989  }
990 
991  if( !IsDiagonal<MT2>::value )
992  resetNonDiagonal();
993 
994  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
995  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
996 
997  return *this;
998 }
1000 //*************************************************************************************************
1001 
1002 
1003 //*************************************************************************************************
1016 template< typename MT // Type of the adapted sparse matrix
1017  , bool SO > // Storage order of the adapted sparse matrix
1018 template< typename MT2 // Type of the right-hand side matrix
1019  , bool SO2 > // Storage order of the right-hand side matrix
1020 inline DisableIf_< IsComputation<MT2>, DiagonalMatrix<MT,SO,false>& >
1021  DiagonalMatrix<MT,SO,false>::operator+=( const Matrix<MT2,SO2>& rhs )
1022 {
1023  if( !IsDiagonal<MT2>::value && !isDiagonal( ~rhs ) ) {
1024  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1025  }
1026 
1027  matrix_ += decldiag( ~rhs );
1028 
1029  if( !IsDiagonal<MT2>::value )
1030  resetNonDiagonal();
1031 
1032  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1033  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1034 
1035  return *this;
1036 }
1038 //*************************************************************************************************
1039 
1040 
1041 //*************************************************************************************************
1054 template< typename MT // Type of the adapted sparse matrix
1055  , bool SO > // Storage order of the adapted sparse matrix
1056 template< typename MT2 // Type of the right-hand side matrix
1057  , bool SO2 > // Storage order of the right-hand side matrix
1058 inline EnableIf_< IsComputation<MT2>, DiagonalMatrix<MT,SO,false>& >
1059  DiagonalMatrix<MT,SO,false>::operator+=( const Matrix<MT2,SO2>& rhs )
1060 {
1061  if( !IsSquare<MT2>::value && !isSquare( ~rhs ) ) {
1062  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1063  }
1064 
1065  if( IsDiagonal<MT2>::value ) {
1066  matrix_ += ~rhs;
1067  }
1068  else {
1069  const ResultType_<MT2> tmp( ~rhs );
1070 
1071  if( !isDiagonal( tmp ) ) {
1072  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1073  }
1074 
1075  matrix_ += decldiag( tmp );
1076  }
1077 
1078  if( !IsDiagonal<MT2>::value )
1079  resetNonDiagonal();
1080 
1081  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1082  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1083 
1084  return *this;
1085 }
1087 //*************************************************************************************************
1088 
1089 
1090 //*************************************************************************************************
1103 template< typename MT // Type of the adapted sparse matrix
1104  , bool SO > // Storage order of the adapted sparse matrix
1105 template< typename MT2 // Type of the right-hand side matrix
1106  , bool SO2 > // Storage order of the right-hand side matrix
1107 inline DisableIf_< IsComputation<MT2>, DiagonalMatrix<MT,SO,false>& >
1108  DiagonalMatrix<MT,SO,false>::operator-=( const Matrix<MT2,SO2>& rhs )
1109 {
1110  if( !IsDiagonal<MT2>::value && !isDiagonal( ~rhs ) ) {
1111  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1112  }
1113 
1114  matrix_ -= decldiag( ~rhs );
1115 
1116  if( !IsDiagonal<MT2>::value )
1117  resetNonDiagonal();
1118 
1119  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1120  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1121 
1122  return *this;
1123 }
1125 //*************************************************************************************************
1126 
1127 
1128 //*************************************************************************************************
1141 template< typename MT // Type of the adapted sparse matrix
1142  , bool SO > // Storage order of the adapted sparse matrix
1143 template< typename MT2 // Type of the right-hand side matrix
1144  , bool SO2 > // Storage order of the right-hand side matrix
1145 inline EnableIf_< IsComputation<MT2>, DiagonalMatrix<MT,SO,false>& >
1146  DiagonalMatrix<MT,SO,false>::operator-=( const Matrix<MT2,SO2>& rhs )
1147 {
1148  if( !IsSquare<MT2>::value && !isSquare( ~rhs ) ) {
1149  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1150  }
1151 
1152  if( IsDiagonal<MT2>::value ) {
1153  matrix_ -= ~rhs;
1154  }
1155  else {
1156  const ResultType_<MT2> tmp( ~rhs );
1157 
1158  if( !isDiagonal( tmp ) ) {
1159  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1160  }
1161 
1162  matrix_ -= decldiag( tmp );
1163  }
1164 
1165  if( !IsDiagonal<MT2>::value )
1166  resetNonDiagonal();
1167 
1168  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1169  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1170 
1171  return *this;
1172 }
1174 //*************************************************************************************************
1175 
1176 
1177 //*************************************************************************************************
1188 template< typename MT // Type of the adapted sparse matrix
1189  , bool SO > // Storage order of the adapted sparse matrix
1190 template< typename MT2 // Type of the right-hand side matrix
1191  , bool SO2 > // Storage order of the right-hand side matrix
1192 inline DiagonalMatrix<MT,SO,false>&
1193  DiagonalMatrix<MT,SO,false>::operator%=( const Matrix<MT2,SO2>& rhs )
1194 {
1195  if( !IsSquare<MT2>::value && !isSquare( ~rhs ) ) {
1196  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1197  }
1198 
1199  matrix_ %= ~rhs;
1200 
1201  if( !IsDiagonal<MT2>::value )
1202  resetNonDiagonal();
1203 
1204  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1205  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1206 
1207  return *this;
1208 }
1210 //*************************************************************************************************
1211 
1212 
1213 
1214 
1215 //=================================================================================================
1216 //
1217 // UTILITY FUNCTIONS
1218 //
1219 //=================================================================================================
1220 
1221 //*************************************************************************************************
1227 template< typename MT // Type of the adapted sparse matrix
1228  , bool SO > // Storage order of the adapted sparse matrix
1229 inline size_t DiagonalMatrix<MT,SO,false>::rows() const noexcept
1230 {
1231  return matrix_.rows();
1232 }
1234 //*************************************************************************************************
1235 
1236 
1237 //*************************************************************************************************
1243 template< typename MT // Type of the adapted sparse matrix
1244  , bool SO > // Storage order of the adapted sparse matrix
1245 inline size_t DiagonalMatrix<MT,SO,false>::columns() const noexcept
1246 {
1247  return matrix_.columns();
1248 }
1250 //*************************************************************************************************
1251 
1252 
1253 //*************************************************************************************************
1259 template< typename MT // Type of the adapted sparse matrix
1260  , bool SO > // Storage order of the adapted sparse matrix
1261 inline size_t DiagonalMatrix<MT,SO,false>::capacity() const noexcept
1262 {
1263  return matrix_.capacity();
1264 }
1266 //*************************************************************************************************
1267 
1268 
1269 //*************************************************************************************************
1281 template< typename MT // Type of the adapted sparse matrix
1282  , bool SO > // Storage order of the adapted sparse matrix
1283 inline size_t DiagonalMatrix<MT,SO,false>::capacity( size_t i ) const noexcept
1284 {
1285  return matrix_.capacity(i);
1286 }
1288 //*************************************************************************************************
1289 
1290 
1291 //*************************************************************************************************
1297 template< typename MT // Type of the adapted sparse matrix
1298  , bool SO > // Storage order of the adapted sparse matrix
1299 inline size_t DiagonalMatrix<MT,SO,false>::nonZeros() const
1300 {
1301  return matrix_.nonZeros();
1302 }
1304 //*************************************************************************************************
1305 
1306 
1307 //*************************************************************************************************
1319 template< typename MT // Type of the adapted sparse matrix
1320  , bool SO > // Storage order of the adapted sparse matrix
1321 inline size_t DiagonalMatrix<MT,SO,false>::nonZeros( size_t i ) const
1322 {
1323  return matrix_.nonZeros(i);
1324 }
1326 //*************************************************************************************************
1327 
1328 
1329 //*************************************************************************************************
1335 template< typename MT // Type of the adapted sparse matrix
1336  , bool SO > // Storage order of the adapted sparse matrix
1338 {
1339  matrix_.reset();
1340 }
1342 //*************************************************************************************************
1343 
1344 
1345 //*************************************************************************************************
1358 template< typename MT // Type of the adapted sparse matrix
1359  , bool SO > // Storage order of the adapted sparse matrix
1360 inline void DiagonalMatrix<MT,SO,false>::reset( size_t i )
1361 {
1362  matrix_.reset( i );
1363 }
1365 //*************************************************************************************************
1366 
1367 
1368 //*************************************************************************************************
1376 template< typename MT // Type of the adapted sparse matrix
1377  , bool SO > // Storage order of the adapted sparse matrix
1379 {
1380  using blaze::clear;
1381 
1382  clear( matrix_ );
1383 }
1385 //*************************************************************************************************
1386 
1387 
1388 //*************************************************************************************************
1403 template< typename MT // Type of the adapted sparse matrix
1404  , bool SO > // Storage order of the adapted sparse matrix
1405 void DiagonalMatrix<MT,SO,false>::resize( size_t n, bool preserve )
1406 {
1408 
1409  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1410 
1411  matrix_.resize( n, n, preserve );
1412 }
1414 //*************************************************************************************************
1415 
1416 
1417 //*************************************************************************************************
1428 template< typename MT // Type of the adapted sparse matrix
1429  , bool SO > // Storage order of the adapted sparse matrix
1430 inline void DiagonalMatrix<MT,SO,false>::reserve( size_t nonzeros )
1431 {
1432  matrix_.reserve( nonzeros );
1433 }
1435 //*************************************************************************************************
1436 
1437 
1438 //*************************************************************************************************
1452 template< typename MT // Type of the adapted sparse matrix
1453  , bool SO > // Storage order of the adapted sparse matrix
1454 inline void DiagonalMatrix<MT,SO,false>::reserve( size_t i, size_t nonzeros )
1455 {
1456  matrix_.reserve( i, nonzeros );
1457 }
1459 //*************************************************************************************************
1460 
1461 
1462 //*************************************************************************************************
1473 template< typename MT // Type of the adapted sparse matrix
1474  , bool SO > // Storage order of the adapted sparse matrix
1475 inline void DiagonalMatrix<MT,SO,false>::trim()
1476 {
1477  matrix_.trim();
1478 }
1480 //*************************************************************************************************
1481 
1482 
1483 //*************************************************************************************************
1495 template< typename MT // Type of the adapted sparse matrix
1496  , bool SO > // Storage order of the adapted sparse matrix
1497 inline void DiagonalMatrix<MT,SO,false>::trim( size_t i )
1498 {
1499  matrix_.trim( i );
1500 }
1502 //*************************************************************************************************
1503 
1504 
1505 //*************************************************************************************************
1515 template< typename MT // Type of the adapted sparse matrix
1516  , bool SO > // Storage order of the adapted sparse matrix
1518 {
1519  matrix_.shrinkToFit();
1520 }
1522 //*************************************************************************************************
1523 
1524 
1525 //*************************************************************************************************
1532 template< typename MT // Type of the adapted sparse matrix
1533  , bool SO > // Storage order of the adapted sparse matrix
1534 inline void DiagonalMatrix<MT,SO,false>::swap( DiagonalMatrix& m ) noexcept
1535 {
1536  using std::swap;
1537 
1538  swap( matrix_, m.matrix_ );
1539 }
1541 //*************************************************************************************************
1542 
1543 
1544 //*************************************************************************************************
1550 template< typename MT // Type of the adapted dense matrix
1551  , bool SO > // Storage order of the adapted dense matrix
1552 inline void DiagonalMatrix<MT,SO,false>::resetNonDiagonal()
1553 {
1554  for( size_t i=0UL; i<rows(); ++i ) {
1555  matrix_.erase( i, matrix_.begin( i ), matrix_.lowerBound( i, i ) );
1556  matrix_.erase( i, matrix_.upperBound( i, i ), matrix_.end( i ) );
1557  }
1558 }
1560 //*************************************************************************************************
1561 
1562 
1563 
1564 
1565 //=================================================================================================
1566 //
1567 // INSERTION FUNCTIONS
1568 //
1569 //=================================================================================================
1570 
1571 //*************************************************************************************************
1587 template< typename MT // Type of the adapted sparse matrix
1588  , bool SO > // Storage order of the adapted sparse matrix
1590  DiagonalMatrix<MT,SO,false>::set( size_t i, size_t j, const ElementType& value )
1591 {
1592  if( i < j ) {
1593  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to upper matrix element" );
1594  }
1595 
1596  return matrix_.set( i, j, value );
1597 }
1599 //*************************************************************************************************
1600 
1601 
1602 //*************************************************************************************************
1619 template< typename MT // Type of the adapted sparse matrix
1620  , bool SO > // Storage order of the adapted sparse matrix
1622  DiagonalMatrix<MT,SO,false>::insert( size_t i, size_t j, const ElementType& value )
1623 {
1624  if( i < j ) {
1625  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to upper matrix element" );
1626  }
1627 
1628  return matrix_.insert( i, j, value );
1629 }
1631 //*************************************************************************************************
1632 
1633 
1634 //*************************************************************************************************
1684 template< typename MT // Type of the adapted sparse matrix
1685  , bool SO > // Storage order of the adapted sparse matrix
1686 inline void DiagonalMatrix<MT,SO,false>::append( size_t i, size_t j, const ElementType& value, bool check )
1687 {
1688  if( i < j ) {
1689  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to upper matrix element" );
1690  }
1691 
1692  matrix_.append( i, j, value, check );
1693 }
1695 //*************************************************************************************************
1696 
1697 
1698 //*************************************************************************************************
1712 template< typename MT // Type of the adapted sparse matrix
1713  , bool SO > // Storage order of the adapted sparse matrix
1714 inline void DiagonalMatrix<MT,SO,false>::finalize( size_t i )
1715 {
1716  matrix_.finalize( i );
1717 }
1719 //*************************************************************************************************
1720 
1721 
1722 
1723 
1724 //=================================================================================================
1725 //
1726 // ERASE FUNCTIONS
1727 //
1728 //=================================================================================================
1729 
1730 //*************************************************************************************************
1740 template< typename MT // Type of the adapted sparse matrix
1741  , bool SO > // Storage order of the adapted sparse matrix
1742 inline void DiagonalMatrix<MT,SO,false>::erase( size_t i, size_t j )
1743 {
1744  matrix_.erase( i, j );
1745 }
1747 //*************************************************************************************************
1748 
1749 
1750 //*************************************************************************************************
1762 template< typename MT // Type of the adapted sparse matrix
1763  , bool SO > // Storage order of the adapted sparse matrix
1765  DiagonalMatrix<MT,SO,false>::erase( size_t i, Iterator pos )
1766 {
1767  return matrix_.erase( i, pos );
1768 }
1770 //*************************************************************************************************
1771 
1772 
1773 //*************************************************************************************************
1787 template< typename MT // Type of the adapted sparse matrix
1788  , bool SO > // Storage order of the adapted sparse matrix
1790  DiagonalMatrix<MT,SO,false>::erase( size_t i, Iterator first, Iterator last )
1791 {
1792  return matrix_.erase( i, first, last );
1793 }
1795 //*************************************************************************************************
1796 
1797 
1798 //*************************************************************************************************
1820 template< typename MT // Type of the adapted sparse matrix
1821  , bool SO > // Storage order of the adapted sparse matrix
1822 template< typename Pred > // Type of the unary predicate
1823 inline void DiagonalMatrix<MT,SO,false>::erase( Pred predicate )
1824 {
1825  matrix_.erase( predicate );
1826 
1827  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1828 }
1830 //*************************************************************************************************
1831 
1832 
1833 //*************************************************************************************************
1861 template< typename MT // Type of the adapted sparse matrix
1862  , bool SO > // Storage order of the adapted sparse matrix
1863 template< typename Pred > // Type of the unary predicate
1864 inline void DiagonalMatrix<MT,SO,false>::erase( size_t i, Iterator first, Iterator last, Pred predicate )
1865 {
1866  matrix_.erase( i, first, last, predicate );
1867 
1868  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1869 }
1871 //*************************************************************************************************
1872 
1873 
1874 
1875 
1876 //=================================================================================================
1877 //
1878 // LOOKUP FUNCTIONS
1879 //
1880 //=================================================================================================
1881 
1882 //*************************************************************************************************
1898 template< typename MT // Type of the adapted sparse matrix
1899  , bool SO > // Storage order of the adapted sparse matrix
1901  DiagonalMatrix<MT,SO,false>::find( size_t i, size_t j )
1902 {
1903  return matrix_.find( i, j );
1904 }
1906 //*************************************************************************************************
1907 
1908 
1909 //*************************************************************************************************
1925 template< typename MT // Type of the adapted sparse matrix
1926  , bool SO > // Storage order of the adapted sparse matrix
1928  DiagonalMatrix<MT,SO,false>::find( size_t i, size_t j ) const
1929 {
1930  return matrix_.find( i, j );
1931 }
1933 //*************************************************************************************************
1934 
1935 
1936 //*************************************************************************************************
1952 template< typename MT // Type of the adapted sparse matrix
1953  , bool SO > // Storage order of the adapted sparse matrix
1955  DiagonalMatrix<MT,SO,false>::lowerBound( size_t i, size_t j )
1956 {
1957  return matrix_.lowerBound( i, j );
1958 }
1960 //*************************************************************************************************
1961 
1962 
1963 //*************************************************************************************************
1979 template< typename MT // Type of the adapted sparse matrix
1980  , bool SO > // Storage order of the adapted sparse matrix
1982  DiagonalMatrix<MT,SO,false>::lowerBound( size_t i, size_t j ) const
1983 {
1984  return matrix_.lowerBound( i, j );
1985 }
1987 //*************************************************************************************************
1988 
1989 
1990 //*************************************************************************************************
2006 template< typename MT // Type of the adapted sparse matrix
2007  , bool SO > // Storage order of the adapted sparse matrix
2009  DiagonalMatrix<MT,SO,false>::upperBound( size_t i, size_t j )
2010 {
2011  return matrix_.upperBound( i, j );
2012 }
2014 //*************************************************************************************************
2015 
2016 
2017 //*************************************************************************************************
2033 template< typename MT // Type of the adapted sparse matrix
2034  , bool SO > // Storage order of the adapted sparse matrix
2036  DiagonalMatrix<MT,SO,false>::upperBound( size_t i, size_t j ) const
2037 {
2038  return matrix_.upperBound( i, j );
2039 }
2041 //*************************************************************************************************
2042 
2043 
2044 
2045 
2046 //=================================================================================================
2047 //
2048 // NUMERIC FUNCTIONS
2049 //
2050 //=================================================================================================
2051 
2052 //*************************************************************************************************
2070 template< typename MT // Type of the adapted sparse matrix
2071  , bool SO > // Storage order of the adapted sparse matrix
2072 template< typename Other > // Data type of the scalar value
2073 inline DiagonalMatrix<MT,SO,false>&
2074  DiagonalMatrix<MT,SO,false>::scale( const Other& scalar )
2075 {
2076  matrix_.scale( scalar );
2077  return *this;
2078 }
2080 //*************************************************************************************************
2081 
2082 
2083 
2084 
2085 //=================================================================================================
2086 //
2087 // DEBUGGING FUNCTIONS
2088 //
2089 //=================================================================================================
2090 
2091 //*************************************************************************************************
2101 template< typename MT // Type of the adapted sparse matrix
2102  , bool SO > // Storage order of the adapted sparse matrix
2103 inline bool DiagonalMatrix<MT,SO,false>::isIntact() const noexcept
2104 {
2105  using blaze::isIntact;
2106 
2107  return ( isIntact( matrix_ ) && isDiagonal( matrix_ ) );
2108 }
2110 //*************************************************************************************************
2111 
2112 
2113 
2114 
2115 //=================================================================================================
2116 //
2117 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
2118 //
2119 //=================================================================================================
2120 
2121 //*************************************************************************************************
2132 template< typename MT // Type of the adapted sparse matrix
2133  , bool SO > // Storage order of the adapted sparse matrix
2134 template< typename Other > // Data type of the foreign expression
2135 inline bool DiagonalMatrix<MT,SO,false>::canAlias( const Other* alias ) const noexcept
2136 {
2137  return matrix_.canAlias( alias );
2138 }
2140 //*************************************************************************************************
2141 
2142 
2143 //*************************************************************************************************
2154 template< typename MT // Type of the adapted sparse matrix
2155  , bool SO > // Storage order of the adapted sparse matrix
2156 template< typename Other > // Data type of the foreign expression
2157 inline bool DiagonalMatrix<MT,SO,false>::isAliased( const Other* alias ) const noexcept
2158 {
2159  return matrix_.isAliased( alias );
2160 }
2162 //*************************************************************************************************
2163 
2164 
2165 //*************************************************************************************************
2176 template< typename MT // Type of the adapted sparse matrix
2177  , bool SO > // Storage order of the adapted sparse matrix
2178 inline bool DiagonalMatrix<MT,SO,false>::canSMPAssign() const noexcept
2179 {
2180  return matrix_.canSMPAssign();
2181 }
2183 //*************************************************************************************************
2184 
2185 } // namespace blaze
2186 
2187 #endif
#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
Header file for auxiliary alias declarations.
CompressedMatrix< Type, false > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: CompressedMatrix.h:3077
decltype(auto) decldiag(const DenseMatrix< MT, SO > &dm)
Declares the given dense matrix expression dm as diagonal.
Definition: DMatDeclDiagExpr.h:996
#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
BLAZE_ALWAYS_INLINE size_t capacity(const Matrix< MT, SO > &matrix) noexcept
Returns the maximum capacity of the matrix.
Definition: Matrix.h:522
Header file for basic type definitions.
#define BLAZE_CONSTRAINT_MUST_BE_MATRIX_WITH_STORAGE_ORDER(T, SO)
Constraint on the data type.In case the given data type T is not a dense or sparse matrix type and in...
Definition: StorageOrder.h:63
Header file for the IsDiagonal type trait.
Constraint on the data type.
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:3076
BLAZE_ALWAYS_INLINE MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:364
CompressedMatrix< Type, true > This
Type of this CompressedMatrix instance.
Definition: CompressedMatrix.h:3074
Constraint on the data type.
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:588
BLAZE_ALWAYS_INLINE void shrinkToFit(Matrix< MT, SO > &matrix)
Requesting the removal of unused capacity.
Definition: Matrix.h:775
void clear(CompressedMatrix< Type, SO > &m)
Clearing the given compressed matrix.
Definition: CompressedMatrix.h:5829
CompressedMatrix< Type, false > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:3078
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:3083
#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
bool isDiagonal(const DenseMatrix< MT, SO > &dm)
Checks if the give dense matrix is diagonal.
Definition: DenseMatrix.h:1725
BLAZE_ALWAYS_INLINE size_t nonZeros(const Matrix< MT, SO > &matrix)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:560
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:3084
Header file for the extended initializer_list functionality.
Constraint on the data type.
BLAZE_ALWAYS_INLINE MT::ConstIterator cend(const Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:474
BLAZE_ALWAYS_INLINE MT::ConstIterator cbegin(const Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:408
Constraint on the data type.
Constraint on the data type.
Header file for the SparseMatrix base class.
Header file for utility functions for sparse matrices.
Header file for the IsSquare type trait.
Constraint on the data type.
Header file for the implementation of a matrix representation of an initializer list.
Header file for the DisableIf class template.
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:3082
Header file for the DiagonalProxy class.
Header file for the clear shim.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
void swap(CompressedMatrix< Type, SO > &a, CompressedMatrix< Type, SO > &b) noexcept
Swapping the contents of two compressed matrices.
Definition: CompressedMatrix.h:5908
Compile time assertion.
bool isIntact(const CompressedMatrix< Type, SO > &m)
Returns whether the invariants of the given compressed matrix are intact.
Definition: CompressedMatrix.h:5891
SparseMatrix< This, true > BaseType
Base type of this CompressedMatrix instance.
Definition: CompressedMatrix.h:3075
#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
Type ElementType
Type of the compressed matrix elements.
Definition: CompressedMatrix.h:3079
#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
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:3085
Constraint on the data type.
BLAZE_ALWAYS_INLINE size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:506
Constraints on the storage order of matrix types.
Header file for the exception macros of the math module.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_UPPER_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a upper triangular matrix type...
Definition: Upper.h:81
BLAZE_ALWAYS_INLINE void resize(Matrix< MT, SO > &matrix, size_t rows, size_t columns, bool preserve=true)
Changing the size of the matrix.
Definition: Matrix.h:714
BLAZE_ALWAYS_INLINE 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:430
Header file for the EnableIf class template.
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:608
BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral< T >, HasSize< T, 1UL > >, If_< IsSigned< T >, SIMDint8, SIMDuint8 > > set(T value) noexcept
Sets all values in the vector to the given 1-byte integral value.
Definition: Set.h:76
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a symmetric matrix type, a compilation error is created.
Definition: Symmetric.h:79
BLAZE_ALWAYS_INLINE T1 & operator+=(SIMDPack< T1 > &lhs, const SIMDPack< T2 > &rhs)
Addition assignment operator for the addition of two SIMD packs.
Definition: BasicTypes.h:1357
Header file for run time assertion macros.
Constraint on the data type.
Constraint on the data type.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_LOWER_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a lower triangular matrix type...
Definition: Lower.h:81
#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:272
Constraint on the data type.
Constraint on the data type.
BLAZE_ALWAYS_INLINE size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:490
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:3080
Header file for the implementation of the base template of the DiagonalMatrix.
#define BLAZE_CONSTRAINT_MUST_BE_RESIZABLE_TYPE(T)
Constraint on the data type.In case the given data type T is not resizable, i.e. does not have a &#39;res...
Definition: Resizable.h:61
Header file for the IsComputation type trait class.
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:3081
#define BLAZE_CONSTRAINT_MUST_NOT_BE_EXPRESSION_TYPE(T)
Constraint on the data type.In case the given data type T is an expression (i.e. a type derived from ...
Definition: Expression.h:81
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:254
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:628
#define BLAZE_CONSTRAINT_MUST_NOT_BE_HERMITIAN_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is an Hermitian matrix type, a compilation error is created.
Definition: Hermitian.h:79
BLAZE_ALWAYS_INLINE T1 & operator-=(SIMDPack< T1 > &lhs, const SIMDPack< T2 > &rhs)
Subtraction assignment operator for the subtraction of two SIMD packs.
Definition: BasicTypes.h:1375
#define BLAZE_STATIC_ASSERT(expr)
Compile time assertion macro.In case of an invalid compile time expression, a compilation error is cr...
Definition: StaticAssert.h:112
BLAZE_ALWAYS_INLINE bool isSquare(const Matrix< MT, SO > &matrix) noexcept
Checks if the given matrix is a square matrix.
Definition: Matrix.h:908
Header file for the Size type trait.
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_INTERNAL_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERTION flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:101
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a sparse, N-dimensional matrix type...
Definition: SparseMatrix.h:61