Blaze  3.6
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>
59 #include <blaze/math/Exception.h>
62 #include <blaze/math/shims/Clear.h>
69 #include <blaze/util/Assert.h>
74 #include <blaze/util/DisableIf.h>
75 #include <blaze/util/EnableIf.h>
77 #include <blaze/util/Types.h>
78 
79 
80 namespace blaze {
81 
82 //=================================================================================================
83 //
84 // CLASS TEMPLATE SPECIALIZATION FOR SPARSE MATRICES
85 //
86 //=================================================================================================
87 
88 //*************************************************************************************************
96 template< typename MT // Type of the adapted sparse matrix
97  , bool SO > // Storage order of the adapted sparse matrix
98 class DiagonalMatrix<MT,SO,false>
99  : public SparseMatrix< DiagonalMatrix<MT,SO,false>, SO >
100 {
101  private:
102  //**Type definitions****************************************************************************
103  using OT = OppositeType_t<MT>;
104  using TT = TransposeType_t<MT>;
105  using ET = ElementType_t<MT>;
106  //**********************************************************************************************
107 
108  public:
109  //**Type definitions****************************************************************************
110  using This = DiagonalMatrix<MT,SO,false>;
111  using BaseType = SparseMatrix<This,SO>;
112  using ResultType = This;
113  using OppositeType = DiagonalMatrix<OT,!SO,false>;
114  using TransposeType = DiagonalMatrix<TT,!SO,false>;
115  using ElementType = ET;
116  using ReturnType = ReturnType_t<MT>;
117  using CompositeType = const This&;
118  using Reference = DiagonalProxy<MT>;
119  using ConstReference = ConstReference_t<MT>;
120  using Iterator = Iterator_t<MT>;
121  using ConstIterator = ConstIterator_t<MT>;
122  //**********************************************************************************************
123 
124  //**Rebind struct definition********************************************************************
127  template< typename NewType > // Data type of the other matrix
128  struct Rebind {
130  using Other = DiagonalMatrix< typename MT::template Rebind<NewType>::Other >;
131  };
132  //**********************************************************************************************
133 
134  //**Resize struct definition********************************************************************
137  template< size_t NewM // Number of rows of the other matrix
138  , size_t NewN > // Number of columns of the other matrix
139  struct Resize {
141  using Other = DiagonalMatrix< typename MT::template Resize<NewM,NewN>::Other >;
142  };
143  //**********************************************************************************************
144 
145  //**Compilation flags***************************************************************************
147  static constexpr bool smpAssignable = false;
148  //**********************************************************************************************
149 
150  //**Constructors********************************************************************************
153  explicit inline DiagonalMatrix();
154  explicit inline DiagonalMatrix( size_t n );
155  explicit inline DiagonalMatrix( size_t n, size_t nonzeros );
156  explicit inline DiagonalMatrix( size_t n, const std::vector<size_t>& nonzeros );
157  inline DiagonalMatrix( initializer_list< initializer_list<ElementType> > list );
158 
159  inline DiagonalMatrix( const DiagonalMatrix& m );
160  inline DiagonalMatrix( DiagonalMatrix&& m ) noexcept;
161 
162  template< typename MT2, bool SO2 >
163  inline DiagonalMatrix( const Matrix<MT2,SO2>& m );
165  //**********************************************************************************************
166 
167  //**Destructor**********************************************************************************
170  ~DiagonalMatrix() = default;
172  //**********************************************************************************************
173 
174  //**Data access functions***********************************************************************
177  inline Reference operator()( size_t i, size_t j );
178  inline ConstReference operator()( size_t i, size_t j ) const;
179  inline Reference at( size_t i, size_t j );
180  inline ConstReference at( size_t i, size_t j ) const;
181  inline Iterator begin ( size_t i );
182  inline ConstIterator begin ( size_t i ) const;
183  inline ConstIterator cbegin( size_t i ) const;
184  inline Iterator end ( size_t i );
185  inline ConstIterator end ( size_t i ) const;
186  inline ConstIterator cend ( size_t i ) const;
188  //**********************************************************************************************
189 
190  //**Assignment operators************************************************************************
193  inline DiagonalMatrix& operator=( initializer_list< initializer_list<ElementType> > list );
194 
195  inline DiagonalMatrix& operator=( const DiagonalMatrix& rhs );
196  inline DiagonalMatrix& operator=( DiagonalMatrix&& rhs ) noexcept;
197 
198  template< typename MT2, bool SO2 >
199  inline auto operator=( const Matrix<MT2,SO2>& rhs )
200  -> DisableIf_t< IsComputation_v<MT2>, DiagonalMatrix& >;
201 
202  template< typename MT2, bool SO2 >
203  inline auto operator=( const Matrix<MT2,SO2>& rhs )
204  -> EnableIf_t< IsComputation_v<MT2>, DiagonalMatrix& >;
205 
206  template< typename MT2, bool SO2 >
207  inline auto operator+=( const Matrix<MT2,SO2>& rhs )
208  -> DisableIf_t< IsComputation_v<MT2>, DiagonalMatrix& >;
209 
210  template< typename MT2, bool SO2 >
211  inline auto operator+=( const Matrix<MT2,SO2>& rhs )
212  -> EnableIf_t< IsComputation_v<MT2>, DiagonalMatrix& >;
213 
214  template< typename MT2, bool SO2 >
215  inline auto operator-=( const Matrix<MT2,SO2>& rhs )
216  -> DisableIf_t< IsComputation_v<MT2>, DiagonalMatrix& >;
217 
218  template< typename MT2, bool SO2 >
219  inline auto operator-=( const Matrix<MT2,SO2>& rhs )
220  -> EnableIf_t< IsComputation_v<MT2>, DiagonalMatrix& >;
221 
222  template< typename MT2, bool SO2 >
223  inline auto operator%=( const Matrix<MT2,SO2>& rhs ) -> DiagonalMatrix&;
225  //**********************************************************************************************
226 
227  //**Utility functions***************************************************************************
230  inline size_t rows() const noexcept;
231  inline size_t columns() const noexcept;
232  inline size_t capacity() const noexcept;
233  inline size_t capacity( size_t i ) const noexcept;
234  inline size_t nonZeros() const;
235  inline size_t nonZeros( size_t i ) const;
236  inline void reset();
237  inline void reset( size_t i );
238  inline void clear();
239  inline void resize ( size_t n, bool preserve=true );
240  inline void reserve( size_t nonzeros );
241  inline void reserve( size_t i, size_t nonzeros );
242  inline void trim();
243  inline void trim( size_t i );
244  inline void shrinkToFit();
245  inline void swap( DiagonalMatrix& m ) noexcept;
247  //**********************************************************************************************
248 
249  //**Insertion functions*************************************************************************
252  inline Iterator set ( size_t i, size_t j, const ElementType& value );
253  inline Iterator insert ( size_t i, size_t j, const ElementType& value );
254  inline void append ( size_t i, size_t j, const ElementType& value, bool check=false );
255  inline void finalize( size_t i );
257  //**********************************************************************************************
258 
259  //**Erase functions*****************************************************************************
262  inline void erase( size_t i, size_t j );
263  inline Iterator erase( size_t i, Iterator pos );
264  inline Iterator erase( size_t i, Iterator first, Iterator last );
265 
266  template< typename Pred >
267  inline void erase( Pred predicate );
268 
269  template< typename Pred >
270  inline void erase( size_t i, Iterator first, Iterator last, Pred predicate );
272  //**********************************************************************************************
273 
274  //**Lookup functions****************************************************************************
277  inline Iterator find ( size_t i, size_t j );
278  inline ConstIterator find ( size_t i, size_t j ) const;
279  inline Iterator lowerBound( size_t i, size_t j );
280  inline ConstIterator lowerBound( size_t i, size_t j ) const;
281  inline Iterator upperBound( size_t i, size_t j );
282  inline ConstIterator upperBound( size_t i, size_t j ) const;
284  //**********************************************************************************************
285 
286  //**Numeric functions***************************************************************************
289  template< typename Other > inline DiagonalMatrix& scale( const Other& scalar );
291  //**********************************************************************************************
292 
293  //**Debugging functions*************************************************************************
296  inline bool isIntact() const noexcept;
298  //**********************************************************************************************
299 
300  //**Expression template evaluation functions****************************************************
303  template< typename Other > inline bool canAlias ( const Other* alias ) const noexcept;
304  template< typename Other > inline bool isAliased( const Other* alias ) const noexcept;
305 
306  inline bool canSMPAssign() const noexcept;
308  //**********************************************************************************************
309 
310  private:
311  //**Utility functions***************************************************************************
314  inline void resetNonDiagonal();
316  //**********************************************************************************************
317 
318  //**Member variables****************************************************************************
321  MT matrix_;
322 
323  //**********************************************************************************************
324 
325  //**Friend declarations*************************************************************************
326  template< bool RF, typename MT2, bool SO2, bool DF2 >
327  friend bool isDefault( const DiagonalMatrix<MT2,SO2,DF2>& m );
328 
329  template< typename MT2, bool SO2, bool DF2 >
330  friend MT2& derestrict( DiagonalMatrix<MT2,SO2,DF2>& m );
331  //**********************************************************************************************
332 
333  //**Compile time checks*************************************************************************
348  BLAZE_STATIC_ASSERT( ( Size_v<MT,0UL> == Size_v<MT,1UL> ) );
349  //**********************************************************************************************
350 };
352 //*************************************************************************************************
353 
354 
355 
356 
357 //=================================================================================================
358 //
359 // CONSTRUCTORS
360 //
361 //=================================================================================================
362 
363 //*************************************************************************************************
367 template< typename MT // Type of the adapted sparse matrix
368  , bool SO > // Storage order of the adapted sparse matrix
369 inline DiagonalMatrix<MT,SO,false>::DiagonalMatrix()
370  : matrix_() // The adapted sparse matrix
371 {
372  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
373 }
375 //*************************************************************************************************
376 
377 
378 //*************************************************************************************************
386 template< typename MT // Type of the adapted sparse matrix
387  , bool SO > // Storage order of the adapted sparse matrix
388 inline DiagonalMatrix<MT,SO,false>::DiagonalMatrix( size_t n )
389  : matrix_( n, n ) // The adapted sparse matrix
390 {
392 
393  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
394 }
396 //*************************************************************************************************
397 
398 
399 //*************************************************************************************************
408 template< typename MT // Type of the adapted sparse matrix
409  , bool SO > // Storage order of the adapted sparse matrix
410 inline DiagonalMatrix<MT,SO,false>::DiagonalMatrix( size_t n, size_t nonzeros )
411  : matrix_( n, n, nonzeros ) // The adapted sparse matrix
412 {
414 
415  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
416 }
418 //*************************************************************************************************
419 
420 
421 //*************************************************************************************************
432 template< typename MT // Type of the adapted sparse matrix
433  , bool SO > // Storage order of the adapted sparse matrix
434 inline DiagonalMatrix<MT,SO,false>::DiagonalMatrix( size_t n, const std::vector<size_t>& nonzeros )
435  : matrix_( n, n, nonzeros ) // The adapted sparse matrix
436 {
438 
439  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
440 }
442 //*************************************************************************************************
443 
444 
445 //*************************************************************************************************
469 template< typename MT // Type of the adapted sparse matrix
470  , bool SO > // Storage order of the adapted sparse matrix
471 inline DiagonalMatrix<MT,SO,false>::DiagonalMatrix( initializer_list< initializer_list<ElementType> > list )
472  : matrix_( list ) // The adapted sparse matrix
473 {
474  if( !isDiagonal( matrix_ ) ) {
475  BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of diagonal matrix" );
476  }
477 
478  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
479 }
481 //*************************************************************************************************
482 
483 
484 //*************************************************************************************************
490 template< typename MT // Type of the adapted sparse matrix
491  , bool SO > // Storage order of the adapted sparse matrix
492 inline DiagonalMatrix<MT,SO,false>::DiagonalMatrix( const DiagonalMatrix& m )
493  : matrix_( m.matrix_ ) // The adapted sparse matrix
494 {
495  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
496  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
497 }
499 //*************************************************************************************************
500 
501 
502 //*************************************************************************************************
508 template< typename MT // Type of the adapted sparse matrix
509  , bool SO > // Storage order of the adapted sparse matrix
510 inline DiagonalMatrix<MT,SO,false>::DiagonalMatrix( DiagonalMatrix&& m ) noexcept
511  : matrix_( std::move( m.matrix_ ) ) // The adapted sparse matrix
512 {
513  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
514  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
515 }
517 //*************************************************************************************************
518 
519 
520 //*************************************************************************************************
530 template< typename MT // Type of the adapted sparse matrix
531  , bool SO > // Storage order of the adapted sparse matrix
532 template< typename MT2 // Type of the foreign matrix
533  , bool SO2 > // Storage order of the foreign matrix
534 inline DiagonalMatrix<MT,SO,false>::DiagonalMatrix( const Matrix<MT2,SO2>& m )
535  : matrix_( ~m ) // The adapted sparse matrix
536 {
537  if( !IsDiagonal_v<MT2> && !isDiagonal( matrix_ ) ) {
538  BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of diagonal matrix" );
539  }
540 
541  if( !IsDiagonal_v<MT2> )
542  resetNonDiagonal();
543 
544  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
545  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
546 }
548 //*************************************************************************************************
549 
550 
551 
552 
553 //=================================================================================================
554 //
555 // DATA ACCESS FUNCTIONS
556 //
557 //=================================================================================================
558 
559 //*************************************************************************************************
575 template< typename MT // Type of the adapted sparse matrix
576  , bool SO > // Storage order of the adapted sparse matrix
577 inline typename DiagonalMatrix<MT,SO,false>::Reference
578  DiagonalMatrix<MT,SO,false>::operator()( size_t i, size_t j )
579 {
580  BLAZE_USER_ASSERT( i<rows() , "Invalid row access index" );
581  BLAZE_USER_ASSERT( j<columns(), "Invalid column access index" );
582 
583  return Reference( matrix_, i, j );
584 }
586 //*************************************************************************************************
587 
588 
589 //*************************************************************************************************
605 template< typename MT // Type of the adapted sparse matrix
606  , bool SO > // Storage order of the adapted sparse matrix
607 inline typename DiagonalMatrix<MT,SO,false>::ConstReference
608  DiagonalMatrix<MT,SO,false>::operator()( size_t i, size_t j ) const
609 {
610  BLAZE_USER_ASSERT( i<rows() , "Invalid row access index" );
611  BLAZE_USER_ASSERT( j<columns(), "Invalid column access index" );
612 
613  return matrix_(i,j);
614 }
616 //*************************************************************************************************
617 
618 
619 //*************************************************************************************************
636 template< typename MT // Type of the adapted sparse matrix
637  , bool SO > // Storage order of the adapted sparse matrix
638 inline typename DiagonalMatrix<MT,SO,false>::Reference
639  DiagonalMatrix<MT,SO,false>::at( size_t i, size_t j )
640 {
641  if( i >= rows() ) {
642  BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
643  }
644  if( j >= columns() ) {
645  BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
646  }
647  return (*this)(i,j);
648 }
650 //*************************************************************************************************
651 
652 
653 //*************************************************************************************************
670 template< typename MT // Type of the adapted sparse matrix
671  , bool SO > // Storage order of the adapted sparse matrix
672 inline typename DiagonalMatrix<MT,SO,false>::ConstReference
673  DiagonalMatrix<MT,SO,false>::at( size_t i, size_t j ) const
674 {
675  if( i >= rows() ) {
676  BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
677  }
678  if( j >= columns() ) {
679  BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
680  }
681  return (*this)(i,j);
682 }
684 //*************************************************************************************************
685 
686 
687 //*************************************************************************************************
699 template< typename MT // Type of the adapted sparse matrix
700  , bool SO > // Storage order of the adapted sparse matrix
701 inline typename DiagonalMatrix<MT,SO,false>::Iterator
703 {
704  return matrix_.begin(i);
705 }
707 //*************************************************************************************************
708 
709 
710 //*************************************************************************************************
722 template< typename MT // Type of the adapted sparse matrix
723  , bool SO > // Storage order of the adapted sparse matrix
724 inline typename DiagonalMatrix<MT,SO,false>::ConstIterator
725  DiagonalMatrix<MT,SO,false>::begin( size_t i ) const
726 {
727  return matrix_.begin(i);
728 }
730 //*************************************************************************************************
731 
732 
733 //*************************************************************************************************
745 template< typename MT // Type of the adapted sparse matrix
746  , bool SO > // Storage order of the adapted sparse matrix
747 inline typename DiagonalMatrix<MT,SO,false>::ConstIterator
748  DiagonalMatrix<MT,SO,false>::cbegin( size_t i ) const
749 {
750  return matrix_.cbegin(i);
751 }
753 //*************************************************************************************************
754 
755 
756 //*************************************************************************************************
768 template< typename MT // Type of the adapted sparse matrix
769  , bool SO > // Storage order of the adapted sparse matrix
770 inline typename DiagonalMatrix<MT,SO,false>::Iterator
772 {
773  return matrix_.end(i);
774 }
776 //*************************************************************************************************
777 
778 
779 //*************************************************************************************************
791 template< typename MT // Type of the adapted sparse matrix
792  , bool SO > // Storage order of the adapted sparse matrix
793 inline typename DiagonalMatrix<MT,SO,false>::ConstIterator
794  DiagonalMatrix<MT,SO,false>::end( size_t i ) const
795 {
796  return matrix_.end(i);
797 }
799 //*************************************************************************************************
800 
801 
802 //*************************************************************************************************
814 template< typename MT // Type of the adapted sparse matrix
815  , bool SO > // Storage order of the adapted sparse matrix
816 inline typename DiagonalMatrix<MT,SO,false>::ConstIterator
817  DiagonalMatrix<MT,SO,false>::cend( size_t i ) const
818 {
819  return matrix_.cend(i);
820 }
822 //*************************************************************************************************
823 
824 
825 
826 
827 //=================================================================================================
828 //
829 // ASSIGNMENT OPERATORS
830 //
831 //=================================================================================================
832 
833 //*************************************************************************************************
858 template< typename MT // Type of the adapted sparse matrix
859  , bool SO > // Storage order of the adapted sparse matrix
860 inline DiagonalMatrix<MT,SO,false>&
861  DiagonalMatrix<MT,SO,false>::operator=( initializer_list< initializer_list<ElementType> > list )
862 {
863  const InitializerMatrix<ElementType> tmp( list, list.size() );
864 
865  if( !isDiagonal( tmp ) ) {
866  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
867  }
868 
869  matrix_ = list;
870 
871  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
872  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
873 
874  return *this;
875 }
877 //*************************************************************************************************
878 
879 
880 //*************************************************************************************************
890 template< typename MT // Type of the adapted sparse matrix
891  , bool SO > // Storage order of the adapted sparse matrix
892 inline DiagonalMatrix<MT,SO,false>&
893  DiagonalMatrix<MT,SO,false>::operator=( const DiagonalMatrix& rhs )
894 {
895  matrix_ = rhs.matrix_;
896 
897  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
898  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
899 
900  return *this;
901 }
903 //*************************************************************************************************
904 
905 
906 //*************************************************************************************************
913 template< typename MT // Type of the adapted sparse matrix
914  , bool SO > // Storage order of the adapted sparse matrix
915 inline DiagonalMatrix<MT,SO,false>&
916  DiagonalMatrix<MT,SO,false>::operator=( DiagonalMatrix&& rhs ) noexcept
917 {
918  matrix_ = std::move( rhs.matrix_ );
919 
920  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
921  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
922 
923  return *this;
924 }
926 //*************************************************************************************************
927 
928 
929 //*************************************************************************************************
942 template< typename MT // Type of the adapted sparse matrix
943  , bool SO > // Storage order of the adapted sparse matrix
944 template< typename MT2 // Type of the right-hand side matrix
945  , bool SO2 > // Storage order of the right-hand side matrix
946 inline auto DiagonalMatrix<MT,SO,false>::operator=( const Matrix<MT2,SO2>& rhs )
947  -> DisableIf_t< IsComputation_v<MT2>, DiagonalMatrix& >
948 {
949  if( !IsDiagonal_v<MT2> && !isDiagonal( ~rhs ) ) {
950  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
951  }
952 
953  matrix_ = decldiag( ~rhs );
954 
955  if( !IsDiagonal_v<MT2> )
956  resetNonDiagonal();
957 
958  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
959  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
960 
961  return *this;
962 }
964 //*************************************************************************************************
965 
966 
967 //*************************************************************************************************
980 template< typename MT // Type of the adapted sparse matrix
981  , bool SO > // Storage order of the adapted sparse matrix
982 template< typename MT2 // Type of the right-hand side matrix
983  , bool SO2 > // Storage order of the right-hand side matrix
984 inline auto DiagonalMatrix<MT,SO,false>::operator=( const Matrix<MT2,SO2>& rhs )
985  -> EnableIf_t< IsComputation_v<MT2>, DiagonalMatrix& >
986 {
987  if( !IsSquare_v<MT2> && !isSquare( ~rhs ) ) {
988  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
989  }
990 
991  if( IsDiagonal_v<MT2> ) {
992  matrix_ = ~rhs;
993  }
994  else {
995  MT tmp( ~rhs );
996 
997  if( !isDiagonal( tmp ) ) {
998  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
999  }
1000 
1001  matrix_ = std::move( tmp );
1002  }
1003 
1004  if( !IsDiagonal_v<MT2> )
1005  resetNonDiagonal();
1006 
1007  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1008  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1009 
1010  return *this;
1011 }
1013 //*************************************************************************************************
1014 
1015 
1016 //*************************************************************************************************
1029 template< typename MT // Type of the adapted sparse matrix
1030  , bool SO > // Storage order of the adapted sparse matrix
1031 template< typename MT2 // Type of the right-hand side matrix
1032  , bool SO2 > // Storage order of the right-hand side matrix
1033 inline auto DiagonalMatrix<MT,SO,false>::operator+=( const Matrix<MT2,SO2>& rhs )
1034  -> DisableIf_t< IsComputation_v<MT2>, DiagonalMatrix& >
1035 {
1036  if( !IsDiagonal_v<MT2> && !isDiagonal( ~rhs ) ) {
1037  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1038  }
1039 
1040  matrix_ += decldiag( ~rhs );
1041 
1042  if( !IsDiagonal_v<MT2> )
1043  resetNonDiagonal();
1044 
1045  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1046  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1047 
1048  return *this;
1049 }
1051 //*************************************************************************************************
1052 
1053 
1054 //*************************************************************************************************
1067 template< typename MT // Type of the adapted sparse matrix
1068  , bool SO > // Storage order of the adapted sparse matrix
1069 template< typename MT2 // Type of the right-hand side matrix
1070  , bool SO2 > // Storage order of the right-hand side matrix
1071 inline auto DiagonalMatrix<MT,SO,false>::operator+=( const Matrix<MT2,SO2>& rhs )
1072  -> EnableIf_t< IsComputation_v<MT2>, DiagonalMatrix& >
1073 {
1074  if( !IsSquare_v<MT2> && !isSquare( ~rhs ) ) {
1075  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1076  }
1077 
1078  if( IsDiagonal_v<MT2> ) {
1079  matrix_ += ~rhs;
1080  }
1081  else {
1082  const ResultType_t<MT2> tmp( ~rhs );
1083 
1084  if( !isDiagonal( tmp ) ) {
1085  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1086  }
1087 
1088  matrix_ += decldiag( tmp );
1089  }
1090 
1091  if( !IsDiagonal_v<MT2> )
1092  resetNonDiagonal();
1093 
1094  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1095  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1096 
1097  return *this;
1098 }
1100 //*************************************************************************************************
1101 
1102 
1103 //*************************************************************************************************
1116 template< typename MT // Type of the adapted sparse matrix
1117  , bool SO > // Storage order of the adapted sparse matrix
1118 template< typename MT2 // Type of the right-hand side matrix
1119  , bool SO2 > // Storage order of the right-hand side matrix
1120 inline auto DiagonalMatrix<MT,SO,false>::operator-=( const Matrix<MT2,SO2>& rhs )
1121  -> DisableIf_t< IsComputation_v<MT2>, DiagonalMatrix& >
1122 {
1123  if( !IsDiagonal_v<MT2> && !isDiagonal( ~rhs ) ) {
1124  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1125  }
1126 
1127  matrix_ -= decldiag( ~rhs );
1128 
1129  if( !IsDiagonal_v<MT2> )
1130  resetNonDiagonal();
1131 
1132  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1133  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1134 
1135  return *this;
1136 }
1138 //*************************************************************************************************
1139 
1140 
1141 //*************************************************************************************************
1154 template< typename MT // Type of the adapted sparse matrix
1155  , bool SO > // Storage order of the adapted sparse matrix
1156 template< typename MT2 // Type of the right-hand side matrix
1157  , bool SO2 > // Storage order of the right-hand side matrix
1158 inline auto DiagonalMatrix<MT,SO,false>::operator-=( const Matrix<MT2,SO2>& rhs )
1159  -> EnableIf_t< IsComputation_v<MT2>, DiagonalMatrix& >
1160 {
1161  if( !IsSquare_v<MT2> && !isSquare( ~rhs ) ) {
1162  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1163  }
1164 
1165  if( IsDiagonal_v<MT2> ) {
1166  matrix_ -= ~rhs;
1167  }
1168  else {
1169  const ResultType_t<MT2> tmp( ~rhs );
1170 
1171  if( !isDiagonal( tmp ) ) {
1172  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1173  }
1174 
1175  matrix_ -= decldiag( tmp );
1176  }
1177 
1178  if( !IsDiagonal_v<MT2> )
1179  resetNonDiagonal();
1180 
1181  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1182  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1183 
1184  return *this;
1185 }
1187 //*************************************************************************************************
1188 
1189 
1190 //*************************************************************************************************
1201 template< typename MT // Type of the adapted sparse matrix
1202  , bool SO > // Storage order of the adapted sparse matrix
1203 template< typename MT2 // Type of the right-hand side matrix
1204  , bool SO2 > // Storage order of the right-hand side matrix
1205 inline auto DiagonalMatrix<MT,SO,false>::operator%=( const Matrix<MT2,SO2>& rhs )
1206  -> DiagonalMatrix&
1207 {
1208  if( !IsSquare_v<MT2> && !isSquare( ~rhs ) ) {
1209  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1210  }
1211 
1212  matrix_ %= ~rhs;
1213 
1214  if( !IsDiagonal_v<MT2> )
1215  resetNonDiagonal();
1216 
1217  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1218  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1219 
1220  return *this;
1221 }
1223 //*************************************************************************************************
1224 
1225 
1226 
1227 
1228 //=================================================================================================
1229 //
1230 // UTILITY FUNCTIONS
1231 //
1232 //=================================================================================================
1233 
1234 //*************************************************************************************************
1240 template< typename MT // Type of the adapted sparse matrix
1241  , bool SO > // Storage order of the adapted sparse matrix
1242 inline size_t DiagonalMatrix<MT,SO,false>::rows() const noexcept
1243 {
1244  return matrix_.rows();
1245 }
1247 //*************************************************************************************************
1248 
1249 
1250 //*************************************************************************************************
1256 template< typename MT // Type of the adapted sparse matrix
1257  , bool SO > // Storage order of the adapted sparse matrix
1258 inline size_t DiagonalMatrix<MT,SO,false>::columns() const noexcept
1259 {
1260  return matrix_.columns();
1261 }
1263 //*************************************************************************************************
1264 
1265 
1266 //*************************************************************************************************
1272 template< typename MT // Type of the adapted sparse matrix
1273  , bool SO > // Storage order of the adapted sparse matrix
1274 inline size_t DiagonalMatrix<MT,SO,false>::capacity() const noexcept
1275 {
1276  return matrix_.capacity();
1277 }
1279 //*************************************************************************************************
1280 
1281 
1282 //*************************************************************************************************
1294 template< typename MT // Type of the adapted sparse matrix
1295  , bool SO > // Storage order of the adapted sparse matrix
1296 inline size_t DiagonalMatrix<MT,SO,false>::capacity( size_t i ) const noexcept
1297 {
1298  return matrix_.capacity(i);
1299 }
1301 //*************************************************************************************************
1302 
1303 
1304 //*************************************************************************************************
1310 template< typename MT // Type of the adapted sparse matrix
1311  , bool SO > // Storage order of the adapted sparse matrix
1312 inline size_t DiagonalMatrix<MT,SO,false>::nonZeros() const
1313 {
1314  return matrix_.nonZeros();
1315 }
1317 //*************************************************************************************************
1318 
1319 
1320 //*************************************************************************************************
1332 template< typename MT // Type of the adapted sparse matrix
1333  , bool SO > // Storage order of the adapted sparse matrix
1334 inline size_t DiagonalMatrix<MT,SO,false>::nonZeros( size_t i ) const
1335 {
1336  return matrix_.nonZeros(i);
1337 }
1339 //*************************************************************************************************
1340 
1341 
1342 //*************************************************************************************************
1348 template< typename MT // Type of the adapted sparse matrix
1349  , bool SO > // Storage order of the adapted sparse matrix
1351 {
1352  matrix_.reset();
1353 }
1355 //*************************************************************************************************
1356 
1357 
1358 //*************************************************************************************************
1371 template< typename MT // Type of the adapted sparse matrix
1372  , bool SO > // Storage order of the adapted sparse matrix
1373 inline void DiagonalMatrix<MT,SO,false>::reset( size_t i )
1374 {
1375  matrix_.reset( i );
1376 }
1378 //*************************************************************************************************
1379 
1380 
1381 //*************************************************************************************************
1389 template< typename MT // Type of the adapted sparse matrix
1390  , bool SO > // Storage order of the adapted sparse matrix
1392 {
1393  using blaze::clear;
1394 
1395  clear( matrix_ );
1396 }
1398 //*************************************************************************************************
1399 
1400 
1401 //*************************************************************************************************
1416 template< typename MT // Type of the adapted sparse matrix
1417  , bool SO > // Storage order of the adapted sparse matrix
1418 void DiagonalMatrix<MT,SO,false>::resize( size_t n, bool preserve )
1419 {
1421 
1422  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1423 
1424  matrix_.resize( n, n, preserve );
1425 }
1427 //*************************************************************************************************
1428 
1429 
1430 //*************************************************************************************************
1441 template< typename MT // Type of the adapted sparse matrix
1442  , bool SO > // Storage order of the adapted sparse matrix
1443 inline void DiagonalMatrix<MT,SO,false>::reserve( size_t nonzeros )
1444 {
1445  matrix_.reserve( nonzeros );
1446 }
1448 //*************************************************************************************************
1449 
1450 
1451 //*************************************************************************************************
1465 template< typename MT // Type of the adapted sparse matrix
1466  , bool SO > // Storage order of the adapted sparse matrix
1467 inline void DiagonalMatrix<MT,SO,false>::reserve( size_t i, size_t nonzeros )
1468 {
1469  matrix_.reserve( i, nonzeros );
1470 }
1472 //*************************************************************************************************
1473 
1474 
1475 //*************************************************************************************************
1486 template< typename MT // Type of the adapted sparse matrix
1487  , bool SO > // Storage order of the adapted sparse matrix
1488 inline void DiagonalMatrix<MT,SO,false>::trim()
1489 {
1490  matrix_.trim();
1491 }
1493 //*************************************************************************************************
1494 
1495 
1496 //*************************************************************************************************
1508 template< typename MT // Type of the adapted sparse matrix
1509  , bool SO > // Storage order of the adapted sparse matrix
1510 inline void DiagonalMatrix<MT,SO,false>::trim( size_t i )
1511 {
1512  matrix_.trim( i );
1513 }
1515 //*************************************************************************************************
1516 
1517 
1518 //*************************************************************************************************
1528 template< typename MT // Type of the adapted sparse matrix
1529  , bool SO > // Storage order of the adapted sparse matrix
1531 {
1532  matrix_.shrinkToFit();
1533 }
1535 //*************************************************************************************************
1536 
1537 
1538 //*************************************************************************************************
1545 template< typename MT // Type of the adapted sparse matrix
1546  , bool SO > // Storage order of the adapted sparse matrix
1547 inline void DiagonalMatrix<MT,SO,false>::swap( DiagonalMatrix& m ) noexcept
1548 {
1549  using std::swap;
1550 
1551  swap( matrix_, m.matrix_ );
1552 }
1554 //*************************************************************************************************
1555 
1556 
1557 //*************************************************************************************************
1563 template< typename MT // Type of the adapted sparse matrix
1564  , bool SO > // Storage order of the adapted sparse matrix
1565 inline void DiagonalMatrix<MT,SO,false>::resetNonDiagonal()
1566 {
1567  using blaze::erase;
1568 
1569  for( size_t i=0UL; i<rows(); ++i ) {
1570  erase( matrix_, i, matrix_.begin( i ), matrix_.lowerBound( i, i ) );
1571  erase( matrix_, i, matrix_.upperBound( i, i ), matrix_.end( i ) );
1572  }
1573 }
1575 //*************************************************************************************************
1576 
1577 
1578 
1579 
1580 //=================================================================================================
1581 //
1582 // INSERTION FUNCTIONS
1583 //
1584 //=================================================================================================
1585 
1586 //*************************************************************************************************
1602 template< typename MT // Type of the adapted sparse matrix
1603  , bool SO > // Storage order of the adapted sparse matrix
1604 inline typename DiagonalMatrix<MT,SO,false>::Iterator
1605  DiagonalMatrix<MT,SO,false>::set( size_t i, size_t j, const ElementType& value )
1606 {
1607  if( i < j ) {
1608  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to upper matrix element" );
1609  }
1610 
1611  return matrix_.set( i, j, value );
1612 }
1614 //*************************************************************************************************
1615 
1616 
1617 //*************************************************************************************************
1634 template< typename MT // Type of the adapted sparse matrix
1635  , bool SO > // Storage order of the adapted sparse matrix
1636 inline typename DiagonalMatrix<MT,SO,false>::Iterator
1637  DiagonalMatrix<MT,SO,false>::insert( size_t i, size_t j, const ElementType& value )
1638 {
1639  if( i < j ) {
1640  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to upper matrix element" );
1641  }
1642 
1643  return matrix_.insert( i, j, value );
1644 }
1646 //*************************************************************************************************
1647 
1648 
1649 //*************************************************************************************************
1699 template< typename MT // Type of the adapted sparse matrix
1700  , bool SO > // Storage order of the adapted sparse matrix
1701 inline void DiagonalMatrix<MT,SO,false>::append( size_t i, size_t j, const ElementType& value, bool check )
1702 {
1703  if( i < j ) {
1704  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to upper matrix element" );
1705  }
1706 
1707  matrix_.append( i, j, value, check );
1708 }
1710 //*************************************************************************************************
1711 
1712 
1713 //*************************************************************************************************
1727 template< typename MT // Type of the adapted sparse matrix
1728  , bool SO > // Storage order of the adapted sparse matrix
1729 inline void DiagonalMatrix<MT,SO,false>::finalize( size_t i )
1730 {
1731  matrix_.finalize( i );
1732 }
1734 //*************************************************************************************************
1735 
1736 
1737 
1738 
1739 //=================================================================================================
1740 //
1741 // ERASE FUNCTIONS
1742 //
1743 //=================================================================================================
1744 
1745 //*************************************************************************************************
1755 template< typename MT // Type of the adapted sparse matrix
1756  , bool SO > // Storage order of the adapted sparse matrix
1757 inline void DiagonalMatrix<MT,SO,false>::erase( size_t i, size_t j )
1758 {
1759  using blaze::erase;
1760 
1761  erase( matrix_, i, j );
1762 }
1764 //*************************************************************************************************
1765 
1766 
1767 //*************************************************************************************************
1779 template< typename MT // Type of the adapted sparse matrix
1780  , bool SO > // Storage order of the adapted sparse matrix
1781 inline typename DiagonalMatrix<MT,SO,false>::Iterator
1782  DiagonalMatrix<MT,SO,false>::erase( size_t i, Iterator pos )
1783 {
1784  using blaze::erase;
1785 
1786  return erase( matrix_, i, pos );
1787 }
1789 //*************************************************************************************************
1790 
1791 
1792 //*************************************************************************************************
1806 template< typename MT // Type of the adapted sparse matrix
1807  , bool SO > // Storage order of the adapted sparse matrix
1808 inline typename DiagonalMatrix<MT,SO,false>::Iterator
1809  DiagonalMatrix<MT,SO,false>::erase( size_t i, Iterator first, Iterator last )
1810 {
1811  using blaze::erase;
1812 
1813  return erase( matrix_, i, first, last );
1814 }
1816 //*************************************************************************************************
1817 
1818 
1819 //*************************************************************************************************
1841 template< typename MT // Type of the adapted sparse matrix
1842  , bool SO > // Storage order of the adapted sparse matrix
1843 template< typename Pred > // Type of the unary predicate
1844 inline void DiagonalMatrix<MT,SO,false>::erase( Pred predicate )
1845 {
1846  using blaze::erase;
1847 
1848  erase( matrix_, predicate );
1849 
1850  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1851 }
1853 //*************************************************************************************************
1854 
1855 
1856 //*************************************************************************************************
1884 template< typename MT // Type of the adapted sparse matrix
1885  , bool SO > // Storage order of the adapted sparse matrix
1886 template< typename Pred > // Type of the unary predicate
1887 inline void DiagonalMatrix<MT,SO,false>::erase( size_t i, Iterator first, Iterator last, Pred predicate )
1888 {
1889  using blaze::erase;
1890 
1891  erase( matrix_, i, first, last, predicate );
1892 
1893  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1894 }
1896 //*************************************************************************************************
1897 
1898 
1899 
1900 
1901 //=================================================================================================
1902 //
1903 // LOOKUP FUNCTIONS
1904 //
1905 //=================================================================================================
1906 
1907 //*************************************************************************************************
1923 template< typename MT // Type of the adapted sparse matrix
1924  , bool SO > // Storage order of the adapted sparse matrix
1925 inline typename DiagonalMatrix<MT,SO,false>::Iterator
1926  DiagonalMatrix<MT,SO,false>::find( size_t i, size_t j )
1927 {
1928  return matrix_.find( i, j );
1929 }
1931 //*************************************************************************************************
1932 
1933 
1934 //*************************************************************************************************
1950 template< typename MT // Type of the adapted sparse matrix
1951  , bool SO > // Storage order of the adapted sparse matrix
1952 inline typename DiagonalMatrix<MT,SO,false>::ConstIterator
1953  DiagonalMatrix<MT,SO,false>::find( size_t i, size_t j ) const
1954 {
1955  return matrix_.find( i, j );
1956 }
1958 //*************************************************************************************************
1959 
1960 
1961 //*************************************************************************************************
1977 template< typename MT // Type of the adapted sparse matrix
1978  , bool SO > // Storage order of the adapted sparse matrix
1979 inline typename DiagonalMatrix<MT,SO,false>::Iterator
1980  DiagonalMatrix<MT,SO,false>::lowerBound( size_t i, size_t j )
1981 {
1982  return matrix_.lowerBound( i, j );
1983 }
1985 //*************************************************************************************************
1986 
1987 
1988 //*************************************************************************************************
2004 template< typename MT // Type of the adapted sparse matrix
2005  , bool SO > // Storage order of the adapted sparse matrix
2006 inline typename DiagonalMatrix<MT,SO,false>::ConstIterator
2007  DiagonalMatrix<MT,SO,false>::lowerBound( size_t i, size_t j ) const
2008 {
2009  return matrix_.lowerBound( i, j );
2010 }
2012 //*************************************************************************************************
2013 
2014 
2015 //*************************************************************************************************
2031 template< typename MT // Type of the adapted sparse matrix
2032  , bool SO > // Storage order of the adapted sparse matrix
2033 inline typename DiagonalMatrix<MT,SO,false>::Iterator
2034  DiagonalMatrix<MT,SO,false>::upperBound( size_t i, size_t j )
2035 {
2036  return matrix_.upperBound( i, j );
2037 }
2039 //*************************************************************************************************
2040 
2041 
2042 //*************************************************************************************************
2058 template< typename MT // Type of the adapted sparse matrix
2059  , bool SO > // Storage order of the adapted sparse matrix
2060 inline typename DiagonalMatrix<MT,SO,false>::ConstIterator
2061  DiagonalMatrix<MT,SO,false>::upperBound( size_t i, size_t j ) const
2062 {
2063  return matrix_.upperBound( i, j );
2064 }
2066 //*************************************************************************************************
2067 
2068 
2069 
2070 
2071 //=================================================================================================
2072 //
2073 // NUMERIC FUNCTIONS
2074 //
2075 //=================================================================================================
2076 
2077 //*************************************************************************************************
2095 template< typename MT // Type of the adapted sparse matrix
2096  , bool SO > // Storage order of the adapted sparse matrix
2097 template< typename Other > // Data type of the scalar value
2098 inline DiagonalMatrix<MT,SO,false>&
2099  DiagonalMatrix<MT,SO,false>::scale( const Other& scalar )
2100 {
2101  matrix_.scale( scalar );
2102  return *this;
2103 }
2105 //*************************************************************************************************
2106 
2107 
2108 
2109 
2110 //=================================================================================================
2111 //
2112 // DEBUGGING FUNCTIONS
2113 //
2114 //=================================================================================================
2115 
2116 //*************************************************************************************************
2126 template< typename MT // Type of the adapted sparse matrix
2127  , bool SO > // Storage order of the adapted sparse matrix
2128 inline bool DiagonalMatrix<MT,SO,false>::isIntact() const noexcept
2129 {
2130  using blaze::isIntact;
2131 
2132  return ( isIntact( matrix_ ) && isDiagonal( matrix_ ) );
2133 }
2135 //*************************************************************************************************
2136 
2137 
2138 
2139 
2140 //=================================================================================================
2141 //
2142 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
2143 //
2144 //=================================================================================================
2145 
2146 //*************************************************************************************************
2157 template< typename MT // Type of the adapted sparse matrix
2158  , bool SO > // Storage order of the adapted sparse matrix
2159 template< typename Other > // Data type of the foreign expression
2160 inline bool DiagonalMatrix<MT,SO,false>::canAlias( const Other* alias ) const noexcept
2161 {
2162  return matrix_.canAlias( alias );
2163 }
2165 //*************************************************************************************************
2166 
2167 
2168 //*************************************************************************************************
2179 template< typename MT // Type of the adapted sparse matrix
2180  , bool SO > // Storage order of the adapted sparse matrix
2181 template< typename Other > // Data type of the foreign expression
2182 inline bool DiagonalMatrix<MT,SO,false>::isAliased( const Other* alias ) const noexcept
2183 {
2184  return matrix_.isAliased( alias );
2185 }
2187 //*************************************************************************************************
2188 
2189 
2190 //*************************************************************************************************
2201 template< typename MT // Type of the adapted sparse matrix
2202  , bool SO > // Storage order of the adapted sparse matrix
2203 inline bool DiagonalMatrix<MT,SO,false>::canSMPAssign() const noexcept
2204 {
2205  return matrix_.canSMPAssign();
2206 }
2208 //*************************************************************************************************
2209 
2210 } // namespace blaze
2211 
2212 #endif
#define BLAZE_CONSTRAINT_MUST_NOT_BE_TRANSFORMATION_TYPE(T)
Constraint on the data type.In case the given data type T is a transformation expression (i....
Definition: Transformation.h:81
#define BLAZE_CONSTRAINT_MUST_NOT_BE_CONST(T)
Constraint on the data type.In case the given data type is a const-qualified type,...
Definition: Const.h:79
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.This macro encapsulates the default way o...
Definition: Exception.h:235
Constraint on the data type.
Header file for auxiliary alias declarations.
auto operator-=(DenseMatrix< MT, SO > &mat, ST scalar) -> EnableIf_t< IsNumeric_v< ST >, MT & >
Subtraction assignment operator for the subtraction of a dense matrix and a scalar value ( ).
Definition: DenseMatrix.h:432
constexpr ptrdiff_t Size_v
Auxiliary variable template for the Size type trait.The Size_v variable template provides a convenien...
Definition: Size.h:176
decltype(auto) decldiag(const DenseMatrix< MT, SO > &dm)
Declares the given dense matrix expression dm as diagonal.
Definition: DMatDeclDiagExpr.h:975
Constraint on the data type.
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.In case of an invalid run time expression,...
Definition: Assert.h:117
size_t capacity(const Matrix< MT, SO > &matrix) noexcept
Returns the maximum capacity of the matrix.
Definition: Matrix.h:546
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.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE(T)
Constraint on the data type.In case the given data type T is a computational expression (i....
Definition: Computation.h:81
Constraint on the data type.
MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:372
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:595
void shrinkToFit(Matrix< MT, SO > &matrix)
Requesting the removal of unused capacity.
Definition: Matrix.h:799
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE(T)
Constraint on the data type.In case the given data type is a volatile-qualified type,...
Definition: Volatile.h:79
bool isDiagonal(const DenseMatrix< MT, SO > &dm)
Checks if the give dense matrix is diagonal.
Definition: DenseMatrix.h:2328
size_t nonZeros(const Matrix< MT, SO > &matrix)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:584
Header file for the extended initializer_list functionality.
Constraint on the data type.
constexpr size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:514
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:482
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:416
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.
Header file for the DiagonalProxy class.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Compile time assertion.
#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
#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
auto operator+=(DenseMatrix< MT, SO > &mat, ST scalar) -> EnableIf_t< IsNumeric_v< ST >, MT & >
Addition assignment operator for the addition of a dense matrix and a scalar value ( ).
Definition: DenseMatrix.h:370
Constraint on the data type.
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
void resize(Matrix< MT, SO > &matrix, size_t rows, size_t columns, bool preserve=true)
Changing the size of the matrix.
Definition: Matrix.h:738
MT::Iterator end(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:438
Header file for the EnableIf class template.
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:615
#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,...
Definition: Symmetric.h:79
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,...
Definition: Reference.h:79
Header file for the isDefault shim.
void swap(DiagonalMatrix< MT, SO, DF > &a, DiagonalMatrix< MT, SO, DF > &b) noexcept
Swapping the contents of two matrices.
Definition: DiagonalMatrix.h:282
BLAZE_ALWAYS_INLINE const EnableIf_t< IsIntegral_v< T > &&HasSize_v< T, 1UL >, If_t< IsSigned_v< T >, SIMDint8, SIMDuint8 > > set(T value) noexcept
Sets all values in the vector to the given 1-byte integral value.
Definition: Set.h:75
Constraint on the data type.
Constraint on the data type.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VIEW_TYPE(T)
Constraint on the data type.In case the given data type T is a view type (i.e. a subvector,...
Definition: View.h:81
constexpr size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:498
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 'res...
Definition: Resizable.h:61
Header file for the IsComputation type trait class.
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:264
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:635
#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,...
Definition: Hermitian.h:79
#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
bool isSquare(const Matrix< MT, SO > &matrix) noexcept
Checks if the given matrix is a square matrix.
Definition: Matrix.h:951
Constraint on the data type.
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,...
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
Header file for the clear shim.