Dense.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_ADAPTORS_UPPERMATRIX_DENSE_H_
36 #define _BLAZE_MATH_ADAPTORS_UPPERMATRIX_DENSE_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
57 #include <blaze/math/Intrinsics.h>
58 #include <blaze/math/shims/Clear.h>
60 #include <blaze/math/shims/Move.h>
69 #include <blaze/system/Inline.h>
70 #include <blaze/util/Assert.h>
76 #include <blaze/util/DisableIf.h>
77 #include <blaze/util/EnableIf.h>
78 #include <blaze/util/Exception.h>
79 #include <blaze/util/FalseType.h>
81 #include <blaze/util/TrueType.h>
82 #include <blaze/util/Types.h>
84 #include <blaze/util/Unused.h>
85 
86 
87 namespace blaze {
88 
89 //=================================================================================================
90 //
91 // CLASS TEMPLATE SPECIALIZATION FOR DENSE MATRICES
92 //
93 //=================================================================================================
94 
95 //*************************************************************************************************
103 template< typename MT // Type of the adapted dense matrix
104  , bool SO > // Storage order of the adapted dense matrix
105 class UpperMatrix<MT,SO,true>
106  : public DenseMatrix< UpperMatrix<MT,SO,true>, SO >
107 {
108  private:
109  //**Type definitions****************************************************************************
110  typedef typename MT::OppositeType OT;
111  typedef typename MT::TransposeType TT;
112  typedef typename MT::ElementType ET;
113  typedef IntrinsicTrait<ET> IT;
114  //**********************************************************************************************
115 
116  public:
117  //**Type definitions****************************************************************************
118  typedef UpperMatrix<MT,SO,true> This;
119  typedef This ResultType;
120  typedef UpperMatrix<OT,!SO,true> OppositeType;
121  typedef LowerMatrix<TT,!SO,true> TransposeType;
122  typedef ET ElementType;
123  typedef typename MT::IntrinsicType IntrinsicType;
124  typedef typename MT::ReturnType ReturnType;
125  typedef const This& CompositeType;
126  typedef UpperProxy<MT> Reference;
127  typedef typename MT::ConstReference ConstReference;
128  typedef typename MT::Pointer Pointer;
129  typedef typename MT::ConstPointer ConstPointer;
130  typedef typename MT::ConstIterator ConstIterator;
131  //**********************************************************************************************
132 
133  //**Rebind struct definition********************************************************************
136  template< typename ET > // Data type of the other matrix
137  struct Rebind {
139  typedef UpperMatrix< typename MT::template Rebind<ET>::Other > Other;
140  };
141  //**********************************************************************************************
142 
143  //**Iterator class definition*******************************************************************
146  class Iterator
147  {
148  public:
149  //**Type definitions*************************************************************************
150  typedef std::random_access_iterator_tag IteratorCategory;
151  typedef typename MT::ElementType ValueType;
152  typedef UpperProxy<MT> PointerType;
153  typedef UpperProxy<MT> ReferenceType;
154  typedef ptrdiff_t DifferenceType;
155 
156  // STL iterator requirements
157  typedef IteratorCategory iterator_category;
158  typedef ValueType value_type;
159  typedef PointerType pointer;
160  typedef ReferenceType reference;
161  typedef DifferenceType difference_type;
162  //*******************************************************************************************
163 
164  //**Constructor******************************************************************************
167  inline Iterator()
168  : matrix_( NULL ) // Reference to the adapted dense matrix
169  , row_ ( 0UL ) // The current row index of the iterator
170  , column_( 0UL ) // The current column index of the iterator
171  {}
172  //*******************************************************************************************
173 
174  //**Constructor******************************************************************************
181  inline Iterator( MT& matrix, size_t row, size_t column )
182  : matrix_( &matrix ) // Reference to the adapted dense matrix
183  , row_ ( row ) // The current row-index of the iterator
184  , column_( column ) // The current column-index of the iterator
185  {}
186  //*******************************************************************************************
187 
188  //**Addition assignment operator*************************************************************
194  inline Iterator& operator+=( size_t inc ) {
195  ( SO )?( row_ += inc ):( column_ += inc );
196  return *this;
197  }
198  //*******************************************************************************************
199 
200  //**Subtraction assignment operator**********************************************************
206  inline Iterator& operator-=( size_t dec ) {
207  ( SO )?( row_ -= dec ):( column_ -= dec );
208  return *this;
209  }
210  //*******************************************************************************************
211 
212  //**Prefix increment operator****************************************************************
217  inline Iterator& operator++() {
218  ( SO )?( ++row_ ):( ++column_ );
219  return *this;
220  }
221  //*******************************************************************************************
222 
223  //**Postfix increment operator***************************************************************
228  inline const Iterator operator++( int ) {
229  const Iterator tmp( *this );
230  ++(*this);
231  return tmp;
232  }
233  //*******************************************************************************************
234 
235  //**Prefix decrement operator****************************************************************
240  inline Iterator& operator--() {
241  ( SO )?( --row_ ):( --column_ );
242  return *this;
243  }
244  //*******************************************************************************************
245 
246  //**Postfix decrement operator***************************************************************
251  inline const Iterator operator--( int ) {
252  const Iterator tmp( *this );
253  --(*this);
254  return tmp;
255  }
256  //*******************************************************************************************
257 
258  //**Element access operator******************************************************************
263  inline ReferenceType operator*() const {
264  return ReferenceType( *matrix_, row_, column_ );
265  }
266  //*******************************************************************************************
267 
268  //**Element access operator******************************************************************
273  inline PointerType operator->() const {
274  return PointerType( *matrix_, row_, column_ );
275  }
276  //*******************************************************************************************
277 
278  //**Conversion operator**********************************************************************
283  inline operator ConstIterator() const {
284  if( SO )
285  return matrix_->begin( column_ ) + row_;
286  else
287  return matrix_->begin( row_ ) + column_;
288  }
289  //*******************************************************************************************
290 
291  //**Equality operator************************************************************************
298  friend inline bool operator==( const Iterator& lhs, const Iterator& rhs ) {
299  return ( SO )?( lhs.row_ == rhs.row_ ):( lhs.column_ == rhs.column_ );
300  }
301  //*******************************************************************************************
302 
303  //**Equality operator************************************************************************
310  friend inline bool operator==( const Iterator& lhs, const ConstIterator& rhs ) {
311  return ( ConstIterator( lhs ) == rhs );
312  }
313  //*******************************************************************************************
314 
315  //**Equality operator************************************************************************
322  friend inline bool operator==( const ConstIterator& lhs, const Iterator& rhs ) {
323  return ( lhs == ConstIterator( rhs ) );
324  }
325  //*******************************************************************************************
326 
327  //**Inequality operator**********************************************************************
334  friend inline bool operator!=( const Iterator& lhs, const Iterator& rhs ) {
335  return ( SO )?( lhs.row_ != rhs.row_ ):( lhs.column_ != rhs.column_ );
336  }
337  //*******************************************************************************************
338 
339  //**Inequality operator**********************************************************************
346  friend inline bool operator!=( const Iterator& lhs, const ConstIterator& rhs ) {
347  return ( ConstIterator( lhs ) != rhs );
348  }
349  //*******************************************************************************************
350 
351  //**Inequality operator**********************************************************************
358  friend inline bool operator!=( const ConstIterator& lhs, const Iterator& rhs ) {
359  return ( lhs != ConstIterator( rhs ) );
360  }
361  //*******************************************************************************************
362 
363  //**Less-than operator***********************************************************************
370  friend inline bool operator<( const Iterator& lhs, const Iterator& rhs ) {
371  return ( SO )?( lhs.row_ < rhs.row_ ):( lhs.column_ < rhs.column_ );
372  }
373  //*******************************************************************************************
374 
375  //**Less-than operator***********************************************************************
382  friend inline bool operator<( const Iterator& lhs, const ConstIterator& rhs ) {
383  return ( ConstIterator( lhs ) < rhs );
384  }
385  //*******************************************************************************************
386 
387  //**Less-than operator***********************************************************************
394  friend inline bool operator<( const ConstIterator& lhs, const Iterator& rhs ) {
395  return ( lhs < ConstIterator( rhs ) );
396  }
397  //*******************************************************************************************
398 
399  //**Greater-than operator********************************************************************
406  friend inline bool operator>( const Iterator& lhs, const Iterator& rhs ) {
407  return ( SO )?( lhs.row_ > rhs.row_ ):( lhs.column_ > rhs.column_ );
408  }
409  //*******************************************************************************************
410 
411  //**Greater-than operator********************************************************************
418  friend inline bool operator>( const Iterator& lhs, const ConstIterator& rhs ) {
419  return ( ConstIterator( lhs ) > rhs );
420  }
421  //*******************************************************************************************
422 
423  //**Greater-than operator********************************************************************
430  friend inline bool operator>( const ConstIterator& lhs, const Iterator& rhs ) {
431  return ( lhs > ConstIterator( rhs ) );
432  }
433  //*******************************************************************************************
434 
435  //**Less-or-equal-than operator**************************************************************
442  friend inline bool operator<=( const Iterator& lhs, const Iterator& rhs ) {
443  return ( SO )?( lhs.row_ <= rhs.row_ ):( lhs.column_ <= rhs.column_ );
444  }
445  //*******************************************************************************************
446 
447  //**Less-or-equal-than operator**************************************************************
454  friend inline bool operator<=( const Iterator& lhs, const ConstIterator& rhs ) {
455  return ( ConstIterator( lhs ) <= rhs );
456  }
457  //*******************************************************************************************
458 
459  //**Less-or-equal-than operator**************************************************************
466  friend inline bool operator<=( const ConstIterator& lhs, const Iterator& rhs ) {
467  return ( lhs <= ConstIterator( rhs ) );
468  }
469  //*******************************************************************************************
470 
471  //**Greater-or-equal-than operator***********************************************************
478  friend inline bool operator>=( const Iterator& lhs, const Iterator& rhs ) {
479  return ( SO )?( lhs.row_ >= rhs.row_ ):( lhs.column_ >= rhs.column_ );
480  }
481  //*******************************************************************************************
482 
483  //**Greater-or-equal-than operator***********************************************************
490  friend inline bool operator>=( const Iterator& lhs, const ConstIterator& rhs ) {
491  return ( ConstIterator( lhs ) >= rhs );
492  }
493  //*******************************************************************************************
494 
495  //**Greater-or-equal-than operator***********************************************************
502  friend inline bool operator>=( const ConstIterator& lhs, const Iterator& rhs ) {
503  return ( lhs >= ConstIterator( rhs ) );
504  }
505  //*******************************************************************************************
506 
507  //**Subtraction operator*********************************************************************
513  inline DifferenceType operator-( const Iterator& rhs ) const {
514  return ( SO )?( row_ - rhs.row_ ):( column_ - rhs.column_ );
515  }
516  //*******************************************************************************************
517 
518  //**Addition operator************************************************************************
525  friend inline const Iterator operator+( const Iterator& it, size_t inc ) {
526  if( SO )
527  return Iterator( *it.matrix_, it.row_ + inc, it.column_ );
528  else
529  return Iterator( *it.matrix_, it.row_, it.column_ + inc );
530  }
531  //*******************************************************************************************
532 
533  //**Addition operator************************************************************************
540  friend inline const Iterator operator+( size_t inc, const Iterator& it ) {
541  if( SO )
542  return Iterator( *it.matrix_, it.row_ + inc, it.column_ );
543  else
544  return Iterator( *it.matrix_, it.row_, it.column_ + inc );
545  }
546  //*******************************************************************************************
547 
548  //**Subtraction operator*********************************************************************
555  friend inline const Iterator operator-( const Iterator& it, size_t dec ) {
556  if( SO )
557  return Iterator( *it.matrix_, it.row_ - dec, it.column_ );
558  else
559  return Iterator( *it.matrix_, it.row_, it.column_ - dec );
560  }
561  //*******************************************************************************************
562 
563  private:
564  //**Member variables*************************************************************************
565  MT* matrix_;
566  size_t row_;
567  size_t column_;
568  //*******************************************************************************************
569  };
570  //**********************************************************************************************
571 
572  //**Compilation flags***************************************************************************
574  enum { vectorizable = MT::vectorizable };
575 
577  enum { smpAssignable = MT::smpAssignable };
578  //**********************************************************************************************
579 
580  //**Constructors********************************************************************************
583  explicit inline UpperMatrix();
584  template< typename A1 > explicit inline UpperMatrix( const A1& a1 );
585  explicit inline UpperMatrix( size_t n, const ElementType& init );
586 
587  explicit inline UpperMatrix( ElementType* ptr, size_t n );
588  explicit inline UpperMatrix( ElementType* ptr, size_t n, size_t nn );
589 
590  template< typename Deleter >
591  explicit inline UpperMatrix( ElementType* ptr, size_t n, Deleter d );
592 
593  template< typename Deleter >
594  explicit inline UpperMatrix( ElementType* ptr, size_t n, size_t nn, Deleter d );
595 
596  inline UpperMatrix( const UpperMatrix& m );
598  //**********************************************************************************************
599 
600  //**Destructor**********************************************************************************
601  // No explicitly declared destructor.
602  //**********************************************************************************************
603 
604  //**Data access functions***********************************************************************
607  inline Reference operator()( size_t i, size_t j );
608  inline ConstReference operator()( size_t i, size_t j ) const;
609  inline Reference at( size_t i, size_t j );
610  inline ConstReference at( size_t i, size_t j ) const;
611  inline ConstPointer data () const;
612  inline ConstPointer data ( size_t i ) const;
613  inline Iterator begin ( size_t i );
614  inline ConstIterator begin ( size_t i ) const;
615  inline ConstIterator cbegin( size_t i ) const;
616  inline Iterator end ( size_t i );
617  inline ConstIterator end ( size_t i ) const;
618  inline ConstIterator cend ( size_t i ) const;
620  //**********************************************************************************************
621 
622  //**Assignment operators************************************************************************
625  inline UpperMatrix& operator=( const ElementType& rhs );
626  inline UpperMatrix& operator=( const UpperMatrix& rhs );
627 
628  template< typename MT2, bool SO2 >
629  inline typename DisableIf< IsComputation<MT2>, UpperMatrix& >::Type
630  operator=( const Matrix<MT2,SO2>& rhs );
631 
632  template< typename MT2, bool SO2 >
633  inline typename EnableIf< IsComputation<MT2>, UpperMatrix& >::Type
634  operator=( const Matrix<MT2,SO2>& rhs );
635 
636  template< typename MT2, bool SO2 >
637  inline typename DisableIf< IsComputation<MT2>, UpperMatrix& >::Type
638  operator+=( const Matrix<MT2,SO2>& rhs );
639 
640  template< typename MT2, bool SO2 >
641  inline typename EnableIf< IsComputation<MT2>, UpperMatrix& >::Type
642  operator+=( const Matrix<MT2,SO2>& rhs );
643 
644  template< typename MT2, bool SO2 >
645  inline typename DisableIf< IsComputation<MT2>, UpperMatrix& >::Type
646  operator-=( const Matrix<MT2,SO2>& rhs );
647 
648  template< typename MT2, bool SO2 >
649  inline typename EnableIf< IsComputation<MT2>, UpperMatrix& >::Type
650  operator-=( const Matrix<MT2,SO2>& rhs );
651 
652  template< typename MT2, bool SO2 >
653  inline UpperMatrix& operator*=( const Matrix<MT2,SO2>& rhs );
654 
655  template< typename Other >
656  inline typename EnableIf< IsNumeric<Other>, UpperMatrix >::Type&
657  operator*=( Other rhs );
658 
659  template< typename Other >
660  inline typename EnableIf< IsNumeric<Other>, UpperMatrix >::Type&
661  operator/=( Other rhs );
663  //**********************************************************************************************
664 
665  //**Utility functions***************************************************************************
668  inline size_t rows() const;
669  inline size_t columns() const;
670  inline size_t spacing() const;
671  inline size_t capacity() const;
672  inline size_t capacity( size_t i ) const;
673  inline size_t nonZeros() const;
674  inline size_t nonZeros( size_t i ) const;
675  inline void reset();
676  inline void reset( size_t i );
677  inline void clear();
678  void resize ( size_t n, bool preserve=true );
679  inline void extend ( size_t n, bool preserve=true );
680  inline void reserve( size_t elements );
681  template< typename Other > inline UpperMatrix& scale( const Other& scalar );
682  inline void swap( UpperMatrix& m ) /* throw() */;
683 
684  static inline size_t maxNonZeros();
685  static inline size_t maxNonZeros( size_t n );
687  //**********************************************************************************************
688 
689  //**Debugging functions*************************************************************************
692  inline bool isIntact() const;
694  //**********************************************************************************************
695 
696  //**Expression template evaluation functions****************************************************
699  template< typename Other > inline bool canAlias ( const Other* alias ) const;
700  template< typename Other > inline bool isAliased( const Other* alias ) const;
701 
702  inline bool isAligned () const;
703  inline bool canSMPAssign() const;
704 
705  BLAZE_ALWAYS_INLINE IntrinsicType load ( size_t i, size_t j ) const;
706  BLAZE_ALWAYS_INLINE IntrinsicType loada( size_t i, size_t j ) const;
707  BLAZE_ALWAYS_INLINE IntrinsicType loadu( size_t i, size_t j ) const;
709  //**********************************************************************************************
710 
711  private:
712  //**Construction functions**********************************************************************
715  inline const MT construct( size_t n , TrueType );
716  inline const MT construct( const ElementType& value, FalseType );
717 
718  template< typename MT2, bool SO2, typename T >
719  inline const MT construct( const Matrix<MT2,SO2>& m, T );
721  //**********************************************************************************************
722 
723  //**Member variables****************************************************************************
726  MT matrix_;
727 
728  //**********************************************************************************************
729 
730  //**Friend declarations*************************************************************************
731  template< typename MT2, bool SO2, bool DF2 >
732  friend bool isDefault( const UpperMatrix<MT2,SO2,DF2>& m );
733 
734  template< typename MT2, bool SO2, bool DF2 >
735  friend MT2& derestrict( UpperMatrix<MT2,SO2,DF2>& m );
736  //**********************************************************************************************
737 
738  //**Compile time checks*************************************************************************
751  BLAZE_STATIC_ASSERT( Rows<MT>::value == Columns<MT>::value );
752  //**********************************************************************************************
753 };
755 //*************************************************************************************************
756 
757 
758 
759 
760 //=================================================================================================
761 //
762 // CONSTRUCTORS
763 //
764 //=================================================================================================
765 
766 //*************************************************************************************************
770 template< typename MT // Type of the adapted dense matrix
771  , bool SO > // Storage order of the adapted dense matrix
772 inline UpperMatrix<MT,SO,true>::UpperMatrix()
773  : matrix_() // The adapted dense matrix
774 {
775  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square upper matrix detected" );
776  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
777 }
779 //*************************************************************************************************
780 
781 
782 //*************************************************************************************************
800 template< typename MT // Type of the adapted dense matrix
801  , bool SO > // Storage order of the adapted dense matrix
802 template< typename A1 > // Type of the constructor argument
803 inline UpperMatrix<MT,SO,true>::UpperMatrix( const A1& a1 )
804  : matrix_( construct( a1, typename IsResizable<MT>::Type() ) ) // The adapted dense matrix
805 {
806  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square upper matrix detected" );
807  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
808 }
810 //*************************************************************************************************
811 
812 
813 //*************************************************************************************************
820 template< typename MT // Type of the adapted dense matrix
821  , bool SO > // Storage order of the adapted dense matrix
822 inline UpperMatrix<MT,SO,true>::UpperMatrix( size_t n, const ElementType& init )
823  : matrix_( n, n, ElementType() ) // The adapted dense matrix
824 {
826 
827  if( SO ) {
828  for( size_t j=0UL; j<columns(); ++j )
829  for( size_t i=0UL; i<=j; ++i )
830  matrix_(i,j) = init;
831  }
832  else {
833  for( size_t i=0UL; i<rows(); ++i )
834  for( size_t j=i; j<columns(); ++j )
835  matrix_(i,j) = init;
836  }
837 
838  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square upper matrix detected" );
839  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
840 }
842 //*************************************************************************************************
843 
844 
845 //*************************************************************************************************
866 template< typename MT // Type of the adapted dense matrix
867  , bool SO > // Storage order of the adapted dense matrix
868 inline UpperMatrix<MT,SO,true>::UpperMatrix( ElementType* ptr, size_t n )
869  : matrix_( ptr, n, n ) // The adapted dense matrix
870 {
871  if( !isUpper( matrix_ ) ) {
872  BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of upper matrix" );
873  }
874 
875  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
876 }
878 //*************************************************************************************************
879 
880 
881 //*************************************************************************************************
904 template< typename MT // Type of the adapted dense matrix
905  , bool SO > // Storage order of the adapted dense matrix
906 inline UpperMatrix<MT,SO,true>::UpperMatrix( ElementType* ptr, size_t n, size_t nn )
907  : matrix_( ptr, n, n, nn ) // The adapted dense matrix
908 {
909  if( !isUpper( matrix_ ) ) {
910  BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of upper matrix" );
911  }
912 
913  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
914 }
916 //*************************************************************************************************
917 
918 
919 //*************************************************************************************************
940 template< typename MT // Type of the adapted dense matrix
941  , bool SO > // Storage order of the adapted dense matrix
942 template< typename Deleter > // Type of the custom deleter
943 inline UpperMatrix<MT,SO,true>::UpperMatrix( ElementType* ptr, size_t n, Deleter d )
944  : matrix_( ptr, n, n, d ) // The adapted dense matrix
945 {
946  if( !isUpper( matrix_ ) ) {
947  BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of upper matrix" );
948  }
949 
950  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
951 }
953 //*************************************************************************************************
954 
955 
956 //*************************************************************************************************
978 template< typename MT // Type of the adapted dense matrix
979  , bool SO > // Storage order of the adapted dense matrix
980 template< typename Deleter > // Type of the custom deleter
981 inline UpperMatrix<MT,SO,true>::UpperMatrix( ElementType* ptr, size_t n, size_t nn, Deleter d )
982  : matrix_( ptr, n, n, nn, d ) // The adapted dense matrix
983 {
984  if( !isUpper( matrix_ ) ) {
985  BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of upper matrix" );
986  }
987 
988  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
989 }
991 //*************************************************************************************************
992 
993 
994 //*************************************************************************************************
1000 template< typename MT // Type of the adapted dense matrix
1001  , bool SO > // Storage order of the adapted dense matrix
1002 inline UpperMatrix<MT,SO,true>::UpperMatrix( const UpperMatrix& m )
1003  : matrix_( m.matrix_ ) // The adapted dense matrix
1004 {
1005  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square upper matrix detected" );
1006  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1007 }
1009 //*************************************************************************************************
1010 
1011 
1012 
1013 
1014 //=================================================================================================
1015 //
1016 // DATA ACCESS FUNCTIONS
1017 //
1018 //=================================================================================================
1019 
1020 //*************************************************************************************************
1036 template< typename MT // Type of the adapted dense matrix
1037  , bool SO > // Storage order of the adapted dense matrix
1038 inline typename UpperMatrix<MT,SO,true>::Reference
1039  UpperMatrix<MT,SO,true>::operator()( size_t i, size_t j )
1040 {
1041  BLAZE_USER_ASSERT( i<rows() , "Invalid row access index" );
1042  BLAZE_USER_ASSERT( j<columns(), "Invalid column access index" );
1043 
1044  return Reference( matrix_, i, j );
1045 }
1047 //*************************************************************************************************
1048 
1049 
1050 //*************************************************************************************************
1066 template< typename MT // Type of the adapted dense matrix
1067  , bool SO > // Storage order of the adapted dense matrix
1069  UpperMatrix<MT,SO,true>::operator()( size_t i, size_t j ) const
1070 {
1071  BLAZE_USER_ASSERT( i<rows() , "Invalid row access index" );
1072  BLAZE_USER_ASSERT( j<columns(), "Invalid column access index" );
1073 
1074  return matrix_(i,j);
1075 }
1077 //*************************************************************************************************
1078 
1079 
1080 //*************************************************************************************************
1097 template< typename MT // Type of the adapted dense matrix
1098  , bool SO > // Storage order of the adapted dense matrix
1099 inline typename UpperMatrix<MT,SO,true>::Reference
1100  UpperMatrix<MT,SO,true>::at( size_t i, size_t j )
1101 {
1102  if( i >= rows() ) {
1103  BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
1104  }
1105  if( j >= columns() ) {
1106  BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
1107  }
1108  return (*this)(i,j);
1109 }
1111 //*************************************************************************************************
1112 
1113 
1114 //*************************************************************************************************
1131 template< typename MT // Type of the adapted dense matrix
1132  , bool SO > // Storage order of the adapted dense matrix
1134  UpperMatrix<MT,SO,true>::at( size_t i, size_t j ) const
1135 {
1136  if( i >= rows() ) {
1137  BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
1138  }
1139  if( j >= columns() ) {
1140  BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
1141  }
1142  return (*this)(i,j);
1143 }
1145 //*************************************************************************************************
1146 
1147 
1148 //*************************************************************************************************
1161 template< typename MT // Type of the adapted dense matrix
1162  , bool SO > // Storage order of the adapted dense matrix
1163 inline typename UpperMatrix<MT,SO,true>::ConstPointer
1164  UpperMatrix<MT,SO,true>::data() const
1165 {
1166  return matrix_.data();
1167 }
1169 //*************************************************************************************************
1170 
1171 
1172 //*************************************************************************************************
1181 template< typename MT // Type of the adapted dense matrix
1182  , bool SO > // Storage order of the adapted dense matrix
1183 inline typename UpperMatrix<MT,SO,true>::ConstPointer
1184  UpperMatrix<MT,SO,true>::data( size_t i ) const
1185 {
1186  return matrix_.data(i);
1187 }
1189 //*************************************************************************************************
1190 
1191 
1192 //*************************************************************************************************
1204 template< typename MT // Type of the adapted dense matrix
1205  , bool SO > // Storage order of the adapted dense matrix
1206 inline typename UpperMatrix<MT,SO,true>::Iterator
1207  UpperMatrix<MT,SO,true>::begin( size_t i )
1208 {
1209  if( SO )
1210  return Iterator( matrix_, 0UL, i );
1211  else
1212  return Iterator( matrix_, i, 0UL );
1213 }
1215 //*************************************************************************************************
1216 
1217 
1218 //*************************************************************************************************
1230 template< typename MT // Type of the adapted dense matrix
1231  , bool SO > // Storage order of the adapted dense matrix
1233  UpperMatrix<MT,SO,true>::begin( size_t i ) const
1234 {
1235  return matrix_.begin(i);
1236 }
1238 //*************************************************************************************************
1239 
1240 
1241 //*************************************************************************************************
1253 template< typename MT // Type of the adapted dense matrix
1254  , bool SO > // Storage order of the adapted dense matrix
1256  UpperMatrix<MT,SO,true>::cbegin( size_t i ) const
1257 {
1258  return matrix_.cbegin(i);
1259 }
1261 //*************************************************************************************************
1262 
1263 
1264 //*************************************************************************************************
1276 template< typename MT // Type of the adapted dense matrix
1277  , bool SO > // Storage order of the adapted dense matrix
1278 inline typename UpperMatrix<MT,SO,true>::Iterator
1279  UpperMatrix<MT,SO,true>::end( size_t i )
1280 {
1281  if( SO )
1282  return Iterator( matrix_, rows(), i );
1283  else
1284  return Iterator( matrix_, i, columns() );
1285 }
1287 //*************************************************************************************************
1288 
1289 
1290 //*************************************************************************************************
1302 template< typename MT // Type of the adapted dense matrix
1303  , bool SO > // Storage order of the adapted dense matrix
1305  UpperMatrix<MT,SO,true>::end( size_t i ) const
1306 {
1307  return matrix_.end(i);
1308 }
1310 //*************************************************************************************************
1311 
1312 
1313 //*************************************************************************************************
1325 template< typename MT // Type of the adapted dense matrix
1326  , bool SO > // Storage order of the adapted dense matrix
1328  UpperMatrix<MT,SO,true>::cend( size_t i ) const
1329 {
1330  return matrix_.cend(i);
1331 }
1333 //*************************************************************************************************
1334 
1335 
1336 
1337 
1338 //=================================================================================================
1339 //
1340 // ASSIGNMENT OPERATORS
1341 //
1342 //=================================================================================================
1343 
1344 //*************************************************************************************************
1351 template< typename MT // Type of the adapted dense matrix
1352  , bool SO > // Storage order of the adapted dense matrix
1353 inline UpperMatrix<MT,SO,true>&
1354  UpperMatrix<MT,SO,true>::operator=( const ElementType& rhs )
1355 {
1356  if( SO ) {
1357  for( size_t j=0UL; j<columns(); ++j )
1358  for( size_t i=0UL; i<=j; ++i )
1359  matrix_(i,j) = rhs;
1360  }
1361  else {
1362  for( size_t i=0UL; i<rows(); ++i )
1363  for( size_t j=i; j<columns(); ++j )
1364  matrix_(i,j) = rhs;
1365  }
1366 
1367  return *this;
1368 }
1370 //*************************************************************************************************
1371 
1372 
1373 //*************************************************************************************************
1383 template< typename MT // Type of the adapted dense matrix
1384  , bool SO > // Storage order of the adapted dense matrix
1385 inline UpperMatrix<MT,SO,true>&
1386  UpperMatrix<MT,SO,true>::operator=( const UpperMatrix& rhs )
1387 {
1388  matrix_ = rhs.matrix_;
1389 
1390  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square upper matrix detected" );
1391  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1392 
1393  return *this;
1394 }
1396 //*************************************************************************************************
1397 
1398 
1399 //*************************************************************************************************
1412 template< typename MT // Type of the adapted dense matrix
1413  , bool SO > // Storage order of the adapted dense matrix
1414 template< typename MT2 // Type of the right-hand side matrix
1415  , bool SO2 > // Storage order of the right-hand side matrix
1416 inline typename DisableIf< IsComputation<MT2>, UpperMatrix<MT,SO,true>& >::Type
1417  UpperMatrix<MT,SO,true>::operator=( const Matrix<MT2,SO2>& rhs )
1418 {
1419  if( !IsUpper<MT2>::value && !isUpper( ~rhs ) ) {
1420  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to upper matrix" );
1421  }
1422 
1423  matrix_ = ~rhs;
1424 
1425  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square upper matrix detected" );
1426  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1427 
1428  return *this;
1429 }
1431 //*************************************************************************************************
1432 
1433 
1434 //*************************************************************************************************
1447 template< typename MT // Type of the adapted dense matrix
1448  , bool SO > // Storage order of the adapted dense matrix
1449 template< typename MT2 // Type of the right-hand side matrix
1450  , bool SO2 > // Storage order of the right-hand side matrix
1451 inline typename EnableIf< IsComputation<MT2>, UpperMatrix<MT,SO,true>& >::Type
1452  UpperMatrix<MT,SO,true>::operator=( const Matrix<MT2,SO2>& rhs )
1453 {
1454  if( !IsSquare<MT2>::value && !isSquare( ~rhs ) ) {
1455  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to upper matrix" );
1456  }
1457 
1458  if( IsUpper<MT2>::value ) {
1459  matrix_ = ~rhs;
1460  }
1461  else {
1462  MT tmp( ~rhs );
1463 
1464  if( !isUpper( tmp ) ) {
1465  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to upper matrix" );
1466  }
1467 
1468  move( matrix_, tmp );
1469  }
1470 
1471  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square upper matrix detected" );
1472  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1473 
1474  return *this;
1475 }
1477 //*************************************************************************************************
1478 
1479 
1480 //*************************************************************************************************
1493 template< typename MT // Type of the adapted dense matrix
1494  , bool SO > // Storage order of the adapted dense matrix
1495 template< typename MT2 // Type of the right-hand side matrix
1496  , bool SO2 > // Storage order of the right-hand side matrix
1497 inline typename DisableIf< IsComputation<MT2>, UpperMatrix<MT,SO,true>& >::Type
1498  UpperMatrix<MT,SO,true>::operator+=( const Matrix<MT2,SO2>& rhs )
1499 {
1500  if( !IsUpper<MT2>::value && !isUpper( ~rhs ) ) {
1501  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to upper matrix" );
1502  }
1503 
1504  matrix_ += ~rhs;
1505 
1506  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square upper matrix detected" );
1507  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1508 
1509  return *this;
1510 }
1512 //*************************************************************************************************
1513 
1514 
1515 //*************************************************************************************************
1528 template< typename MT // Type of the adapted dense matrix
1529  , bool SO > // Storage order of the adapted dense matrix
1530 template< typename MT2 // Type of the right-hand side matrix
1531  , bool SO2 > // Storage order of the right-hand side matrix
1532 inline typename EnableIf< IsComputation<MT2>, UpperMatrix<MT,SO,true>& >::Type
1533  UpperMatrix<MT,SO,true>::operator+=( const Matrix<MT2,SO2>& rhs )
1534 {
1535  if( !IsSquare<MT2>::value && !isSquare( ~rhs ) ) {
1536  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to upper matrix" );
1537  }
1538 
1539  if( IsUpper<MT2>::value ) {
1540  matrix_ += ~rhs;
1541  }
1542  else {
1543  typename MT2::ResultType tmp( ~rhs );
1544 
1545  if( !isUpper( tmp ) ) {
1546  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to upper matrix" );
1547  }
1548 
1549  matrix_ += tmp;
1550  }
1551 
1552  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square upper matrix detected" );
1553  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1554 
1555  return *this;
1556 }
1558 //*************************************************************************************************
1559 
1560 
1561 //*************************************************************************************************
1574 template< typename MT // Type of the adapted dense matrix
1575  , bool SO > // Storage order of the adapted dense matrix
1576 template< typename MT2 // Type of the right-hand side matrix
1577  , bool SO2 > // Storage order of the right-hand side matrix
1578 inline typename DisableIf< IsComputation<MT2>, UpperMatrix<MT,SO,true>& >::Type
1579  UpperMatrix<MT,SO,true>::operator-=( const Matrix<MT2,SO2>& rhs )
1580 {
1581  if( !IsUpper<MT2>::value && !isUpper( ~rhs ) ) {
1582  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to upper matrix" );
1583  }
1584 
1585  matrix_ -= ~rhs;
1586 
1587  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square upper matrix detected" );
1588  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1589 
1590  return *this;
1591 }
1593 //*************************************************************************************************
1594 
1595 
1596 //*************************************************************************************************
1609 template< typename MT // Type of the adapted dense matrix
1610  , bool SO > // Storage order of the adapted dense matrix
1611 template< typename MT2 // Type of the right-hand side matrix
1612  , bool SO2 > // Storage order of the right-hand side matrix
1613 inline typename EnableIf< IsComputation<MT2>, UpperMatrix<MT,SO,true>& >::Type
1614  UpperMatrix<MT,SO,true>::operator-=( const Matrix<MT2,SO2>& rhs )
1615 {
1616  if( !IsSquare<MT2>::value && !isSquare( ~rhs ) ) {
1617  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to upper matrix" );
1618  }
1619 
1620  if( IsUpper<MT2>::value ) {
1621  matrix_ -= ~rhs;
1622  }
1623  else {
1624  typename MT2::ResultType tmp( ~rhs );
1625 
1626  if( !isUpper( tmp ) ) {
1627  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to upper matrix" );
1628  }
1629 
1630  matrix_ -= tmp;
1631  }
1632 
1633  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square upper matrix detected" );
1634  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1635 
1636  return *this;
1637 }
1639 //*************************************************************************************************
1640 
1641 
1642 //*************************************************************************************************
1654 template< typename MT // Type of the adapted dense matrix
1655  , bool SO > // Storage order of the adapted dense matrix
1656 template< typename MT2 // Type of the right-hand side matrix
1657  , bool SO2 > // Storage order of the right-hand side matrix
1658 inline UpperMatrix<MT,SO,true>&
1659  UpperMatrix<MT,SO,true>::operator*=( const Matrix<MT2,SO2>& rhs )
1660 {
1661  if( matrix_.rows() != (~rhs).columns() ) {
1662  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to upper matrix" );
1663  }
1664 
1665  MT tmp( matrix_ * ~rhs );
1666 
1667  if( !isUpper( tmp ) ) {
1668  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to upper matrix" );
1669  }
1670 
1671  move( matrix_, tmp );
1672 
1673  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square upper matrix detected" );
1674  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1675 
1676  return *this;
1677 }
1679 //*************************************************************************************************
1680 
1681 
1682 //*************************************************************************************************
1690 template< typename MT // Type of the adapted dense matrix
1691  , bool SO > // Storage order of the adapted dense matrix
1692 template< typename Other > // Data type of the right-hand side scalar
1693 inline typename EnableIf< IsNumeric<Other>, UpperMatrix<MT,SO,true> >::Type&
1694  UpperMatrix<MT,SO,true>::operator*=( Other rhs )
1695 {
1696  matrix_ *= rhs;
1697  return *this;
1698 }
1699 //*************************************************************************************************
1700 
1701 
1702 //*************************************************************************************************
1710 template< typename MT // Type of the adapted dense matrix
1711  , bool SO > // Storage order of the adapted dense matrix
1712 template< typename Other > // Data type of the right-hand side scalar
1713 inline typename EnableIf< IsNumeric<Other>, UpperMatrix<MT,SO,true> >::Type&
1714  UpperMatrix<MT,SO,true>::operator/=( Other rhs )
1715 {
1716  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
1717 
1718  matrix_ /= rhs;
1719  return *this;
1720 }
1722 //*************************************************************************************************
1723 
1724 
1725 
1726 
1727 //=================================================================================================
1728 //
1729 // UTILITY FUNCTIONS
1730 //
1731 //=================================================================================================
1732 
1733 //*************************************************************************************************
1739 template< typename MT // Type of the adapted dense matrix
1740  , bool SO > // Storage order of the adapted dense matrix
1741 inline size_t UpperMatrix<MT,SO,true>::rows() const
1742 {
1743  return matrix_.rows();
1744 }
1746 //*************************************************************************************************
1747 
1748 
1749 //*************************************************************************************************
1755 template< typename MT // Type of the adapted dense matrix
1756  , bool SO > // Storage order of the adapted dense matrix
1757 inline size_t UpperMatrix<MT,SO,true>::columns() const
1758 {
1759  return matrix_.columns();
1760 }
1762 //*************************************************************************************************
1763 
1764 
1765 //*************************************************************************************************
1776 template< typename MT // Type of the adapted dense matrix
1777  , bool SO > // Storage order of the adapted dense matrix
1778 inline size_t UpperMatrix<MT,SO,true>::spacing() const
1779 {
1780  return matrix_.spacing();
1781 }
1783 //*************************************************************************************************
1784 
1785 
1786 //*************************************************************************************************
1792 template< typename MT // Type of the adapted dense matrix
1793  , bool SO > // Storage order of the adapted dense matrix
1794 inline size_t UpperMatrix<MT,SO,true>::capacity() const
1795 {
1796  return matrix_.capacity();
1797 }
1799 //*************************************************************************************************
1800 
1801 
1802 //*************************************************************************************************
1814 template< typename MT // Type of the adapted dense matrix
1815  , bool SO > // Storage order of the adapted dense matrix
1816 inline size_t UpperMatrix<MT,SO,true>::capacity( size_t i ) const
1817 {
1818  return matrix_.capacity(i);
1819 }
1821 //*************************************************************************************************
1822 
1823 
1824 //*************************************************************************************************
1830 template< typename MT // Type of the adapted dense matrix
1831  , bool SO > // Storage order of the adapted dense matrix
1832 inline size_t UpperMatrix<MT,SO,true>::nonZeros() const
1833 {
1834  return matrix_.nonZeros();
1835 }
1837 //*************************************************************************************************
1838 
1839 
1840 //*************************************************************************************************
1852 template< typename MT // Type of the adapted dense matrix
1853  , bool SO > // Storage order of the adapted dense matrix
1854 inline size_t UpperMatrix<MT,SO,true>::nonZeros( size_t i ) const
1855 {
1856  return matrix_.nonZeros(i);
1857 }
1859 //*************************************************************************************************
1860 
1861 
1862 //*************************************************************************************************
1868 template< typename MT // Type of the adapted dense matrix
1869  , bool SO > // Storage order of the adapted dense matrix
1870 inline void UpperMatrix<MT,SO,true>::reset()
1871 {
1872  using blaze::clear;
1873 
1874  if( SO ) {
1875  for( size_t j=0UL; j<columns(); ++j )
1876  for( size_t i=0UL; i<=j; ++i )
1877  clear( matrix_(i,j) );
1878  }
1879  else {
1880  for( size_t i=0UL; i<rows(); ++i )
1881  for( size_t j=i; j<columns(); ++j )
1882  clear( matrix_(i,j) );
1883  }
1884 }
1886 //*************************************************************************************************
1887 
1888 
1889 //*************************************************************************************************
1902 template< typename MT // Type of the adapted dense matrix
1903  , bool SO > // Storage order of the adapted dense matrix
1904 inline void UpperMatrix<MT,SO,true>::reset( size_t i )
1905 {
1906  using blaze::clear;
1907 
1908  if( SO ) {
1909  for( size_t j=0UL; j<=i; ++j )
1910  clear( matrix_(j,i) );
1911  }
1912  else {
1913  for( size_t j=i; j<columns(); ++j )
1914  clear( matrix_(i,j) );
1915  }
1916 }
1918 //*************************************************************************************************
1919 
1920 
1921 //*************************************************************************************************
1933 template< typename MT // Type of the adapted dense matrix
1934  , bool SO > // Storage order of the adapted dense matrix
1935 inline void UpperMatrix<MT,SO,true>::clear()
1936 {
1937  using blaze::clear;
1938 
1939  if( IsResizable<MT>::value ) {
1940  clear( matrix_ );
1941  }
1942  else {
1943  reset();
1944  }
1945 }
1947 //*************************************************************************************************
1948 
1949 
1950 //*************************************************************************************************
1986 template< typename MT // Type of the adapted dense matrix
1987  , bool SO > // Storage order of the adapted dense matrix
1988 void UpperMatrix<MT,SO,true>::resize( size_t n, bool preserve )
1989 {
1991 
1992  UNUSED_PARAMETER( preserve );
1993 
1994  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square upper matrix detected" );
1995 
1996  const size_t oldsize( matrix_.rows() );
1997 
1998  matrix_.resize( n, n, true );
1999 
2000  if( n > oldsize ) {
2001  const size_t increment( n - oldsize );
2002  submatrix( matrix_, oldsize, 0UL, increment, n-1 ).reset();
2003  }
2004 }
2006 //*************************************************************************************************
2007 
2008 
2009 //*************************************************************************************************
2022 template< typename MT // Type of the adapted dense matrix
2023  , bool SO > // Storage order of the adapted dense matrix
2024 inline void UpperMatrix<MT,SO,true>::extend( size_t n, bool preserve )
2025 {
2027 
2028  UNUSED_PARAMETER( preserve );
2029 
2030  resize( rows() + n, true );
2031 }
2032 //*************************************************************************************************
2033 
2034 
2035 //*************************************************************************************************
2045 template< typename MT // Type of the adapted dense matrix
2046  , bool SO > // Storage order of the adapted dense matrix
2047 inline void UpperMatrix<MT,SO,true>::reserve( size_t elements )
2048 {
2049  matrix_.reserve( elements );
2050 }
2052 //*************************************************************************************************
2053 
2054 
2055 //*************************************************************************************************
2062 template< typename MT // Type of the adapted dense matrix
2063  , bool SO > // Storage order of the adapted dense matrix
2064 template< typename Other > // Data type of the scalar value
2065 inline UpperMatrix<MT,SO,true>& UpperMatrix<MT,SO,true>::scale( const Other& scalar )
2066 {
2067  matrix_.scale( scalar );
2068  return *this;
2069 }
2071 //*************************************************************************************************
2072 
2073 
2074 //*************************************************************************************************
2082 template< typename MT // Type of the adapted dense matrix
2083  , bool SO > // Storage order of the adapted dense matrix
2084 inline void UpperMatrix<MT,SO,true>::swap( UpperMatrix& m ) /* throw() */
2085 {
2086  using std::swap;
2087 
2088  swap( matrix_, m.matrix_ );
2089 }
2091 //*************************************************************************************************
2092 
2093 
2094 //*************************************************************************************************
2106 template< typename MT // Type of the adapted dense matrix
2107  , bool SO > // Storage order of the adapted dense matrix
2108 inline size_t UpperMatrix<MT,SO,true>::maxNonZeros()
2109 {
2111 
2112  return maxNonZeros( Rows<MT>::value );
2113 }
2115 //*************************************************************************************************
2116 
2117 
2118 //*************************************************************************************************
2128 template< typename MT // Type of the adapted dense matrix
2129  , bool SO > // Storage order of the adapted dense matrix
2130 inline size_t UpperMatrix<MT,SO,true>::maxNonZeros( size_t n )
2131 {
2132  return ( ( n + 1UL ) * n ) / 2UL;
2133 }
2135 //*************************************************************************************************
2136 
2137 
2138 
2139 
2140 //=================================================================================================
2141 //
2142 // DEBUGGING FUNCTIONS
2143 //
2144 //=================================================================================================
2145 
2146 //*************************************************************************************************
2156 template< typename MT // Type of the adapted dense matrix
2157  , bool SO > // Storage order of the adapted dense matrix
2158 inline bool UpperMatrix<MT,SO,true>::isIntact() const
2159 {
2160  using blaze::isIntact;
2161 
2162  return ( isIntact( matrix_ ) && isUpper( matrix_ ) );
2163 }
2165 //*************************************************************************************************
2166 
2167 
2168 
2169 
2170 //=================================================================================================
2171 //
2172 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
2173 //
2174 //=================================================================================================
2175 
2176 //*************************************************************************************************
2187 template< typename MT // Type of the adapted dense matrix
2188  , bool SO > // Storage order of the adapted dense matrix
2189 template< typename Other > // Data type of the foreign expression
2190 inline bool UpperMatrix<MT,SO,true>::canAlias( const Other* alias ) const
2191 {
2192  return matrix_.canAlias( alias );
2193 }
2195 //*************************************************************************************************
2196 
2197 
2198 //*************************************************************************************************
2209 template< typename MT // Type of the adapted dense matrix
2210  , bool SO > // Storage order of the adapted dense matrix
2211 template< typename Other > // Data type of the foreign expression
2212 inline bool UpperMatrix<MT,SO,true>::isAliased( const Other* alias ) const
2213 {
2214  return matrix_.isAliased( alias );
2215 }
2217 //*************************************************************************************************
2218 
2219 
2220 //*************************************************************************************************
2230 template< typename MT // Type of the adapted dense matrix
2231  , bool SO > // Storage order of the adapted dense matrix
2232 inline bool UpperMatrix<MT,SO,true>::isAligned() const
2233 {
2234  return matrix_.isAligned();
2235 }
2237 //*************************************************************************************************
2238 
2239 
2240 //*************************************************************************************************
2251 template< typename MT // Type of the adapted dense matrix
2252  , bool SO > // Storage order of the adapted dense matrix
2253 inline bool UpperMatrix<MT,SO,true>::canSMPAssign() const
2254 {
2255  return matrix_.canSMPAssign();
2256 }
2258 //*************************************************************************************************
2259 
2260 
2261 //*************************************************************************************************
2277 template< typename MT // Type of the adapted dense matrix
2278  , bool SO > // Storage order of the adapted dense matrix
2279 BLAZE_ALWAYS_INLINE typename UpperMatrix<MT,SO,true>::IntrinsicType
2280  UpperMatrix<MT,SO,true>::load( size_t i, size_t j ) const
2281 {
2282  return matrix_.load( i, j );
2283 }
2285 //*************************************************************************************************
2286 
2287 
2288 //*************************************************************************************************
2304 template< typename MT // Type of the adapted dense matrix
2305  , bool SO > // Storage order of the adapted dense matrix
2306 BLAZE_ALWAYS_INLINE typename UpperMatrix<MT,SO,true>::IntrinsicType
2307  UpperMatrix<MT,SO,true>::loada( size_t i, size_t j ) const
2308 {
2309  return matrix_.loada( i, j );
2310 }
2312 //*************************************************************************************************
2313 
2314 
2315 //*************************************************************************************************
2331 template< typename MT // Type of the adapted dense matrix
2332  , bool SO > // Storage order of the adapted dense matrix
2333 BLAZE_ALWAYS_INLINE typename UpperMatrix<MT,SO,true>::IntrinsicType
2334  UpperMatrix<MT,SO,true>::loadu( size_t i, size_t j ) const
2335 {
2336  return matrix_.loadu( i, j );
2337 }
2339 //*************************************************************************************************
2340 
2341 
2342 
2343 
2344 //=================================================================================================
2345 //
2346 // CONSTRUCTION FUNCTIONS
2347 //
2348 //=================================================================================================
2349 
2350 //*************************************************************************************************
2357 template< typename MT // Type of the adapted dense matrix
2358  , bool SO > // Storage order of the adapted dense matrix
2359 inline const MT UpperMatrix<MT,SO,true>::construct( size_t n, TrueType )
2360 {
2362 
2363  return MT( n, n, ElementType() );
2364 }
2366 //*************************************************************************************************
2367 
2368 
2369 //*************************************************************************************************
2376 template< typename MT // Type of the adapted dense matrix
2377  , bool SO > // Storage order of the adapted dense matrix
2378 inline const MT UpperMatrix<MT,SO,true>::construct( const ElementType& init, FalseType )
2379 {
2382 
2383  MT tmp;
2384 
2385  if( SO ) {
2386  for( size_t j=0UL; j<columns(); ++j )
2387  for( size_t i=0UL; i<=j; ++i )
2388  tmp(i,j) = init;
2389  }
2390  else {
2391  for( size_t i=0UL; i<rows(); ++i )
2392  for( size_t j=i; j<columns(); ++j )
2393  tmp(i,j) = init;
2394  }
2395 
2396  return tmp;
2397 }
2399 //*************************************************************************************************
2400 
2401 
2402 //*************************************************************************************************
2413 template< typename MT // Type of the adapted dense matrix
2414  , bool SO > // Storage order of the adapted dense matrix
2415 template< typename MT2 // Type of the foreign matrix
2416  , bool SO2 // Storage order of the foreign matrix
2417  , typename T > // Type of the third argument
2418 inline const MT UpperMatrix<MT,SO,true>::construct( const Matrix<MT2,SO2>& m, T )
2419 {
2420  const MT tmp( ~m );
2421 
2422  if( !IsUpper<MT2>::value && !isUpper( tmp ) ) {
2423  BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of upper matrix" );
2424  }
2425 
2426  return tmp;
2427 }
2429 //*************************************************************************************************
2430 
2431 } // namespace blaze
2432 
2433 #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
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
#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
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 implementation of the base template of the UpperMatrix.
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 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
bool isUpper(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is an upper triangular matrix.
Definition: DenseMatrix.h:1277
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
Header file for the UpperProxy class.
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.
Header file for all adaptor forward declarations.
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 the IsUpper type trait.
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.