All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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>
67 #include <blaze/util/Assert.h>
73 #include <blaze/util/DisableIf.h>
74 #include <blaze/util/EnableIf.h>
75 #include <blaze/util/InvalidType.h>
76 #include <blaze/util/mpl/If.h>
79 #include <blaze/util/Types.h>
80 #include <blaze/util/Unused.h>
81 
82 
83 namespace blaze {
84 
85 //=================================================================================================
86 //
87 // CLASS TEMPLATE SPECIALIZATION FOR SPARSE MATRICES WITH NUMERIC ELEMENT TYPE
88 //
89 //=================================================================================================
90 
91 //*************************************************************************************************
99 template< typename MT // Type of the adapted sparse matrix
100  , bool SO > // Storage order of the adapted sparse matrix
101 class SymmetricMatrix<MT,SO,false,true>
102  : public SparseMatrix< SymmetricMatrix<MT,SO,false,true>, SO >
103 {
104  private:
105  //**Type definitions****************************************************************************
106  typedef typename MT::OppositeType OT;
107  typedef typename MT::TransposeType TT;
108  typedef typename MT::ElementType ET;
109  //**********************************************************************************************
110 
111  public:
112  //**Type definitions****************************************************************************
113  typedef SymmetricMatrix<MT,SO,false,true> This;
114  typedef This ResultType;
115  typedef SymmetricMatrix<OT,!SO,false,true> OppositeType;
116  typedef SymmetricMatrix<TT,!SO,false,true> TransposeType;
117  typedef ET ElementType;
118  typedef typename MT::ReturnType ReturnType;
119  typedef const This& CompositeType;
120  typedef NumericProxy<MT> Reference;
121  typedef typename MT::ConstReference ConstReference;
122  typedef typename MT::ConstIterator ConstIterator;
123  //**********************************************************************************************
124 
125  //**Rebind struct definition********************************************************************
128  template< typename ET > // Data type of the other matrix
129  struct Rebind {
131  typedef SymmetricMatrix< typename MT::template Rebind<ET>::Other > Other;
132  };
133  //**********************************************************************************************
134 
135  //**SymmetricValue class definition*************************************************************
138  class SymmetricValue
139  {
140  private:
141  //**struct BuiltinType***********************************************************************
144  template< typename T >
145  struct BuiltinType { typedef INVALID_TYPE Type; };
146  //*******************************************************************************************
147 
148  //**struct ComplexType***********************************************************************
151  template< typename T >
152  struct ComplexType { typedef typename T::value_type Type; };
153  //*******************************************************************************************
154 
155  public:
156  //**Type definitions*************************************************************************
158  typedef typename If< IsComplex<ElementType>
159  , ComplexType<ElementType>
160  , BuiltinType<ElementType> >::Type::Type ValueType;
161  //*******************************************************************************************
162 
163  //**Constructor******************************************************************************
169  inline SymmetricValue( ElementType& v1, ElementType& v2 )
170  : v1_( &v1 ) // The first represented value.
171  , v2_( &v2 ) // The second represented value.
172  {}
173  //*******************************************************************************************
174 
175  //*******************************************************************************************
181  inline SymmetricValue& operator=( const SymmetricValue& sv ) {
182  *v1_ = *sv.v1_;
183  if( v1_ != v2_ )
184  v2_ = *sv.v2_;
185  return *this;
186  }
187  //*******************************************************************************************
188 
189  //*******************************************************************************************
195  template< typename T > inline SymmetricValue& operator=( const T& v ) {
196  *v1_ = v;
197  if( v1_ != v2_ )
198  *v2_ = v;
199  return *this;
200  }
201  //*******************************************************************************************
202 
203  //*******************************************************************************************
209  template< typename T > inline SymmetricValue& operator+=( const T& v ) {
210  *v1_ += v;
211  if( v1_ != v2_ )
212  *v2_ += v;
213  return *this;
214  }
215  //*******************************************************************************************
216 
217  //*******************************************************************************************
223  template< typename T > inline SymmetricValue& operator-=( const T& v ) {
224  *v1_ -= v;
225  if( v1_ != v2_ )
226  *v2_ -= v;
227  return *this;
228  }
229  //*******************************************************************************************
230 
231  //*******************************************************************************************
237  template< typename T > inline SymmetricValue& operator*=( const T& v ) {
238  *v1_ *= v;
239  if( v1_ != v2_ )
240  *v2_ *= v;
241  return *this;
242  }
243  //*******************************************************************************************
244 
245  //*******************************************************************************************
251  template< typename T > inline SymmetricValue& operator/=( const T& v ) {
252  *v1_ /= v;
253  if( v1_ != v2_ )
254  *v2_ /= v;
255  return *this;
256  }
257  //*******************************************************************************************
258 
259  //*******************************************************************************************
264  inline operator ElementType() const {
265  return *v1_;
266  }
267  //*******************************************************************************************
268 
269  //*******************************************************************************************
277  inline ValueType real() const {
278  return v1_->real();
279  }
280  //*******************************************************************************************
281 
282  //*******************************************************************************************
291  inline void real( ValueType value ) const {
292  v1_->real( value );
293  if( v1_ != v2_ )
294  v2_->real( value );
295  }
296  //*******************************************************************************************
297 
298  //*******************************************************************************************
306  inline ValueType imag() const {
307  return v1_->imag();
308  }
309  //*******************************************************************************************
310 
311  //*******************************************************************************************
320  inline void imag( ValueType value ) const {
321  v1_->imag( value );
322  if( v1_ != v2_ )
323  v2_->imag( value );
324  }
325  //*******************************************************************************************
326 
327  private:
328  //**Member variables*************************************************************************
329  ElementType* v1_;
330  ElementType* v2_;
331  //*******************************************************************************************
332  };
333  //**********************************************************************************************
334 
335  //**SymmetricElement class definition***********************************************************
338  class SymmetricElement : private SparseElement
339  {
340  private:
341  //**Type definitions*************************************************************************
342  typedef typename MT::Iterator IteratorType;
343  //*******************************************************************************************
344 
345  public:
346  //**Type definitions*************************************************************************
347  typedef SymmetricValue ValueType;
348  typedef size_t IndexType;
349  typedef SymmetricValue Reference;
350  typedef const SymmetricValue ConstReference;
351  typedef SymmetricElement* Pointer;
352  //*******************************************************************************************
353 
354  //**Constructor******************************************************************************
360  inline SymmetricElement( IteratorType e1, IteratorType e2 )
361  : e1_( e1 ) // The first represented sparse element
362  , e2_( e2 ) // The second represented sparse element
363  {}
364  //*******************************************************************************************
365 
366  //**Assignment operator**********************************************************************
372  template< typename T > inline SymmetricElement& operator=( const T& v ) {
373  *e1_ = v;
374  if( e1_ != e2_ )
375  *e2_ = v;
376  return *this;
377  }
378  //*******************************************************************************************
379 
380  //**Addition assignment operator*************************************************************
386  template< typename T > inline SymmetricElement& operator+=( const T& v ) {
387  *e1_ += v;
388  if( e1_ != e2_ )
389  *e2_ += v;
390  return *this;
391  }
392  //*******************************************************************************************
393 
394  //**Subtraction assignment operator**********************************************************
400  template< typename T > inline SymmetricElement& operator-=( const T& v ) {
401  *e1_ -= v;
402  if( e1_ != e2_ )
403  *e2_ -= v;
404  return *this;
405  }
406  //*******************************************************************************************
407 
408  //**Multiplication assignment operator*******************************************************
414  template< typename T > inline SymmetricElement& operator*=( const T& v ) {
415  *e1_ *= v;
416  if( e1_ != e2_ )
417  *e2_ *= v;
418  return *this;
419  }
420  //*******************************************************************************************
421 
422  //**Division assignment operator*************************************************************
428  template< typename T > inline SymmetricElement& operator/=( const T& v ) {
429  *e1_ /= v;
430  if( e1_ != e2_ )
431  *e2_ /= v;
432  return *this;
433  }
434  //*******************************************************************************************
435 
436  //**Element access operator******************************************************************
441  inline Pointer operator->() {
442  return this;
443  }
444  //*******************************************************************************************
445 
446  //**Value function***************************************************************************
451  inline Reference value() const {
452  return Reference( e1_->value(), e2_->value() );
453  }
454  //*******************************************************************************************
455 
456  //**Index function***************************************************************************
461  inline IndexType index() const {
462  return e1_->index();
463  }
464  //*******************************************************************************************
465 
466  private:
467  //**Member variables*************************************************************************
468  IteratorType e1_;
469  IteratorType e2_;
470  //*******************************************************************************************
471  };
472  //**********************************************************************************************
473 
474  //**Iterator class definition*******************************************************************
477  class Iterator
478  {
479  public:
480  //**Type definitions*************************************************************************
481  typedef typename MT::Iterator IteratorType;
482 
483  typedef std::forward_iterator_tag IteratorCategory;
484  typedef SymmetricElement ValueType;
485  typedef ValueType PointerType;
486  typedef ValueType ReferenceType;
487  typedef ptrdiff_t DifferenceType;
488 
489  // STL iterator requirements
490  typedef IteratorCategory iterator_category;
491  typedef ValueType value_type;
492  typedef PointerType pointer;
493  typedef ReferenceType reference;
494  typedef DifferenceType difference_type;
495  //*******************************************************************************************
496 
497  //**Default constructor**********************************************************************
500  inline Iterator()
501  : pos_ ( ) // Iterator to the current sparse symmetric matrix element
502  , matrix_( NULL ) // The sparse matrix containing the iterator
503  , index_ ( 0UL ) // The row/column index of the iterator
504  {}
505  //*******************************************************************************************
506 
507  //**Constructor******************************************************************************
514  inline Iterator( IteratorType pos, MT& matrix, size_t index )
515  : pos_ ( pos ) // Iterator to the current sparse symmetric matrix element
516  , matrix_( &matrix ) // The sparse matrix containing the iterator
517  , index_ ( index ) // The row/column index of the iterator
518  {}
519  //*******************************************************************************************
520 
521  //**Prefix increment operator****************************************************************
526  inline Iterator& operator++() {
527  ++pos_;
528  return *this;
529  }
530  //*******************************************************************************************
531 
532  //**Postfix increment operator***************************************************************
537  inline const Iterator operator++( int ) {
538  const Iterator tmp( *this );
539  ++(*this);
540  return tmp;
541  }
542  //*******************************************************************************************
543 
544  //**Element access operator******************************************************************
549  inline ReferenceType operator*() const {
550  const IteratorType pos2( SO ? matrix_->find( index_, pos_->index() )
551  : matrix_->find( pos_->index(), index_ ) );
552  BLAZE_INTERNAL_ASSERT( pos2 != matrix_->end( pos_->index() ), "Missing matrix element detected" );
553  return ReferenceType( pos_, pos2 );
554  }
555  //*******************************************************************************************
556 
557  //**Element access operator******************************************************************
562  inline PointerType operator->() const {
563  const IteratorType pos2( SO ? matrix_->find( index_, pos_->index() )
564  : matrix_->find( pos_->index(), index_ ) );
565  BLAZE_INTERNAL_ASSERT( pos2 != matrix_->end( pos_->index() ), "Missing matrix element detected" );
566  return PointerType( pos_, pos2 );
567  }
568  //*******************************************************************************************
569 
570  //**Conversion operator**********************************************************************
575  inline operator ConstIterator() const {
576  return pos_;
577  }
578  //*******************************************************************************************
579 
580  //**Equality operator************************************************************************
586  inline bool operator==( const Iterator& rhs ) const {
587  return pos_ == rhs.pos_;
588  }
589  //*******************************************************************************************
590 
591  //**Inequality operator**********************************************************************
597  inline bool operator!=( const Iterator& rhs ) const {
598  return !( *this == rhs );
599  }
600  //*******************************************************************************************
601 
602  //**Subtraction operator*********************************************************************
608  inline DifferenceType operator-( const Iterator& rhs ) const {
609  return pos_ - rhs.pos_;
610  }
611  //*******************************************************************************************
612 
613  //**Base function****************************************************************************
618  inline IteratorType base() const {
619  return pos_;
620  }
621  //*******************************************************************************************
622 
623  private:
624  //**Member variables*************************************************************************
625  IteratorType pos_;
626  MT* matrix_;
627  size_t index_;
628  //*******************************************************************************************
629  };
630  //**********************************************************************************************
631 
632  //**Compilation flags***************************************************************************
634  enum { smpAssignable = 0 };
635  //**********************************************************************************************
636 
637  //**Constructors********************************************************************************
640  explicit inline SymmetricMatrix();
641  explicit inline SymmetricMatrix( size_t n );
642  explicit inline SymmetricMatrix( size_t n, size_t nonzeros );
643  explicit inline SymmetricMatrix( size_t n, const std::vector<size_t>& nonzeros );
644 
645  inline SymmetricMatrix( const SymmetricMatrix& m );
646  template< typename MT2 > inline SymmetricMatrix( const Matrix<MT2,SO>& m );
647  template< typename MT2 > inline SymmetricMatrix( const Matrix<MT2,!SO>& m );
649  //**********************************************************************************************
650 
651  //**Destructor**********************************************************************************
652  // No explicitly declared destructor.
653  //**********************************************************************************************
654 
655  //**Data access functions***********************************************************************
658  inline Reference operator()( size_t i, size_t j );
659  inline ConstReference operator()( size_t i, size_t j ) const;
660  inline Iterator begin ( size_t i );
661  inline ConstIterator begin ( size_t i ) const;
662  inline ConstIterator cbegin( size_t i ) const;
663  inline Iterator end ( size_t i );
664  inline ConstIterator end ( size_t i ) const;
665  inline ConstIterator cend ( size_t i ) const;
667  //**********************************************************************************************
668 
669  //**Assignment operators************************************************************************
672  inline SymmetricMatrix& operator=( const SymmetricMatrix& rhs );
673 
674  template< typename MT2 >
675  inline typename DisableIf< IsComputation<MT2>, SymmetricMatrix& >::Type
676  operator=( const Matrix<MT2,SO>& rhs );
677 
678  template< typename MT2 >
679  inline typename EnableIf< IsComputation<MT2>, SymmetricMatrix& >::Type
680  operator=( const Matrix<MT2,SO>& rhs );
681 
682  template< typename MT2 >
683  inline SymmetricMatrix& operator=( const Matrix<MT2,!SO>& rhs );
684 
685  template< typename MT2 >
686  inline typename DisableIf< IsComputation<MT2>, SymmetricMatrix& >::Type
687  operator+=( const Matrix<MT2,SO>& rhs );
688 
689  template< typename MT2 >
690  inline typename EnableIf< IsComputation<MT2>, SymmetricMatrix& >::Type
691  operator+=( const Matrix<MT2,SO>& rhs );
692 
693  template< typename MT2 >
694  inline SymmetricMatrix& operator+=( const Matrix<MT2,!SO>& rhs );
695 
696  template< typename MT2 >
697  inline typename DisableIf< IsComputation<MT2>, SymmetricMatrix& >::Type
698  operator-=( const Matrix<MT2,SO>& rhs );
699 
700  template< typename MT2 >
701  inline typename EnableIf< IsComputation<MT2>, SymmetricMatrix& >::Type
702  operator-=( const Matrix<MT2,SO>& rhs );
703 
704  template< typename MT2 >
705  inline SymmetricMatrix& operator-=( const Matrix<MT2,!SO>& rhs );
706 
707  template< typename MT2, bool SO2 >
708  inline SymmetricMatrix& operator*=( const Matrix<MT2,SO2>& rhs );
709 
710  template< typename Other >
711  inline typename EnableIf< IsNumeric<Other>, SymmetricMatrix >::Type&
712  operator*=( Other rhs );
713 
714  template< typename Other >
715  inline typename EnableIf< IsNumeric<Other>, SymmetricMatrix >::Type&
716  operator/=( Other rhs );
718  //**********************************************************************************************
719 
720  //**Utility functions***************************************************************************
723  inline size_t rows() const;
724  inline size_t columns() const;
725  inline size_t capacity() const;
726  inline size_t capacity( size_t i ) const;
727  inline size_t nonZeros() const;
728  inline size_t nonZeros( size_t i ) const;
729  inline void reset();
730  inline void reset( size_t i );
731  inline void clear();
732  inline Iterator set( size_t i, size_t j, const ElementType& value );
733  inline Iterator insert( size_t i, size_t j, const ElementType& value );
734  inline void erase( size_t i, size_t j );
735  inline Iterator erase( size_t i, Iterator pos );
736  inline Iterator erase( size_t i, Iterator first, Iterator last );
737  inline void resize ( size_t n, bool preserve=true );
738  inline void reserve( size_t nonzeros );
739  inline void reserve( size_t i, size_t nonzeros );
740  inline void trim();
741  inline void trim( size_t i );
742  inline SymmetricMatrix& transpose();
743  template< typename Other > inline SymmetricMatrix& scale( const Other& scalar );
744  template< typename Other > inline SymmetricMatrix& scaleDiagonal( Other scale );
745  inline void swap( SymmetricMatrix& m ) /* throw() */;
747  //**********************************************************************************************
748 
749  //**Lookup functions****************************************************************************
752  inline Iterator find ( size_t i, size_t j );
753  inline ConstIterator find ( size_t i, size_t j ) const;
754  inline Iterator lowerBound( size_t i, size_t j );
755  inline ConstIterator lowerBound( size_t i, size_t j ) const;
756  inline Iterator upperBound( size_t i, size_t j );
757  inline ConstIterator upperBound( size_t i, size_t j ) const;
759  //**********************************************************************************************
760 
761  //**Low-level utility functions*****************************************************************
764  inline void append ( size_t i, size_t j, const ElementType& value, bool check=false );
765  inline void finalize( size_t i );
767  //**********************************************************************************************
768 
769  //**Expression template evaluation functions****************************************************
772  template< typename Other > inline bool canAlias ( const Other* alias ) const;
773  template< typename Other > inline bool isAliased( const Other* alias ) const;
774 
775  inline bool canSMPAssign() const;
777  //**********************************************************************************************
778 
779  private:
780  //**Member variables****************************************************************************
783  MT matrix_;
784 
785  //**********************************************************************************************
786 
787  //**Friend declarations*************************************************************************
788  template< typename MT2, bool SO2, bool DF2, bool NF2 >
789  friend bool isDefault( const SymmetricMatrix<MT2,SO2,DF2,NF2>& m );
790  //**********************************************************************************************
791 
792  //**Compile time checks*************************************************************************
805  BLAZE_STATIC_ASSERT( IsResizable<MT>::value || IsSquare<MT>::value );
806  //**********************************************************************************************
807 };
809 //*************************************************************************************************
810 
811 
812 
813 
814 //=================================================================================================
815 //
816 // CONSTRUCTORS
817 //
818 //=================================================================================================
819 
820 //*************************************************************************************************
824 template< typename MT // Type of the adapted sparse matrix
825  , bool SO > // Storage order of the adapted sparse matrix
826 inline SymmetricMatrix<MT,SO,false,true>::SymmetricMatrix()
827  : matrix_() // The adapted sparse matrix
828 {
829  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
830 }
832 //*************************************************************************************************
833 
834 
835 //*************************************************************************************************
843 template< typename MT // Type of the adapted sparse matrix
844  , bool SO > // Storage order of the adapted sparse matrix
845 inline SymmetricMatrix<MT,SO,false,true>::SymmetricMatrix( size_t n )
846  : matrix_( n, n ) // The adapted sparse matrix
847 {
849 
850  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
851 }
853 //*************************************************************************************************
854 
855 
856 //*************************************************************************************************
865 template< typename MT // Type of the adapted sparse matrix
866  , bool SO > // Storage order of the adapted sparse matrix
867 inline SymmetricMatrix<MT,SO,false,true>::SymmetricMatrix( size_t n, size_t nonzeros )
868  : matrix_( n, n, nonzeros ) // The adapted sparse matrix
869 {
871 
872  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
873 }
875 //*************************************************************************************************
876 
877 
878 //*************************************************************************************************
887 template< typename MT // Type of the adapted sparse matrix
888  , bool SO > // Storage order of the adapted sparse matrix
889 inline SymmetricMatrix<MT,SO,false,true>::SymmetricMatrix( size_t n, const std::vector<size_t>& nonzeros )
890  : matrix_( n, n, nonzeros ) // The adapted sparse matrix
891 {
893 
894  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
895 }
897 //*************************************************************************************************
898 
899 
900 //*************************************************************************************************
906 template< typename MT // Type of the adapted sparse matrix
907  , bool SO > // Storage order of the adapted sparse matrix
908 inline SymmetricMatrix<MT,SO,false,true>::SymmetricMatrix( const SymmetricMatrix& m )
909  : matrix_( m.matrix_ ) // The adapted sparse matrix
910 {
911  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
912 }
914 //*************************************************************************************************
915 
916 
917 //*************************************************************************************************
927 template< typename MT // Type of the adapted sparse matrix
928  , bool SO > // Storage order of the adapted sparse matrix
929 template< typename MT2 > // Type of the foreign matrix
930 inline SymmetricMatrix<MT,SO,false,true>::SymmetricMatrix( const Matrix<MT2,SO>& m )
931  : matrix_( ~m ) // The adapted sparse matrix
932 {
933  if( IsLower<MT2>::value || IsUpper<MT2>::value ||
934  ( !IsSymmetric<MT2>::value && !isSymmetric( matrix_ ) ) )
935  throw std::invalid_argument( "Invalid setup of symmetric matrix" );
936 
937  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
938 }
940 //*************************************************************************************************
941 
942 
943 //*************************************************************************************************
953 template< typename MT // Type of the adapted sparse matrix
954  , bool SO > // Storage order of the adapted sparse matrix
955 template< typename MT2 > // Type of the foreign matrix
956 inline SymmetricMatrix<MT,SO,false,true>::SymmetricMatrix( const Matrix<MT2,!SO>& m )
957  : matrix_( trans( ~m ) ) // The adapted sparse matrix
958 {
959  if( IsLower<MT2>::value || IsUpper<MT2>::value ||
960  ( !IsSymmetric<MT2>::value && !isSymmetric( matrix_ ) ) )
961  throw std::invalid_argument( "Invalid setup of symmetric matrix" );
962 
963  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
964 }
966 //*************************************************************************************************
967 
968 
969 
970 
971 //=================================================================================================
972 //
973 // DATA ACCESS FUNCTIONS
974 //
975 //=================================================================================================
976 
977 //*************************************************************************************************
989 template< typename MT // Type of the adapted sparse matrix
990  , bool SO > // Storage order of the adapted sparse matrix
992  SymmetricMatrix<MT,SO,false,true>::operator()( size_t i, size_t j )
993 {
994  BLAZE_USER_ASSERT( i<rows() , "Invalid row access index" );
995  BLAZE_USER_ASSERT( j<columns(), "Invalid column access index" );
996 
997  return Reference( matrix_, i, j );
998 }
1000 //*************************************************************************************************
1001 
1002 
1003 //*************************************************************************************************
1015 template< typename MT // Type of the adapted sparse matrix
1016  , bool SO > // Storage order of the adapted sparse matrix
1018  SymmetricMatrix<MT,SO,false,true>::operator()( size_t i, size_t j ) const
1019 {
1020  BLAZE_USER_ASSERT( i<rows() , "Invalid row access index" );
1021  BLAZE_USER_ASSERT( j<columns(), "Invalid column access index" );
1022 
1023  return matrix_(i,j);
1024 }
1026 //*************************************************************************************************
1027 
1028 
1029 //*************************************************************************************************
1041 template< typename MT // Type of the adapted sparse matrix
1042  , bool SO > // Storage order of the adapted sparse matrix
1045 {
1046  return Iterator( matrix_.begin(i), matrix_, i );
1047 }
1049 //*************************************************************************************************
1050 
1051 
1052 //*************************************************************************************************
1064 template< typename MT // Type of the adapted sparse matrix
1065  , bool SO > // Storage order of the adapted sparse matrix
1068 {
1069  return matrix_.begin(i);
1070 }
1072 //*************************************************************************************************
1073 
1074 
1075 //*************************************************************************************************
1087 template< typename MT // Type of the adapted sparse matrix
1088  , bool SO > // Storage order of the adapted sparse matrix
1091 {
1092  return matrix_.cbegin(i);
1093 }
1095 //*************************************************************************************************
1096 
1097 
1098 //*************************************************************************************************
1110 template< typename MT // Type of the adapted sparse matrix
1111  , bool SO > // Storage order of the adapted sparse matrix
1114 {
1115  return Iterator( matrix_.end(i), matrix_, i );
1116 }
1118 //*************************************************************************************************
1119 
1120 
1121 //*************************************************************************************************
1133 template< typename MT // Type of the adapted sparse matrix
1134  , bool SO > // Storage order of the adapted sparse matrix
1136  SymmetricMatrix<MT,SO,false,true>::end( size_t i ) const
1137 {
1138  return matrix_.end(i);
1139 }
1141 //*************************************************************************************************
1142 
1143 
1144 //*************************************************************************************************
1156 template< typename MT // Type of the adapted sparse matrix
1157  , bool SO > // Storage order of the adapted sparse matrix
1159  SymmetricMatrix<MT,SO,false,true>::cend( size_t i ) const
1160 {
1161  return matrix_.cend(i);
1162 }
1164 //*************************************************************************************************
1165 
1166 
1167 
1168 
1169 //=================================================================================================
1170 //
1171 // ASSIGNMENT OPERATORS
1172 //
1173 //=================================================================================================
1174 
1175 //*************************************************************************************************
1185 template< typename MT // Type of the adapted sparse matrix
1186  , bool SO > // Storage order of the adapted sparse matrix
1187 inline SymmetricMatrix<MT,SO,false,true>&
1188  SymmetricMatrix<MT,SO,false,true>::operator=( const SymmetricMatrix& rhs )
1189 {
1190  matrix_ = rhs.matrix_;
1191 
1192  return *this;
1193 }
1195 //*************************************************************************************************
1196 
1197 
1198 //*************************************************************************************************
1211 template< typename MT // Type of the adapted sparse matrix
1212  , bool SO > // Storage order of the adapted sparse matrix
1213 template< typename MT2 > // Type of the right-hand side matrix
1214 inline typename DisableIf< IsComputation<MT2>, SymmetricMatrix<MT,SO,false,true>& >::Type
1215  SymmetricMatrix<MT,SO,false,true>::operator=( const Matrix<MT2,SO>& rhs )
1216 {
1217  if( IsLower<MT2>::value || IsUpper<MT2>::value ||
1218  ( !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  using std::swap;
1249 
1250  if( IsLower<MT2>::value || IsUpper<MT2>::value || !isSquare( ~rhs ) )
1251  throw std::invalid_argument( "Invalid assignment to symmetric matrix" );
1252 
1253  if( IsSymmetric<MT2>::value ) {
1254  matrix_ = ~rhs;
1255  }
1256  else {
1257  MT tmp( ~rhs );
1258 
1259  if( !isSymmetric( tmp ) )
1260  throw std::invalid_argument( "Invalid assignment to symmetric matrix" );
1261 
1262  move( matrix_, tmp );
1263  }
1264 
1265  return *this;
1266 }
1268 //*************************************************************************************************
1269 
1270 
1271 //*************************************************************************************************
1284 template< typename MT // Type of the adapted sparse matrix
1285  , bool SO > // Storage order of the adapted sparse matrix
1286 template< typename MT2 > // Type of the right-hand side matrix
1287 inline SymmetricMatrix<MT,SO,false,true>&
1288  SymmetricMatrix<MT,SO,false,true>::operator=( const Matrix<MT2,!SO>& rhs )
1289 {
1290  return this->operator=( trans( ~rhs ) );
1291 }
1293 //*************************************************************************************************
1294 
1295 
1296 //*************************************************************************************************
1309 template< typename MT // Type of the adapted sparse matrix
1310  , bool SO > // Storage order of the adapted sparse matrix
1311 template< typename MT2 > // Type of the right-hand side matrix
1312 inline typename DisableIf< IsComputation<MT2>, SymmetricMatrix<MT,SO,false,true>& >::Type
1313  SymmetricMatrix<MT,SO,false,true>::operator+=( const Matrix<MT2,SO>& rhs )
1314 {
1315  if( IsLower<MT2>::value || IsUpper<MT2>::value ||
1316  ( !IsSymmetric<MT2>::value && !isSymmetric( ~rhs ) ) )
1317  throw std::invalid_argument( "Invalid assignment to symmetric matrix" );
1318 
1319  matrix_ += ~rhs;
1320 
1321  return *this;
1322 }
1324 //*************************************************************************************************
1325 
1326 
1327 //*************************************************************************************************
1340 template< typename MT // Type of the adapted sparse matrix
1341  , bool SO > // Storage order of the adapted sparse matrix
1342 template< typename MT2 > // Type of the right-hand side matrix
1343 inline typename EnableIf< IsComputation<MT2>, SymmetricMatrix<MT,SO,false,true>& >::Type
1344  SymmetricMatrix<MT,SO,false,true>::operator+=( const Matrix<MT2,SO>& rhs )
1345 {
1346  if( IsLower<MT2>::value || IsUpper<MT2>::value || !isSquare( ~rhs ) )
1347  throw std::invalid_argument( "Invalid assignment to symmetric matrix" );
1348 
1349  if( IsSymmetric<MT2>::value ) {
1350  matrix_ += ~rhs;
1351  }
1352  else {
1353  typename MT2::ResultType tmp( ~rhs );
1354 
1355  if( !isSymmetric( tmp ) )
1356  throw std::invalid_argument( "Invalid assignment to symmetric matrix" );
1357 
1358  matrix_ += tmp;
1359  }
1360 
1361  return *this;
1362 }
1364 //*************************************************************************************************
1365 
1366 
1367 //*************************************************************************************************
1381 template< typename MT // Type of the adapted sparse matrix
1382  , bool SO > // Storage order of the adapted sparse matrix
1383 template< typename MT2 > // Type of the right-hand side matrix
1384 inline SymmetricMatrix<MT,SO,false,true>&
1385  SymmetricMatrix<MT,SO,false,true>::operator+=( const Matrix<MT2,!SO>& rhs )
1386 {
1387  return this->operator+=( trans( ~rhs ) );
1388 }
1390 //*************************************************************************************************
1391 
1392 
1393 //*************************************************************************************************
1406 template< typename MT // Type of the adapted sparse matrix
1407  , bool SO > // Storage order of the adapted sparse matrix
1408 template< typename MT2 > // Type of the right-hand side matrix
1409 inline typename DisableIf< IsComputation<MT2>, SymmetricMatrix<MT,SO,false,true>& >::Type
1410  SymmetricMatrix<MT,SO,false,true>::operator-=( const Matrix<MT2,SO>& rhs )
1411 {
1412  if( IsLower<MT2>::value || IsUpper<MT2>::value ||
1413  ( !IsSymmetric<MT2>::value && !isSymmetric( ~rhs ) ) )
1414  throw std::invalid_argument( "Invalid assignment to symmetric matrix" );
1415 
1416  matrix_ -= ~rhs;
1417 
1418  return *this;
1419 }
1421 //*************************************************************************************************
1422 
1423 
1424 //*************************************************************************************************
1437 template< typename MT // Type of the adapted sparse matrix
1438  , bool SO > // Storage order of the adapted sparse matrix
1439 template< typename MT2 > // Type of the right-hand side matrix
1440 inline typename EnableIf< IsComputation<MT2>, SymmetricMatrix<MT,SO,false,true>& >::Type
1441  SymmetricMatrix<MT,SO,false,true>::operator-=( const Matrix<MT2,SO>& rhs )
1442 {
1443  if( IsLower<MT2>::value || IsUpper<MT2>::value || !isSquare( ~rhs ) )
1444  throw std::invalid_argument( "Invalid assignment to symmetric matrix" );
1445 
1446  if( IsSymmetric<MT2>::value ) {
1447  matrix_ -= ~rhs;
1448  }
1449  else {
1450  typename MT2::ResultType tmp( ~rhs );
1451 
1452  if( !isSymmetric( tmp ) )
1453  throw std::invalid_argument( "Invalid assignment to symmetric matrix" );
1454 
1455  matrix_ -= tmp;
1456  }
1457 
1458  return *this;
1459 }
1461 //*************************************************************************************************
1462 
1463 
1464 //*************************************************************************************************
1478 template< typename MT // Type of the adapted sparse matrix
1479  , bool SO > // Storage order of the adapted sparse matrix
1480 template< typename MT2 > // Type of the right-hand side matrix
1481 inline SymmetricMatrix<MT,SO,false,true>&
1482  SymmetricMatrix<MT,SO,false,true>::operator-=( const Matrix<MT2,!SO>& rhs )
1483 {
1484  return this->operator-=( trans( ~rhs ) );
1485 }
1487 //*************************************************************************************************
1488 
1489 
1490 //*************************************************************************************************
1502 template< typename MT // Type of the adapted sparse matrix
1503  , bool SO > // Storage order of the adapted sparse matrix
1504 template< typename MT2 // Type of the right-hand side matrix
1505  , bool SO2 > // Storage order of the right-hand side matrix
1506 inline SymmetricMatrix<MT,SO,false,true>&
1507  SymmetricMatrix<MT,SO,false,true>::operator*=( const Matrix<MT2,SO2>& rhs )
1508 {
1509  using std::swap;
1510 
1511  if( matrix_.rows() != (~rhs).columns() )
1512  throw std::invalid_argument( "Invalid assignment to symmetric matrix" );
1513 
1514  MT tmp( matrix_ * ~rhs );
1515 
1516  if( !isSymmetric( tmp ) )
1517  throw std::invalid_argument( "Invalid assignment to symmetric matrix" );
1518 
1519  move( matrix_, tmp );
1520 
1521  return *this;
1522 }
1524 //*************************************************************************************************
1525 
1526 
1527 //*************************************************************************************************
1535 template< typename MT // Type of the adapted sparse matrix
1536  , bool SO > // Storage order of the adapted sparse matrix
1537 template< typename Other > // Data type of the right-hand side scalar
1538 inline typename EnableIf< IsNumeric<Other>, SymmetricMatrix<MT,SO,false,true> >::Type&
1539  SymmetricMatrix<MT,SO,false,true>::operator*=( Other rhs )
1540 {
1541  matrix_ *= rhs;
1542  return *this;
1543 }
1544 //*************************************************************************************************
1545 
1546 
1547 //*************************************************************************************************
1555 template< typename MT // Type of the adapted sparse matrix
1556  , bool SO > // Storage order of the adapted sparse matrix
1557 template< typename Other > // Data type of the right-hand side scalar
1558 inline typename EnableIf< IsNumeric<Other>, SymmetricMatrix<MT,SO,false,true> >::Type&
1559  SymmetricMatrix<MT,SO,false,true>::operator/=( Other rhs )
1560 {
1561  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
1562 
1563  matrix_ /= rhs;
1564  return *this;
1565 }
1567 //*************************************************************************************************
1568 
1569 
1570 
1571 
1572 //=================================================================================================
1573 //
1574 // UTILITY FUNCTIONS
1575 //
1576 //=================================================================================================
1577 
1578 //*************************************************************************************************
1584 template< typename MT // Type of the adapted sparse matrix
1585  , bool SO > // Storage order of the adapted sparse matrix
1586 inline size_t SymmetricMatrix<MT,SO,false,true>::rows() const
1587 {
1588  return matrix_.rows();
1589 }
1591 //*************************************************************************************************
1592 
1593 
1594 //*************************************************************************************************
1600 template< typename MT // Type of the adapted sparse matrix
1601  , bool SO > // Storage order of the adapted sparse matrix
1602 inline size_t SymmetricMatrix<MT,SO,false,true>::columns() const
1603 {
1604  return matrix_.columns();
1605 }
1607 //*************************************************************************************************
1608 
1609 
1610 //*************************************************************************************************
1616 template< typename MT // Type of the adapted sparse matrix
1617  , bool SO > // Storage order of the adapted sparse matrix
1618 inline size_t SymmetricMatrix<MT,SO,false,true>::capacity() const
1619 {
1620  return matrix_.capacity();
1621 }
1623 //*************************************************************************************************
1624 
1625 
1626 //*************************************************************************************************
1637 template< typename MT // Type of the adapted sparse matrix
1638  , bool SO > // Storage order of the adapted sparse matrix
1639 inline size_t SymmetricMatrix<MT,SO,false,true>::capacity( size_t i ) const
1640 {
1641  return matrix_.capacity(i);
1642 }
1644 //*************************************************************************************************
1645 
1646 
1647 //*************************************************************************************************
1653 template< typename MT // Type of the adapted sparse matrix
1654  , bool SO > // Storage order of the adapted sparse matrix
1655 inline size_t SymmetricMatrix<MT,SO,false,true>::nonZeros() const
1656 {
1657  return matrix_.nonZeros();
1658 }
1660 //*************************************************************************************************
1661 
1662 
1663 //*************************************************************************************************
1675 template< typename MT // Type of the adapted sparse matrix
1676  , bool SO > // Storage order of the adapted sparse matrix
1677 inline size_t SymmetricMatrix<MT,SO,false,true>::nonZeros( size_t i ) const
1678 {
1679  return matrix_.nonZeros(i);
1680 }
1682 //*************************************************************************************************
1683 
1684 
1685 //*************************************************************************************************
1691 template< typename MT // Type of the adapted sparse matrix
1692  , bool SO > // Storage order of the adapted sparse matrix
1694 {
1695  matrix_.reset();
1696 }
1698 //*************************************************************************************************
1699 
1700 
1701 //*************************************************************************************************
1737 template< typename MT // Type of the adapted sparse matrix
1738  , bool SO > // Storage order of the adapted sparse matrix
1739 inline void SymmetricMatrix<MT,SO,false,true>::reset( size_t i )
1740 {
1741  for( typename MT::Iterator it=matrix_.begin(i); it!=matrix_.end(i); ++it )
1742  {
1743  const size_t j( it->index() );
1744 
1745  if( i == j )
1746  continue;
1747 
1748  if( SO ) {
1749  const typename MT::Iterator pos( matrix_.find( i, j ) );
1750  BLAZE_INTERNAL_ASSERT( pos != matrix_.end( j ), "Missing element detected" );
1751  matrix_.erase( j, pos );
1752  }
1753  else {
1754  const typename MT::Iterator pos( matrix_.find( j, i ) );
1755  BLAZE_INTERNAL_ASSERT( pos != matrix_.end( j ), "Missing element detected" );
1756  matrix_.erase( j, pos );
1757  }
1758  }
1759 
1760  matrix_.reset( i );
1761 }
1763 //*************************************************************************************************
1764 
1765 
1766 //*************************************************************************************************
1774 template< typename MT // Type of the adapted sparse matrix
1775  , bool SO > // Storage order of the adapted sparse matrix
1777 {
1778  using blaze::clear;
1779 
1780  clear( matrix_ );
1781 }
1783 //*************************************************************************************************
1784 
1785 
1786 //*************************************************************************************************
1800 template< typename MT // Type of the adapted sparse matrix
1801  , bool SO > // Storage order of the adapted sparse matrix
1803  SymmetricMatrix<MT,SO,false,true>::set( size_t i, size_t j, const ElementType& value )
1804 {
1805  if( i != j )
1806  matrix_.set( j, i, value );
1807  return Iterator( matrix_.set( i, j, value ), matrix_, ( SO ? j : i ) );
1808 }
1810 //*************************************************************************************************
1811 
1812 
1813 //*************************************************************************************************
1828 template< typename MT // Type of the adapted sparse matrix
1829  , bool SO > // Storage order of the adapted sparse matrix
1831  SymmetricMatrix<MT,SO,false,true>::insert( size_t i, size_t j, const ElementType& value )
1832 {
1833  if( i != j )
1834  matrix_.insert( j, i, value );
1835  return Iterator( matrix_.insert( i, j, value ), matrix_, ( SO ? j : i ) );
1836 }
1838 //*************************************************************************************************
1839 
1840 
1841 //*************************************************************************************************
1851 template< typename MT // Type of the adapted sparse matrix
1852  , bool SO > // Storage order of the adapted sparse matrix
1853 inline void SymmetricMatrix<MT,SO,false,true>::erase( size_t i, size_t j )
1854 {
1855  matrix_.erase( i, j );
1856  if( i != j )
1857  matrix_.erase( j, i );
1858 }
1860 //*************************************************************************************************
1861 
1862 
1863 //*************************************************************************************************
1875 template< typename MT // Type of the adapted sparse matrix
1876  , bool SO > // Storage order of the adapted sparse matrix
1878  SymmetricMatrix<MT,SO,false,true>::erase( size_t i, Iterator pos )
1879 {
1880  const typename MT::Iterator base( pos.base() );
1881 
1882  if( base == matrix_.end( i ) )
1883  return pos;
1884 
1885  const size_t j( base->index() );
1886 
1887  if( i == j ) {
1888  BLAZE_INTERNAL_ASSERT( matrix_.find( i, i ) != matrix_.end( i ), "Missing element detected" );
1889  return Iterator( matrix_.erase( i, base ), matrix_, i );
1890  }
1891 
1892  if( SO ) {
1893  BLAZE_INTERNAL_ASSERT( matrix_.find( i, j ) != matrix_.end( j ), "Missing element detected" );
1894  matrix_.erase( j, matrix_.find( i, j ) );
1895  return Iterator( matrix_.erase( i, base ), matrix_, i );
1896  }
1897  else {
1898  BLAZE_INTERNAL_ASSERT( matrix_.find( j, i ) != matrix_.end( j ), "Missing element detected" );
1899  matrix_.erase( j, matrix_.find( j, i ) );
1900  return Iterator( matrix_.erase( i, base ), matrix_, i );
1901  }
1902 }
1904 //*************************************************************************************************
1905 
1906 
1907 //*************************************************************************************************
1921 template< typename MT // Type of the adapted sparse matrix
1922  , bool SO > // Storage order of the adapted sparse matrix
1924  SymmetricMatrix<MT,SO,false,true>::erase( size_t i, Iterator first, Iterator last )
1925 {
1926  for( typename MT::Iterator it=first.base(); it!=last.base(); ++it )
1927  {
1928  const size_t j( it->index() );
1929 
1930  if( i == j )
1931  continue;
1932 
1933  if( SO ) {
1934  BLAZE_INTERNAL_ASSERT( matrix_.find( i, j ) != matrix_.end( j ), "Missing element detected" );
1935  matrix_.erase( i, j );
1936  }
1937  else {
1938  BLAZE_INTERNAL_ASSERT( matrix_.find( j, i ) != matrix_.end( j ), "Missing element detected" );
1939  matrix_.erase( j, i );
1940  }
1941  }
1942 
1943  return Iterator( matrix_.erase( i, first.base(), last.base() ), matrix_, i );
1944 }
1946 //*************************************************************************************************
1947 
1948 
1949 //*************************************************************************************************
1964 template< typename MT // Type of the adapted sparse matrix
1965  , bool SO > // Storage order of the adapted sparse matrix
1966 void SymmetricMatrix<MT,SO,false,true>::resize( size_t n, bool preserve )
1967 {
1969 
1970  UNUSED_PARAMETER( preserve );
1971 
1972  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
1973 
1974  matrix_.resize( n, n, true );
1975 }
1977 //*************************************************************************************************
1978 
1979 
1980 //*************************************************************************************************
1991 template< typename MT // Type of the adapted sparse matrix
1992  , bool SO > // Storage order of the adapted sparse matrix
1993 inline void SymmetricMatrix<MT,SO,false,true>::reserve( size_t nonzeros )
1994 {
1995  matrix_.reserve( nonzeros );
1996 }
1998 //*************************************************************************************************
1999 
2000 
2001 //*************************************************************************************************
2015 template< typename MT // Type of the adapted sparse matrix
2016  , bool SO > // Storage order of the adapted sparse matrix
2017 inline void SymmetricMatrix<MT,SO,false,true>::reserve( size_t i, size_t nonzeros )
2018 {
2019  matrix_.reserve( i, nonzeros );
2020 }
2022 //*************************************************************************************************
2023 
2024 
2025 //*************************************************************************************************
2036 template< typename MT // Type of the adapted sparse matrix
2037  , bool SO > // Storage order of the adapted sparse matrix
2038 inline void SymmetricMatrix<MT,SO,false,true>::trim()
2039 {
2040  matrix_.trim();
2041 }
2043 //*************************************************************************************************
2044 
2045 
2046 //*************************************************************************************************
2058 template< typename MT // Type of the adapted sparse matrix
2059  , bool SO > // Storage order of the adapted sparse matrix
2060 inline void SymmetricMatrix<MT,SO,false,true>::trim( size_t i )
2061 {
2062  matrix_.trim( i );
2063 }
2065 //*************************************************************************************************
2066 
2067 
2068 //*************************************************************************************************
2074 template< typename MT // Type of the adapted sparse matrix
2075  , bool SO > // Storage order of the adapted sparse matrix
2076 inline SymmetricMatrix<MT,SO,false,true>& SymmetricMatrix<MT,SO,false,true>::transpose()
2077 {
2078  return *this;
2079 }
2081 //*************************************************************************************************
2082 
2083 
2084 //*************************************************************************************************
2091 template< typename MT // Type of the adapted sparse matrix
2092  , bool SO > // Storage order of the adapted sparse matrix
2093 template< typename Other > // Data type of the scalar value
2094 inline SymmetricMatrix<MT,SO,false,true>&
2095  SymmetricMatrix<MT,SO,false,true>::scale( const Other& scalar )
2096 {
2097  matrix_.scale( scalar );
2098  return *this;
2099 }
2101 //*************************************************************************************************
2102 
2103 
2104 //*************************************************************************************************
2111 template< typename MT // Type of the adapted sparse matrix
2112  , bool SO > // Storage order of the adapted sparse matrix
2113 template< typename Other > // Data type of the scalar value
2114 inline SymmetricMatrix<MT,SO,false,true>&
2115  SymmetricMatrix<MT,SO,false,true>::scaleDiagonal( Other scalar )
2116 {
2117  matrix_.scaleDiagonal( scalar );
2118  return *this;
2119 }
2121 //*************************************************************************************************
2122 
2123 
2124 //*************************************************************************************************
2132 template< typename MT // Type of the adapted sparse matrix
2133  , bool SO > // Storage order of the adapted sparse matrix
2134 inline void SymmetricMatrix<MT,SO,false,true>::swap( SymmetricMatrix& m ) /* throw() */
2135 {
2136  using std::swap;
2137 
2138  swap( matrix_, m.matrix_ );
2139 }
2141 //*************************************************************************************************
2142 
2143 
2144 
2145 
2146 //=================================================================================================
2147 //
2148 // LOOKUP FUNCTIONS
2149 //
2150 //=================================================================================================
2151 
2152 //*************************************************************************************************
2168 template< typename MT // Type of the adapted sparse matrix
2169  , bool SO > // Storage order of the adapted sparse matrix
2171  SymmetricMatrix<MT,SO,false,true>::find( size_t i, size_t j )
2172 {
2173  return Iterator( matrix_.find( i, j ), matrix_, ( SO ? j : i ) );
2174 }
2176 //*************************************************************************************************
2177 
2178 
2179 //*************************************************************************************************
2195 template< typename MT // Type of the adapted sparse matrix
2196  , bool SO > // Storage order of the adapted sparse matrix
2198  SymmetricMatrix<MT,SO,false,true>::find( size_t i, size_t j ) const
2199 {
2200  return matrix_.find( i, j );
2201 }
2203 //*************************************************************************************************
2204 
2205 
2206 //*************************************************************************************************
2222 template< typename MT // Type of the adapted sparse matrix
2223  , bool SO > // Storage order of the adapted sparse matrix
2225  SymmetricMatrix<MT,SO,false,true>::lowerBound( size_t i, size_t j )
2226 {
2227  return Iterator( matrix_.lowerBound( i, j ), matrix_, ( SO ? j : i ) );
2228 }
2230 //*************************************************************************************************
2231 
2232 
2233 //*************************************************************************************************
2249 template< typename MT // Type of the adapted sparse matrix
2250  , bool SO > // Storage order of the adapted sparse matrix
2252  SymmetricMatrix<MT,SO,false,true>::lowerBound( size_t i, size_t j ) const
2253 {
2254  return matrix_.lowerBound( i, j );
2255 }
2257 //*************************************************************************************************
2258 
2259 
2260 //*************************************************************************************************
2276 template< typename MT // Type of the adapted sparse matrix
2277  , bool SO > // Storage order of the adapted sparse matrix
2279  SymmetricMatrix<MT,SO,false,true>::upperBound( size_t i, size_t j )
2280 {
2281  return Iterator( matrix_.upperBound( i, j ), matrix_, ( SO ? j : i ) );
2282 }
2284 //*************************************************************************************************
2285 
2286 
2287 //*************************************************************************************************
2303 template< typename MT // Type of the adapted sparse matrix
2304  , bool SO > // Storage order of the adapted sparse matrix
2306  SymmetricMatrix<MT,SO,false,true>::upperBound( size_t i, size_t j ) const
2307 {
2308  return matrix_.upperBound( i, j );
2309 }
2311 //*************************************************************************************************
2312 
2313 
2314 
2315 
2316 //=================================================================================================
2317 //
2318 // LOW-LEVEL UTILITY FUNCTIONS
2319 //
2320 //=================================================================================================
2321 
2322 //*************************************************************************************************
2377 template< typename MT // Type of the adapted sparse matrix
2378  , bool SO > // Storage order of the adapted sparse matrix
2379 inline void SymmetricMatrix<MT,SO,false,true>::append( size_t i, size_t j, const ElementType& value, bool check )
2380 {
2381  matrix_.append( i, j, value, check );
2382  if( i != j && ( !check || !isDefault( value ) ) )
2383  matrix_.insert( j, i, value );
2384 }
2386 //*************************************************************************************************
2387 
2388 
2389 //*************************************************************************************************
2403 template< typename MT // Type of the adapted sparse matrix
2404  , bool SO > // Storage order of the adapted sparse matrix
2405 inline void SymmetricMatrix<MT,SO,false,true>::finalize( size_t i )
2406 {
2407  matrix_.trim( i );
2408 }
2410 //*************************************************************************************************
2411 
2412 
2413 
2414 
2415 //=================================================================================================
2416 //
2417 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
2418 //
2419 //=================================================================================================
2420 
2421 //*************************************************************************************************
2432 template< typename MT // Type of the adapted sparse matrix
2433  , bool SO > // Storage order of the adapted sparse matrix
2434 template< typename Other > // Data type of the foreign expression
2435 inline bool SymmetricMatrix<MT,SO,false,true>::canAlias( const Other* alias ) const
2436 {
2437  return matrix_.canAlias( alias );
2438 }
2440 //*************************************************************************************************
2441 
2442 
2443 //*************************************************************************************************
2454 template< typename MT // Type of the adapted sparse matrix
2455  , bool SO > // Storage order of the adapted sparse matrix
2456 template< typename Other > // Data type of the foreign expression
2457 inline bool SymmetricMatrix<MT,SO,false,true>::isAliased( const Other* alias ) const
2458 {
2459  return matrix_.isAliased( alias );
2460 }
2462 //*************************************************************************************************
2463 
2464 
2465 //*************************************************************************************************
2476 template< typename MT // Type of the adapted sparse matrix
2477  , bool SO > // Storage order of the adapted sparse matrix
2478 inline bool SymmetricMatrix<MT,SO,false,true>::canSMPAssign() const
2479 {
2480  return matrix_.canSMPAssign();
2481 }
2483 //*************************************************************************************************
2484 
2485 } // namespace blaze
2486 
2487 #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.
void swap(SymmetricMatrix< MT, SO, DF, NF > &a, SymmetricMatrix< MT, SO, DF, NF > &b)
Swapping the contents of two matrices.
Definition: SymmetricMatrix.h:195
#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:4838
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:4772
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:731
Constraint on the data type.
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2478
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:4709
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:2472
#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:2474
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:4736
Header file for the DisableIf class template.
Header file for the IsSymmetric type trait.
Header file for the clear shim.
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:4754
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2482
#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
BLAZE_ALWAYS_INLINE void clear(const NonNumericProxy< MT > &proxy)
Clearing the represented element.
Definition: NonNumericProxy.h:854
Constraint on the data type.
Header file for the IsLower type trait.
Header file for the SparseElement base class.
CompressedMatrix< Type, false > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:2475
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:2476
Header file for all forward declarations for expression class templates.
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2480
Header file for the EnableIf class template.
Header file for the IsNumeric type trait.
BLAZE_ALWAYS_INLINE EnableIf< IsIntegral< T >, Set< T, sizeof(T)> >::Type::Type set(T value)
Sets all values in the vector to the given integral value.
Definition: Set.h:211
#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:2477
Header file for run time assertion macros.
Utility type for generic codes.
Constraint on the data type.
Constraint on the data type.
Header file for the implementation of the base template of the SymmetricMatrix.
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:2481
Header file for the isDefault shim.
BLAZE_ALWAYS_INLINE bool isDefault(const NonNumericProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: NonNumericProxy.h:874
Constraint on the data type.
Constraint on the data type.
BLAZE_ALWAYS_INLINE void reset(const NonNumericProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: NonNumericProxy.h:833
double real
Floating point data type of the Blaze library.This type definition offers the possibility to switch t...
Definition: Precision.h:47
#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:932
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:2473
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 basic type definitions.
Header file for the IsComplex type trait.
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2479
Header file for the IsUpper type trait.
#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