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>
56 #include <blaze/math/Exception.h>
58 #include <blaze/math/shims/Clear.h>
66 #include <blaze/util/Assert.h>
71 #include <blaze/util/DisableIf.h>
72 #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 
156  inline DiagonalMatrix( const DiagonalMatrix& m );
157  inline DiagonalMatrix( DiagonalMatrix&& m ) noexcept;
158 
159  template< typename MT2, bool SO2 >
160  inline DiagonalMatrix( const Matrix<MT2,SO2>& m );
162  //**********************************************************************************************
163 
164  //**Destructor**********************************************************************************
165  // No explicitly declared destructor.
166  //**********************************************************************************************
167 
168  //**Data access functions***********************************************************************
171  inline Reference operator()( size_t i, size_t j );
172  inline ConstReference operator()( size_t i, size_t j ) const;
173  inline Reference at( size_t i, size_t j );
174  inline ConstReference at( size_t i, size_t j ) const;
175  inline Iterator begin ( size_t i );
176  inline ConstIterator begin ( size_t i ) const;
177  inline ConstIterator cbegin( size_t i ) const;
178  inline Iterator end ( size_t i );
179  inline ConstIterator end ( size_t i ) const;
180  inline ConstIterator cend ( size_t i ) const;
182  //**********************************************************************************************
183 
184  //**Assignment operators************************************************************************
187  inline DiagonalMatrix& operator=( const DiagonalMatrix& rhs );
188  inline DiagonalMatrix& operator=( DiagonalMatrix&& rhs ) noexcept;
189 
190  template< typename MT2, bool SO2 >
191  inline DisableIf_< IsComputation<MT2>, DiagonalMatrix& > operator=( const Matrix<MT2,SO2>& rhs );
192 
193  template< typename MT2, bool SO2 >
194  inline EnableIf_< IsComputation<MT2>, DiagonalMatrix& > operator=( const Matrix<MT2,SO2>& rhs );
195 
196  template< typename MT2, bool SO2 >
197  inline DisableIf_< IsComputation<MT2>, DiagonalMatrix& > operator+=( const Matrix<MT2,SO2>& rhs );
198 
199  template< typename MT2, bool SO2 >
200  inline EnableIf_< IsComputation<MT2>, DiagonalMatrix& > operator+=( const Matrix<MT2,SO2>& rhs );
201 
202  template< typename MT2, bool SO2 >
203  inline DisableIf_< IsComputation<MT2>, DiagonalMatrix& > operator-=( const Matrix<MT2,SO2>& rhs );
204 
205  template< typename MT2, bool SO2 >
206  inline EnableIf_< IsComputation<MT2>, DiagonalMatrix& > operator-=( const Matrix<MT2,SO2>& rhs );
207 
208  template< typename MT2, bool SO2 >
209  inline DiagonalMatrix& operator%=( const Matrix<MT2,SO2>& rhs );
210 
211  template< typename MT2, bool SO2 >
212  inline DiagonalMatrix& operator*=( const Matrix<MT2,SO2>& rhs );
213 
214  template< typename Other >
215  inline EnableIf_< IsNumeric<Other>, DiagonalMatrix >& operator*=( Other rhs );
216 
217  template< typename Other >
218  inline EnableIf_< IsNumeric<Other>, DiagonalMatrix >& operator/=( Other rhs );
220  //**********************************************************************************************
221 
222  //**Utility functions***************************************************************************
225  inline size_t rows() const noexcept;
226  inline size_t columns() const noexcept;
227  inline size_t capacity() const noexcept;
228  inline size_t capacity( size_t i ) const noexcept;
229  inline size_t nonZeros() const;
230  inline size_t nonZeros( size_t i ) const;
231  inline void reset();
232  inline void reset( size_t i );
233  inline void clear();
234  inline void resize ( size_t n, bool preserve=true );
235  inline void reserve( size_t nonzeros );
236  inline void reserve( size_t i, size_t nonzeros );
237  inline void trim();
238  inline void trim( size_t i );
239  inline void shrinkToFit();
240  inline void swap( DiagonalMatrix& m ) noexcept;
242  //**********************************************************************************************
243 
244  //**Insertion functions*************************************************************************
247  inline Iterator set ( size_t i, size_t j, const ElementType& value );
248  inline Iterator insert ( size_t i, size_t j, const ElementType& value );
249  inline void append ( size_t i, size_t j, const ElementType& value, bool check=false );
250  inline void finalize( size_t i );
252  //**********************************************************************************************
253 
254  //**Erase functions*****************************************************************************
257  inline void erase( size_t i, size_t j );
258  inline Iterator erase( size_t i, Iterator pos );
259  inline Iterator erase( size_t i, Iterator first, Iterator last );
260 
261  template< typename Pred >
262  inline void erase( Pred predicate );
263 
264  template< typename Pred >
265  inline void erase( size_t i, Iterator first, Iterator last, Pred predicate );
267  //**********************************************************************************************
268 
269  //**Lookup functions****************************************************************************
272  inline Iterator find ( size_t i, size_t j );
273  inline ConstIterator find ( size_t i, size_t j ) const;
274  inline Iterator lowerBound( size_t i, size_t j );
275  inline ConstIterator lowerBound( size_t i, size_t j ) const;
276  inline Iterator upperBound( size_t i, size_t j );
277  inline ConstIterator upperBound( size_t i, size_t j ) const;
279  //**********************************************************************************************
280 
281  //**Numeric functions***************************************************************************
284  template< typename Other > inline DiagonalMatrix& scale( const Other& scalar );
285  template< typename Other > inline DiagonalMatrix& scaleDiagonal( const Other& scale );
287  //**********************************************************************************************
288 
289  //**Debugging functions*************************************************************************
292  inline bool isIntact() const noexcept;
294  //**********************************************************************************************
295 
296  //**Expression template evaluation functions****************************************************
299  template< typename Other > inline bool canAlias ( const Other* alias ) const noexcept;
300  template< typename Other > inline bool isAliased( const Other* alias ) const noexcept;
301 
302  inline bool canSMPAssign() const noexcept;
304  //**********************************************************************************************
305 
306  private:
307  //**Utility functions***************************************************************************
310  inline void resetNonDiagonal();
312  //**********************************************************************************************
313 
314  //**Member variables****************************************************************************
317  MT matrix_;
318 
319  //**********************************************************************************************
320 
321  //**Friend declarations*************************************************************************
322  template< bool RF, typename MT2, bool SO2, bool DF2 >
323  friend bool isDefault( const DiagonalMatrix<MT2,SO2,DF2>& m );
324 
325  template< typename MT2, bool SO2, bool DF2 >
326  friend MT2& derestrict( DiagonalMatrix<MT2,SO2,DF2>& m );
327  //**********************************************************************************************
328 
329  //**Compile time checks*************************************************************************
342  BLAZE_STATIC_ASSERT( Rows<MT>::value == Columns<MT>::value );
343  //**********************************************************************************************
344 };
346 //*************************************************************************************************
347 
348 
349 
350 
351 //=================================================================================================
352 //
353 // CONSTRUCTORS
354 //
355 //=================================================================================================
356 
357 //*************************************************************************************************
361 template< typename MT // Type of the adapted sparse matrix
362  , bool SO > // Storage order of the adapted sparse matrix
363 inline DiagonalMatrix<MT,SO,false>::DiagonalMatrix()
364  : matrix_() // The adapted sparse matrix
365 {
366  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
367 }
369 //*************************************************************************************************
370 
371 
372 //*************************************************************************************************
380 template< typename MT // Type of the adapted sparse matrix
381  , bool SO > // Storage order of the adapted sparse matrix
382 inline DiagonalMatrix<MT,SO,false>::DiagonalMatrix( size_t n )
383  : matrix_( n, n ) // The adapted sparse matrix
384 {
386 
387  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
388 }
390 //*************************************************************************************************
391 
392 
393 //*************************************************************************************************
402 template< typename MT // Type of the adapted sparse matrix
403  , bool SO > // Storage order of the adapted sparse matrix
404 inline DiagonalMatrix<MT,SO,false>::DiagonalMatrix( size_t n, size_t nonzeros )
405  : matrix_( n, n, nonzeros ) // The adapted sparse matrix
406 {
408 
409  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
410 }
412 //*************************************************************************************************
413 
414 
415 //*************************************************************************************************
426 template< typename MT // Type of the adapted sparse matrix
427  , bool SO > // Storage order of the adapted sparse matrix
428 inline DiagonalMatrix<MT,SO,false>::DiagonalMatrix( size_t n, const std::vector<size_t>& nonzeros )
429  : matrix_( n, n, nonzeros ) // The adapted sparse matrix
430 {
432 
433  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
434 }
436 //*************************************************************************************************
437 
438 
439 //*************************************************************************************************
445 template< typename MT // Type of the adapted sparse matrix
446  , bool SO > // Storage order of the adapted sparse matrix
447 inline DiagonalMatrix<MT,SO,false>::DiagonalMatrix( const DiagonalMatrix& m )
448  : matrix_( m.matrix_ ) // The adapted sparse matrix
449 {
450  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
451  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
452 }
454 //*************************************************************************************************
455 
456 
457 //*************************************************************************************************
463 template< typename MT // Type of the adapted sparse matrix
464  , bool SO > // Storage order of the adapted sparse matrix
465 inline DiagonalMatrix<MT,SO,false>::DiagonalMatrix( DiagonalMatrix&& m ) noexcept
466  : matrix_( std::move( m.matrix_ ) ) // The adapted sparse matrix
467 {
468  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
469  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
470 }
472 //*************************************************************************************************
473 
474 
475 //*************************************************************************************************
485 template< typename MT // Type of the adapted sparse matrix
486  , bool SO > // Storage order of the adapted sparse matrix
487 template< typename MT2 // Type of the foreign matrix
488  , bool SO2 > // Storage order of the foreign matrix
489 inline DiagonalMatrix<MT,SO,false>::DiagonalMatrix( const Matrix<MT2,SO2>& m )
490  : matrix_( ~m ) // The adapted sparse matrix
491 {
492  if( !IsDiagonal<MT2>::value && !isDiagonal( matrix_ ) ) {
493  BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of diagonal matrix" );
494  }
495 
496  if( !IsDiagonal<MT2>::value )
497  resetNonDiagonal();
498 
499  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
500  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
501 }
503 //*************************************************************************************************
504 
505 
506 
507 
508 //=================================================================================================
509 //
510 // DATA ACCESS FUNCTIONS
511 //
512 //=================================================================================================
513 
514 //*************************************************************************************************
530 template< typename MT // Type of the adapted sparse matrix
531  , bool SO > // Storage order of the adapted sparse matrix
533  DiagonalMatrix<MT,SO,false>::operator()( size_t i, size_t j )
534 {
535  BLAZE_USER_ASSERT( i<rows() , "Invalid row access index" );
536  BLAZE_USER_ASSERT( j<columns(), "Invalid column access index" );
537 
538  return Reference( matrix_, i, j );
539 }
541 //*************************************************************************************************
542 
543 
544 //*************************************************************************************************
560 template< typename MT // Type of the adapted sparse matrix
561  , bool SO > // Storage order of the adapted sparse matrix
563  DiagonalMatrix<MT,SO,false>::operator()( size_t i, size_t j ) const
564 {
565  BLAZE_USER_ASSERT( i<rows() , "Invalid row access index" );
566  BLAZE_USER_ASSERT( j<columns(), "Invalid column access index" );
567 
568  return matrix_(i,j);
569 }
571 //*************************************************************************************************
572 
573 
574 //*************************************************************************************************
591 template< typename MT // Type of the adapted sparse matrix
592  , bool SO > // Storage order of the adapted sparse matrix
594  DiagonalMatrix<MT,SO,false>::at( size_t i, size_t j )
595 {
596  if( i >= rows() ) {
597  BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
598  }
599  if( j >= columns() ) {
600  BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
601  }
602  return (*this)(i,j);
603 }
605 //*************************************************************************************************
606 
607 
608 //*************************************************************************************************
625 template< typename MT // Type of the adapted sparse matrix
626  , bool SO > // Storage order of the adapted sparse matrix
628  DiagonalMatrix<MT,SO,false>::at( size_t i, size_t j ) const
629 {
630  if( i >= rows() ) {
631  BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
632  }
633  if( j >= columns() ) {
634  BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
635  }
636  return (*this)(i,j);
637 }
639 //*************************************************************************************************
640 
641 
642 //*************************************************************************************************
654 template< typename MT // Type of the adapted sparse matrix
655  , bool SO > // Storage order of the adapted sparse matrix
658 {
659  return matrix_.begin(i);
660 }
662 //*************************************************************************************************
663 
664 
665 //*************************************************************************************************
677 template< typename MT // Type of the adapted sparse matrix
678  , bool SO > // Storage order of the adapted sparse matrix
680  DiagonalMatrix<MT,SO,false>::begin( size_t i ) const
681 {
682  return matrix_.begin(i);
683 }
685 //*************************************************************************************************
686 
687 
688 //*************************************************************************************************
700 template< typename MT // Type of the adapted sparse matrix
701  , bool SO > // Storage order of the adapted sparse matrix
703  DiagonalMatrix<MT,SO,false>::cbegin( size_t i ) const
704 {
705  return matrix_.cbegin(i);
706 }
708 //*************************************************************************************************
709 
710 
711 //*************************************************************************************************
723 template< typename MT // Type of the adapted sparse matrix
724  , bool SO > // Storage order of the adapted sparse matrix
727 {
728  return matrix_.end(i);
729 }
731 //*************************************************************************************************
732 
733 
734 //*************************************************************************************************
746 template< typename MT // Type of the adapted sparse matrix
747  , bool SO > // Storage order of the adapted sparse matrix
749  DiagonalMatrix<MT,SO,false>::end( size_t i ) const
750 {
751  return matrix_.end(i);
752 }
754 //*************************************************************************************************
755 
756 
757 //*************************************************************************************************
769 template< typename MT // Type of the adapted sparse matrix
770  , bool SO > // Storage order of the adapted sparse matrix
772  DiagonalMatrix<MT,SO,false>::cend( size_t i ) const
773 {
774  return matrix_.cend(i);
775 }
777 //*************************************************************************************************
778 
779 
780 
781 
782 //=================================================================================================
783 //
784 // ASSIGNMENT OPERATORS
785 //
786 //=================================================================================================
787 
788 //*************************************************************************************************
798 template< typename MT // Type of the adapted sparse matrix
799  , bool SO > // Storage order of the adapted sparse matrix
800 inline DiagonalMatrix<MT,SO,false>&
801  DiagonalMatrix<MT,SO,false>::operator=( const DiagonalMatrix& rhs )
802 {
803  matrix_ = rhs.matrix_;
804 
805  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
806  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
807 
808  return *this;
809 }
811 //*************************************************************************************************
812 
813 
814 //*************************************************************************************************
821 template< typename MT // Type of the adapted sparse matrix
822  , bool SO > // Storage order of the adapted sparse matrix
823 inline DiagonalMatrix<MT,SO,false>&
824  DiagonalMatrix<MT,SO,false>::operator=( DiagonalMatrix&& rhs ) noexcept
825 {
826  matrix_ = std::move( rhs.matrix_ );
827 
828  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
829  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
830 
831  return *this;
832 }
834 //*************************************************************************************************
835 
836 
837 //*************************************************************************************************
850 template< typename MT // Type of the adapted sparse matrix
851  , bool SO > // Storage order of the adapted sparse matrix
852 template< typename MT2 // Type of the right-hand side matrix
853  , bool SO2 > // Storage order of the right-hand side matrix
854 inline DisableIf_< IsComputation<MT2>, DiagonalMatrix<MT,SO,false>& >
855  DiagonalMatrix<MT,SO,false>::operator=( const Matrix<MT2,SO2>& rhs )
856 {
857  if( !IsDiagonal<MT2>::value && !isDiagonal( ~rhs ) ) {
858  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
859  }
860 
861  matrix_ = decldiag( ~rhs );
862 
863  if( !IsDiagonal<MT2>::value )
864  resetNonDiagonal();
865 
866  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
867  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
868 
869  return *this;
870 }
872 //*************************************************************************************************
873 
874 
875 //*************************************************************************************************
888 template< typename MT // Type of the adapted sparse matrix
889  , bool SO > // Storage order of the adapted sparse matrix
890 template< typename MT2 // Type of the right-hand side matrix
891  , bool SO2 > // Storage order of the right-hand side matrix
892 inline EnableIf_< IsComputation<MT2>, DiagonalMatrix<MT,SO,false>& >
893  DiagonalMatrix<MT,SO,false>::operator=( const Matrix<MT2,SO2>& rhs )
894 {
895  if( !IsSquare<MT2>::value && !isSquare( ~rhs ) ) {
896  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
897  }
898 
899  if( IsDiagonal<MT2>::value ) {
900  matrix_ = ~rhs;
901  }
902  else {
903  MT tmp( ~rhs );
904 
905  if( !isDiagonal( tmp ) ) {
906  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
907  }
908 
909  matrix_ = std::move( tmp );
910  }
911 
912  if( !IsDiagonal<MT2>::value )
913  resetNonDiagonal();
914 
915  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
916  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
917 
918  return *this;
919 }
921 //*************************************************************************************************
922 
923 
924 //*************************************************************************************************
937 template< typename MT // Type of the adapted sparse matrix
938  , bool SO > // Storage order of the adapted sparse matrix
939 template< typename MT2 // Type of the right-hand side matrix
940  , bool SO2 > // Storage order of the right-hand side matrix
941 inline DisableIf_< IsComputation<MT2>, DiagonalMatrix<MT,SO,false>& >
942  DiagonalMatrix<MT,SO,false>::operator+=( const Matrix<MT2,SO2>& rhs )
943 {
944  if( !IsDiagonal<MT2>::value && !isDiagonal( ~rhs ) ) {
945  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
946  }
947 
948  matrix_ += decldiag( ~rhs );
949 
950  if( !IsDiagonal<MT2>::value )
951  resetNonDiagonal();
952 
953  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
954  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
955 
956  return *this;
957 }
959 //*************************************************************************************************
960 
961 
962 //*************************************************************************************************
975 template< typename MT // Type of the adapted sparse matrix
976  , bool SO > // Storage order of the adapted sparse matrix
977 template< typename MT2 // Type of the right-hand side matrix
978  , bool SO2 > // Storage order of the right-hand side matrix
979 inline EnableIf_< IsComputation<MT2>, DiagonalMatrix<MT,SO,false>& >
980  DiagonalMatrix<MT,SO,false>::operator+=( const Matrix<MT2,SO2>& rhs )
981 {
982  if( !IsSquare<MT2>::value && !isSquare( ~rhs ) ) {
983  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
984  }
985 
986  if( IsDiagonal<MT2>::value ) {
987  matrix_ += ~rhs;
988  }
989  else {
990  const ResultType_<MT2> tmp( ~rhs );
991 
992  if( !isDiagonal( tmp ) ) {
993  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
994  }
995 
996  matrix_ += decldiag( tmp );
997  }
998 
999  if( !IsDiagonal<MT2>::value )
1000  resetNonDiagonal();
1001 
1002  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1003  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1004 
1005  return *this;
1006 }
1008 //*************************************************************************************************
1009 
1010 
1011 //*************************************************************************************************
1024 template< typename MT // Type of the adapted sparse matrix
1025  , bool SO > // Storage order of the adapted sparse matrix
1026 template< typename MT2 // Type of the right-hand side matrix
1027  , bool SO2 > // Storage order of the right-hand side matrix
1028 inline DisableIf_< IsComputation<MT2>, DiagonalMatrix<MT,SO,false>& >
1029  DiagonalMatrix<MT,SO,false>::operator-=( const Matrix<MT2,SO2>& rhs )
1030 {
1031  if( !IsDiagonal<MT2>::value && !isDiagonal( ~rhs ) ) {
1032  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1033  }
1034 
1035  matrix_ -= decldiag( ~rhs );
1036 
1037  if( !IsDiagonal<MT2>::value )
1038  resetNonDiagonal();
1039 
1040  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1041  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1042 
1043  return *this;
1044 }
1046 //*************************************************************************************************
1047 
1048 
1049 //*************************************************************************************************
1062 template< typename MT // Type of the adapted sparse matrix
1063  , bool SO > // Storage order of the adapted sparse matrix
1064 template< typename MT2 // Type of the right-hand side matrix
1065  , bool SO2 > // Storage order of the right-hand side matrix
1066 inline EnableIf_< IsComputation<MT2>, DiagonalMatrix<MT,SO,false>& >
1067  DiagonalMatrix<MT,SO,false>::operator-=( const Matrix<MT2,SO2>& rhs )
1068 {
1069  if( !IsSquare<MT2>::value && !isSquare( ~rhs ) ) {
1070  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1071  }
1072 
1073  if( IsDiagonal<MT2>::value ) {
1074  matrix_ -= ~rhs;
1075  }
1076  else {
1077  const ResultType_<MT2> tmp( ~rhs );
1078 
1079  if( !isDiagonal( tmp ) ) {
1080  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1081  }
1082 
1083  matrix_ -= decldiag( tmp );
1084  }
1085 
1086  if( !IsDiagonal<MT2>::value )
1087  resetNonDiagonal();
1088 
1089  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1090  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1091 
1092  return *this;
1093 }
1095 //*************************************************************************************************
1096 
1097 
1098 //*************************************************************************************************
1109 template< typename MT // Type of the adapted sparse matrix
1110  , bool SO > // Storage order of the adapted sparse matrix
1111 template< typename MT2 // Type of the right-hand side matrix
1112  , bool SO2 > // Storage order of the right-hand side matrix
1113 inline DiagonalMatrix<MT,SO,false>&
1114  DiagonalMatrix<MT,SO,false>::operator%=( const Matrix<MT2,SO2>& rhs )
1115 {
1116  if( !IsSquare<MT2>::value && !isSquare( ~rhs ) ) {
1117  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1118  }
1119 
1120  matrix_ %= ~rhs;
1121 
1122  if( !IsDiagonal<MT2>::value )
1123  resetNonDiagonal();
1124 
1125  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1126  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1127 
1128  return *this;
1129 }
1131 //*************************************************************************************************
1132 
1133 
1134 //*************************************************************************************************
1146 template< typename MT // Type of the adapted sparse matrix
1147  , bool SO > // Storage order of the adapted sparse matrix
1148 template< typename MT2 // Type of the right-hand side matrix
1149  , bool SO2 > // Storage order of the right-hand side matrix
1150 inline DiagonalMatrix<MT,SO,false>&
1151  DiagonalMatrix<MT,SO,false>::operator*=( const Matrix<MT2,SO2>& rhs )
1152 {
1153  if( matrix_.rows() != (~rhs).columns() ) {
1154  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1155  }
1156 
1157  MT tmp( matrix_ * ~rhs );
1158 
1159  if( !isDiagonal( tmp ) ) {
1160  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1161  }
1162 
1163  matrix_ = std::move( tmp );
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 //*************************************************************************************************
1185 template< typename MT // Type of the adapted sparse matrix
1186  , bool SO > // Storage order of the adapted sparse matrix
1187 template< typename Other > // Data type of the right-hand side scalar
1188 inline EnableIf_< IsNumeric<Other>, DiagonalMatrix<MT,SO,false> >&
1190 {
1191  matrix_ *= rhs;
1192  return *this;
1193 }
1194 //*************************************************************************************************
1195 
1196 
1197 //*************************************************************************************************
1205 template< typename MT // Type of the adapted sparse matrix
1206  , bool SO > // Storage order of the adapted sparse matrix
1207 template< typename Other > // Data type of the right-hand side scalar
1208 inline EnableIf_< IsNumeric<Other>, DiagonalMatrix<MT,SO,false> >&
1210 {
1211  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
1212 
1213  matrix_ /= rhs;
1214  return *this;
1215 }
1217 //*************************************************************************************************
1218 
1219 
1220 
1221 
1222 //=================================================================================================
1223 //
1224 // UTILITY FUNCTIONS
1225 //
1226 //=================================================================================================
1227 
1228 //*************************************************************************************************
1234 template< typename MT // Type of the adapted sparse matrix
1235  , bool SO > // Storage order of the adapted sparse matrix
1236 inline size_t DiagonalMatrix<MT,SO,false>::rows() const noexcept
1237 {
1238  return matrix_.rows();
1239 }
1241 //*************************************************************************************************
1242 
1243 
1244 //*************************************************************************************************
1250 template< typename MT // Type of the adapted sparse matrix
1251  , bool SO > // Storage order of the adapted sparse matrix
1252 inline size_t DiagonalMatrix<MT,SO,false>::columns() const noexcept
1253 {
1254  return matrix_.columns();
1255 }
1257 //*************************************************************************************************
1258 
1259 
1260 //*************************************************************************************************
1266 template< typename MT // Type of the adapted sparse matrix
1267  , bool SO > // Storage order of the adapted sparse matrix
1268 inline size_t DiagonalMatrix<MT,SO,false>::capacity() const noexcept
1269 {
1270  return matrix_.capacity();
1271 }
1273 //*************************************************************************************************
1274 
1275 
1276 //*************************************************************************************************
1288 template< typename MT // Type of the adapted sparse matrix
1289  , bool SO > // Storage order of the adapted sparse matrix
1290 inline size_t DiagonalMatrix<MT,SO,false>::capacity( size_t i ) const noexcept
1291 {
1292  return matrix_.capacity(i);
1293 }
1295 //*************************************************************************************************
1296 
1297 
1298 //*************************************************************************************************
1304 template< typename MT // Type of the adapted sparse matrix
1305  , bool SO > // Storage order of the adapted sparse matrix
1306 inline size_t DiagonalMatrix<MT,SO,false>::nonZeros() const
1307 {
1308  return matrix_.nonZeros();
1309 }
1311 //*************************************************************************************************
1312 
1313 
1314 //*************************************************************************************************
1326 template< typename MT // Type of the adapted sparse matrix
1327  , bool SO > // Storage order of the adapted sparse matrix
1328 inline size_t DiagonalMatrix<MT,SO,false>::nonZeros( size_t i ) const
1329 {
1330  return matrix_.nonZeros(i);
1331 }
1333 //*************************************************************************************************
1334 
1335 
1336 //*************************************************************************************************
1342 template< typename MT // Type of the adapted sparse matrix
1343  , bool SO > // Storage order of the adapted sparse matrix
1345 {
1346  matrix_.reset();
1347 }
1349 //*************************************************************************************************
1350 
1351 
1352 //*************************************************************************************************
1365 template< typename MT // Type of the adapted sparse matrix
1366  , bool SO > // Storage order of the adapted sparse matrix
1367 inline void DiagonalMatrix<MT,SO,false>::reset( size_t i )
1368 {
1369  matrix_.reset( i );
1370 }
1372 //*************************************************************************************************
1373 
1374 
1375 //*************************************************************************************************
1383 template< typename MT // Type of the adapted sparse matrix
1384  , bool SO > // Storage order of the adapted sparse matrix
1386 {
1387  using blaze::clear;
1388 
1389  clear( matrix_ );
1390 }
1392 //*************************************************************************************************
1393 
1394 
1395 //*************************************************************************************************
1410 template< typename MT // Type of the adapted sparse matrix
1411  , bool SO > // Storage order of the adapted sparse matrix
1412 void DiagonalMatrix<MT,SO,false>::resize( size_t n, bool preserve )
1413 {
1415 
1416  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1417 
1418  matrix_.resize( n, n, preserve );
1419 }
1421 //*************************************************************************************************
1422 
1423 
1424 //*************************************************************************************************
1435 template< typename MT // Type of the adapted sparse matrix
1436  , bool SO > // Storage order of the adapted sparse matrix
1437 inline void DiagonalMatrix<MT,SO,false>::reserve( size_t nonzeros )
1438 {
1439  matrix_.reserve( nonzeros );
1440 }
1442 //*************************************************************************************************
1443 
1444 
1445 //*************************************************************************************************
1459 template< typename MT // Type of the adapted sparse matrix
1460  , bool SO > // Storage order of the adapted sparse matrix
1461 inline void DiagonalMatrix<MT,SO,false>::reserve( size_t i, size_t nonzeros )
1462 {
1463  matrix_.reserve( i, nonzeros );
1464 }
1466 //*************************************************************************************************
1467 
1468 
1469 //*************************************************************************************************
1480 template< typename MT // Type of the adapted sparse matrix
1481  , bool SO > // Storage order of the adapted sparse matrix
1482 inline void DiagonalMatrix<MT,SO,false>::trim()
1483 {
1484  matrix_.trim();
1485 }
1487 //*************************************************************************************************
1488 
1489 
1490 //*************************************************************************************************
1502 template< typename MT // Type of the adapted sparse matrix
1503  , bool SO > // Storage order of the adapted sparse matrix
1504 inline void DiagonalMatrix<MT,SO,false>::trim( size_t i )
1505 {
1506  matrix_.trim( i );
1507 }
1509 //*************************************************************************************************
1510 
1511 
1512 //*************************************************************************************************
1522 template< typename MT // Type of the adapted sparse matrix
1523  , bool SO > // Storage order of the adapted sparse matrix
1525 {
1526  matrix_.shrinkToFit();
1527 }
1529 //*************************************************************************************************
1530 
1531 
1532 //*************************************************************************************************
1539 template< typename MT // Type of the adapted sparse matrix
1540  , bool SO > // Storage order of the adapted sparse matrix
1541 inline void DiagonalMatrix<MT,SO,false>::swap( DiagonalMatrix& m ) noexcept
1542 {
1543  using std::swap;
1544 
1545  swap( matrix_, m.matrix_ );
1546 }
1548 //*************************************************************************************************
1549 
1550 
1551 //*************************************************************************************************
1557 template< typename MT // Type of the adapted dense matrix
1558  , bool SO > // Storage order of the adapted dense matrix
1559 inline void DiagonalMatrix<MT,SO,false>::resetNonDiagonal()
1560 {
1561  for( size_t i=0UL; i<rows(); ++i ) {
1562  matrix_.erase( i, matrix_.begin( i ), matrix_.lowerBound( i, i ) );
1563  matrix_.erase( i, matrix_.upperBound( i, i ), matrix_.end( i ) );
1564  }
1565 }
1567 //*************************************************************************************************
1568 
1569 
1570 
1571 
1572 //=================================================================================================
1573 //
1574 // INSERTION FUNCTIONS
1575 //
1576 //=================================================================================================
1577 
1578 //*************************************************************************************************
1594 template< typename MT // Type of the adapted sparse matrix
1595  , bool SO > // Storage order of the adapted sparse matrix
1597  DiagonalMatrix<MT,SO,false>::set( size_t i, size_t j, const ElementType& value )
1598 {
1599  if( i < j ) {
1600  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to upper matrix element" );
1601  }
1602 
1603  return matrix_.set( i, j, value );
1604 }
1606 //*************************************************************************************************
1607 
1608 
1609 //*************************************************************************************************
1626 template< typename MT // Type of the adapted sparse matrix
1627  , bool SO > // Storage order of the adapted sparse matrix
1629  DiagonalMatrix<MT,SO,false>::insert( size_t i, size_t j, const ElementType& value )
1630 {
1631  if( i < j ) {
1632  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to upper matrix element" );
1633  }
1634 
1635  return matrix_.insert( i, j, value );
1636 }
1638 //*************************************************************************************************
1639 
1640 
1641 //*************************************************************************************************
1691 template< typename MT // Type of the adapted sparse matrix
1692  , bool SO > // Storage order of the adapted sparse matrix
1693 inline void DiagonalMatrix<MT,SO,false>::append( size_t i, size_t j, const ElementType& value, bool check )
1694 {
1695  if( i < j ) {
1696  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to upper matrix element" );
1697  }
1698 
1699  matrix_.append( i, j, value, check );
1700 }
1702 //*************************************************************************************************
1703 
1704 
1705 //*************************************************************************************************
1719 template< typename MT // Type of the adapted sparse matrix
1720  , bool SO > // Storage order of the adapted sparse matrix
1721 inline void DiagonalMatrix<MT,SO,false>::finalize( size_t i )
1722 {
1723  matrix_.finalize( i );
1724 }
1726 //*************************************************************************************************
1727 
1728 
1729 
1730 
1731 //=================================================================================================
1732 //
1733 // ERASE FUNCTIONS
1734 //
1735 //=================================================================================================
1736 
1737 //*************************************************************************************************
1747 template< typename MT // Type of the adapted sparse matrix
1748  , bool SO > // Storage order of the adapted sparse matrix
1749 inline void DiagonalMatrix<MT,SO,false>::erase( size_t i, size_t j )
1750 {
1751  matrix_.erase( i, j );
1752 }
1754 //*************************************************************************************************
1755 
1756 
1757 //*************************************************************************************************
1769 template< typename MT // Type of the adapted sparse matrix
1770  , bool SO > // Storage order of the adapted sparse matrix
1772  DiagonalMatrix<MT,SO,false>::erase( size_t i, Iterator pos )
1773 {
1774  return matrix_.erase( i, pos );
1775 }
1777 //*************************************************************************************************
1778 
1779 
1780 //*************************************************************************************************
1794 template< typename MT // Type of the adapted sparse matrix
1795  , bool SO > // Storage order of the adapted sparse matrix
1797  DiagonalMatrix<MT,SO,false>::erase( size_t i, Iterator first, Iterator last )
1798 {
1799  return matrix_.erase( i, first, last );
1800 }
1802 //*************************************************************************************************
1803 
1804 
1805 //*************************************************************************************************
1827 template< typename MT // Type of the adapted sparse matrix
1828  , bool SO > // Storage order of the adapted sparse matrix
1829 template< typename Pred > // Type of the unary predicate
1830 inline void DiagonalMatrix<MT,SO,false>::erase( Pred predicate )
1831 {
1832  matrix_.erase( predicate );
1833 
1834  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1835 }
1837 //*************************************************************************************************
1838 
1839 
1840 //*************************************************************************************************
1868 template< typename MT // Type of the adapted sparse matrix
1869  , bool SO > // Storage order of the adapted sparse matrix
1870 template< typename Pred > // Type of the unary predicate
1871 inline void DiagonalMatrix<MT,SO,false>::erase( size_t i, Iterator first, Iterator last, Pred predicate )
1872 {
1873  matrix_.erase( i, first, last, predicate );
1874 
1875  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1876 }
1878 //*************************************************************************************************
1879 
1880 
1881 
1882 
1883 //=================================================================================================
1884 //
1885 // LOOKUP FUNCTIONS
1886 //
1887 //=================================================================================================
1888 
1889 //*************************************************************************************************
1905 template< typename MT // Type of the adapted sparse matrix
1906  , bool SO > // Storage order of the adapted sparse matrix
1908  DiagonalMatrix<MT,SO,false>::find( size_t i, size_t j )
1909 {
1910  return matrix_.find( i, j );
1911 }
1913 //*************************************************************************************************
1914 
1915 
1916 //*************************************************************************************************
1932 template< typename MT // Type of the adapted sparse matrix
1933  , bool SO > // Storage order of the adapted sparse matrix
1935  DiagonalMatrix<MT,SO,false>::find( size_t i, size_t j ) const
1936 {
1937  return matrix_.find( i, j );
1938 }
1940 //*************************************************************************************************
1941 
1942 
1943 //*************************************************************************************************
1959 template< typename MT // Type of the adapted sparse matrix
1960  , bool SO > // Storage order of the adapted sparse matrix
1962  DiagonalMatrix<MT,SO,false>::lowerBound( size_t i, size_t j )
1963 {
1964  return matrix_.lowerBound( i, j );
1965 }
1967 //*************************************************************************************************
1968 
1969 
1970 //*************************************************************************************************
1986 template< typename MT // Type of the adapted sparse matrix
1987  , bool SO > // Storage order of the adapted sparse matrix
1989  DiagonalMatrix<MT,SO,false>::lowerBound( size_t i, size_t j ) const
1990 {
1991  return matrix_.lowerBound( i, j );
1992 }
1994 //*************************************************************************************************
1995 
1996 
1997 //*************************************************************************************************
2013 template< typename MT // Type of the adapted sparse matrix
2014  , bool SO > // Storage order of the adapted sparse matrix
2016  DiagonalMatrix<MT,SO,false>::upperBound( size_t i, size_t j )
2017 {
2018  return matrix_.upperBound( i, j );
2019 }
2021 //*************************************************************************************************
2022 
2023 
2024 //*************************************************************************************************
2040 template< typename MT // Type of the adapted sparse matrix
2041  , bool SO > // Storage order of the adapted sparse matrix
2043  DiagonalMatrix<MT,SO,false>::upperBound( size_t i, size_t j ) const
2044 {
2045  return matrix_.upperBound( i, j );
2046 }
2048 //*************************************************************************************************
2049 
2050 
2051 
2052 
2053 //=================================================================================================
2054 //
2055 // NUMERIC FUNCTIONS
2056 //
2057 //=================================================================================================
2058 
2059 //*************************************************************************************************
2077 template< typename MT // Type of the adapted sparse matrix
2078  , bool SO > // Storage order of the adapted sparse matrix
2079 template< typename Other > // Data type of the scalar value
2080 inline DiagonalMatrix<MT,SO,false>&
2081  DiagonalMatrix<MT,SO,false>::scale( const Other& scalar )
2082 {
2083  matrix_.scale( scalar );
2084  return *this;
2085 }
2087 //*************************************************************************************************
2088 
2089 
2090 //*************************************************************************************************
2100 template< typename MT // Type of the adapted sparse matrix
2101  , bool SO > // Storage order of the adapted sparse matrix
2102 template< typename Other > // Data type of the scalar value
2103 inline DiagonalMatrix<MT,SO,false>&
2104  DiagonalMatrix<MT,SO,false>::scaleDiagonal( const Other& scalar )
2105 {
2106  matrix_.scaleDiagonal( scalar );
2107  return *this;
2108 }
2110 //*************************************************************************************************
2111 
2112 
2113 
2114 
2115 //=================================================================================================
2116 //
2117 // DEBUGGING FUNCTIONS
2118 //
2119 //=================================================================================================
2120 
2121 //*************************************************************************************************
2131 template< typename MT // Type of the adapted sparse matrix
2132  , bool SO > // Storage order of the adapted sparse matrix
2133 inline bool DiagonalMatrix<MT,SO,false>::isIntact() const noexcept
2134 {
2135  using blaze::isIntact;
2136 
2137  return ( isIntact( matrix_ ) && isDiagonal( matrix_ ) );
2138 }
2140 //*************************************************************************************************
2141 
2142 
2143 
2144 
2145 //=================================================================================================
2146 //
2147 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
2148 //
2149 //=================================================================================================
2150 
2151 //*************************************************************************************************
2162 template< typename MT // Type of the adapted sparse matrix
2163  , bool SO > // Storage order of the adapted sparse matrix
2164 template< typename Other > // Data type of the foreign expression
2165 inline bool DiagonalMatrix<MT,SO,false>::canAlias( const Other* alias ) const noexcept
2166 {
2167  return matrix_.canAlias( alias );
2168 }
2170 //*************************************************************************************************
2171 
2172 
2173 //*************************************************************************************************
2184 template< typename MT // Type of the adapted sparse matrix
2185  , bool SO > // Storage order of the adapted sparse matrix
2186 template< typename Other > // Data type of the foreign expression
2187 inline bool DiagonalMatrix<MT,SO,false>::isAliased( const Other* alias ) const noexcept
2188 {
2189  return matrix_.isAliased( alias );
2190 }
2192 //*************************************************************************************************
2193 
2194 
2195 //*************************************************************************************************
2206 template< typename MT // Type of the adapted sparse matrix
2207  , bool SO > // Storage order of the adapted sparse matrix
2208 inline bool DiagonalMatrix<MT,SO,false>::canSMPAssign() const noexcept
2209 {
2210  return matrix_.canSMPAssign();
2211 }
2213 //*************************************************************************************************
2214 
2215 } // namespace blaze
2216 
2217 #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:3079
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
Header file for the Rows type trait.
BLAZE_ALWAYS_INLINE size_t capacity(const Matrix< MT, SO > &matrix) noexcept
Returns the maximum capacity of the matrix.
Definition: Matrix.h:356
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.
BLAZE_ALWAYS_INLINE T1 & operator/=(SIMDPack< T1 > &lhs, const SIMDPack< T2 > &rhs)
Division assignment operator for the division of two SIMD packs.
Definition: BasicTypes.h:1411
Constraint on the data type.
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:3078
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:198
CompressedMatrix< Type, true > This
Type of this CompressedMatrix instance.
Definition: CompressedMatrix.h:3076
Constraint on the data type.
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:560
BLAZE_ALWAYS_INLINE void shrinkToFit(Matrix< MT, SO > &matrix)
Requesting the removal of unused capacity.
Definition: Matrix.h:609
void clear(CompressedMatrix< Type, SO > &m)
Clearing the given compressed matrix.
Definition: CompressedMatrix.h:5845
CompressedMatrix< Type, false > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:3080
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:3085
#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:1584
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:394
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:3086
BLAZE_ALWAYS_INLINE T1 & operator*=(SIMDPack< T1 > &lhs, const SIMDPack< T2 > &rhs)
Multiplication assignment operator for the multiplication of two SIMD packs.
Definition: BasicTypes.h:1393
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:308
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:242
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 DisableIf class template.
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:3084
Header file for the DiagonalProxy class.
Header file for the clear shim.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
void swap(CompressedMatrix< Type, SO > &a, CompressedMatrix< Type, SO > &b) noexcept
Swapping the contents of two compressed matrices.
Definition: CompressedMatrix.h:5924
Compile time assertion.
bool isIntact(const CompressedMatrix< Type, SO > &m)
Returns whether the invariants of the given compressed matrix are intact.
Definition: CompressedMatrix.h:5907
SparseMatrix< This, true > BaseType
Base type of this CompressedMatrix instance.
Definition: CompressedMatrix.h:3077
#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:3081
#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
Header file for the Columns type trait.
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:3087
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:340
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:548
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:264
Header file for the EnableIf class template.
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:580
Header file for the IsNumeric type trait.
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:270
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:324
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:3082
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:3083
#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:252
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:600
#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:742
#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