Dense.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_ADAPTORS_DIAGONALMATRIX_DENSE_H_
36 #define _BLAZE_MATH_ADAPTORS_DIAGONALMATRIX_DENSE_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
56 #include <blaze/math/Intrinsics.h>
57 #include <blaze/math/shims/Clear.h>
59 #include <blaze/math/shims/Move.h>
68 #include <blaze/system/Inline.h>
69 #include <blaze/util/Assert.h>
75 #include <blaze/util/DisableIf.h>
76 #include <blaze/util/EnableIf.h>
77 #include <blaze/util/Exception.h>
78 #include <blaze/util/FalseType.h>
80 #include <blaze/util/TrueType.h>
81 #include <blaze/util/Types.h>
83 #include <blaze/util/Unused.h>
84 
85 
86 namespace blaze {
87 
88 //=================================================================================================
89 //
90 // CLASS TEMPLATE SPECIALIZATION FOR DENSE MATRICES
91 //
92 //=================================================================================================
93 
94 //*************************************************************************************************
102 template< typename MT // Type of the adapted dense matrix
103  , bool SO > // Storage order of the adapted dense matrix
104 class DiagonalMatrix<MT,SO,true>
105  : public DenseMatrix< DiagonalMatrix<MT,SO,true>, SO >
106 {
107  private:
108  //**Type definitions****************************************************************************
109  typedef typename MT::OppositeType OT;
110  typedef typename MT::TransposeType TT;
111  typedef typename MT::ElementType ET;
112  typedef IntrinsicTrait<ET> IT;
113  //**********************************************************************************************
114 
115  public:
116  //**Type definitions****************************************************************************
117  typedef DiagonalMatrix<MT,SO,true> This;
118  typedef This ResultType;
119  typedef DiagonalMatrix<OT,!SO,true> OppositeType;
120  typedef DiagonalMatrix<TT,!SO,true> TransposeType;
121  typedef ET ElementType;
122  typedef typename MT::IntrinsicType IntrinsicType;
123  typedef typename MT::ReturnType ReturnType;
124  typedef const This& CompositeType;
125  typedef DiagonalProxy<MT> Reference;
126  typedef typename MT::ConstReference ConstReference;
127  typedef typename MT::Pointer Pointer;
128  typedef typename MT::ConstPointer ConstPointer;
129  typedef typename MT::ConstIterator ConstIterator;
130  //**********************************************************************************************
131 
132  //**Rebind struct definition********************************************************************
135  template< typename ET > // Data type of the other matrix
136  struct Rebind {
138  typedef DiagonalMatrix< typename MT::template Rebind<ET>::Other > Other;
139  };
140  //**********************************************************************************************
141 
142  //**Iterator class definition*******************************************************************
145  class Iterator
146  {
147  public:
148  //**Type definitions*************************************************************************
149  typedef std::random_access_iterator_tag IteratorCategory;
150  typedef typename MT::ElementType ValueType;
151  typedef DiagonalProxy<MT> PointerType;
152  typedef DiagonalProxy<MT> ReferenceType;
153  typedef ptrdiff_t DifferenceType;
154 
155  // STL iterator requirements
156  typedef IteratorCategory iterator_category;
157  typedef ValueType value_type;
158  typedef PointerType pointer;
159  typedef ReferenceType reference;
160  typedef DifferenceType difference_type;
161  //*******************************************************************************************
162 
163  //**Constructor******************************************************************************
166  inline Iterator()
167  : matrix_( NULL ) // Reference to the adapted dense matrix
168  , row_ ( 0UL ) // The current row index of the iterator
169  , column_( 0UL ) // The current column index of the iterator
170  {}
171  //*******************************************************************************************
172 
173  //**Constructor******************************************************************************
180  inline Iterator( MT& matrix, size_t row, size_t column )
181  : matrix_( &matrix ) // Reference to the adapted dense matrix
182  , row_ ( row ) // The current row-index of the iterator
183  , column_( column ) // The current column-index of the iterator
184  {}
185  //*******************************************************************************************
186 
187  //**Addition assignment operator*************************************************************
193  inline Iterator& operator+=( size_t inc ) {
194  ( SO )?( row_ += inc ):( column_ += inc );
195  return *this;
196  }
197  //*******************************************************************************************
198 
199  //**Subtraction assignment operator**********************************************************
205  inline Iterator& operator-=( size_t dec ) {
206  ( SO )?( row_ -= dec ):( column_ -= dec );
207  return *this;
208  }
209  //*******************************************************************************************
210 
211  //**Prefix increment operator****************************************************************
216  inline Iterator& operator++() {
217  ( SO )?( ++row_ ):( ++column_ );
218  return *this;
219  }
220  //*******************************************************************************************
221 
222  //**Postfix increment operator***************************************************************
227  inline const Iterator operator++( int ) {
228  const Iterator tmp( *this );
229  ++(*this);
230  return tmp;
231  }
232  //*******************************************************************************************
233 
234  //**Prefix decrement operator****************************************************************
239  inline Iterator& operator--() {
240  ( SO )?( --row_ ):( --column_ );
241  return *this;
242  }
243  //*******************************************************************************************
244 
245  //**Postfix decrement operator***************************************************************
250  inline const Iterator operator--( int ) {
251  const Iterator tmp( *this );
252  --(*this);
253  return tmp;
254  }
255  //*******************************************************************************************
256 
257  //**Element access operator******************************************************************
262  inline ReferenceType operator*() const {
263  return ReferenceType( *matrix_, row_, column_ );
264  }
265  //*******************************************************************************************
266 
267  //**Element access operator******************************************************************
272  inline PointerType operator->() const {
273  return PointerType( *matrix_, row_, column_ );
274  }
275  //*******************************************************************************************
276 
277  //**Conversion operator**********************************************************************
282  inline operator ConstIterator() const {
283  if( SO )
284  return matrix_->begin( column_ ) + row_;
285  else
286  return matrix_->begin( row_ ) + column_;
287  }
288  //*******************************************************************************************
289 
290  //**Equality operator************************************************************************
297  friend inline bool operator==( const Iterator& lhs, const Iterator& rhs ) {
298  return ( SO )?( lhs.row_ == rhs.row_ ):( lhs.column_ == rhs.column_ );
299  }
300  //*******************************************************************************************
301 
302  //**Equality operator************************************************************************
309  friend inline bool operator==( const Iterator& lhs, const ConstIterator& rhs ) {
310  return ( ConstIterator( lhs ) == rhs );
311  }
312  //*******************************************************************************************
313 
314  //**Equality operator************************************************************************
321  friend inline bool operator==( const ConstIterator& lhs, const Iterator& rhs ) {
322  return ( lhs == ConstIterator( rhs ) );
323  }
324  //*******************************************************************************************
325 
326  //**Inequality operator**********************************************************************
333  friend inline bool operator!=( const Iterator& lhs, const Iterator& rhs ) {
334  return ( SO )?( lhs.row_ != rhs.row_ ):( lhs.column_ != rhs.column_ );
335  }
336  //*******************************************************************************************
337 
338  //**Inequality operator**********************************************************************
345  friend inline bool operator!=( const Iterator& lhs, const ConstIterator& rhs ) {
346  return ( ConstIterator( lhs ) != rhs );
347  }
348  //*******************************************************************************************
349 
350  //**Inequality operator**********************************************************************
357  friend inline bool operator!=( const ConstIterator& lhs, const Iterator& rhs ) {
358  return ( lhs != ConstIterator( rhs ) );
359  }
360  //*******************************************************************************************
361 
362  //**Less-than operator***********************************************************************
369  friend inline bool operator<( const Iterator& lhs, const Iterator& rhs ) {
370  return ( SO )?( lhs.row_ < rhs.row_ ):( lhs.column_ < rhs.column_ );
371  }
372  //*******************************************************************************************
373 
374  //**Less-than operator***********************************************************************
381  friend inline bool operator<( const Iterator& lhs, const ConstIterator& rhs ) {
382  return ( ConstIterator( lhs ) < rhs );
383  }
384  //*******************************************************************************************
385 
386  //**Less-than operator***********************************************************************
393  friend inline bool operator<( const ConstIterator& lhs, const Iterator& rhs ) {
394  return ( lhs < ConstIterator( rhs ) );
395  }
396  //*******************************************************************************************
397 
398  //**Greater-than operator********************************************************************
405  friend inline bool operator>( const Iterator& lhs, const Iterator& rhs ) {
406  return ( SO )?( lhs.row_ > rhs.row_ ):( lhs.column_ > rhs.column_ );
407  }
408  //*******************************************************************************************
409 
410  //**Greater-than operator********************************************************************
417  friend inline bool operator>( const Iterator& lhs, const ConstIterator& rhs ) {
418  return ( ConstIterator( lhs ) > rhs );
419  }
420  //*******************************************************************************************
421 
422  //**Greater-than operator********************************************************************
429  friend inline bool operator>( const ConstIterator& lhs, const Iterator& rhs ) {
430  return ( lhs > ConstIterator( rhs ) );
431  }
432  //*******************************************************************************************
433 
434  //**Less-or-equal-than operator**************************************************************
441  friend inline bool operator<=( const Iterator& lhs, const Iterator& rhs ) {
442  return ( SO )?( lhs.row_ <= rhs.row_ ):( lhs.column_ <= rhs.column_ );
443  }
444  //*******************************************************************************************
445 
446  //**Less-or-equal-than operator**************************************************************
453  friend inline bool operator<=( const Iterator& lhs, const ConstIterator& rhs ) {
454  return ( ConstIterator( lhs ) <= rhs );
455  }
456  //*******************************************************************************************
457 
458  //**Less-or-equal-than operator**************************************************************
465  friend inline bool operator<=( const ConstIterator& lhs, const Iterator& rhs ) {
466  return ( lhs <= ConstIterator( rhs ) );
467  }
468  //*******************************************************************************************
469 
470  //**Greater-or-equal-than operator***********************************************************
477  friend inline bool operator>=( const Iterator& lhs, const Iterator& rhs ) {
478  return ( SO )?( lhs.row_ >= rhs.row_ ):( lhs.column_ >= rhs.column_ );
479  }
480  //*******************************************************************************************
481 
482  //**Greater-or-equal-than operator***********************************************************
489  friend inline bool operator>=( const Iterator& lhs, const ConstIterator& rhs ) {
490  return ( ConstIterator( lhs ) >= rhs );
491  }
492  //*******************************************************************************************
493 
494  //**Greater-or-equal-than operator***********************************************************
501  friend inline bool operator>=( const ConstIterator& lhs, const Iterator& rhs ) {
502  return ( lhs >= ConstIterator( rhs ) );
503  }
504  //*******************************************************************************************
505 
506  //**Subtraction operator*********************************************************************
512  inline DifferenceType operator-( const Iterator& rhs ) const {
513  return ( SO )?( row_ - rhs.row_ ):( column_ - rhs.column_ );
514  }
515  //*******************************************************************************************
516 
517  //**Addition operator************************************************************************
524  friend inline const Iterator operator+( const Iterator& it, size_t inc ) {
525  if( SO )
526  return Iterator( *it.matrix_, it.row_ + inc, it.column_ );
527  else
528  return Iterator( *it.matrix_, it.row_, it.column_ + inc );
529  }
530  //*******************************************************************************************
531 
532  //**Addition operator************************************************************************
539  friend inline const Iterator operator+( size_t inc, const Iterator& it ) {
540  if( SO )
541  return Iterator( *it.matrix_, it.row_ + inc, it.column_ );
542  else
543  return Iterator( *it.matrix_, it.row_, it.column_ + inc );
544  }
545  //*******************************************************************************************
546 
547  //**Subtraction operator*********************************************************************
554  friend inline const Iterator operator-( const Iterator& it, size_t dec ) {
555  if( SO )
556  return Iterator( *it.matrix_, it.row_ - dec, it.column_ );
557  else
558  return Iterator( *it.matrix_, it.row_, it.column_ - dec );
559  }
560  //*******************************************************************************************
561 
562  private:
563  //**Member variables*************************************************************************
564  MT* matrix_;
565  size_t row_;
566  size_t column_;
567  //*******************************************************************************************
568  };
569  //**********************************************************************************************
570 
571  //**Compilation flags***************************************************************************
573  enum { vectorizable = MT::vectorizable };
574 
576  enum { smpAssignable = MT::smpAssignable };
577  //**********************************************************************************************
578 
579  //**Constructors********************************************************************************
582  explicit inline DiagonalMatrix();
583  template< typename A1 > explicit inline DiagonalMatrix( const A1& a1 );
584  explicit inline DiagonalMatrix( size_t n, const ElementType& init );
585 
586  explicit inline DiagonalMatrix( ElementType* ptr, size_t n );
587  explicit inline DiagonalMatrix( ElementType* ptr, size_t n, size_t nn );
588 
589  template< typename Deleter >
590  explicit inline DiagonalMatrix( ElementType* ptr, size_t n, Deleter d );
591 
592  template< typename Deleter >
593  explicit inline DiagonalMatrix( ElementType* ptr, size_t n, size_t nn, Deleter d );
594 
595  inline DiagonalMatrix( const DiagonalMatrix& m );
597  //**********************************************************************************************
598 
599  //**Destructor**********************************************************************************
600  // No explicitly declared destructor.
601  //**********************************************************************************************
602 
603  //**Data access functions***********************************************************************
606  inline Reference operator()( size_t i, size_t j );
607  inline ConstReference operator()( size_t i, size_t j ) const;
608  inline Reference at( size_t i, size_t j );
609  inline ConstReference at( size_t i, size_t j ) const;
610  inline ConstPointer data () const;
611  inline ConstPointer data ( size_t i ) const;
612  inline Iterator begin ( size_t i );
613  inline ConstIterator begin ( size_t i ) const;
614  inline ConstIterator cbegin( size_t i ) const;
615  inline Iterator end ( size_t i );
616  inline ConstIterator end ( size_t i ) const;
617  inline ConstIterator cend ( size_t i ) const;
619  //**********************************************************************************************
620 
621  //**Assignment operators************************************************************************
624  inline DiagonalMatrix& operator=( const ElementType& rhs );
625  inline DiagonalMatrix& operator=( const DiagonalMatrix& rhs );
626 
627  template< typename MT2, bool SO2 >
628  inline typename DisableIf< IsComputation<MT2>, DiagonalMatrix& >::Type
629  operator=( const Matrix<MT2,SO2>& rhs );
630 
631  template< typename MT2, bool SO2 >
632  inline typename EnableIf< IsComputation<MT2>, DiagonalMatrix& >::Type
633  operator=( const Matrix<MT2,SO2>& rhs );
634 
635  template< typename MT2, bool SO2 >
636  inline typename DisableIf< IsComputation<MT2>, DiagonalMatrix& >::Type
637  operator+=( const Matrix<MT2,SO2>& rhs );
638 
639  template< typename MT2, bool SO2 >
640  inline typename EnableIf< IsComputation<MT2>, DiagonalMatrix& >::Type
641  operator+=( const Matrix<MT2,SO2>& rhs );
642 
643  template< typename MT2, bool SO2 >
644  inline typename DisableIf< IsComputation<MT2>, DiagonalMatrix& >::Type
645  operator-=( const Matrix<MT2,SO2>& rhs );
646 
647  template< typename MT2, bool SO2 >
648  inline typename EnableIf< IsComputation<MT2>, DiagonalMatrix& >::Type
649  operator-=( const Matrix<MT2,SO2>& rhs );
650 
651  template< typename MT2, bool SO2 >
652  inline DiagonalMatrix& operator*=( const Matrix<MT2,SO2>& rhs );
653 
654  template< typename Other >
655  inline typename EnableIf< IsNumeric<Other>, DiagonalMatrix >::Type&
656  operator*=( Other rhs );
657 
658  template< typename Other >
659  inline typename EnableIf< IsNumeric<Other>, DiagonalMatrix >::Type&
660  operator/=( Other rhs );
662  //**********************************************************************************************
663 
664  //**Utility functions***************************************************************************
667  inline size_t rows() const;
668  inline size_t columns() const;
669  inline size_t spacing() const;
670  inline size_t capacity() const;
671  inline size_t capacity( size_t i ) const;
672  inline size_t nonZeros() const;
673  inline size_t nonZeros( size_t i ) const;
674  inline void reset();
675  inline void reset( size_t i );
676  inline void clear();
677  void resize ( size_t n, bool preserve=true );
678  inline void extend ( size_t n, bool preserve=true );
679  inline void reserve( size_t elements );
680  template< typename Other > inline DiagonalMatrix& scale( const Other& scalar );
681  inline void swap( DiagonalMatrix& m ) /* throw() */;
683  //**********************************************************************************************
684 
685  //**Debugging functions*************************************************************************
688  inline bool isIntact() const;
690  //**********************************************************************************************
691 
692  //**Expression template evaluation functions****************************************************
695  template< typename Other > inline bool canAlias ( const Other* alias ) const;
696  template< typename Other > inline bool isAliased( const Other* alias ) const;
697 
698  inline bool isAligned () const;
699  inline bool canSMPAssign() const;
700 
701  BLAZE_ALWAYS_INLINE IntrinsicType load ( size_t i, size_t j ) const;
702  BLAZE_ALWAYS_INLINE IntrinsicType loada( size_t i, size_t j ) const;
703  BLAZE_ALWAYS_INLINE IntrinsicType loadu( size_t i, size_t j ) const;
705  //**********************************************************************************************
706 
707  private:
708  //**Construction functions**********************************************************************
711  inline const MT construct( size_t n , TrueType );
712  inline const MT construct( const ElementType& value, FalseType );
713 
714  template< typename MT2, bool SO2, typename T >
715  inline const MT construct( const Matrix<MT2,SO2>& m, T );
717  //**********************************************************************************************
718 
719  //**Member variables****************************************************************************
722  MT matrix_;
723 
724  //**********************************************************************************************
725 
726  //**Friend declarations*************************************************************************
727  template< typename MT2, bool SO2, bool DF2 >
728  friend bool isDefault( const DiagonalMatrix<MT2,SO2,DF2>& m );
729 
730  template< typename MT2, bool SO2, bool DF2 >
731  friend MT2& derestrict( DiagonalMatrix<MT2,SO2,DF2>& m );
732  //**********************************************************************************************
733 
734  //**Compile time checks*************************************************************************
747  BLAZE_STATIC_ASSERT( Rows<MT>::value == Columns<MT>::value );
748  //**********************************************************************************************
749 };
751 //*************************************************************************************************
752 
753 
754 
755 
756 //=================================================================================================
757 //
758 // CONSTRUCTORS
759 //
760 //=================================================================================================
761 
762 //*************************************************************************************************
766 template< typename MT // Type of the adapted dense matrix
767  , bool SO > // Storage order of the adapted dense matrix
768 inline DiagonalMatrix<MT,SO,true>::DiagonalMatrix()
769  : matrix_() // The adapted dense matrix
770 {
771  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
772  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
773 }
775 //*************************************************************************************************
776 
777 
778 //*************************************************************************************************
796 template< typename MT // Type of the adapted dense matrix
797  , bool SO > // Storage order of the adapted dense matrix
798 template< typename A1 > // Type of the constructor argument
799 inline DiagonalMatrix<MT,SO,true>::DiagonalMatrix( const A1& a1 )
800  : matrix_( construct( a1, typename IsResizable<MT>::Type() ) ) // The adapted dense matrix
801 {
802  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
803  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
804 }
806 //*************************************************************************************************
807 
808 
809 //*************************************************************************************************
816 template< typename MT // Type of the adapted dense matrix
817  , bool SO > // Storage order of the adapted dense matrix
818 inline DiagonalMatrix<MT,SO,true>::DiagonalMatrix( size_t n, const ElementType& init )
819  : matrix_( n, n, ElementType() ) // The adapted dense matrix
820 {
822 
823  for( size_t i=0UL; i<n; ++i )
824  matrix_(i,i) = init;
825 
826  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
827  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
828 }
830 //*************************************************************************************************
831 
832 
833 //*************************************************************************************************
854 template< typename MT // Type of the adapted dense matrix
855  , bool SO > // Storage order of the adapted dense matrix
856 inline DiagonalMatrix<MT,SO,true>::DiagonalMatrix( ElementType* ptr, size_t n )
857  : matrix_( ptr, n, n ) // The adapted dense matrix
858 {
859  if( !isDiagonal( matrix_ ) ) {
860  BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of diagonal matrix" );
861  }
862 
863  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
864 }
866 //*************************************************************************************************
867 
868 
869 //*************************************************************************************************
892 template< typename MT // Type of the adapted dense matrix
893  , bool SO > // Storage order of the adapted dense matrix
894 inline DiagonalMatrix<MT,SO,true>::DiagonalMatrix( ElementType* ptr, size_t n, size_t nn )
895  : matrix_( ptr, n, n, nn ) // The adapted dense matrix
896 {
897  if( !isDiagonal( matrix_ ) ) {
898  BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of diagonal matrix" );
899  }
900 
901  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
902 }
904 //*************************************************************************************************
905 
906 
907 //*************************************************************************************************
928 template< typename MT // Type of the adapted dense matrix
929  , bool SO > // Storage order of the adapted dense matrix
930 template< typename Deleter > // Type of the custom deleter
931 inline DiagonalMatrix<MT,SO,true>::DiagonalMatrix( ElementType* ptr, size_t n, Deleter d )
932  : matrix_( ptr, n, n, d ) // The adapted dense matrix
933 {
934  if( !isDiagonal( matrix_ ) ) {
935  BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of diagonal matrix" );
936  }
937 
938  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
939 }
941 //*************************************************************************************************
942 
943 
944 //*************************************************************************************************
966 template< typename MT // Type of the adapted dense matrix
967  , bool SO > // Storage order of the adapted dense matrix
968 template< typename Deleter > // Type of the custom deleter
969 inline DiagonalMatrix<MT,SO,true>::DiagonalMatrix( ElementType* ptr, size_t n, size_t nn, Deleter d )
970  : matrix_( ptr, n, n, nn, d ) // The adapted dense matrix
971 {
972  if( !isDiagonal( matrix_ ) ) {
973  BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of diagonal matrix" );
974  }
975 
976  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
977 }
979 //*************************************************************************************************
980 
981 
982 //*************************************************************************************************
988 template< typename MT // Type of the adapted dense matrix
989  , bool SO > // Storage order of the adapted dense matrix
990 inline DiagonalMatrix<MT,SO,true>::DiagonalMatrix( const DiagonalMatrix& m )
991  : matrix_( m.matrix_ ) // The adapted dense matrix
992 {
993  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
994  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
995 }
997 //*************************************************************************************************
998 
999 
1000 
1001 
1002 //=================================================================================================
1003 //
1004 // DATA ACCESS FUNCTIONS
1005 //
1006 //=================================================================================================
1007 
1008 //*************************************************************************************************
1024 template< typename MT // Type of the adapted dense matrix
1025  , bool SO > // Storage order of the adapted dense matrix
1027  DiagonalMatrix<MT,SO,true>::operator()( size_t i, size_t j )
1028 {
1029  BLAZE_USER_ASSERT( i<rows() , "Invalid row access index" );
1030  BLAZE_USER_ASSERT( j<columns(), "Invalid column access index" );
1031 
1032  return Reference( matrix_, i, j );
1033 }
1035 //*************************************************************************************************
1036 
1037 
1038 //*************************************************************************************************
1054 template< typename MT // Type of the adapted dense matrix
1055  , bool SO > // Storage order of the adapted dense matrix
1057  DiagonalMatrix<MT,SO,true>::operator()( size_t i, size_t j ) const
1058 {
1059  BLAZE_USER_ASSERT( i<rows() , "Invalid row access index" );
1060  BLAZE_USER_ASSERT( j<columns(), "Invalid column access index" );
1061 
1062  return matrix_(i,j);
1063 }
1065 //*************************************************************************************************
1066 
1067 
1068 //*************************************************************************************************
1085 template< typename MT // Type of the adapted dense matrix
1086  , bool SO > // Storage order of the adapted dense matrix
1088  DiagonalMatrix<MT,SO,true>::at( size_t i, size_t j )
1089 {
1090  if( i >= rows() ) {
1091  BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
1092  }
1093  if( j >= columns() ) {
1094  BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
1095  }
1096  return (*this)(i,j);
1097 }
1099 //*************************************************************************************************
1100 
1101 
1102 //*************************************************************************************************
1119 template< typename MT // Type of the adapted dense matrix
1120  , bool SO > // Storage order of the adapted dense matrix
1122  DiagonalMatrix<MT,SO,true>::at( size_t i, size_t j ) const
1123 {
1124  if( i >= rows() ) {
1125  BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
1126  }
1127  if( j >= columns() ) {
1128  BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
1129  }
1130  return (*this)(i,j);
1131 }
1133 //*************************************************************************************************
1134 
1135 
1136 //*************************************************************************************************
1149 template< typename MT // Type of the adapted dense matrix
1150  , bool SO > // Storage order of the adapted dense matrix
1151 inline typename DiagonalMatrix<MT,SO,true>::ConstPointer
1152  DiagonalMatrix<MT,SO,true>::data() const
1153 {
1154  return matrix_.data();
1155 }
1157 //*************************************************************************************************
1158 
1159 
1160 //*************************************************************************************************
1169 template< typename MT // Type of the adapted dense matrix
1170  , bool SO > // Storage order of the adapted dense matrix
1171 inline typename DiagonalMatrix<MT,SO,true>::ConstPointer
1172  DiagonalMatrix<MT,SO,true>::data( size_t i ) const
1173 {
1174  return matrix_.data(i);
1175 }
1177 //*************************************************************************************************
1178 
1179 
1180 //*************************************************************************************************
1192 template< typename MT // Type of the adapted dense matrix
1193  , bool SO > // Storage order of the adapted dense matrix
1196 {
1197  if( SO )
1198  return Iterator( matrix_, 0UL, i );
1199  else
1200  return Iterator( matrix_, i, 0UL );
1201 }
1203 //*************************************************************************************************
1204 
1205 
1206 //*************************************************************************************************
1218 template< typename MT // Type of the adapted dense matrix
1219  , bool SO > // Storage order of the adapted dense matrix
1221  DiagonalMatrix<MT,SO,true>::begin( size_t i ) const
1222 {
1223  return matrix_.begin(i);
1224 }
1226 //*************************************************************************************************
1227 
1228 
1229 //*************************************************************************************************
1241 template< typename MT // Type of the adapted dense matrix
1242  , bool SO > // Storage order of the adapted dense matrix
1244  DiagonalMatrix<MT,SO,true>::cbegin( size_t i ) const
1245 {
1246  return matrix_.cbegin(i);
1247 }
1249 //*************************************************************************************************
1250 
1251 
1252 //*************************************************************************************************
1264 template< typename MT // Type of the adapted dense matrix
1265  , bool SO > // Storage order of the adapted dense matrix
1268 {
1269  if( SO )
1270  return Iterator( matrix_, rows(), i );
1271  else
1272  return Iterator( matrix_, i, columns() );
1273 }
1275 //*************************************************************************************************
1276 
1277 
1278 //*************************************************************************************************
1290 template< typename MT // Type of the adapted dense matrix
1291  , bool SO > // Storage order of the adapted dense matrix
1293  DiagonalMatrix<MT,SO,true>::end( size_t i ) const
1294 {
1295  return matrix_.end(i);
1296 }
1298 //*************************************************************************************************
1299 
1300 
1301 //*************************************************************************************************
1313 template< typename MT // Type of the adapted dense matrix
1314  , bool SO > // Storage order of the adapted dense matrix
1316  DiagonalMatrix<MT,SO,true>::cend( size_t i ) const
1317 {
1318  return matrix_.cend(i);
1319 }
1321 //*************************************************************************************************
1322 
1323 
1324 
1325 
1326 //=================================================================================================
1327 //
1328 // ASSIGNMENT OPERATORS
1329 //
1330 //=================================================================================================
1331 
1332 //*************************************************************************************************
1339 template< typename MT // Type of the adapted dense matrix
1340  , bool SO > // Storage order of the adapted dense matrix
1341 inline DiagonalMatrix<MT,SO,true>&
1342  DiagonalMatrix<MT,SO,true>::operator=( const ElementType& rhs )
1343 {
1344  if( SO ) {
1345  for( size_t j=0UL; j<columns(); ++j )
1346  matrix_(j,j) = rhs;
1347  }
1348  else {
1349  for( size_t i=0UL; i<rows(); ++i )
1350  matrix_(i,i) = rhs;
1351  }
1352 
1353  return *this;
1354 }
1356 //*************************************************************************************************
1357 
1358 
1359 //*************************************************************************************************
1369 template< typename MT // Type of the adapted dense matrix
1370  , bool SO > // Storage order of the adapted dense matrix
1371 inline DiagonalMatrix<MT,SO,true>&
1372  DiagonalMatrix<MT,SO,true>::operator=( const DiagonalMatrix& rhs )
1373 {
1374  matrix_ = rhs.matrix_;
1375 
1376  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1377  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1378 
1379  return *this;
1380 }
1382 //*************************************************************************************************
1383 
1384 
1385 //*************************************************************************************************
1398 template< typename MT // Type of the adapted dense matrix
1399  , bool SO > // Storage order of the adapted dense matrix
1400 template< typename MT2 // Type of the right-hand side matrix
1401  , bool SO2 > // Storage order of the right-hand side matrix
1402 inline typename DisableIf< IsComputation<MT2>, DiagonalMatrix<MT,SO,true>& >::Type
1403  DiagonalMatrix<MT,SO,true>::operator=( const Matrix<MT2,SO2>& rhs )
1404 {
1405  if( !IsDiagonal<MT2>::value && !isDiagonal( ~rhs ) ) {
1406  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1407  }
1408 
1409  matrix_ = ~rhs;
1410 
1411  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1412  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1413 
1414  return *this;
1415 }
1417 //*************************************************************************************************
1418 
1419 
1420 //*************************************************************************************************
1433 template< typename MT // Type of the adapted dense matrix
1434  , bool SO > // Storage order of the adapted dense matrix
1435 template< typename MT2 // Type of the right-hand side matrix
1436  , bool SO2 > // Storage order of the right-hand side matrix
1437 inline typename EnableIf< IsComputation<MT2>, DiagonalMatrix<MT,SO,true>& >::Type
1438  DiagonalMatrix<MT,SO,true>::operator=( const Matrix<MT2,SO2>& rhs )
1439 {
1440  if( !IsSquare<MT2>::value && !isSquare( ~rhs ) ) {
1441  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1442  }
1443 
1444  if( IsDiagonal<MT2>::value ) {
1445  matrix_ = ~rhs;
1446  }
1447  else {
1448  MT tmp( ~rhs );
1449 
1450  if( !isDiagonal( tmp ) ) {
1451  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1452  }
1453 
1454  move( matrix_, tmp );
1455  }
1456 
1457  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1458  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1459 
1460  return *this;
1461 }
1463 //*************************************************************************************************
1464 
1465 
1466 //*************************************************************************************************
1479 template< typename MT // Type of the adapted dense matrix
1480  , bool SO > // Storage order of the adapted dense matrix
1481 template< typename MT2 // Type of the right-hand side matrix
1482  , bool SO2 > // Storage order of the right-hand side matrix
1483 inline typename DisableIf< IsComputation<MT2>, DiagonalMatrix<MT,SO,true>& >::Type
1484  DiagonalMatrix<MT,SO,true>::operator+=( const Matrix<MT2,SO2>& rhs )
1485 {
1486  if( !IsDiagonal<MT2>::value && !isDiagonal( ~rhs ) ) {
1487  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1488  }
1489 
1490  matrix_ += ~rhs;
1491 
1492  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1493  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1494 
1495  return *this;
1496 }
1498 //*************************************************************************************************
1499 
1500 
1501 //*************************************************************************************************
1514 template< typename MT // Type of the adapted dense matrix
1515  , bool SO > // Storage order of the adapted dense matrix
1516 template< typename MT2 // Type of the right-hand side matrix
1517  , bool SO2 > // Storage order of the right-hand side matrix
1518 inline typename EnableIf< IsComputation<MT2>, DiagonalMatrix<MT,SO,true>& >::Type
1519  DiagonalMatrix<MT,SO,true>::operator+=( const Matrix<MT2,SO2>& rhs )
1520 {
1521  if( !IsSquare<MT2>::value && !isSquare( ~rhs ) ) {
1522  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1523  }
1524 
1525  if( IsDiagonal<MT2>::value ) {
1526  matrix_ += ~rhs;
1527  }
1528  else {
1529  typename MT2::ResultType tmp( ~rhs );
1530 
1531  if( !isDiagonal( tmp ) ) {
1532  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1533  }
1534 
1535  matrix_ += tmp;
1536  }
1537 
1538  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1539  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1540 
1541  return *this;
1542 }
1544 //*************************************************************************************************
1545 
1546 
1547 //*************************************************************************************************
1560 template< typename MT // Type of the adapted dense matrix
1561  , bool SO > // Storage order of the adapted dense matrix
1562 template< typename MT2 // Type of the right-hand side matrix
1563  , bool SO2 > // Storage order of the right-hand side matrix
1564 inline typename DisableIf< IsComputation<MT2>, DiagonalMatrix<MT,SO,true>& >::Type
1565  DiagonalMatrix<MT,SO,true>::operator-=( const Matrix<MT2,SO2>& rhs )
1566 {
1567  if( !IsDiagonal<MT2>::value && !isDiagonal( ~rhs ) ) {
1568  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1569  }
1570 
1571  matrix_ -= ~rhs;
1572 
1573  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1574  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1575 
1576  return *this;
1577 }
1579 //*************************************************************************************************
1580 
1581 
1582 //*************************************************************************************************
1595 template< typename MT // Type of the adapted dense matrix
1596  , bool SO > // Storage order of the adapted dense matrix
1597 template< typename MT2 // Type of the right-hand side matrix
1598  , bool SO2 > // Storage order of the right-hand side matrix
1599 inline typename EnableIf< IsComputation<MT2>, DiagonalMatrix<MT,SO,true>& >::Type
1600  DiagonalMatrix<MT,SO,true>::operator-=( const Matrix<MT2,SO2>& rhs )
1601 {
1602  if( !IsSquare<MT2>::value && !isSquare( ~rhs ) ) {
1603  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1604  }
1605 
1606  if( IsDiagonal<MT2>::value ) {
1607  matrix_ -= ~rhs;
1608  }
1609  else {
1610  typename MT2::ResultType tmp( ~rhs );
1611 
1612  if( !isDiagonal( tmp ) ) {
1613  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1614  }
1615 
1616  matrix_ -= tmp;
1617  }
1618 
1619  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1620  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1621 
1622  return *this;
1623 }
1625 //*************************************************************************************************
1626 
1627 
1628 //*************************************************************************************************
1640 template< typename MT // Type of the adapted dense matrix
1641  , bool SO > // Storage order of the adapted dense matrix
1642 template< typename MT2 // Type of the right-hand side matrix
1643  , bool SO2 > // Storage order of the right-hand side matrix
1644 inline DiagonalMatrix<MT,SO,true>&
1645  DiagonalMatrix<MT,SO,true>::operator*=( const Matrix<MT2,SO2>& rhs )
1646 {
1647  if( matrix_.rows() != (~rhs).columns() ) {
1648  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1649  }
1650 
1651  MT tmp( matrix_ * ~rhs );
1652 
1653  if( !isDiagonal( tmp ) ) {
1654  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix" );
1655  }
1656 
1657  move( matrix_, tmp );
1658 
1659  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1660  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1661 
1662  return *this;
1663 }
1665 //*************************************************************************************************
1666 
1667 
1668 //*************************************************************************************************
1676 template< typename MT // Type of the adapted dense matrix
1677  , bool SO > // Storage order of the adapted dense matrix
1678 template< typename Other > // Data type of the right-hand side scalar
1679 inline typename EnableIf< IsNumeric<Other>, DiagonalMatrix<MT,SO,true> >::Type&
1680  DiagonalMatrix<MT,SO,true>::operator*=( Other rhs )
1681 {
1682  matrix_ *= rhs;
1683  return *this;
1684 }
1685 //*************************************************************************************************
1686 
1687 
1688 //*************************************************************************************************
1696 template< typename MT // Type of the adapted dense matrix
1697  , bool SO > // Storage order of the adapted dense matrix
1698 template< typename Other > // Data type of the right-hand side scalar
1699 inline typename EnableIf< IsNumeric<Other>, DiagonalMatrix<MT,SO,true> >::Type&
1700  DiagonalMatrix<MT,SO,true>::operator/=( Other rhs )
1701 {
1702  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
1703 
1704  matrix_ /= rhs;
1705  return *this;
1706 }
1708 //*************************************************************************************************
1709 
1710 
1711 
1712 
1713 //=================================================================================================
1714 //
1715 // UTILITY FUNCTIONS
1716 //
1717 //=================================================================================================
1718 
1719 //*************************************************************************************************
1725 template< typename MT // Type of the adapted dense matrix
1726  , bool SO > // Storage order of the adapted dense matrix
1727 inline size_t DiagonalMatrix<MT,SO,true>::rows() const
1728 {
1729  return matrix_.rows();
1730 }
1732 //*************************************************************************************************
1733 
1734 
1735 //*************************************************************************************************
1741 template< typename MT // Type of the adapted dense matrix
1742  , bool SO > // Storage order of the adapted dense matrix
1743 inline size_t DiagonalMatrix<MT,SO,true>::columns() const
1744 {
1745  return matrix_.columns();
1746 }
1748 //*************************************************************************************************
1749 
1750 
1751 //*************************************************************************************************
1762 template< typename MT // Type of the adapted dense matrix
1763  , bool SO > // Storage order of the adapted dense matrix
1764 inline size_t DiagonalMatrix<MT,SO,true>::spacing() const
1765 {
1766  return matrix_.spacing();
1767 }
1769 //*************************************************************************************************
1770 
1771 
1772 //*************************************************************************************************
1778 template< typename MT // Type of the adapted dense matrix
1779  , bool SO > // Storage order of the adapted dense matrix
1780 inline size_t DiagonalMatrix<MT,SO,true>::capacity() const
1781 {
1782  return matrix_.capacity();
1783 }
1785 //*************************************************************************************************
1786 
1787 
1788 //*************************************************************************************************
1800 template< typename MT // Type of the adapted dense matrix
1801  , bool SO > // Storage order of the adapted dense matrix
1802 inline size_t DiagonalMatrix<MT,SO,true>::capacity( size_t i ) const
1803 {
1804  return matrix_.capacity(i);
1805 }
1807 //*************************************************************************************************
1808 
1809 
1810 //*************************************************************************************************
1816 template< typename MT // Type of the adapted dense matrix
1817  , bool SO > // Storage order of the adapted dense matrix
1818 inline size_t DiagonalMatrix<MT,SO,true>::nonZeros() const
1819 {
1820  return matrix_.nonZeros();
1821 }
1823 //*************************************************************************************************
1824 
1825 
1826 //*************************************************************************************************
1838 template< typename MT // Type of the adapted dense matrix
1839  , bool SO > // Storage order of the adapted dense matrix
1840 inline size_t DiagonalMatrix<MT,SO,true>::nonZeros( size_t i ) const
1841 {
1842  return matrix_.nonZeros(i);
1843 }
1845 //*************************************************************************************************
1846 
1847 
1848 //*************************************************************************************************
1854 template< typename MT // Type of the adapted dense matrix
1855  , bool SO > // Storage order of the adapted dense matrix
1857 {
1858  matrix_.reset();
1859 }
1861 //*************************************************************************************************
1862 
1863 
1864 //*************************************************************************************************
1877 template< typename MT // Type of the adapted dense matrix
1878  , bool SO > // Storage order of the adapted dense matrix
1879 inline void DiagonalMatrix<MT,SO,true>::reset( size_t i )
1880 {
1881  matrix_.reset( i );
1882 }
1884 //*************************************************************************************************
1885 
1886 
1887 //*************************************************************************************************
1899 template< typename MT // Type of the adapted dense matrix
1900  , bool SO > // Storage order of the adapted dense matrix
1902 {
1903  using blaze::clear;
1904 
1905  clear( matrix_ );
1906 }
1908 //*************************************************************************************************
1909 
1910 
1911 //*************************************************************************************************
1947 template< typename MT // Type of the adapted dense matrix
1948  , bool SO > // Storage order of the adapted dense matrix
1949 void DiagonalMatrix<MT,SO,true>::resize( size_t n, bool preserve )
1950 {
1952 
1953  UNUSED_PARAMETER( preserve );
1954 
1955  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square diagonal matrix detected" );
1956 
1957  const size_t oldsize( matrix_.rows() );
1958 
1959  matrix_.resize( n, n, true );
1960 
1961  if( n > oldsize ) {
1962  const size_t increment( n - oldsize );
1963  submatrix( matrix_, 0UL, oldsize, n, increment ).reset();
1964  submatrix( matrix_, oldsize, 0UL, increment, increment ).reset();
1965  }
1966 }
1968 //*************************************************************************************************
1969 
1970 
1971 //*************************************************************************************************
1984 template< typename MT // Type of the adapted dense matrix
1985  , bool SO > // Storage order of the adapted dense matrix
1986 inline void DiagonalMatrix<MT,SO,true>::extend( size_t n, bool preserve )
1987 {
1989 
1990  UNUSED_PARAMETER( preserve );
1991 
1992  resize( rows() + n, true );
1993 }
1994 //*************************************************************************************************
1995 
1996 
1997 //*************************************************************************************************
2007 template< typename MT // Type of the adapted dense matrix
2008  , bool SO > // Storage order of the adapted dense matrix
2009 inline void DiagonalMatrix<MT,SO,true>::reserve( size_t elements )
2010 {
2011  matrix_.reserve( elements );
2012 }
2014 //*************************************************************************************************
2015 
2016 
2017 //*************************************************************************************************
2024 template< typename MT // Type of the adapted dense matrix
2025  , bool SO > // Storage order of the adapted dense matrix
2026 template< typename Other > // Data type of the scalar value
2027 inline DiagonalMatrix<MT,SO,true>& DiagonalMatrix<MT,SO,true>::scale( const Other& scalar )
2028 {
2029  matrix_.scale( scalar );
2030  return *this;
2031 }
2033 //*************************************************************************************************
2034 
2035 
2036 //*************************************************************************************************
2044 template< typename MT // Type of the adapted dense matrix
2045  , bool SO > // Storage order of the adapted dense matrix
2046 inline void DiagonalMatrix<MT,SO,true>::swap( DiagonalMatrix& m ) /* throw() */
2047 {
2048  using std::swap;
2049 
2050  swap( matrix_, m.matrix_ );
2051 }
2053 //*************************************************************************************************
2054 
2055 
2056 
2057 
2058 //=================================================================================================
2059 //
2060 // DEBUGGING FUNCTIONS
2061 //
2062 //=================================================================================================
2063 
2064 //*************************************************************************************************
2074 template< typename MT // Type of the adapted dense matrix
2075  , bool SO > // Storage order of the adapted dense matrix
2076 inline bool DiagonalMatrix<MT,SO,true>::isIntact() const
2077 {
2078  using blaze::isIntact;
2079 
2080  return ( isIntact( matrix_ ) && isDiagonal( matrix_ ) );
2081 }
2083 //*************************************************************************************************
2084 
2085 
2086 
2087 
2088 //=================================================================================================
2089 //
2090 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
2091 //
2092 //=================================================================================================
2093 
2094 //*************************************************************************************************
2105 template< typename MT // Type of the adapted dense matrix
2106  , bool SO > // Storage order of the adapted dense matrix
2107 template< typename Other > // Data type of the foreign expression
2108 inline bool DiagonalMatrix<MT,SO,true>::canAlias( const Other* alias ) const
2109 {
2110  return matrix_.canAlias( alias );
2111 }
2113 //*************************************************************************************************
2114 
2115 
2116 //*************************************************************************************************
2127 template< typename MT // Type of the adapted dense matrix
2128  , bool SO > // Storage order of the adapted dense matrix
2129 template< typename Other > // Data type of the foreign expression
2130 inline bool DiagonalMatrix<MT,SO,true>::isAliased( const Other* alias ) const
2131 {
2132  return matrix_.isAliased( alias );
2133 }
2135 //*************************************************************************************************
2136 
2137 
2138 //*************************************************************************************************
2148 template< typename MT // Type of the adapted dense matrix
2149  , bool SO > // Storage order of the adapted dense matrix
2150 inline bool DiagonalMatrix<MT,SO,true>::isAligned() const
2151 {
2152  return matrix_.isAligned();
2153 }
2155 //*************************************************************************************************
2156 
2157 
2158 //*************************************************************************************************
2169 template< typename MT // Type of the adapted dense matrix
2170  , bool SO > // Storage order of the adapted dense matrix
2171 inline bool DiagonalMatrix<MT,SO,true>::canSMPAssign() const
2172 {
2173  return matrix_.canSMPAssign();
2174 }
2176 //*************************************************************************************************
2177 
2178 
2179 //*************************************************************************************************
2195 template< typename MT // Type of the adapted dense matrix
2196  , bool SO > // Storage order of the adapted dense matrix
2197 BLAZE_ALWAYS_INLINE typename DiagonalMatrix<MT,SO,true>::IntrinsicType
2198  DiagonalMatrix<MT,SO,true>::load( size_t i, size_t j ) const
2199 {
2200  return matrix_.load( i, j );
2201 }
2203 //*************************************************************************************************
2204 
2205 
2206 //*************************************************************************************************
2222 template< typename MT // Type of the adapted dense matrix
2223  , bool SO > // Storage order of the adapted dense matrix
2224 BLAZE_ALWAYS_INLINE typename DiagonalMatrix<MT,SO,true>::IntrinsicType
2225  DiagonalMatrix<MT,SO,true>::loada( size_t i, size_t j ) const
2226 {
2227  return matrix_.loada( i, j );
2228 }
2230 //*************************************************************************************************
2231 
2232 
2233 //*************************************************************************************************
2249 template< typename MT // Type of the adapted dense matrix
2250  , bool SO > // Storage order of the adapted dense matrix
2251 BLAZE_ALWAYS_INLINE typename DiagonalMatrix<MT,SO,true>::IntrinsicType
2252  DiagonalMatrix<MT,SO,true>::loadu( size_t i, size_t j ) const
2253 {
2254  return matrix_.loadu( i, j );
2255 }
2257 //*************************************************************************************************
2258 
2259 
2260 
2261 
2262 //=================================================================================================
2263 //
2264 // CONSTRUCTION FUNCTIONS
2265 //
2266 //=================================================================================================
2267 
2268 //*************************************************************************************************
2275 template< typename MT // Type of the adapted dense matrix
2276  , bool SO > // Storage order of the adapted dense matrix
2277 inline const MT DiagonalMatrix<MT,SO,true>::construct( size_t n, TrueType )
2278 {
2280 
2281  return MT( n, n, ElementType() );
2282 }
2284 //*************************************************************************************************
2285 
2286 
2287 //*************************************************************************************************
2294 template< typename MT // Type of the adapted dense matrix
2295  , bool SO > // Storage order of the adapted dense matrix
2296 inline const MT DiagonalMatrix<MT,SO,true>::construct( const ElementType& init, FalseType )
2297 {
2300 
2301  MT tmp;
2302 
2303  for( size_t i=0UL; i<tmp.rows(); ++i )
2304  tmp(i,i) = init;
2305 
2306  return tmp;
2307 }
2309 //*************************************************************************************************
2310 
2311 
2312 //*************************************************************************************************
2323 template< typename MT // Type of the adapted dense matrix
2324  , bool SO > // Storage order of the adapted dense matrix
2325 template< typename MT2 // Type of the foreign matrix
2326  , bool SO2 // Storage order of the foreign matrix
2327  , typename T > // Type of the third argument
2328 inline const MT DiagonalMatrix<MT,SO,true>::construct( const Matrix<MT2,SO2>& m, T )
2329 {
2330  const MT tmp( ~m );
2331 
2332  if( !IsDiagonal<MT2>::value && !isDiagonal( tmp ) ) {
2333  BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of diagonal matrix" );
2334  }
2335 
2336  return tmp;
2337 }
2339 //*************************************************************************************************
2340 
2341 } // namespace blaze
2342 
2343 #endif
Constraint on the data type.
Header file for all restructuring submatrix functions.
#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:116
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exceptionThis macro encapsulates the default way of...
Definition: Exception.h:187
#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
bool isDiagonal(const DenseMatrix< MT, SO > &dm)
Checks if the give dense matrix is diagonal.
Definition: DenseMatrix.h:1511
Header file for the Rows type trait.
Header file for the UNUSED_PARAMETER function template.
const DMatDMatMultExpr< T1, T2 > operator*(const DenseMatrix< T1, false > &lhs, const DenseMatrix< T2, false > &rhs)
Multiplication operator for the multiplication of two row-major dense matrices ( ).
Definition: DMatDMatMultExpr.h:7820
Header file for basic type definitions.
BLAZE_ALWAYS_INLINE bool isSquare(const Matrix< MT, SO > &matrix)
Checks if the given matrix is a square matrix.
Definition: Matrix.h:603
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:229
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:292
bool operator<=(const NegativeAccuracy< A > &, const T &rhs)
Less-or-equal-than comparison between a NegativeAccuracy object and a floating point value...
Definition: Accuracy.h:404
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:250
Header file for the FalseType type/value trait base class.
#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:81
Header file for the IsDiagonal type trait.
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a dense, N-dimensional matrix type...
Definition: DenseMatrix.h:79
Header file for the implementation of the base template of the DiagonalMatrix.
Constraint on the data type.
Constraint on the data type.
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:507
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2588
BLAZE_ALWAYS_INLINE size_t capacity(const Matrix< MT, SO > &matrix)
Returns the maximum capacity of the matrix.
Definition: Matrix.h:340
BLAZE_ALWAYS_INLINE size_t rows(const Matrix< MT, SO > &matrix)
Returns the current number of rows of the matrix.
Definition: Matrix.h:308
void clear(CompressedMatrix< Type, SO > &m)
Clearing the given compressed matrix.
Definition: CompressedMatrix.h:4926
DisableIf< Or< IsComputation< MT >, IsTransExpr< MT > >, typename ColumnExprTrait< MT >::Type >::Type column(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific column of the given matrix.
Definition: Column.h:107
void UNUSED_PARAMETER(const T1 &)
Suppression of unused parameter warnings.
Definition: Unused.h:81
bool operator>(const NegativeAccuracy< A > &lhs, const T &rhs)
Greater-than comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:366
CompressedMatrix< Type, true > This
Type of this CompressedMatrix instance.
Definition: CompressedMatrix.h:2582
bool operator>=(const NegativeAccuracy< A > &, const T &rhs)
Greater-or-equal-than comparison between a NegativeAccuracy object and a floating point value...
Definition: Accuracy.h:442
#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:116
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:378
#define BLAZE_CONSTRAINT_MUST_BE_SQUARE(T)
Constraint on the data type.In case the given data type T is not a square matrix type, a compilation error is created.
Definition: Square.h:78
void move(CustomMatrix< Type, AF, PF, SO > &dst, CustomMatrix< Type, AF, PF, SO > &src)
Moving the contents of one custom matrix to another.
Definition: CustomMatrix.h:6085
Constraint on the data type.
CompressedMatrix< Type, false > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: CompressedMatrix.h:2584
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:547
Constraint on the data type.
Constraint on the data type.
Header file for the IsSquare type trait.
Constraint on the data type.
Constraint on the data type.
Header file for the DenseSubmatrix class template.
Header file for the DisableIf class template.
BLAZE_ALWAYS_INLINE EnableIf< And< IsIntegral< T >, HasSize< T, 2UL > >, simd_int16_t >::Type loadu(const T *address)
Loads a vector of 2-byte integral values.
Definition: Loadu.h:74
Header file for the DiagonalProxy class.
Header file for the clear shim.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
#define BLAZE_ALWAYS_INLINE
Platform dependent setup of an enforced inline keyword.
Definition: Inline.h:85
Compile time assertion.
void swap(CompressedMatrix< Type, SO > &a, CompressedMatrix< Type, SO > &b)
Swapping the contents of two compressed matrices.
Definition: CompressedMatrix.h:4998
bool isIntact(const CompressedMatrix< Type, SO > &m)
Returns whether the invariants of the given compressed matrix are intact.
Definition: CompressedMatrix.h:4980
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2592
#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:116
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exceptionThis macro encapsulates the default way of Bla...
Definition: Exception.h:331
const DenseIterator< Type, AF > operator+(const DenseIterator< Type, AF > &it, ptrdiff_t inc)
Addition between a DenseIterator and an integral value.
Definition: DenseIterator.h:610
Header file for the DenseMatrix base class.
Header file for the Columns type trait.
Constraint on the data type.
const DenseIterator< Type, AF > operator-(const DenseIterator< Type, AF > &it, ptrdiff_t inc)
Subtraction between a DenseIterator and an integral value.
Definition: DenseIterator.h:642
CompressedMatrix< Type, false > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:2585
Constraints on the storage order of matrix types.
#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:118
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:187
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:532
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2586
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2590
Header file for the EnableIf class template.
Header file for utility functions for dense matrices.
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:527
Header file for the IsNumeric type trait.
const bool spacing
Adding an additional spacing line between two log messages.This setting gives the opportunity to add ...
Definition: Logging.h:70
DisableIf< Or< IsComputation< MT >, IsTransExpr< MT > >, typename RowExprTrait< MT >::Type >::Type row(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific row of the given matrix.
Definition: Row.h:107
BLAZE_ALWAYS_INLINE EnableIf< And< IsIntegral< T >, HasSize< T, 2UL > >, simd_int16_t >::Type loada(const T *address)
Loads a vector of 2-byte integral values.
Definition: Loada.h:77
#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:116
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2587
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:118
#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:116
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2591
Header file for the isDefault shim.
Constraint on the data type.
Constraint on the data type.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_RESIZABLE(T)
Constraint on the data type.In case the given data type T is resizable, i.e. has a 'resize' member fu...
Definition: Resizable.h:118
void swap(DiagonalMatrix< MT, SO, DF > &a, DiagonalMatrix< MT, SO, DF > &b)
Swapping the contents of two matrices.
Definition: DiagonalMatrix.h:256
Header file for all intrinsic functionality.
Header file for the move shim.
SubmatrixExprTrait< MT, unaligned >::Type submatrix(Matrix< MT, SO > &matrix, size_t row, size_t column, size_t m, size_t n)
Creating a view on a specific submatrix of the given matrix.
Definition: Submatrix.h:146
bool operator<(const NegativeAccuracy< A > &lhs, const T &rhs)
Less-than comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:328
#define BLAZE_CONSTRAINT_MUST_BE_RESIZABLE(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:79
Header file for the IsComputation type trait class.
boost::false_type FalseType
Type/value traits base class.The FalseType class is used as base class for type traits and value trai...
Definition: FalseType.h:61
#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:118
bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value. ...
Definition: Accuracy.h:249
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2583
BLAZE_ALWAYS_INLINE size_t columns(const Matrix< MT, SO > &matrix)
Returns the current number of columns of the matrix.
Definition: Matrix.h:324
bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:289
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:237
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2589
#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:116
Header file for exception macros.
boost::true_type TrueType
Type traits base class.The TrueType class is used as base class for type traits and value traits that...
Definition: TrueType.h:61
#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:143
Header file for the IsResizable type trait.
System settings for the inline keywords.
#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
Header file for the TrueType type/value trait base class.