DenseNumeric.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_ADAPTORS_SYMMETRICMATRIX_DENSENUMERIC_H_
36 #define _BLAZE_MATH_ADAPTORS_SYMMETRICMATRIX_DENSENUMERIC_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <algorithm>
44 #include <iterator>
58 #include <blaze/math/Functions.h>
59 #include <blaze/math/Intrinsics.h>
60 #include <blaze/math/shims/Clear.h>
62 #include <blaze/math/shims/Move.h>
72 #include <blaze/math/views/Row.h>
74 #include <blaze/system/Inline.h>
75 #include <blaze/util/Assert.h>
81 #include <blaze/util/DisableIf.h>
82 #include <blaze/util/EnableIf.h>
83 #include <blaze/util/Exception.h>
84 #include <blaze/util/mpl/If.h>
86 #include <blaze/util/Types.h>
89 #include <blaze/util/Unused.h>
90 
91 
92 namespace blaze {
93 
94 //=================================================================================================
95 //
96 // CLASS TEMPLATE SPECIALIZATION FOR DENSE MATRICES WITH NUMERIC ELEMENT TYPE
97 //
98 //=================================================================================================
99 
100 //*************************************************************************************************
108 template< typename MT // Type of the adapted dense matrix
109  , bool SO > // Storage order of the adapted dense matrix
110 class SymmetricMatrix<MT,SO,true,true>
111  : public DenseMatrix< SymmetricMatrix<MT,SO,true,true>, SO >
112 {
113  private:
114  //**Type definitions****************************************************************************
115  typedef typename MT::OppositeType OT;
116  typedef typename MT::TransposeType TT;
117  typedef typename MT::ElementType ET;
118  typedef IntrinsicTrait<ET> IT;
119  //**********************************************************************************************
120 
121  public:
122  //**Type definitions****************************************************************************
123  typedef SymmetricMatrix<MT,SO,true,true> This;
124  typedef This ResultType;
125  typedef SymmetricMatrix<OT,!SO,true,true> OppositeType;
126  typedef SymmetricMatrix<TT,!SO,true,true> TransposeType;
127  typedef ET ElementType;
128  typedef typename MT::IntrinsicType IntrinsicType;
129  typedef typename MT::ReturnType ReturnType;
130  typedef const This& CompositeType;
131  typedef NumericProxy<MT> Reference;
132  typedef typename MT::ConstReference ConstReference;
133  typedef typename MT::Pointer Pointer;
134  typedef typename MT::ConstPointer ConstPointer;
135  typedef typename MT::ConstIterator ConstIterator;
136  //**********************************************************************************************
137 
138  //**Rebind struct definition********************************************************************
141  template< typename ET > // Data type of the other matrix
142  struct Rebind {
144  typedef SymmetricMatrix< typename MT::template Rebind<ET>::Other > Other;
145  };
146  //**********************************************************************************************
147 
148  //**Iterator class definition*******************************************************************
151  class Iterator
152  {
153  public:
154  //**Type definitions*************************************************************************
155  typedef std::random_access_iterator_tag IteratorCategory;
156  typedef typename MT::ElementType ValueType;
157  typedef NumericProxy<MT> PointerType;
158  typedef NumericProxy<MT> ReferenceType;
159  typedef ptrdiff_t DifferenceType;
160 
161  // STL iterator requirements
162  typedef IteratorCategory iterator_category;
163  typedef ValueType value_type;
164  typedef PointerType pointer;
165  typedef ReferenceType reference;
166  typedef DifferenceType difference_type;
167  //*******************************************************************************************
168 
169  //**Constructor******************************************************************************
172  inline Iterator()
173  : matrix_( NULL ) // Reference to the adapted dense matrix
174  , row_ ( 0UL ) // The current row index of the iterator
175  , column_( 0UL ) // The current column index of the iterator
176  {}
177  //*******************************************************************************************
178 
179  //**Constructor******************************************************************************
186  inline Iterator( MT& matrix, size_t row, size_t column )
187  : matrix_( &matrix ) // Reference to the adapted dense matrix
188  , row_ ( row ) // The current row index of the iterator
189  , column_( column ) // The current column index of the iterator
190  {}
191  //*******************************************************************************************
192 
193  //**Addition assignment operator*************************************************************
199  inline Iterator& operator+=( size_t inc ) {
200  ( SO )?( row_ += inc ):( column_ += inc );
201  return *this;
202  }
203  //*******************************************************************************************
204 
205  //**Subtraction assignment operator**********************************************************
211  inline Iterator& operator-=( size_t dec ) {
212  ( SO )?( row_ -= dec ):( column_ -= dec );
213  return *this;
214  }
215  //*******************************************************************************************
216 
217  //**Prefix increment operator****************************************************************
222  inline Iterator& operator++() {
223  ( SO )?( ++row_ ):( ++column_ );
224  return *this;
225  }
226  //*******************************************************************************************
227 
228  //**Postfix increment operator***************************************************************
233  inline const Iterator operator++( int ) {
234  const Iterator tmp( *this );
235  ++(*this);
236  return tmp;
237  }
238  //*******************************************************************************************
239 
240  //**Prefix decrement operator****************************************************************
245  inline Iterator& operator--() {
246  ( SO )?( --row_ ):( --column_ );
247  return *this;
248  }
249  //*******************************************************************************************
250 
251  //**Postfix decrement operator***************************************************************
256  inline const Iterator operator--( int ) {
257  const Iterator tmp( *this );
258  --(*this);
259  return tmp;
260  }
261  //*******************************************************************************************
262 
263  //**Element access operator******************************************************************
268  inline ReferenceType operator*() const {
269  return ReferenceType( *matrix_, row_, column_ );
270  }
271  //*******************************************************************************************
272 
273  //**Element access operator******************************************************************
278  inline PointerType operator->() const {
279  return PointerType( *matrix_, row_, column_ );
280  }
281  //*******************************************************************************************
282 
283  //**Conversion operator**********************************************************************
288  inline operator ConstIterator() const {
289  if( SO )
290  return matrix_->begin( column_ ) + row_;
291  else
292  return matrix_->begin( row_ ) + column_;
293  }
294  //*******************************************************************************************
295 
296  //**Equality operator************************************************************************
303  friend inline bool operator==( const Iterator& lhs, const Iterator& rhs ) {
304  return ( SO )?( lhs.row_ == rhs.row_ ):( lhs.column_ == rhs.column_ );
305  }
306  //*******************************************************************************************
307 
308  //**Equality operator************************************************************************
315  friend inline bool operator==( const Iterator& lhs, const ConstIterator& rhs ) {
316  return ( ConstIterator( lhs ) == rhs );
317  }
318  //*******************************************************************************************
319 
320  //**Equality operator************************************************************************
327  friend inline bool operator==( const ConstIterator& lhs, const Iterator& rhs ) {
328  return ( lhs == ConstIterator( rhs ) );
329  }
330  //*******************************************************************************************
331 
332  //**Inequality operator**********************************************************************
339  friend inline bool operator!=( const Iterator& lhs, const Iterator& rhs ) {
340  return ( SO )?( lhs.row_ != rhs.row_ ):( lhs.column_ != rhs.column_ );
341  }
342  //*******************************************************************************************
343 
344  //**Inequality operator**********************************************************************
351  friend inline bool operator!=( const Iterator& lhs, const ConstIterator& rhs ) {
352  return ( ConstIterator( lhs ) != rhs );
353  }
354  //*******************************************************************************************
355 
356  //**Inequality operator**********************************************************************
363  friend inline bool operator!=( const ConstIterator& lhs, const Iterator& rhs ) {
364  return ( lhs != ConstIterator( rhs ) );
365  }
366  //*******************************************************************************************
367 
368  //**Less-than operator***********************************************************************
375  friend inline bool operator<( const Iterator& lhs, const Iterator& rhs ) {
376  return ( SO )?( lhs.row_ < rhs.row_ ):( lhs.column_ < rhs.column_ );
377  }
378  //*******************************************************************************************
379 
380  //**Less-than operator***********************************************************************
387  friend inline bool operator<( const Iterator& lhs, const ConstIterator& rhs ) {
388  return ( ConstIterator( lhs ) < rhs );
389  }
390  //*******************************************************************************************
391 
392  //**Less-than operator***********************************************************************
399  friend inline bool operator<( const ConstIterator& lhs, const Iterator& rhs ) {
400  return ( lhs < ConstIterator( rhs ) );
401  }
402  //*******************************************************************************************
403 
404  //**Greater-than operator********************************************************************
411  friend inline bool operator>( const Iterator& lhs, const Iterator& rhs ) {
412  return ( SO )?( lhs.row_ > rhs.row_ ):( lhs.column_ > rhs.column_ );
413  }
414  //*******************************************************************************************
415 
416  //**Greater-than operator********************************************************************
423  friend inline bool operator>( const Iterator& lhs, const ConstIterator& rhs ) {
424  return ( ConstIterator( lhs ) > rhs );
425  }
426  //*******************************************************************************************
427 
428  //**Greater-than operator********************************************************************
435  friend inline bool operator>( const ConstIterator& lhs, const Iterator& rhs ) {
436  return ( lhs > ConstIterator( rhs ) );
437  }
438  //*******************************************************************************************
439 
440  //**Less-or-equal-than operator**************************************************************
447  friend inline bool operator<=( const Iterator& lhs, const Iterator& rhs ) {
448  return ( SO )?( lhs.row_ <= rhs.row_ ):( lhs.column_ <= rhs.column_ );
449  }
450  //*******************************************************************************************
451 
452  //**Less-or-equal-than operator**************************************************************
459  friend inline bool operator<=( const Iterator& lhs, const ConstIterator& rhs ) {
460  return ( ConstIterator( lhs ) <= rhs );
461  }
462  //*******************************************************************************************
463 
464  //**Less-or-equal-than operator**************************************************************
471  friend inline bool operator<=( const ConstIterator& lhs, const Iterator& rhs ) {
472  return ( lhs <= ConstIterator( rhs ) );
473  }
474  //*******************************************************************************************
475 
476  //**Greater-or-equal-than operator***********************************************************
483  friend inline bool operator>=( const Iterator& lhs, const Iterator& rhs ) {
484  return ( SO )?( lhs.row_ >= rhs.row_ ):( lhs.column_ >= rhs.column_ );
485  }
486  //*******************************************************************************************
487 
488  //**Greater-or-equal-than operator***********************************************************
495  friend inline bool operator>=( const Iterator& lhs, const ConstIterator& rhs ) {
496  return ( ConstIterator( lhs ) >= rhs );
497  }
498  //*******************************************************************************************
499 
500  //**Greater-or-equal-than operator***********************************************************
507  friend inline bool operator>=( const ConstIterator& lhs, const Iterator& rhs ) {
508  return ( lhs >= ConstIterator( rhs ) );
509  }
510  //*******************************************************************************************
511 
512  //**Subtraction operator*********************************************************************
518  inline DifferenceType operator-( const Iterator& rhs ) const {
519  return ( SO )?( row_ - rhs.row_ ):( column_ - rhs.column_ );
520  }
521  //*******************************************************************************************
522 
523  //**Addition operator************************************************************************
530  friend inline const Iterator operator+( const Iterator& it, size_t inc ) {
531  if( SO )
532  return Iterator( *it.matrix_, it.row_ + inc, it.column_ );
533  else
534  return Iterator( *it.matrix_, it.row_, it.column_ + inc );
535  }
536  //*******************************************************************************************
537 
538  //**Addition operator************************************************************************
545  friend inline const Iterator operator+( size_t inc, const Iterator& it ) {
546  if( SO )
547  return Iterator( *it.matrix_, it.row_ + inc, it.column_ );
548  else
549  return Iterator( *it.matrix_, it.row_, it.column_ + inc );
550  }
551  //*******************************************************************************************
552 
553  //**Subtraction operator*********************************************************************
560  friend inline const Iterator operator-( const Iterator& it, size_t dec ) {
561  if( SO )
562  return Iterator( *it.matrix_, it.row_ - dec, it.column_ );
563  else
564  return Iterator( *it.matrix_, it.row_, it.column_ - dec );
565  }
566  //*******************************************************************************************
567 
568  private:
569  //**Member variables*************************************************************************
570  MT* matrix_;
571  size_t row_;
572  size_t column_;
573  //*******************************************************************************************
574  };
575  //**********************************************************************************************
576 
577  //**Compilation flags***************************************************************************
579  enum { vectorizable = MT::vectorizable };
580 
582  enum { smpAssignable = MT::smpAssignable };
583  //**********************************************************************************************
584 
585  //**Constructors********************************************************************************
588  explicit inline SymmetricMatrix();
589  explicit inline SymmetricMatrix( size_t n );
590 
591  explicit inline SymmetricMatrix( ElementType* ptr, size_t n );
592  explicit inline SymmetricMatrix( ElementType* ptr, size_t n, size_t nn );
593 
594  template< typename Deleter >
595  explicit inline SymmetricMatrix( ElementType* ptr, size_t n, Deleter d );
596 
597  template< typename Deleter >
598  explicit inline SymmetricMatrix( ElementType* ptr, size_t n, size_t nn, Deleter d );
599 
600  inline SymmetricMatrix( const SymmetricMatrix& m );
601  template< typename MT2 > inline SymmetricMatrix( const Matrix<MT2,SO>& m );
602  template< typename MT2 > inline SymmetricMatrix( const Matrix<MT2,!SO>& m );
604  //**********************************************************************************************
605 
606  //**Destructor**********************************************************************************
607  // No explicitly declared destructor.
608  //**********************************************************************************************
609 
610  //**Data access functions***********************************************************************
613  inline Reference operator()( size_t i, size_t j );
614  inline ConstReference operator()( size_t i, size_t j ) const;
615  inline Reference at( size_t i, size_t j );
616  inline ConstReference at( size_t i, size_t j ) const;
617  inline ConstPointer data () const;
618  inline ConstPointer data ( size_t i ) const;
619  inline Iterator begin ( size_t i );
620  inline ConstIterator begin ( size_t i ) const;
621  inline ConstIterator cbegin( size_t i ) const;
622  inline Iterator end ( size_t i );
623  inline ConstIterator end ( size_t i ) const;
624  inline ConstIterator cend ( size_t i ) const;
626  //**********************************************************************************************
627 
628  //**Assignment operators************************************************************************
631  inline SymmetricMatrix& operator=( const SymmetricMatrix& rhs );
632 
633  template< typename MT2 >
634  inline typename DisableIf< IsComputation<MT2>, SymmetricMatrix& >::Type
635  operator=( const Matrix<MT2,SO>& rhs );
636 
637  template< typename MT2 >
638  inline typename EnableIf< IsComputation<MT2>, SymmetricMatrix& >::Type
639  operator=( const Matrix<MT2,SO>& rhs );
640 
641  template< typename MT2 >
642  inline SymmetricMatrix& operator=( const Matrix<MT2,!SO>& rhs );
643 
644  template< typename MT2 >
645  inline typename DisableIf< IsComputation<MT2>, SymmetricMatrix& >::Type
646  operator+=( const Matrix<MT2,SO>& rhs );
647 
648  template< typename MT2 >
649  inline typename EnableIf< IsComputation<MT2>, SymmetricMatrix& >::Type
650  operator+=( const Matrix<MT2,SO>& rhs );
651 
652  template< typename MT2 >
653  inline SymmetricMatrix& operator+=( const Matrix<MT2,!SO>& rhs );
654 
655  template< typename MT2 >
656  inline typename DisableIf< IsComputation<MT2>, SymmetricMatrix& >::Type
657  operator-=( const Matrix<MT2,SO>& rhs );
658 
659  template< typename MT2 >
660  inline typename EnableIf< IsComputation<MT2>, SymmetricMatrix& >::Type
661  operator-=( const Matrix<MT2,SO>& rhs );
662 
663  template< typename MT2 >
664  inline SymmetricMatrix& operator-=( const Matrix<MT2,!SO>& rhs );
665 
666  template< typename MT2, bool SO2 >
667  inline SymmetricMatrix& operator*=( const Matrix<MT2,SO2>& rhs );
668 
669  template< typename Other >
670  inline typename EnableIf< IsNumeric<Other>, SymmetricMatrix >::Type&
671  operator*=( Other rhs );
672 
673  template< typename Other >
674  inline typename EnableIf< IsNumeric<Other>, SymmetricMatrix >::Type&
675  operator/=( Other rhs );
677  //**********************************************************************************************
678 
679  //**Utility functions***************************************************************************
682  inline size_t rows() const;
683  inline size_t columns() const;
684  inline size_t spacing() const;
685  inline size_t capacity() const;
686  inline size_t capacity( size_t i ) const;
687  inline size_t nonZeros() const;
688  inline size_t nonZeros( size_t i ) const;
689  inline void reset();
690  inline void reset( size_t i );
691  inline void clear();
692  void resize ( size_t n, bool preserve=true );
693  inline void extend ( size_t n, bool preserve=true );
694  inline void reserve( size_t elements );
695  inline SymmetricMatrix& transpose();
696  inline SymmetricMatrix& ctranspose();
697  template< typename Other > inline SymmetricMatrix& scale( const Other& scalar );
698  inline void swap( SymmetricMatrix& m ) /* throw() */;
700  //**********************************************************************************************
701 
702  //**Debugging functions*************************************************************************
705  inline bool isIntact() const;
707  //**********************************************************************************************
708 
709  //**Expression template evaluation functions****************************************************
712  template< typename Other > inline bool canAlias ( const Other* alias ) const;
713  template< typename Other > inline bool isAliased( const Other* alias ) const;
714 
715  inline bool isAligned () const;
716  inline bool canSMPAssign() const;
717 
718  BLAZE_ALWAYS_INLINE IntrinsicType load ( size_t i, size_t j ) const;
719  BLAZE_ALWAYS_INLINE IntrinsicType loada( size_t i, size_t j ) const;
720  BLAZE_ALWAYS_INLINE IntrinsicType loadu( size_t i, size_t j ) const;
721 
722  inline void store ( size_t i, size_t j, const IntrinsicType& value );
723  inline void storea( size_t i, size_t j, const IntrinsicType& value );
724  inline void storeu( size_t i, size_t j, const IntrinsicType& value );
725  inline void stream( size_t i, size_t j, const IntrinsicType& value );
727  //**********************************************************************************************
728 
729  private:
730  //**Member variables****************************************************************************
733  MT matrix_;
734 
735  //**********************************************************************************************
736 
737  //**Friend declarations*************************************************************************
738  template< typename MT2, bool SO2, bool DF2, bool NF2 >
739  friend bool isDefault( const SymmetricMatrix<MT2,SO2,DF2,NF2>& m );
740 
741  template< typename MT2, bool SO2 >
742  friend void invert2x2( SymmetricMatrix<MT2,SO2,true,true>& m );
743 
744  template< typename MT2, bool SO2 >
745  friend void invert3x3( SymmetricMatrix<MT2,SO2,true,true>& m );
746 
747  template< typename MT2, bool SO2 >
748  friend void invert4x4( SymmetricMatrix<MT2,SO2,true,true>& m );
749 
750  template< typename MT2, bool SO2 >
751  friend void invert5x5( SymmetricMatrix<MT2,SO2,true,true>& m );
752 
753  template< typename MT2, bool SO2 >
754  friend void invert6x6( SymmetricMatrix<MT2,SO2,true,true>& m );
755 
756  template< typename MT2, bool SO2 >
757  friend void invertByLU( SymmetricMatrix<MT2,SO2,true,true>& m );
758 
759  template< typename MT2, bool SO2 >
760  friend void invertByLDLT( SymmetricMatrix<MT2,SO2,true,true>& m );
761 
762  template< typename MT2, bool SO2 >
763  friend void invertByLDLH( SymmetricMatrix<MT2,SO2,true,true>& m );
764 
765  template< typename MT2, bool SO2 >
766  friend void invertByLLH( SymmetricMatrix<MT2,SO2,true,true>& m );
767  //**********************************************************************************************
768 
769  //**Compile time checks*************************************************************************
783  BLAZE_STATIC_ASSERT( Rows<MT>::value == Columns<MT>::value );
784  //**********************************************************************************************
785 };
787 //*************************************************************************************************
788 
789 
790 
791 
792 //=================================================================================================
793 //
794 // CONSTRUCTORS
795 //
796 //=================================================================================================
797 
798 //*************************************************************************************************
802 template< typename MT // Type of the adapted dense matrix
803  , bool SO > // Storage order of the adapted dense matrix
804 inline SymmetricMatrix<MT,SO,true,true>::SymmetricMatrix()
805  : matrix_() // The adapted dense matrix
806 {
807  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
808  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
809 }
811 //*************************************************************************************************
812 
813 
814 //*************************************************************************************************
820 template< typename MT // Type of the adapted dense matrix
821  , bool SO > // Storage order of the adapted dense matrix
822 inline SymmetricMatrix<MT,SO,true,true>::SymmetricMatrix( size_t n )
823  : matrix_( n, n, ElementType() ) // The adapted dense matrix
824 {
826 
827  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
828  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
829 }
831 //*************************************************************************************************
832 
833 
834 //*************************************************************************************************
855 template< typename MT // Type of the adapted dense matrix
856  , bool SO > // Storage order of the adapted dense matrix
857 inline SymmetricMatrix<MT,SO,true,true>::SymmetricMatrix( ElementType* ptr, size_t n )
858  : matrix_( ptr, n, n ) // The adapted dense matrix
859 {
860  if( !isSymmetric( matrix_ ) ) {
861  BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of symmetric matrix" );
862  }
863 
864  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
865 }
867 //*************************************************************************************************
868 
869 
870 //*************************************************************************************************
893 template< typename MT // Type of the adapted dense matrix
894  , bool SO > // Storage order of the adapted dense matrix
895 inline SymmetricMatrix<MT,SO,true,true>::SymmetricMatrix( ElementType* ptr, size_t n, size_t nn )
896  : matrix_( ptr, n, n, nn ) // The adapted dense matrix
897 {
898  if( !isSymmetric( matrix_ ) ) {
899  BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of symmetric matrix" );
900  }
901 
902  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
903 }
905 //*************************************************************************************************
906 
907 
908 //*************************************************************************************************
929 template< typename MT // Type of the adapted dense matrix
930  , bool SO > // Storage order of the adapted dense matrix
931 template< typename Deleter > // Type of the custom deleter
932 inline SymmetricMatrix<MT,SO,true,true>::SymmetricMatrix( ElementType* ptr, size_t n, Deleter d )
933  : matrix_( ptr, n, n, d ) // The adapted dense matrix
934 {
935  if( !isSymmetric( matrix_ ) ) {
936  BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of symmetric matrix" );
937  }
938 
939  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
940 }
942 //*************************************************************************************************
943 
944 
945 //*************************************************************************************************
967 template< typename MT // Type of the adapted dense matrix
968  , bool SO > // Storage order of the adapted dense matrix
969 template< typename Deleter > // Type of the custom deleter
970 inline SymmetricMatrix<MT,SO,true,true>::SymmetricMatrix( ElementType* ptr, size_t n, size_t nn, Deleter d )
971  : matrix_( ptr, n, n, nn, d ) // The adapted dense matrix
972 {
973  if( !isSymmetric( matrix_ ) ) {
974  BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of symmetric matrix" );
975  }
976 
977  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
978 }
980 //*************************************************************************************************
981 
982 
983 //*************************************************************************************************
989 template< typename MT // Type of the adapted dense matrix
990  , bool SO > // Storage order of the adapted dense matrix
991 inline SymmetricMatrix<MT,SO,true,true>::SymmetricMatrix( const SymmetricMatrix& m )
992  : matrix_( m.matrix_ ) // The adapted dense matrix
993 {
994  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
995  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
996 }
998 //*************************************************************************************************
999 
1000 
1001 //*************************************************************************************************
1011 template< typename MT // Type of the adapted dense matrix
1012  , bool SO > // Storage order of the adapted dense matrix
1013 template< typename MT2 > // Type of the foreign matrix
1014 inline SymmetricMatrix<MT,SO,true,true>::SymmetricMatrix( const Matrix<MT2,SO>& m )
1015  : matrix_( ~m ) // The adapted dense matrix
1016 {
1017  if( !IsSymmetric<MT2>::value && !isSymmetric( matrix_ ) ) {
1018  BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of symmetric matrix" );
1019  }
1020 
1021  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
1022  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1023 }
1025 //*************************************************************************************************
1026 
1027 
1028 //*************************************************************************************************
1038 template< typename MT // Type of the adapted dense matrix
1039  , bool SO > // Storage order of the adapted dense matrix
1040 template< typename MT2 > // Type of the foreign matrix
1041 inline SymmetricMatrix<MT,SO,true,true>::SymmetricMatrix( const Matrix<MT2,!SO>& m )
1042  : matrix_( trans( ~m ) ) // The adapted dense matrix
1043 {
1044  if( !IsSymmetric<MT2>::value && !isSymmetric( matrix_ ) ) {
1045  BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of symmetric matrix" );
1046  }
1047 
1048  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
1049  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1050 }
1052 //*************************************************************************************************
1053 
1054 
1055 
1056 
1057 //=================================================================================================
1058 //
1059 // DATA ACCESS FUNCTIONS
1060 //
1061 //=================================================================================================
1062 
1063 //*************************************************************************************************
1078 template< typename MT // Type of the adapted dense matrix
1079  , bool SO > // Storage order of the adapted dense matrix
1081  SymmetricMatrix<MT,SO,true,true>::operator()( size_t i, size_t j )
1082 {
1083  BLAZE_USER_ASSERT( i<rows() , "Invalid row access index" );
1084  BLAZE_USER_ASSERT( j<columns(), "Invalid column access index" );
1085 
1086  return Reference( matrix_, i, j );
1087 }
1089 //*************************************************************************************************
1090 
1091 
1092 //*************************************************************************************************
1107 template< typename MT // Type of the adapted dense matrix
1108  , bool SO > // Storage order of the adapted dense matrix
1110  SymmetricMatrix<MT,SO,true,true>::operator()( size_t i, size_t j ) const
1111 {
1112  BLAZE_USER_ASSERT( i<rows() , "Invalid row access index" );
1113  BLAZE_USER_ASSERT( j<columns(), "Invalid column access index" );
1114 
1115  return matrix_(i,j);
1116 }
1118 //*************************************************************************************************
1119 
1120 
1121 //*************************************************************************************************
1137 template< typename MT // Type of the adapted dense matrix
1138  , bool SO > // Storage order of the adapted dense matrix
1140  SymmetricMatrix<MT,SO,true,true>::at( size_t i, size_t j )
1141 {
1142  if( i >= rows() ) {
1143  BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
1144  }
1145  if( j >= columns() ) {
1146  BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
1147  }
1148  return (*this)(i,j);
1149 }
1151 //*************************************************************************************************
1152 
1153 
1154 //*************************************************************************************************
1170 template< typename MT // Type of the adapted dense matrix
1171  , bool SO > // Storage order of the adapted dense matrix
1173  SymmetricMatrix<MT,SO,true,true>::at( size_t i, size_t j ) const
1174 {
1175  if( i >= rows() ) {
1176  BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
1177  }
1178  if( j >= columns() ) {
1179  BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
1180  }
1181  return (*this)(i,j);
1182 }
1184 //*************************************************************************************************
1185 
1186 
1187 //*************************************************************************************************
1201 template< typename MT // Type of the adapted dense matrix
1202  , bool SO > // Storage order of the adapted dense matrix
1203 inline typename SymmetricMatrix<MT,SO,true,true>::ConstPointer
1204  SymmetricMatrix<MT,SO,true,true>::data() const
1205 {
1206  return matrix_.data();
1207 }
1209 //*************************************************************************************************
1210 
1211 
1212 //*************************************************************************************************
1223 template< typename MT // Type of the adapted dense matrix
1224  , bool SO > // Storage order of the adapted dense matrix
1225 inline typename SymmetricMatrix<MT,SO,true,true>::ConstPointer
1226  SymmetricMatrix<MT,SO,true,true>::data( size_t i ) const
1227 {
1228  return matrix_.data(i);
1229 }
1231 //*************************************************************************************************
1232 
1233 
1234 //*************************************************************************************************
1246 template< typename MT // Type of the adapted dense matrix
1247  , bool SO > // Storage order of the adapted dense matrix
1250 {
1251  if( SO )
1252  return Iterator( matrix_, 0UL, i );
1253  else
1254  return Iterator( matrix_, i, 0UL );
1255 }
1257 //*************************************************************************************************
1258 
1259 
1260 //*************************************************************************************************
1272 template< typename MT // Type of the adapted dense matrix
1273  , bool SO > // Storage order of the adapted dense matrix
1275  SymmetricMatrix<MT,SO,true,true>::begin( size_t i ) const
1276 {
1277  return matrix_.begin(i);
1278 }
1280 //*************************************************************************************************
1281 
1282 
1283 //*************************************************************************************************
1295 template< typename MT // Type of the adapted dense matrix
1296  , bool SO > // Storage order of the adapted dense matrix
1299 {
1300  return matrix_.cbegin(i);
1301 }
1303 //*************************************************************************************************
1304 
1305 
1306 //*************************************************************************************************
1318 template< typename MT // Type of the adapted dense matrix
1319  , bool SO > // Storage order of the adapted dense matrix
1322 {
1323  if( SO )
1324  return Iterator( matrix_, rows(), i );
1325  else
1326  return Iterator( matrix_, i, columns() );
1327 }
1329 //*************************************************************************************************
1330 
1331 
1332 //*************************************************************************************************
1344 template< typename MT // Type of the adapted dense matrix
1345  , bool SO > // Storage order of the adapted dense matrix
1347  SymmetricMatrix<MT,SO,true,true>::end( size_t i ) const
1348 {
1349  return matrix_.end(i);
1350 }
1352 //*************************************************************************************************
1353 
1354 
1355 //*************************************************************************************************
1367 template< typename MT // Type of the adapted dense matrix
1368  , bool SO > // Storage order of the adapted dense matrix
1370  SymmetricMatrix<MT,SO,true,true>::cend( size_t i ) const
1371 {
1372  return matrix_.cend(i);
1373 }
1375 //*************************************************************************************************
1376 
1377 
1378 
1379 
1380 //=================================================================================================
1381 //
1382 // ASSIGNMENT OPERATORS
1383 //
1384 //=================================================================================================
1385 
1386 //*************************************************************************************************
1396 template< typename MT // Type of the adapted dense matrix
1397  , bool SO > // Storage order of the adapted dense matrix
1398 inline SymmetricMatrix<MT,SO,true,true>&
1399  SymmetricMatrix<MT,SO,true,true>::operator=( const SymmetricMatrix& rhs )
1400 {
1401  matrix_ = rhs.matrix_;
1402 
1403  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
1404  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1405 
1406  return *this;
1407 }
1409 //*************************************************************************************************
1410 
1411 
1412 //*************************************************************************************************
1425 template< typename MT // Type of the adapted dense matrix
1426  , bool SO > // Storage order of the adapted dense matrix
1427 template< typename MT2 > // Type of the right-hand side matrix
1428 inline typename DisableIf< IsComputation<MT2>, SymmetricMatrix<MT,SO,true,true>& >::Type
1429  SymmetricMatrix<MT,SO,true,true>::operator=( const Matrix<MT2,SO>& rhs )
1430 {
1431  if( !IsSymmetric<MT2>::value && !isSymmetric( ~rhs ) ) {
1432  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to symmetric matrix" );
1433  }
1434 
1435  matrix_ = ~rhs;
1436 
1437  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
1438  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1439 
1440  return *this;
1441 }
1443 //*************************************************************************************************
1444 
1445 
1446 //*************************************************************************************************
1459 template< typename MT // Type of the adapted dense matrix
1460  , bool SO > // Storage order of the adapted dense matrix
1461 template< typename MT2 > // Type of the right-hand side matrix
1462 inline typename EnableIf< IsComputation<MT2>, SymmetricMatrix<MT,SO,true,true>& >::Type
1463  SymmetricMatrix<MT,SO,true,true>::operator=( const Matrix<MT2,SO>& rhs )
1464 {
1465  if( !IsSquare<MT2>::value && !isSquare( ~rhs ) ) {
1466  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to symmetric matrix" );
1467  }
1468 
1469  if( IsSymmetric<MT2>::value ) {
1470  matrix_ = ~rhs;
1471  }
1472  else {
1473  MT tmp( ~rhs );
1474 
1475  if( !isSymmetric( tmp ) ) {
1476  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to symmetric matrix" );
1477  }
1478 
1479  move( matrix_, tmp );
1480  }
1481 
1482  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
1483  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1484 
1485  return *this;
1486 }
1488 //*************************************************************************************************
1489 
1490 
1491 //*************************************************************************************************
1504 template< typename MT // Type of the adapted dense matrix
1505  , bool SO > // Storage order of the adapted dense matrix
1506 template< typename MT2 > // Type of the right-hand side matrix
1507 inline SymmetricMatrix<MT,SO,true,true>&
1508  SymmetricMatrix<MT,SO,true,true>::operator=( const Matrix<MT2,!SO>& rhs )
1509 {
1510  return this->operator=( trans( ~rhs ) );
1511 }
1513 //*************************************************************************************************
1514 
1515 
1516 //*************************************************************************************************
1529 template< typename MT // Type of the adapted dense matrix
1530  , bool SO > // Storage order of the adapted dense matrix
1531 template< typename MT2 > // Type of the right-hand side matrix
1532 inline typename DisableIf< IsComputation<MT2>, SymmetricMatrix<MT,SO,true,true>& >::Type
1533  SymmetricMatrix<MT,SO,true,true>::operator+=( const Matrix<MT2,SO>& rhs )
1534 {
1535  if( !IsSymmetric<MT2>::value && !isSymmetric( ~rhs ) ) {
1536  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to symmetric matrix" );
1537  }
1538 
1539  matrix_ += ~rhs;
1540 
1541  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
1542  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1543 
1544  return *this;
1545 }
1547 //*************************************************************************************************
1548 
1549 
1550 //*************************************************************************************************
1563 template< typename MT // Type of the adapted dense matrix
1564  , bool SO > // Storage order of the adapted dense matrix
1565 template< typename MT2 > // Type of the right-hand side matrix
1566 inline typename EnableIf< IsComputation<MT2>, SymmetricMatrix<MT,SO,true,true>& >::Type
1567  SymmetricMatrix<MT,SO,true,true>::operator+=( const Matrix<MT2,SO>& rhs )
1568 {
1569  if( !IsSquare<MT2>::value && !isSquare( ~rhs ) ) {
1570  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to symmetric matrix" );
1571  }
1572 
1573  if( IsSymmetric<MT2>::value ) {
1574  matrix_ += ~rhs;
1575  }
1576  else {
1577  typename MT2::ResultType tmp( ~rhs );
1578 
1579  if( !isSymmetric( tmp ) ) {
1580  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to symmetric matrix" );
1581  }
1582 
1583  matrix_ += tmp;
1584  }
1585 
1586  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
1587  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1588 
1589  return *this;
1590 }
1592 //*************************************************************************************************
1593 
1594 
1595 //*************************************************************************************************
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 inline SymmetricMatrix<MT,SO,true,true>&
1613  SymmetricMatrix<MT,SO,true,true>::operator+=( const Matrix<MT2,!SO>& rhs )
1614 {
1615  return this->operator+=( trans( ~rhs ) );
1616 }
1618 //*************************************************************************************************
1619 
1620 
1621 //*************************************************************************************************
1634 template< typename MT // Type of the adapted dense matrix
1635  , bool SO > // Storage order of the adapted dense matrix
1636 template< typename MT2 > // Type of the right-hand side matrix
1637 inline typename DisableIf< IsComputation<MT2>, SymmetricMatrix<MT,SO,true,true>& >::Type
1638  SymmetricMatrix<MT,SO,true,true>::operator-=( const Matrix<MT2,SO>& rhs )
1639 {
1640  if( !IsSymmetric<MT2>::value && !isSymmetric( ~rhs ) ) {
1641  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to symmetric matrix" );
1642  }
1643 
1644  matrix_ -= ~rhs;
1645 
1646  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
1647  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1648 
1649  return *this;
1650 }
1652 //*************************************************************************************************
1653 
1654 
1655 //*************************************************************************************************
1668 template< typename MT // Type of the adapted dense matrix
1669  , bool SO > // Storage order of the adapted dense matrix
1670 template< typename MT2 > // Type of the right-hand side matrix
1671 inline typename EnableIf< IsComputation<MT2>, SymmetricMatrix<MT,SO,true,true>& >::Type
1672  SymmetricMatrix<MT,SO,true,true>::operator-=( const Matrix<MT2,SO>& rhs )
1673 {
1674  if( !IsSquare<MT2>::value && !isSquare( ~rhs ) ) {
1675  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to symmetric matrix" );
1676  }
1677 
1678  if( IsSymmetric<MT2>::value ) {
1679  matrix_ -= ~rhs;
1680  }
1681  else {
1682  typename MT2::ResultType tmp( ~rhs );
1683 
1684  if( !isSymmetric( tmp ) ) {
1685  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to symmetric matrix" );
1686  }
1687 
1688  matrix_ -= tmp;
1689  }
1690 
1691  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
1692  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1693 
1694  return *this;
1695 }
1697 //*************************************************************************************************
1698 
1699 
1700 //*************************************************************************************************
1714 template< typename MT // Type of the adapted dense matrix
1715  , bool SO > // Storage order of the adapted dense matrix
1716 template< typename MT2 > // Type of the right-hand side matrix
1717 inline SymmetricMatrix<MT,SO,true,true>&
1718  SymmetricMatrix<MT,SO,true,true>::operator-=( const Matrix<MT2,!SO>& rhs )
1719 {
1720  return this->operator-=( trans( ~rhs ) );
1721 }
1723 //*************************************************************************************************
1724 
1725 
1726 //*************************************************************************************************
1738 template< typename MT // Type of the adapted dense matrix
1739  , bool SO > // Storage order of the adapted dense matrix
1740 template< typename MT2 // Type of the right-hand side matrix
1741  , bool SO2 > // Storage order of the right-hand side matrix
1742 inline SymmetricMatrix<MT,SO,true,true>&
1743  SymmetricMatrix<MT,SO,true,true>::operator*=( const Matrix<MT2,SO2>& rhs )
1744 {
1745  if( matrix_.rows() != (~rhs).columns() ) {
1746  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to symmetric matrix" );
1747  }
1748 
1749  MT tmp( matrix_ * ~rhs );
1750 
1751  if( !isSymmetric( tmp ) ) {
1752  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to symmetric matrix" );
1753  }
1754 
1755  move( matrix_, tmp );
1756 
1757  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
1758  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1759 
1760  return *this;
1761 }
1763 //*************************************************************************************************
1764 
1765 
1766 //*************************************************************************************************
1774 template< typename MT // Type of the adapted dense matrix
1775  , bool SO > // Storage order of the adapted dense matrix
1776 template< typename Other > // Data type of the right-hand side scalar
1777 inline typename EnableIf< IsNumeric<Other>, SymmetricMatrix<MT,SO,true,true> >::Type&
1778  SymmetricMatrix<MT,SO,true,true>::operator*=( Other rhs )
1779 {
1780  matrix_ *= rhs;
1781  return *this;
1782 }
1783 //*************************************************************************************************
1784 
1785 
1786 //*************************************************************************************************
1794 template< typename MT // Type of the adapted dense matrix
1795  , bool SO > // Storage order of the adapted dense matrix
1796 template< typename Other > // Data type of the right-hand side scalar
1797 inline typename EnableIf< IsNumeric<Other>, SymmetricMatrix<MT,SO,true,true> >::Type&
1798  SymmetricMatrix<MT,SO,true,true>::operator/=( Other rhs )
1799 {
1800  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
1801 
1802  matrix_ /= rhs;
1803  return *this;
1804 }
1806 //*************************************************************************************************
1807 
1808 
1809 
1810 
1811 //=================================================================================================
1812 //
1813 // UTILITY FUNCTIONS
1814 //
1815 //=================================================================================================
1816 
1817 //*************************************************************************************************
1823 template< typename MT // Type of the adapted dense matrix
1824  , bool SO > // Storage order of the adapted dense matrix
1825 inline size_t SymmetricMatrix<MT,SO,true,true>::rows() const
1826 {
1827  return matrix_.rows();
1828 }
1830 //*************************************************************************************************
1831 
1832 
1833 //*************************************************************************************************
1839 template< typename MT // Type of the adapted dense matrix
1840  , bool SO > // Storage order of the adapted dense matrix
1841 inline size_t SymmetricMatrix<MT,SO,true,true>::columns() const
1842 {
1843  return matrix_.columns();
1844 }
1846 //*************************************************************************************************
1847 
1848 
1849 //*************************************************************************************************
1861 template< typename MT // Type of the adapted dense matrix
1862  , bool SO > // Storage order of the adapted dense matrix
1863 inline size_t SymmetricMatrix<MT,SO,true,true>::spacing() const
1864 {
1865  return matrix_.spacing();
1866 }
1868 //*************************************************************************************************
1869 
1870 
1871 //*************************************************************************************************
1877 template< typename MT // Type of the adapted dense matrix
1878  , bool SO > // Storage order of the adapted dense matrix
1879 inline size_t SymmetricMatrix<MT,SO,true,true>::capacity() const
1880 {
1881  return matrix_.capacity();
1882 }
1884 //*************************************************************************************************
1885 
1886 
1887 //*************************************************************************************************
1898 template< typename MT // Type of the adapted dense matrix
1899  , bool SO > // Storage order of the adapted dense matrix
1900 inline size_t SymmetricMatrix<MT,SO,true,true>::capacity( size_t i ) const
1901 {
1902  return matrix_.capacity(i);
1903 }
1905 //*************************************************************************************************
1906 
1907 
1908 //*************************************************************************************************
1914 template< typename MT // Type of the adapted dense matrix
1915  , bool SO > // Storage order of the adapted dense matrix
1916 inline size_t SymmetricMatrix<MT,SO,true,true>::nonZeros() const
1917 {
1918  return matrix_.nonZeros();
1919 }
1921 //*************************************************************************************************
1922 
1923 
1924 //*************************************************************************************************
1936 template< typename MT // Type of the adapted dense matrix
1937  , bool SO > // Storage order of the adapted dense matrix
1938 inline size_t SymmetricMatrix<MT,SO,true,true>::nonZeros( size_t i ) const
1939 {
1940  return matrix_.nonZeros(i);
1941 }
1943 //*************************************************************************************************
1944 
1945 
1946 //*************************************************************************************************
1952 template< typename MT // Type of the adapted dense matrix
1953  , bool SO > // Storage order of the adapted dense matrix
1955 {
1956  matrix_.reset();
1957 }
1959 //*************************************************************************************************
1960 
1961 
1962 //*************************************************************************************************
1998 template< typename MT // Type of the adapted dense matrix
1999  , bool SO > // Storage order of the adapted dense matrix
2000 inline void SymmetricMatrix<MT,SO,true,true>::reset( size_t i )
2001 {
2002  row ( matrix_, i ).reset();
2003  column( matrix_, i ).reset();
2004 }
2006 //*************************************************************************************************
2007 
2008 
2009 //*************************************************************************************************
2021 template< typename MT // Type of the adapted dense matrix
2022  , bool SO > // Storage order of the adapted dense matrix
2024 {
2025  using blaze::clear;
2026 
2027  clear( matrix_ );
2028 }
2030 //*************************************************************************************************
2031 
2032 
2033 //*************************************************************************************************
2068 template< typename MT // Type of the adapted dense matrix
2069  , bool SO > // Storage order of the adapted dense matrix
2070 void SymmetricMatrix<MT,SO,true,true>::resize( size_t n, bool preserve )
2071 {
2073 
2074  UNUSED_PARAMETER( preserve );
2075 
2076  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
2077 
2078  const size_t oldsize( matrix_.rows() );
2079 
2080  matrix_.resize( n, n, true );
2081 
2082  if( n > oldsize ) {
2083  const size_t increment( n - oldsize );
2084  submatrix( matrix_, 0UL, oldsize, oldsize, increment ).reset();
2085  submatrix( matrix_, oldsize, 0UL, increment, n ).reset();
2086  }
2087 }
2089 //*************************************************************************************************
2090 
2091 
2092 //*************************************************************************************************
2105 template< typename MT // Type of the adapted dense matrix
2106  , bool SO > // Storage order of the adapted dense matrix
2107 inline void SymmetricMatrix<MT,SO,true,true>::extend( size_t n, bool preserve )
2108 {
2110 
2111  UNUSED_PARAMETER( preserve );
2112 
2113  resize( rows() + n, true );
2114 }
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 void SymmetricMatrix<MT,SO,true,true>::reserve( size_t elements )
2131 {
2132  matrix_.reserve( elements );
2133 }
2135 //*************************************************************************************************
2136 
2137 
2138 //*************************************************************************************************
2144 template< typename MT // Type of the adapted dense matrix
2145  , bool SO > // Storage order of the adapted dense matrix
2146 inline SymmetricMatrix<MT,SO,true,true>& SymmetricMatrix<MT,SO,true,true>::transpose()
2147 {
2148  return *this;
2149 }
2151 //*************************************************************************************************
2152 
2153 
2154 //*************************************************************************************************
2160 template< typename MT // Type of the adapted dense matrix
2161  , bool SO > // Storage order of the adapted dense matrix
2162 inline SymmetricMatrix<MT,SO,true,true>& SymmetricMatrix<MT,SO,true,true>::ctranspose()
2163 {
2164  if( !IsBuiltin<ElementType>::value )
2165  conjugate( matrix_ );
2166 
2167  return *this;
2168 }
2170 //*************************************************************************************************
2171 
2172 
2173 //*************************************************************************************************
2180 template< typename MT // Type of the adapted dense matrix
2181  , bool SO > // Storage order of the adapted dense matrix
2182 template< typename Other > // Data type of the scalar value
2183 inline SymmetricMatrix<MT,SO,true,true>&
2184  SymmetricMatrix<MT,SO,true,true>::scale( const Other& scalar )
2185 {
2186  matrix_.scale( scalar );
2187  return *this;
2188 }
2190 //*************************************************************************************************
2191 
2192 
2193 //*************************************************************************************************
2201 template< typename MT // Type of the adapted dense matrix
2202  , bool SO > // Storage order of the adapted dense matrix
2203 inline void SymmetricMatrix<MT,SO,true,true>::swap( SymmetricMatrix& m ) /* throw() */
2204 {
2205  using std::swap;
2206 
2207  swap( matrix_, m.matrix_ );
2208 }
2210 //*************************************************************************************************
2211 
2212 
2213 
2214 
2215 //=================================================================================================
2216 //
2217 // DEBUGGING FUNCTIONS
2218 //
2219 //=================================================================================================
2220 
2221 //*************************************************************************************************
2231 template< typename MT // Type of the adapted dense matrix
2232  , bool SO > // Storage order of the adapted dense matrix
2234 {
2235  using blaze::isIntact;
2236 
2237  return ( isIntact( matrix_ ) && isSymmetric( matrix_ ) );
2238 }
2240 //*************************************************************************************************
2241 
2242 
2243 
2244 
2245 //=================================================================================================
2246 //
2247 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
2248 //
2249 //=================================================================================================
2250 
2251 //*************************************************************************************************
2262 template< typename MT // Type of the adapted dense matrix
2263  , bool SO > // Storage order of the adapted dense matrix
2264 template< typename Other > // Data type of the foreign expression
2265 inline bool SymmetricMatrix<MT,SO,true,true>::canAlias( const Other* alias ) const
2266 {
2267  return matrix_.canAlias( alias );
2268 }
2270 //*************************************************************************************************
2271 
2272 
2273 //*************************************************************************************************
2284 template< typename MT // Type of the adapted dense matrix
2285  , bool SO > // Storage order of the adapted dense matrix
2286 template< typename Other > // Data type of the foreign expression
2287 inline bool SymmetricMatrix<MT,SO,true,true>::isAliased( const Other* alias ) const
2288 {
2289  return matrix_.isAliased( alias );
2290 }
2292 //*************************************************************************************************
2293 
2294 
2295 //*************************************************************************************************
2305 template< typename MT // Type of the adapted dense matrix
2306  , bool SO > // Storage order of the adapted dense matrix
2307 inline bool SymmetricMatrix<MT,SO,true,true>::isAligned() const
2308 {
2309  return matrix_.isAligned();
2310 }
2312 //*************************************************************************************************
2313 
2314 
2315 //*************************************************************************************************
2326 template< typename MT // Type of the adapted dense matrix
2327  , bool SO > // Storage order of the adapted dense matrix
2328 inline bool SymmetricMatrix<MT,SO,true,true>::canSMPAssign() const
2329 {
2330  return matrix_.canSMPAssign();
2331 }
2333 //*************************************************************************************************
2334 
2335 
2336 //*************************************************************************************************
2352 template< typename MT // Type of the adapted dense matrix
2353  , bool SO > // Storage order of the adapted dense matrix
2354 BLAZE_ALWAYS_INLINE typename SymmetricMatrix<MT,SO,true,true>::IntrinsicType
2355  SymmetricMatrix<MT,SO,true,true>::load( size_t i, size_t j ) const
2356 {
2357  return matrix_.load( i, j );
2358 }
2360 //*************************************************************************************************
2361 
2362 
2363 //*************************************************************************************************
2379 template< typename MT // Type of the adapted dense matrix
2380  , bool SO > // Storage order of the adapted dense matrix
2381 BLAZE_ALWAYS_INLINE typename SymmetricMatrix<MT,SO,true,true>::IntrinsicType
2382  SymmetricMatrix<MT,SO,true,true>::loada( size_t i, size_t j ) const
2383 {
2384  return matrix_.loada( i, j );
2385 }
2387 //*************************************************************************************************
2388 
2389 
2390 //*************************************************************************************************
2406 template< typename MT // Type of the adapted dense matrix
2407  , bool SO > // Storage order of the adapted dense matrix
2408 BLAZE_ALWAYS_INLINE typename SymmetricMatrix<MT,SO,true,true>::IntrinsicType
2409  SymmetricMatrix<MT,SO,true,true>::loadu( size_t i, size_t j ) const
2410 {
2411  return matrix_.loadu( i, j );
2412 }
2414 //*************************************************************************************************
2415 
2416 
2417 //*************************************************************************************************
2434 template< typename MT // Type of the adapted dense matrix
2435  , bool SO > // Storage order of the adapted dense matrix
2436 inline void SymmetricMatrix<MT,SO,true,true>::store( size_t i, size_t j, const IntrinsicType& value )
2437 {
2438  matrix_.store( i, j, value );
2439 
2440  if( SO ) {
2441  const size_t kend( min( i+IT::size, rows() ) );
2442  for( size_t k=i; k<kend; ++k )
2443  matrix_(j,k) = matrix_(k,j);
2444  }
2445  else {
2446  const size_t kend( min( j+IT::size, columns() ) );
2447  for( size_t k=j; k<kend; ++k )
2448  matrix_(k,i) = matrix_(i,k);
2449  }
2450 }
2452 //*************************************************************************************************
2453 
2454 
2455 //*************************************************************************************************
2472 template< typename MT // Type of the adapted dense matrix
2473  , bool SO > // Storage order of the adapted dense matrix
2474 inline void SymmetricMatrix<MT,SO,true,true>::storea( size_t i, size_t j, const IntrinsicType& value )
2475 {
2476  matrix_.storea( i, j, value );
2477 
2478  if( SO ) {
2479  const size_t kend( min( i+IT::size, rows() ) );
2480  for( size_t k=i; k<kend; ++k )
2481  matrix_(j,k) = matrix_(k,j);
2482  }
2483  else {
2484  const size_t kend( min( j+IT::size, columns() ) );
2485  for( size_t k=j; k<kend; ++k )
2486  matrix_(k,i) = matrix_(i,k);
2487  }
2488 }
2490 //*************************************************************************************************
2491 
2492 
2493 //*************************************************************************************************
2510 template< typename MT // Type of the adapted dense matrix
2511  , bool SO > // Storage order of the adapted dense matrix
2512 inline void SymmetricMatrix<MT,SO,true,true>::storeu( size_t i, size_t j, const IntrinsicType& value )
2513 {
2514  matrix_.storeu( i, j, value );
2515 
2516  if( SO ) {
2517  const size_t kend( min( i+IT::size, rows() ) );
2518  for( size_t k=i; k<kend; ++k )
2519  matrix_(j,k) = matrix_(k,j);
2520  }
2521  else {
2522  const size_t kend( min( j+IT::size, columns() ) );
2523  for( size_t k=j; k<kend; ++k )
2524  matrix_(k,i) = matrix_(i,k);
2525  }
2526 }
2528 //*************************************************************************************************
2529 
2530 
2531 //*************************************************************************************************
2548 template< typename MT // Type of the adapted dense matrix
2549  , bool SO > // Storage order of the adapted dense matrix
2550 inline void SymmetricMatrix<MT,SO,true,true>::stream( size_t i, size_t j, const IntrinsicType& value )
2551 {
2552  matrix_.stream( i, j, value );
2553 
2554  if( SO ) {
2555  const size_t kend( min( i+IT::size, rows() ) );
2556  for( size_t k=i; k<kend; ++k )
2557  matrix_(j,k) = matrix_(k,j);
2558  }
2559  else {
2560  const size_t kend( min( j+IT::size, columns() ) );
2561  for( size_t k=j; k<kend; ++k )
2562  matrix_(k,i) = matrix_(i,k);
2563  }
2564 }
2566 //*************************************************************************************************
2567 
2568 } // namespace blaze
2569 
2570 #endif
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
Constraint on the data type.
Header file for mathematical functions.
#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
void move(CompressedMatrix< Type, SO > &dst, CompressedMatrix< Type, SO > &src)
Moving the contents of one compressed matrix to another.
Definition: CompressedMatrix.h:5016
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector)
Returns the current size/dimension of the vector.
Definition: Vector.h:252
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
#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.
bool isSymmetric(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is symmetric.
Definition: DenseMatrix.h:697
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
BLAZE_ALWAYS_INLINE void ctranspose(Matrix< MT, SO > &matrix)
In-place conjugate transpose of the given matrix.
Definition: Matrix.h:584
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
Constraint on the data type.
Header file for the NumericProxy class.
CompressedMatrix< Type, false > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: CompressedMatrix.h:2584
Header file for the implementation of the base template of the SymmetricMatrix.
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:547
Constraint on the data type.
Header file for the DenseColumn class template.
Constraint on the data type.
Header file for the IsSquare type trait.
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 IsSymmetric type trait.
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
Header file for the If class template.
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
BLAZE_ALWAYS_INLINE EnableIf< And< IsIntegral< T >, HasSize< T, 2UL > > >::Type storeu(T *address, const simd_int16_t &value)
Unaligned store of a vector of 2-byte integral values.
Definition: Storeu.h:75
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
const MT::ElementType min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:1682
Header file for the DenseMatrix base class.
Header file for the Columns type trait.
BLAZE_ALWAYS_INLINE void conjugate(T &a)
In-place conjugation of the given value/object.
Definition: Conjugate.h:120
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
Header file for all forward declarations for expression class templates.
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 all restructuring column functions.
Header file for the conjugate shim.
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.
Header file for the DenseRow class template.
Constraint on the data type.
Constraint on the data type.
#define BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE(T)
Constraint on the data type.In case the given data type T is not a numeric (integral or floating poin...
Definition: Numeric.h:79
#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
Constraint on the data type.
Constraint on the data type.
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
const DMatTransExpr< MT,!SO > trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:944
Header file for the IsComputation type trait class.
Header file for the IsBuiltin type trait.
#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 EnableIf< And< IsIntegral< T >, HasSize< T, 2UL > > >::Type stream(T *address, const simd_int16_t &value)
Aligned, non-temporal store of a vector of 2-byte integral values.
Definition: Stream.h:74
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.
#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
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 all restructuring row functions.
BLAZE_ALWAYS_INLINE EnableIf< And< IsIntegral< T >, HasSize< T, 2UL > > >::Type storea(T *address, const simd_int16_t &value)
Aligned store of a vector of 2-byte integral values.
Definition: Storea.h:78
BLAZE_ALWAYS_INLINE void transpose(Matrix< MT, SO > &matrix)
In-place transpose of the given matrix.
Definition: Matrix.h:558