SparseNumeric.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_ADAPTORS_SYMMETRICMATRIX_SPARSENUMERIC_H_
36 #define _BLAZE_MATH_ADAPTORS_SYMMETRICMATRIX_SPARSENUMERIC_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <algorithm>
44 #include <stdexcept>
45 #include <vector>
57 #include <blaze/math/shims/Clear.h>
59 #include <blaze/math/shims/Move.h>
66 #include <blaze/util/Assert.h>
72 #include <blaze/util/DisableIf.h>
73 #include <blaze/util/EnableIf.h>
74 #include <blaze/util/InvalidType.h>
75 #include <blaze/util/mpl/If.h>
78 #include <blaze/util/Types.h>
79 #include <blaze/util/Unused.h>
80 
81 
82 namespace blaze {
83 
84 //=================================================================================================
85 //
86 // CLASS TEMPLATE SPECIALIZATION FOR SPARSE MATRICES WITH NUMERIC ELEMENT TYPE
87 //
88 //=================================================================================================
89 
90 //*************************************************************************************************
98 template< typename MT // Type of the adapted sparse matrix
99  , bool SO > // Storage order of the adapted sparse matrix
100 class SymmetricMatrix<MT,SO,false,true>
101  : public SparseMatrix< SymmetricMatrix<MT,SO,false,true>, SO >
102 {
103  private:
104  //**Type definitions****************************************************************************
105  typedef typename MT::OppositeType OT;
106  typedef typename MT::TransposeType TT;
107  typedef typename MT::ElementType ET;
108  //**********************************************************************************************
109 
110  public:
111  //**Type definitions****************************************************************************
112  typedef SymmetricMatrix<MT,SO,false,true> This;
113  typedef This ResultType;
114  typedef SymmetricMatrix<OT,!SO,false,true> OppositeType;
115  typedef SymmetricMatrix<TT,!SO,false,true> TransposeType;
116  typedef ET ElementType;
117  typedef typename MT::ReturnType ReturnType;
118  typedef const This& CompositeType;
119  typedef NumericProxy<MT> Reference;
120  typedef typename MT::ConstReference ConstReference;
121  typedef typename MT::ConstIterator ConstIterator;
122  //**********************************************************************************************
123 
124  //**Rebind struct definition********************************************************************
127  template< typename ET > // Data type of the other matrix
128  struct Rebind {
130  typedef SymmetricMatrix< typename MT::template Rebind<ET>::Other > Other;
131  };
132  //**********************************************************************************************
133 
134  //**SymmetricValue class definition*************************************************************
137  class SymmetricValue
138  {
139  private:
140  //**struct BuiltinType***********************************************************************
143  template< typename T >
144  struct BuiltinType { typedef INVALID_TYPE Type; };
145  //*******************************************************************************************
146 
147  //**struct ComplexType***********************************************************************
150  template< typename T >
151  struct ComplexType { typedef typename T::value_type Type; };
152  //*******************************************************************************************
153 
154  public:
155  //**Type definitions*************************************************************************
157  typedef typename If< IsComplex<ElementType>
158  , ComplexType<ElementType>
159  , BuiltinType<ElementType> >::Type::Type ValueType;
160 
161  typedef ValueType value_type;
162  //*******************************************************************************************
163 
164  //**Constructor******************************************************************************
170  inline SymmetricValue( ElementType& v1, ElementType& v2 )
171  : v1_( &v1 ) // The first represented value.
172  , v2_( &v2 ) // The second represented value.
173  {}
174  //*******************************************************************************************
175 
176  //*******************************************************************************************
182  inline SymmetricValue& operator=( const SymmetricValue& sv ) {
183  *v1_ = *sv.v1_;
184  if( v1_ != v2_ )
185  v2_ = *sv.v2_;
186  return *this;
187  }
188  //*******************************************************************************************
189 
190  //*******************************************************************************************
196  template< typename T > inline SymmetricValue& operator=( const T& v ) {
197  *v1_ = v;
198  if( v1_ != v2_ )
199  *v2_ = v;
200  return *this;
201  }
202  //*******************************************************************************************
203 
204  //*******************************************************************************************
210  template< typename T > inline SymmetricValue& operator+=( const T& v ) {
211  *v1_ += v;
212  if( v1_ != v2_ )
213  *v2_ += v;
214  return *this;
215  }
216  //*******************************************************************************************
217 
218  //*******************************************************************************************
224  template< typename T > inline SymmetricValue& operator-=( const T& v ) {
225  *v1_ -= v;
226  if( v1_ != v2_ )
227  *v2_ -= v;
228  return *this;
229  }
230  //*******************************************************************************************
231 
232  //*******************************************************************************************
238  template< typename T > inline SymmetricValue& operator*=( const T& v ) {
239  *v1_ *= v;
240  if( v1_ != v2_ )
241  *v2_ *= v;
242  return *this;
243  }
244  //*******************************************************************************************
245 
246  //*******************************************************************************************
252  template< typename T > inline SymmetricValue& operator/=( const T& v ) {
253  *v1_ /= v;
254  if( v1_ != v2_ )
255  *v2_ /= v;
256  return *this;
257  }
258  //*******************************************************************************************
259 
260  //*******************************************************************************************
265  inline operator ElementType() const {
266  return *v1_;
267  }
268  //*******************************************************************************************
269 
270  //*******************************************************************************************
278  inline ValueType real() const {
279  return v1_->real();
280  }
281  //*******************************************************************************************
282 
283  //*******************************************************************************************
292  inline void real( ValueType value ) const {
293  v1_->real( value );
294  if( v1_ != v2_ )
295  v2_->real( value );
296  }
297  //*******************************************************************************************
298 
299  //*******************************************************************************************
307  inline ValueType imag() const {
308  return v1_->imag();
309  }
310  //*******************************************************************************************
311 
312  //*******************************************************************************************
321  inline void imag( ValueType value ) const {
322  v1_->imag( value );
323  if( v1_ != v2_ )
324  v2_->imag( value );
325  }
326  //*******************************************************************************************
327 
328  private:
329  //**Member variables*************************************************************************
330  ElementType* v1_;
331  ElementType* v2_;
332  //*******************************************************************************************
333  };
334  //**********************************************************************************************
335 
336  //**SymmetricElement class definition***********************************************************
339  class SymmetricElement : private SparseElement
340  {
341  private:
342  //**Type definitions*************************************************************************
343  typedef typename MT::Iterator IteratorType;
344  //*******************************************************************************************
345 
346  public:
347  //**Type definitions*************************************************************************
348  typedef SymmetricValue ValueType;
349  typedef size_t IndexType;
350  typedef SymmetricValue Reference;
351  typedef const SymmetricValue ConstReference;
352  typedef SymmetricElement* Pointer;
353  //*******************************************************************************************
354 
355  //**Constructor******************************************************************************
361  inline SymmetricElement( IteratorType e1, IteratorType e2 )
362  : e1_( e1 ) // The first represented sparse element
363  , e2_( e2 ) // The second represented sparse element
364  {}
365  //*******************************************************************************************
366 
367  //**Assignment operator**********************************************************************
373  template< typename T > inline SymmetricElement& operator=( const T& v ) {
374  *e1_ = v;
375  if( e1_ != e2_ )
376  *e2_ = v;
377  return *this;
378  }
379  //*******************************************************************************************
380 
381  //**Addition assignment operator*************************************************************
387  template< typename T > inline SymmetricElement& operator+=( const T& v ) {
388  *e1_ += v;
389  if( e1_ != e2_ )
390  *e2_ += v;
391  return *this;
392  }
393  //*******************************************************************************************
394 
395  //**Subtraction assignment operator**********************************************************
401  template< typename T > inline SymmetricElement& operator-=( const T& v ) {
402  *e1_ -= v;
403  if( e1_ != e2_ )
404  *e2_ -= v;
405  return *this;
406  }
407  //*******************************************************************************************
408 
409  //**Multiplication assignment operator*******************************************************
415  template< typename T > inline SymmetricElement& operator*=( const T& v ) {
416  *e1_ *= v;
417  if( e1_ != e2_ )
418  *e2_ *= v;
419  return *this;
420  }
421  //*******************************************************************************************
422 
423  //**Division assignment operator*************************************************************
429  template< typename T > inline SymmetricElement& operator/=( const T& v ) {
430  *e1_ /= v;
431  if( e1_ != e2_ )
432  *e2_ /= v;
433  return *this;
434  }
435  //*******************************************************************************************
436 
437  //**Element access operator******************************************************************
442  inline Pointer operator->() {
443  return this;
444  }
445  //*******************************************************************************************
446 
447  //**Value function***************************************************************************
452  inline Reference value() const {
453  return Reference( e1_->value(), e2_->value() );
454  }
455  //*******************************************************************************************
456 
457  //**Index function***************************************************************************
462  inline IndexType index() const {
463  return e1_->index();
464  }
465  //*******************************************************************************************
466 
467  private:
468  //**Member variables*************************************************************************
469  IteratorType e1_;
470  IteratorType e2_;
471  //*******************************************************************************************
472  };
473  //**********************************************************************************************
474 
475  //**Iterator class definition*******************************************************************
478  class Iterator
479  {
480  public:
481  //**Type definitions*************************************************************************
482  typedef typename MT::Iterator IteratorType;
483 
484  typedef std::forward_iterator_tag IteratorCategory;
485  typedef SymmetricElement ValueType;
486  typedef ValueType PointerType;
487  typedef ValueType ReferenceType;
488  typedef ptrdiff_t DifferenceType;
489 
490  // STL iterator requirements
491  typedef IteratorCategory iterator_category;
492  typedef ValueType value_type;
493  typedef PointerType pointer;
494  typedef ReferenceType reference;
495  typedef DifferenceType difference_type;
496  //*******************************************************************************************
497 
498  //**Default constructor**********************************************************************
501  inline Iterator()
502  : pos_ ( ) // Iterator to the current sparse symmetric matrix element
503  , matrix_( NULL ) // The sparse matrix containing the iterator
504  , index_ ( 0UL ) // The row/column index of the iterator
505  {}
506  //*******************************************************************************************
507 
508  //**Constructor******************************************************************************
515  inline Iterator( IteratorType pos, MT& matrix, size_t index )
516  : pos_ ( pos ) // Iterator to the current sparse symmetric matrix element
517  , matrix_( &matrix ) // The sparse matrix containing the iterator
518  , index_ ( index ) // The row/column index of the iterator
519  {}
520  //*******************************************************************************************
521 
522  //**Prefix increment operator****************************************************************
527  inline Iterator& operator++() {
528  ++pos_;
529  return *this;
530  }
531  //*******************************************************************************************
532 
533  //**Postfix increment operator***************************************************************
538  inline const Iterator operator++( int ) {
539  const Iterator tmp( *this );
540  ++(*this);
541  return tmp;
542  }
543  //*******************************************************************************************
544 
545  //**Element access operator******************************************************************
550  inline ReferenceType operator*() const {
551  const IteratorType pos2( SO ? matrix_->find( index_, pos_->index() )
552  : matrix_->find( pos_->index(), index_ ) );
553  BLAZE_INTERNAL_ASSERT( pos2 != matrix_->end( pos_->index() ), "Missing matrix element detected" );
554  return ReferenceType( pos_, pos2 );
555  }
556  //*******************************************************************************************
557 
558  //**Element access operator******************************************************************
563  inline PointerType operator->() const {
564  const IteratorType pos2( SO ? matrix_->find( index_, pos_->index() )
565  : matrix_->find( pos_->index(), index_ ) );
566  BLAZE_INTERNAL_ASSERT( pos2 != matrix_->end( pos_->index() ), "Missing matrix element detected" );
567  return PointerType( pos_, pos2 );
568  }
569  //*******************************************************************************************
570 
571  //**Conversion operator**********************************************************************
576  inline operator ConstIterator() const {
577  return pos_;
578  }
579  //*******************************************************************************************
580 
581  //**Equality operator************************************************************************
587  inline bool operator==( const Iterator& rhs ) const {
588  return pos_ == rhs.pos_;
589  }
590  //*******************************************************************************************
591 
592  //**Inequality operator**********************************************************************
598  inline bool operator!=( const Iterator& rhs ) const {
599  return !( *this == rhs );
600  }
601  //*******************************************************************************************
602 
603  //**Subtraction operator*********************************************************************
609  inline DifferenceType operator-( const Iterator& rhs ) const {
610  return pos_ - rhs.pos_;
611  }
612  //*******************************************************************************************
613 
614  //**Base function****************************************************************************
619  inline IteratorType base() const {
620  return pos_;
621  }
622  //*******************************************************************************************
623 
624  private:
625  //**Member variables*************************************************************************
626  IteratorType pos_;
627  MT* matrix_;
628  size_t index_;
629  //*******************************************************************************************
630  };
631  //**********************************************************************************************
632 
633  //**Compilation flags***************************************************************************
635  enum { smpAssignable = 0 };
636  //**********************************************************************************************
637 
638  //**Constructors********************************************************************************
641  explicit inline SymmetricMatrix();
642  explicit inline SymmetricMatrix( size_t n );
643  explicit inline SymmetricMatrix( size_t n, size_t nonzeros );
644  explicit inline SymmetricMatrix( size_t n, const std::vector<size_t>& nonzeros );
645 
646  inline SymmetricMatrix( const SymmetricMatrix& m );
647  template< typename MT2 > inline SymmetricMatrix( const Matrix<MT2,SO>& m );
648  template< typename MT2 > inline SymmetricMatrix( const Matrix<MT2,!SO>& m );
650  //**********************************************************************************************
651 
652  //**Destructor**********************************************************************************
653  // No explicitly declared destructor.
654  //**********************************************************************************************
655 
656  //**Data access functions***********************************************************************
659  inline Reference operator()( size_t i, size_t j );
660  inline ConstReference operator()( size_t i, size_t j ) const;
661  inline Iterator begin ( size_t i );
662  inline ConstIterator begin ( size_t i ) const;
663  inline ConstIterator cbegin( size_t i ) const;
664  inline Iterator end ( size_t i );
665  inline ConstIterator end ( size_t i ) const;
666  inline ConstIterator cend ( size_t i ) const;
668  //**********************************************************************************************
669 
670  //**Assignment operators************************************************************************
673  inline SymmetricMatrix& operator=( const SymmetricMatrix& rhs );
674 
675  template< typename MT2 >
676  inline typename DisableIf< IsComputation<MT2>, SymmetricMatrix& >::Type
677  operator=( const Matrix<MT2,SO>& rhs );
678 
679  template< typename MT2 >
680  inline typename EnableIf< IsComputation<MT2>, SymmetricMatrix& >::Type
681  operator=( const Matrix<MT2,SO>& rhs );
682 
683  template< typename MT2 >
684  inline SymmetricMatrix& operator=( const Matrix<MT2,!SO>& rhs );
685 
686  template< typename MT2 >
687  inline typename DisableIf< IsComputation<MT2>, SymmetricMatrix& >::Type
688  operator+=( const Matrix<MT2,SO>& rhs );
689 
690  template< typename MT2 >
691  inline typename EnableIf< IsComputation<MT2>, SymmetricMatrix& >::Type
692  operator+=( const Matrix<MT2,SO>& rhs );
693 
694  template< typename MT2 >
695  inline SymmetricMatrix& operator+=( const Matrix<MT2,!SO>& rhs );
696 
697  template< typename MT2 >
698  inline typename DisableIf< IsComputation<MT2>, SymmetricMatrix& >::Type
699  operator-=( const Matrix<MT2,SO>& rhs );
700 
701  template< typename MT2 >
702  inline typename EnableIf< IsComputation<MT2>, SymmetricMatrix& >::Type
703  operator-=( const Matrix<MT2,SO>& rhs );
704 
705  template< typename MT2 >
706  inline SymmetricMatrix& operator-=( const Matrix<MT2,!SO>& rhs );
707 
708  template< typename MT2, bool SO2 >
709  inline SymmetricMatrix& operator*=( const Matrix<MT2,SO2>& rhs );
710 
711  template< typename Other >
712  inline typename EnableIf< IsNumeric<Other>, SymmetricMatrix >::Type&
713  operator*=( Other rhs );
714 
715  template< typename Other >
716  inline typename EnableIf< IsNumeric<Other>, SymmetricMatrix >::Type&
717  operator/=( Other rhs );
719  //**********************************************************************************************
720 
721  //**Utility functions***************************************************************************
724  inline size_t rows() const;
725  inline size_t columns() const;
726  inline size_t capacity() const;
727  inline size_t capacity( size_t i ) const;
728  inline size_t nonZeros() const;
729  inline size_t nonZeros( size_t i ) const;
730  inline void reset();
731  inline void reset( size_t i );
732  inline void clear();
733  inline Iterator set( size_t i, size_t j, const ElementType& value );
734  inline Iterator insert( size_t i, size_t j, const ElementType& value );
735  inline void erase( size_t i, size_t j );
736  inline Iterator erase( size_t i, Iterator pos );
737  inline Iterator erase( size_t i, Iterator first, Iterator last );
738  inline void resize ( size_t n, bool preserve=true );
739  inline void reserve( size_t nonzeros );
740  inline void reserve( size_t i, size_t nonzeros );
741  inline void trim();
742  inline void trim( size_t i );
743  inline SymmetricMatrix& transpose();
744  template< typename Other > inline SymmetricMatrix& scale( const Other& scalar );
745  template< typename Other > inline SymmetricMatrix& scaleDiagonal( Other scale );
746  inline void swap( SymmetricMatrix& m ) /* throw() */;
748  //**********************************************************************************************
749 
750  //**Lookup functions****************************************************************************
753  inline Iterator find ( size_t i, size_t j );
754  inline ConstIterator find ( size_t i, size_t j ) const;
755  inline Iterator lowerBound( size_t i, size_t j );
756  inline ConstIterator lowerBound( size_t i, size_t j ) const;
757  inline Iterator upperBound( size_t i, size_t j );
758  inline ConstIterator upperBound( size_t i, size_t j ) const;
760  //**********************************************************************************************
761 
762  //**Low-level utility functions*****************************************************************
765  inline void append ( size_t i, size_t j, const ElementType& value, bool check=false );
766  inline void finalize( size_t i );
768  //**********************************************************************************************
769 
770  //**Expression template evaluation functions****************************************************
773  template< typename Other > inline bool canAlias ( const Other* alias ) const;
774  template< typename Other > inline bool isAliased( const Other* alias ) const;
775 
776  inline bool canSMPAssign() const;
778  //**********************************************************************************************
779 
780  private:
781  //**Member variables****************************************************************************
784  MT matrix_;
785 
786  //**********************************************************************************************
787 
788  //**Friend declarations*************************************************************************
789  template< typename MT2, bool SO2, bool DF2, bool NF2 >
790  friend bool isDefault( const SymmetricMatrix<MT2,SO2,DF2,NF2>& m );
791  //**********************************************************************************************
792 
793  //**Compile time checks*************************************************************************
806  BLAZE_STATIC_ASSERT( IsResizable<MT>::value || IsSquare<MT>::value );
807  //**********************************************************************************************
808 };
810 //*************************************************************************************************
811 
812 
813 
814 
815 //=================================================================================================
816 //
817 // CONSTRUCTORS
818 //
819 //=================================================================================================
820 
821 //*************************************************************************************************
825 template< typename MT // Type of the adapted sparse matrix
826  , bool SO > // Storage order of the adapted sparse matrix
827 inline SymmetricMatrix<MT,SO,false,true>::SymmetricMatrix()
828  : matrix_() // The adapted sparse matrix
829 {
830  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
831 }
833 //*************************************************************************************************
834 
835 
836 //*************************************************************************************************
844 template< typename MT // Type of the adapted sparse matrix
845  , bool SO > // Storage order of the adapted sparse matrix
846 inline SymmetricMatrix<MT,SO,false,true>::SymmetricMatrix( size_t n )
847  : matrix_( n, n ) // The adapted sparse matrix
848 {
850 
851  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
852 }
854 //*************************************************************************************************
855 
856 
857 //*************************************************************************************************
866 template< typename MT // Type of the adapted sparse matrix
867  , bool SO > // Storage order of the adapted sparse matrix
868 inline SymmetricMatrix<MT,SO,false,true>::SymmetricMatrix( size_t n, size_t nonzeros )
869  : matrix_( n, n, nonzeros ) // The adapted sparse matrix
870 {
872 
873  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
874 }
876 //*************************************************************************************************
877 
878 
879 //*************************************************************************************************
890 template< typename MT // Type of the adapted sparse matrix
891  , bool SO > // Storage order of the adapted sparse matrix
892 inline SymmetricMatrix<MT,SO,false,true>::SymmetricMatrix( size_t n, const std::vector<size_t>& nonzeros )
893  : matrix_( n, n, nonzeros ) // The adapted sparse matrix
894 {
896 
897  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
898 }
900 //*************************************************************************************************
901 
902 
903 //*************************************************************************************************
909 template< typename MT // Type of the adapted sparse matrix
910  , bool SO > // Storage order of the adapted sparse matrix
911 inline SymmetricMatrix<MT,SO,false,true>::SymmetricMatrix( const SymmetricMatrix& m )
912  : matrix_( m.matrix_ ) // The adapted sparse matrix
913 {
914  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
915 }
917 //*************************************************************************************************
918 
919 
920 //*************************************************************************************************
930 template< typename MT // Type of the adapted sparse matrix
931  , bool SO > // Storage order of the adapted sparse matrix
932 template< typename MT2 > // Type of the foreign matrix
933 inline SymmetricMatrix<MT,SO,false,true>::SymmetricMatrix( const Matrix<MT2,SO>& m )
934  : matrix_( ~m ) // The adapted sparse matrix
935 {
936  if( !IsSymmetric<MT2>::value && !isSymmetric( matrix_ ) )
937  throw std::invalid_argument( "Invalid setup of symmetric matrix" );
938 
939  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
940 }
942 //*************************************************************************************************
943 
944 
945 //*************************************************************************************************
955 template< typename MT // Type of the adapted sparse matrix
956  , bool SO > // Storage order of the adapted sparse matrix
957 template< typename MT2 > // Type of the foreign matrix
958 inline SymmetricMatrix<MT,SO,false,true>::SymmetricMatrix( const Matrix<MT2,!SO>& m )
959  : matrix_( trans( ~m ) ) // The adapted sparse matrix
960 {
961  if( !IsSymmetric<MT2>::value && !isSymmetric( matrix_ ) )
962  throw std::invalid_argument( "Invalid setup of symmetric matrix" );
963 
964  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
965 }
967 //*************************************************************************************************
968 
969 
970 
971 
972 //=================================================================================================
973 //
974 // DATA ACCESS FUNCTIONS
975 //
976 //=================================================================================================
977 
978 //*************************************************************************************************
990 template< typename MT // Type of the adapted sparse matrix
991  , bool SO > // Storage order of the adapted sparse matrix
993  SymmetricMatrix<MT,SO,false,true>::operator()( size_t i, size_t j )
994 {
995  BLAZE_USER_ASSERT( i<rows() , "Invalid row access index" );
996  BLAZE_USER_ASSERT( j<columns(), "Invalid column access index" );
997 
998  return Reference( matrix_, i, j );
999 }
1001 //*************************************************************************************************
1002 
1003 
1004 //*************************************************************************************************
1016 template< typename MT // Type of the adapted sparse matrix
1017  , bool SO > // Storage order of the adapted sparse matrix
1019  SymmetricMatrix<MT,SO,false,true>::operator()( size_t i, size_t j ) const
1020 {
1021  BLAZE_USER_ASSERT( i<rows() , "Invalid row access index" );
1022  BLAZE_USER_ASSERT( j<columns(), "Invalid column access index" );
1023 
1024  return matrix_(i,j);
1025 }
1027 //*************************************************************************************************
1028 
1029 
1030 //*************************************************************************************************
1042 template< typename MT // Type of the adapted sparse matrix
1043  , bool SO > // Storage order of the adapted sparse matrix
1046 {
1047  return Iterator( matrix_.begin(i), matrix_, i );
1048 }
1050 //*************************************************************************************************
1051 
1052 
1053 //*************************************************************************************************
1065 template< typename MT // Type of the adapted sparse matrix
1066  , bool SO > // Storage order of the adapted sparse matrix
1069 {
1070  return matrix_.begin(i);
1071 }
1073 //*************************************************************************************************
1074 
1075 
1076 //*************************************************************************************************
1088 template< typename MT // Type of the adapted sparse matrix
1089  , bool SO > // Storage order of the adapted sparse matrix
1092 {
1093  return matrix_.cbegin(i);
1094 }
1096 //*************************************************************************************************
1097 
1098 
1099 //*************************************************************************************************
1111 template< typename MT // Type of the adapted sparse matrix
1112  , bool SO > // Storage order of the adapted sparse matrix
1115 {
1116  return Iterator( matrix_.end(i), matrix_, i );
1117 }
1119 //*************************************************************************************************
1120 
1121 
1122 //*************************************************************************************************
1134 template< typename MT // Type of the adapted sparse matrix
1135  , bool SO > // Storage order of the adapted sparse matrix
1137  SymmetricMatrix<MT,SO,false,true>::end( size_t i ) const
1138 {
1139  return matrix_.end(i);
1140 }
1142 //*************************************************************************************************
1143 
1144 
1145 //*************************************************************************************************
1157 template< typename MT // Type of the adapted sparse matrix
1158  , bool SO > // Storage order of the adapted sparse matrix
1160  SymmetricMatrix<MT,SO,false,true>::cend( size_t i ) const
1161 {
1162  return matrix_.cend(i);
1163 }
1165 //*************************************************************************************************
1166 
1167 
1168 
1169 
1170 //=================================================================================================
1171 //
1172 // ASSIGNMENT OPERATORS
1173 //
1174 //=================================================================================================
1175 
1176 //*************************************************************************************************
1186 template< typename MT // Type of the adapted sparse matrix
1187  , bool SO > // Storage order of the adapted sparse matrix
1188 inline SymmetricMatrix<MT,SO,false,true>&
1189  SymmetricMatrix<MT,SO,false,true>::operator=( const SymmetricMatrix& rhs )
1190 {
1191  matrix_ = rhs.matrix_;
1192 
1193  return *this;
1194 }
1196 //*************************************************************************************************
1197 
1198 
1199 //*************************************************************************************************
1212 template< typename MT // Type of the adapted sparse matrix
1213  , bool SO > // Storage order of the adapted sparse matrix
1214 template< typename MT2 > // Type of the right-hand side matrix
1215 inline typename DisableIf< IsComputation<MT2>, SymmetricMatrix<MT,SO,false,true>& >::Type
1216  SymmetricMatrix<MT,SO,false,true>::operator=( const Matrix<MT2,SO>& rhs )
1217 {
1218  if( !IsSymmetric<MT2>::value && !isSymmetric( ~rhs ) )
1219  throw std::invalid_argument( "Invalid assignment to symmetric matrix" );
1220 
1221  matrix_ = ~rhs;
1222 
1223  return *this;
1224 }
1226 //*************************************************************************************************
1227 
1228 
1229 //*************************************************************************************************
1242 template< typename MT // Type of the adapted sparse matrix
1243  , bool SO > // Storage order of the adapted sparse matrix
1244 template< typename MT2 > // Type of the right-hand side matrix
1245 inline typename EnableIf< IsComputation<MT2>, SymmetricMatrix<MT,SO,false,true>& >::Type
1246  SymmetricMatrix<MT,SO,false,true>::operator=( const Matrix<MT2,SO>& rhs )
1247 {
1248  if( !IsSquare<MT2>::value && !isSquare( ~rhs ) )
1249  throw std::invalid_argument( "Invalid assignment to symmetric matrix" );
1250 
1251  if( IsSymmetric<MT2>::value ) {
1252  matrix_ = ~rhs;
1253  }
1254  else {
1255  MT tmp( ~rhs );
1256 
1257  if( !isSymmetric( tmp ) )
1258  throw std::invalid_argument( "Invalid assignment to symmetric matrix" );
1259 
1260  move( matrix_, tmp );
1261  }
1262 
1263  return *this;
1264 }
1266 //*************************************************************************************************
1267 
1268 
1269 //*************************************************************************************************
1282 template< typename MT // Type of the adapted sparse matrix
1283  , bool SO > // Storage order of the adapted sparse matrix
1284 template< typename MT2 > // Type of the right-hand side matrix
1285 inline SymmetricMatrix<MT,SO,false,true>&
1286  SymmetricMatrix<MT,SO,false,true>::operator=( const Matrix<MT2,!SO>& rhs )
1287 {
1288  return this->operator=( trans( ~rhs ) );
1289 }
1291 //*************************************************************************************************
1292 
1293 
1294 //*************************************************************************************************
1307 template< typename MT // Type of the adapted sparse matrix
1308  , bool SO > // Storage order of the adapted sparse matrix
1309 template< typename MT2 > // Type of the right-hand side matrix
1310 inline typename DisableIf< IsComputation<MT2>, SymmetricMatrix<MT,SO,false,true>& >::Type
1311  SymmetricMatrix<MT,SO,false,true>::operator+=( const Matrix<MT2,SO>& rhs )
1312 {
1313  if( !IsSymmetric<MT2>::value && !isSymmetric( ~rhs ) )
1314  throw std::invalid_argument( "Invalid assignment to symmetric matrix" );
1315 
1316  matrix_ += ~rhs;
1317 
1318  return *this;
1319 }
1321 //*************************************************************************************************
1322 
1323 
1324 //*************************************************************************************************
1337 template< typename MT // Type of the adapted sparse matrix
1338  , bool SO > // Storage order of the adapted sparse matrix
1339 template< typename MT2 > // Type of the right-hand side matrix
1340 inline typename EnableIf< IsComputation<MT2>, SymmetricMatrix<MT,SO,false,true>& >::Type
1341  SymmetricMatrix<MT,SO,false,true>::operator+=( const Matrix<MT2,SO>& rhs )
1342 {
1343  if( !IsSquare<MT2>::value && !isSquare( ~rhs ) )
1344  throw std::invalid_argument( "Invalid assignment to symmetric matrix" );
1345 
1346  if( IsSymmetric<MT2>::value ) {
1347  matrix_ += ~rhs;
1348  }
1349  else {
1350  typename MT2::ResultType tmp( ~rhs );
1351 
1352  if( !isSymmetric( tmp ) )
1353  throw std::invalid_argument( "Invalid assignment to symmetric matrix" );
1354 
1355  matrix_ += tmp;
1356  }
1357 
1358  return *this;
1359 }
1361 //*************************************************************************************************
1362 
1363 
1364 //*************************************************************************************************
1378 template< typename MT // Type of the adapted sparse matrix
1379  , bool SO > // Storage order of the adapted sparse matrix
1380 template< typename MT2 > // Type of the right-hand side matrix
1381 inline SymmetricMatrix<MT,SO,false,true>&
1382  SymmetricMatrix<MT,SO,false,true>::operator+=( const Matrix<MT2,!SO>& rhs )
1383 {
1384  return this->operator+=( trans( ~rhs ) );
1385 }
1387 //*************************************************************************************************
1388 
1389 
1390 //*************************************************************************************************
1403 template< typename MT // Type of the adapted sparse matrix
1404  , bool SO > // Storage order of the adapted sparse matrix
1405 template< typename MT2 > // Type of the right-hand side matrix
1406 inline typename DisableIf< IsComputation<MT2>, SymmetricMatrix<MT,SO,false,true>& >::Type
1407  SymmetricMatrix<MT,SO,false,true>::operator-=( const Matrix<MT2,SO>& rhs )
1408 {
1409  if( !IsSymmetric<MT2>::value && !isSymmetric( ~rhs ) )
1410  throw std::invalid_argument( "Invalid assignment to symmetric matrix" );
1411 
1412  matrix_ -= ~rhs;
1413 
1414  return *this;
1415 }
1417 //*************************************************************************************************
1418 
1419 
1420 //*************************************************************************************************
1433 template< typename MT // Type of the adapted sparse matrix
1434  , bool SO > // Storage order of the adapted sparse matrix
1435 template< typename MT2 > // Type of the right-hand side matrix
1436 inline typename EnableIf< IsComputation<MT2>, SymmetricMatrix<MT,SO,false,true>& >::Type
1437  SymmetricMatrix<MT,SO,false,true>::operator-=( const Matrix<MT2,SO>& rhs )
1438 {
1439  if( !IsSquare<MT2>::value && !isSquare( ~rhs ) )
1440  throw std::invalid_argument( "Invalid assignment to symmetric matrix" );
1441 
1442  if( IsSymmetric<MT2>::value ) {
1443  matrix_ -= ~rhs;
1444  }
1445  else {
1446  typename MT2::ResultType tmp( ~rhs );
1447 
1448  if( !isSymmetric( tmp ) )
1449  throw std::invalid_argument( "Invalid assignment to symmetric matrix" );
1450 
1451  matrix_ -= tmp;
1452  }
1453 
1454  return *this;
1455 }
1457 //*************************************************************************************************
1458 
1459 
1460 //*************************************************************************************************
1474 template< typename MT // Type of the adapted sparse matrix
1475  , bool SO > // Storage order of the adapted sparse matrix
1476 template< typename MT2 > // Type of the right-hand side matrix
1477 inline SymmetricMatrix<MT,SO,false,true>&
1478  SymmetricMatrix<MT,SO,false,true>::operator-=( const Matrix<MT2,!SO>& rhs )
1479 {
1480  return this->operator-=( trans( ~rhs ) );
1481 }
1483 //*************************************************************************************************
1484 
1485 
1486 //*************************************************************************************************
1498 template< typename MT // Type of the adapted sparse matrix
1499  , bool SO > // Storage order of the adapted sparse matrix
1500 template< typename MT2 // Type of the right-hand side matrix
1501  , bool SO2 > // Storage order of the right-hand side matrix
1502 inline SymmetricMatrix<MT,SO,false,true>&
1503  SymmetricMatrix<MT,SO,false,true>::operator*=( const Matrix<MT2,SO2>& rhs )
1504 {
1505  if( matrix_.rows() != (~rhs).columns() )
1506  throw std::invalid_argument( "Invalid assignment to symmetric matrix" );
1507 
1508  MT tmp( matrix_ * ~rhs );
1509 
1510  if( !isSymmetric( tmp ) )
1511  throw std::invalid_argument( "Invalid assignment to symmetric matrix" );
1512 
1513  move( matrix_, tmp );
1514 
1515  return *this;
1516 }
1518 //*************************************************************************************************
1519 
1520 
1521 //*************************************************************************************************
1529 template< typename MT // Type of the adapted sparse matrix
1530  , bool SO > // Storage order of the adapted sparse matrix
1531 template< typename Other > // Data type of the right-hand side scalar
1532 inline typename EnableIf< IsNumeric<Other>, SymmetricMatrix<MT,SO,false,true> >::Type&
1533  SymmetricMatrix<MT,SO,false,true>::operator*=( Other rhs )
1534 {
1535  matrix_ *= rhs;
1536  return *this;
1537 }
1538 //*************************************************************************************************
1539 
1540 
1541 //*************************************************************************************************
1549 template< typename MT // Type of the adapted sparse matrix
1550  , bool SO > // Storage order of the adapted sparse matrix
1551 template< typename Other > // Data type of the right-hand side scalar
1552 inline typename EnableIf< IsNumeric<Other>, SymmetricMatrix<MT,SO,false,true> >::Type&
1553  SymmetricMatrix<MT,SO,false,true>::operator/=( Other rhs )
1554 {
1555  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
1556 
1557  matrix_ /= rhs;
1558  return *this;
1559 }
1561 //*************************************************************************************************
1562 
1563 
1564 
1565 
1566 //=================================================================================================
1567 //
1568 // UTILITY FUNCTIONS
1569 //
1570 //=================================================================================================
1571 
1572 //*************************************************************************************************
1578 template< typename MT // Type of the adapted sparse matrix
1579  , bool SO > // Storage order of the adapted sparse matrix
1580 inline size_t SymmetricMatrix<MT,SO,false,true>::rows() const
1581 {
1582  return matrix_.rows();
1583 }
1585 //*************************************************************************************************
1586 
1587 
1588 //*************************************************************************************************
1594 template< typename MT // Type of the adapted sparse matrix
1595  , bool SO > // Storage order of the adapted sparse matrix
1596 inline size_t SymmetricMatrix<MT,SO,false,true>::columns() const
1597 {
1598  return matrix_.columns();
1599 }
1601 //*************************************************************************************************
1602 
1603 
1604 //*************************************************************************************************
1610 template< typename MT // Type of the adapted sparse matrix
1611  , bool SO > // Storage order of the adapted sparse matrix
1612 inline size_t SymmetricMatrix<MT,SO,false,true>::capacity() const
1613 {
1614  return matrix_.capacity();
1615 }
1617 //*************************************************************************************************
1618 
1619 
1620 //*************************************************************************************************
1631 template< typename MT // Type of the adapted sparse matrix
1632  , bool SO > // Storage order of the adapted sparse matrix
1633 inline size_t SymmetricMatrix<MT,SO,false,true>::capacity( size_t i ) const
1634 {
1635  return matrix_.capacity(i);
1636 }
1638 //*************************************************************************************************
1639 
1640 
1641 //*************************************************************************************************
1647 template< typename MT // Type of the adapted sparse matrix
1648  , bool SO > // Storage order of the adapted sparse matrix
1649 inline size_t SymmetricMatrix<MT,SO,false,true>::nonZeros() const
1650 {
1651  return matrix_.nonZeros();
1652 }
1654 //*************************************************************************************************
1655 
1656 
1657 //*************************************************************************************************
1669 template< typename MT // Type of the adapted sparse matrix
1670  , bool SO > // Storage order of the adapted sparse matrix
1671 inline size_t SymmetricMatrix<MT,SO,false,true>::nonZeros( size_t i ) const
1672 {
1673  return matrix_.nonZeros(i);
1674 }
1676 //*************************************************************************************************
1677 
1678 
1679 //*************************************************************************************************
1685 template< typename MT // Type of the adapted sparse matrix
1686  , bool SO > // Storage order of the adapted sparse matrix
1688 {
1689  matrix_.reset();
1690 }
1692 //*************************************************************************************************
1693 
1694 
1695 //*************************************************************************************************
1731 template< typename MT // Type of the adapted sparse matrix
1732  , bool SO > // Storage order of the adapted sparse matrix
1733 inline void SymmetricMatrix<MT,SO,false,true>::reset( size_t i )
1734 {
1735  for( typename MT::Iterator it=matrix_.begin(i); it!=matrix_.end(i); ++it )
1736  {
1737  const size_t j( it->index() );
1738 
1739  if( i == j )
1740  continue;
1741 
1742  if( SO ) {
1743  const typename MT::Iterator pos( matrix_.find( i, j ) );
1744  BLAZE_INTERNAL_ASSERT( pos != matrix_.end( j ), "Missing element detected" );
1745  matrix_.erase( j, pos );
1746  }
1747  else {
1748  const typename MT::Iterator pos( matrix_.find( j, i ) );
1749  BLAZE_INTERNAL_ASSERT( pos != matrix_.end( j ), "Missing element detected" );
1750  matrix_.erase( j, pos );
1751  }
1752  }
1753 
1754  matrix_.reset( i );
1755 }
1757 //*************************************************************************************************
1758 
1759 
1760 //*************************************************************************************************
1768 template< typename MT // Type of the adapted sparse matrix
1769  , bool SO > // Storage order of the adapted sparse matrix
1771 {
1772  using blaze::clear;
1773 
1774  clear( matrix_ );
1775 }
1777 //*************************************************************************************************
1778 
1779 
1780 //*************************************************************************************************
1794 template< typename MT // Type of the adapted sparse matrix
1795  , bool SO > // Storage order of the adapted sparse matrix
1797  SymmetricMatrix<MT,SO,false,true>::set( size_t i, size_t j, const ElementType& value )
1798 {
1799  if( i != j )
1800  matrix_.set( j, i, value );
1801  return Iterator( matrix_.set( i, j, value ), matrix_, ( SO ? j : i ) );
1802 }
1804 //*************************************************************************************************
1805 
1806 
1807 //*************************************************************************************************
1822 template< typename MT // Type of the adapted sparse matrix
1823  , bool SO > // Storage order of the adapted sparse matrix
1825  SymmetricMatrix<MT,SO,false,true>::insert( size_t i, size_t j, const ElementType& value )
1826 {
1827  if( i != j )
1828  matrix_.insert( j, i, value );
1829  return Iterator( matrix_.insert( i, j, value ), matrix_, ( SO ? j : i ) );
1830 }
1832 //*************************************************************************************************
1833 
1834 
1835 //*************************************************************************************************
1845 template< typename MT // Type of the adapted sparse matrix
1846  , bool SO > // Storage order of the adapted sparse matrix
1847 inline void SymmetricMatrix<MT,SO,false,true>::erase( size_t i, size_t j )
1848 {
1849  matrix_.erase( i, j );
1850  if( i != j )
1851  matrix_.erase( j, i );
1852 }
1854 //*************************************************************************************************
1855 
1856 
1857 //*************************************************************************************************
1869 template< typename MT // Type of the adapted sparse matrix
1870  , bool SO > // Storage order of the adapted sparse matrix
1872  SymmetricMatrix<MT,SO,false,true>::erase( size_t i, Iterator pos )
1873 {
1874  const typename MT::Iterator base( pos.base() );
1875 
1876  if( base == matrix_.end( i ) )
1877  return pos;
1878 
1879  const size_t j( base->index() );
1880 
1881  if( i == j ) {
1882  BLAZE_INTERNAL_ASSERT( matrix_.find( i, i ) != matrix_.end( i ), "Missing element detected" );
1883  return Iterator( matrix_.erase( i, base ), matrix_, i );
1884  }
1885 
1886  if( SO ) {
1887  BLAZE_INTERNAL_ASSERT( matrix_.find( i, j ) != matrix_.end( j ), "Missing element detected" );
1888  matrix_.erase( j, matrix_.find( i, j ) );
1889  return Iterator( matrix_.erase( i, base ), matrix_, i );
1890  }
1891  else {
1892  BLAZE_INTERNAL_ASSERT( matrix_.find( j, i ) != matrix_.end( j ), "Missing element detected" );
1893  matrix_.erase( j, matrix_.find( j, i ) );
1894  return Iterator( matrix_.erase( i, base ), matrix_, i );
1895  }
1896 }
1898 //*************************************************************************************************
1899 
1900 
1901 //*************************************************************************************************
1915 template< typename MT // Type of the adapted sparse matrix
1916  , bool SO > // Storage order of the adapted sparse matrix
1918  SymmetricMatrix<MT,SO,false,true>::erase( size_t i, Iterator first, Iterator last )
1919 {
1920  for( typename MT::Iterator it=first.base(); it!=last.base(); ++it )
1921  {
1922  const size_t j( it->index() );
1923 
1924  if( i == j )
1925  continue;
1926 
1927  if( SO ) {
1928  BLAZE_INTERNAL_ASSERT( matrix_.find( i, j ) != matrix_.end( j ), "Missing element detected" );
1929  matrix_.erase( i, j );
1930  }
1931  else {
1932  BLAZE_INTERNAL_ASSERT( matrix_.find( j, i ) != matrix_.end( j ), "Missing element detected" );
1933  matrix_.erase( j, i );
1934  }
1935  }
1936 
1937  return Iterator( matrix_.erase( i, first.base(), last.base() ), matrix_, i );
1938 }
1940 //*************************************************************************************************
1941 
1942 
1943 //*************************************************************************************************
1958 template< typename MT // Type of the adapted sparse matrix
1959  , bool SO > // Storage order of the adapted sparse matrix
1960 void SymmetricMatrix<MT,SO,false,true>::resize( size_t n, bool preserve )
1961 {
1963 
1964  UNUSED_PARAMETER( preserve );
1965 
1966  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
1967 
1968  matrix_.resize( n, n, true );
1969 }
1971 //*************************************************************************************************
1972 
1973 
1974 //*************************************************************************************************
1985 template< typename MT // Type of the adapted sparse matrix
1986  , bool SO > // Storage order of the adapted sparse matrix
1987 inline void SymmetricMatrix<MT,SO,false,true>::reserve( size_t nonzeros )
1988 {
1989  matrix_.reserve( nonzeros );
1990 }
1992 //*************************************************************************************************
1993 
1994 
1995 //*************************************************************************************************
2009 template< typename MT // Type of the adapted sparse matrix
2010  , bool SO > // Storage order of the adapted sparse matrix
2011 inline void SymmetricMatrix<MT,SO,false,true>::reserve( size_t i, size_t nonzeros )
2012 {
2013  matrix_.reserve( i, nonzeros );
2014 }
2016 //*************************************************************************************************
2017 
2018 
2019 //*************************************************************************************************
2030 template< typename MT // Type of the adapted sparse matrix
2031  , bool SO > // Storage order of the adapted sparse matrix
2032 inline void SymmetricMatrix<MT,SO,false,true>::trim()
2033 {
2034  matrix_.trim();
2035 }
2037 //*************************************************************************************************
2038 
2039 
2040 //*************************************************************************************************
2052 template< typename MT // Type of the adapted sparse matrix
2053  , bool SO > // Storage order of the adapted sparse matrix
2054 inline void SymmetricMatrix<MT,SO,false,true>::trim( size_t i )
2055 {
2056  matrix_.trim( i );
2057 }
2059 //*************************************************************************************************
2060 
2061 
2062 //*************************************************************************************************
2068 template< typename MT // Type of the adapted sparse matrix
2069  , bool SO > // Storage order of the adapted sparse matrix
2070 inline SymmetricMatrix<MT,SO,false,true>& SymmetricMatrix<MT,SO,false,true>::transpose()
2071 {
2072  return *this;
2073 }
2075 //*************************************************************************************************
2076 
2077 
2078 //*************************************************************************************************
2085 template< typename MT // Type of the adapted sparse matrix
2086  , bool SO > // Storage order of the adapted sparse matrix
2087 template< typename Other > // Data type of the scalar value
2088 inline SymmetricMatrix<MT,SO,false,true>&
2089  SymmetricMatrix<MT,SO,false,true>::scale( const Other& scalar )
2090 {
2091  matrix_.scale( scalar );
2092  return *this;
2093 }
2095 //*************************************************************************************************
2096 
2097 
2098 //*************************************************************************************************
2105 template< typename MT // Type of the adapted sparse matrix
2106  , bool SO > // Storage order of the adapted sparse matrix
2107 template< typename Other > // Data type of the scalar value
2108 inline SymmetricMatrix<MT,SO,false,true>&
2109  SymmetricMatrix<MT,SO,false,true>::scaleDiagonal( Other scalar )
2110 {
2111  matrix_.scaleDiagonal( scalar );
2112  return *this;
2113 }
2115 //*************************************************************************************************
2116 
2117 
2118 //*************************************************************************************************
2126 template< typename MT // Type of the adapted sparse matrix
2127  , bool SO > // Storage order of the adapted sparse matrix
2128 inline void SymmetricMatrix<MT,SO,false,true>::swap( SymmetricMatrix& m ) /* throw() */
2129 {
2130  using std::swap;
2131 
2132  swap( matrix_, m.matrix_ );
2133 }
2135 //*************************************************************************************************
2136 
2137 
2138 
2139 
2140 //=================================================================================================
2141 //
2142 // LOOKUP FUNCTIONS
2143 //
2144 //=================================================================================================
2145 
2146 //*************************************************************************************************
2162 template< typename MT // Type of the adapted sparse matrix
2163  , bool SO > // Storage order of the adapted sparse matrix
2165  SymmetricMatrix<MT,SO,false,true>::find( size_t i, size_t j )
2166 {
2167  return Iterator( matrix_.find( i, j ), matrix_, ( SO ? j : i ) );
2168 }
2170 //*************************************************************************************************
2171 
2172 
2173 //*************************************************************************************************
2189 template< typename MT // Type of the adapted sparse matrix
2190  , bool SO > // Storage order of the adapted sparse matrix
2192  SymmetricMatrix<MT,SO,false,true>::find( size_t i, size_t j ) const
2193 {
2194  return matrix_.find( i, j );
2195 }
2197 //*************************************************************************************************
2198 
2199 
2200 //*************************************************************************************************
2216 template< typename MT // Type of the adapted sparse matrix
2217  , bool SO > // Storage order of the adapted sparse matrix
2219  SymmetricMatrix<MT,SO,false,true>::lowerBound( size_t i, size_t j )
2220 {
2221  return Iterator( matrix_.lowerBound( i, j ), matrix_, ( SO ? j : i ) );
2222 }
2224 //*************************************************************************************************
2225 
2226 
2227 //*************************************************************************************************
2243 template< typename MT // Type of the adapted sparse matrix
2244  , bool SO > // Storage order of the adapted sparse matrix
2246  SymmetricMatrix<MT,SO,false,true>::lowerBound( size_t i, size_t j ) const
2247 {
2248  return matrix_.lowerBound( i, j );
2249 }
2251 //*************************************************************************************************
2252 
2253 
2254 //*************************************************************************************************
2270 template< typename MT // Type of the adapted sparse matrix
2271  , bool SO > // Storage order of the adapted sparse matrix
2273  SymmetricMatrix<MT,SO,false,true>::upperBound( size_t i, size_t j )
2274 {
2275  return Iterator( matrix_.upperBound( i, j ), matrix_, ( SO ? j : i ) );
2276 }
2278 //*************************************************************************************************
2279 
2280 
2281 //*************************************************************************************************
2297 template< typename MT // Type of the adapted sparse matrix
2298  , bool SO > // Storage order of the adapted sparse matrix
2300  SymmetricMatrix<MT,SO,false,true>::upperBound( size_t i, size_t j ) const
2301 {
2302  return matrix_.upperBound( i, j );
2303 }
2305 //*************************************************************************************************
2306 
2307 
2308 
2309 
2310 //=================================================================================================
2311 //
2312 // LOW-LEVEL UTILITY FUNCTIONS
2313 //
2314 //=================================================================================================
2315 
2316 //*************************************************************************************************
2371 template< typename MT // Type of the adapted sparse matrix
2372  , bool SO > // Storage order of the adapted sparse matrix
2373 inline void SymmetricMatrix<MT,SO,false,true>::append( size_t i, size_t j, const ElementType& value, bool check )
2374 {
2375  matrix_.append( i, j, value, check );
2376  if( i != j && ( !check || !isDefault( value ) ) )
2377  matrix_.insert( j, i, value );
2378 }
2380 //*************************************************************************************************
2381 
2382 
2383 //*************************************************************************************************
2397 template< typename MT // Type of the adapted sparse matrix
2398  , bool SO > // Storage order of the adapted sparse matrix
2399 inline void SymmetricMatrix<MT,SO,false,true>::finalize( size_t i )
2400 {
2401  matrix_.trim( i );
2402 }
2404 //*************************************************************************************************
2405 
2406 
2407 
2408 
2409 //=================================================================================================
2410 //
2411 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
2412 //
2413 //=================================================================================================
2414 
2415 //*************************************************************************************************
2426 template< typename MT // Type of the adapted sparse matrix
2427  , bool SO > // Storage order of the adapted sparse matrix
2428 template< typename Other > // Data type of the foreign expression
2429 inline bool SymmetricMatrix<MT,SO,false,true>::canAlias( const Other* alias ) const
2430 {
2431  return matrix_.canAlias( alias );
2432 }
2434 //*************************************************************************************************
2435 
2436 
2437 //*************************************************************************************************
2448 template< typename MT // Type of the adapted sparse matrix
2449  , bool SO > // Storage order of the adapted sparse matrix
2450 template< typename Other > // Data type of the foreign expression
2451 inline bool SymmetricMatrix<MT,SO,false,true>::isAliased( const Other* alias ) const
2452 {
2453  return matrix_.isAliased( alias );
2454 }
2456 //*************************************************************************************************
2457 
2458 
2459 //*************************************************************************************************
2470 template< typename MT // Type of the adapted sparse matrix
2471  , bool SO > // Storage order of the adapted sparse matrix
2472 inline bool SymmetricMatrix<MT,SO,false,true>::canSMPAssign() const
2473 {
2474  return matrix_.canSMPAssign();
2475 }
2477 //*************************************************************************************************
2478 
2479 } // namespace blaze
2480 
2481 #endif
#define BLAZE_CONSTRAINT_MUST_NOT_BE_CONST(T)
Constraint on the data type.In case the given data type is a const-qualified type, a compilation error is created.
Definition: Const.h:116
Constraint on the data type.
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.In case of an invalid run time expression, 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 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:8247
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:902
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:237
void move(CompressedMatrix< Type, SO > &dst, CompressedMatrix< Type, SO > &src)
Moving the contents of one compressed matrix to another.
Definition: CompressedMatrix.h:4825
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:300
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:258
#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:242
Constraint on the data type.
bool isSymmetric(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is symmetric.
Definition: DenseMatrix.h:692
Constraint on the data type.
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:821
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2507
BLAZE_ALWAYS_INLINE size_t capacity(const Matrix< MT, SO > &matrix)
Returns the maximum capacity of the matrix.
Definition: Matrix.h:348
BLAZE_ALWAYS_INLINE size_t rows(const Matrix< MT, SO > &matrix)
Returns the current number of rows of the matrix.
Definition: Matrix.h:316
void clear(CompressedMatrix< Type, SO > &m)
Clearing the given compressed matrix.
Definition: CompressedMatrix.h:4762
void UNUSED_PARAMETER(const T1 &)
Suppression of unused parameter warnings.
Definition: Unused.h:81
CompressedMatrix< Type, true > This
Type of this CompressedMatrix instance.
Definition: CompressedMatrix.h:2501
#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:386
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:2503
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:861
Constraint on the data type.
Header file for the SparseMatrix base class.
Header file for utility functions for sparse matrices.
Header file for the IsSquare type trait.
Constraint on the data type.
bool isDefault(const CompressedMatrix< Type, SO > &m)
Returns whether the given compressed matrix is in default state.
Definition: CompressedMatrix.h:4789
Header file for the DisableIf class template.
Header file for the IsSymmetric type trait.
Header file for the clear shim.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Header file for the If class template.
void swap(CompressedMatrix< Type, SO > &a, CompressedMatrix< Type, SO > &b)
Swapping the contents of two compressed matrices.
Definition: CompressedMatrix.h:4807
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2511
#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
Constraint on the data type.
Header file for the SparseElement base class.
CompressedMatrix< Type, false > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:2504
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:195
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:535
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2505
Header file for all forward declarations for expression class templates.
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2509
Header file for the EnableIf class template.
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:841
Header file for the IsNumeric type trait.
#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:2506
Header file for run time assertion macros.
Utility type for generic codes.
Constraint on the data type.
Constraint on the data type.
const DenseIterator< Type > operator-(const DenseIterator< Type > &it, ptrdiff_t inc)
Subtraction between a DenseIterator and an integral value.
Definition: DenseIterator.h:585
#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:2510
Header file for the isDefault shim.
Constraint on the data type.
Constraint on the data type.
double real
Floating point data type of the Blaze library.This type definition offers the possibility to switch t...
Definition: Precision.h:47
void swap(DiagonalMatrix< MT, SO, DF > &a, DiagonalMatrix< MT, SO, DF > &b)
Swapping the contents of two matrices.
Definition: DiagonalMatrix.h:200
BLAZE_ALWAYS_INLINE EnableIf< And< IsIntegral< T >, HasSize< T, 2UL > >, sse_int16_t >::Type set(T value)
Sets all values in the vector to the given 2-byte integral value.
Definition: Set.h:73
Header file for the move shim.
#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:937
Header file for the IsComputation type trait class.
#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:2502
BLAZE_ALWAYS_INLINE size_t columns(const Matrix< MT, SO > &matrix)
Returns the current number of columns of the matrix.
Definition: Matrix.h:332
bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:289
Header file for the IsComplex type trait.
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2508
#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.
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_INTERNAL_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERTION flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:101
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a sparse, N-dimensional matrix type...
Definition: SparseMatrix.h:79