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 <utility>
44 #include <vector>
49 #include <blaze/math/Aliases.h>
58 #include <blaze/math/Exception.h>
61 #include <blaze/math/shims/Clear.h>
70 #include <blaze/util/Assert.h>
76 #include <blaze/util/DisableIf.h>
77 #include <blaze/util/EnableIf.h>
81 #include <blaze/util/Types.h>
82 #include <blaze/util/Unused.h>
83 
84 
85 namespace blaze {
86 
87 //=================================================================================================
88 //
89 // CLASS TEMPLATE SPECIALIZATION FOR SPARSE MATRICES WITH NUMERIC ELEMENT TYPE
90 //
91 //=================================================================================================
92 
93 //*************************************************************************************************
101 template< typename MT // Type of the adapted sparse matrix
102  , bool SO > // Storage order of the adapted sparse matrix
103 class SymmetricMatrix<MT,SO,false,true>
104  : public SparseMatrix< SymmetricMatrix<MT,SO,false,true>, SO >
105 {
106  private:
107  //**Type definitions****************************************************************************
108  typedef OppositeType_<MT> OT;
109  typedef TransposeType_<MT> TT;
110  typedef ElementType_<MT> ET;
111  //**********************************************************************************************
112 
113  public:
114  //**Type definitions****************************************************************************
115  typedef SymmetricMatrix<MT,SO,false,true> This;
116  typedef SparseMatrix<This,SO> BaseType;
117  typedef This ResultType;
118  typedef SymmetricMatrix<OT,!SO,false,true> OppositeType;
119  typedef SymmetricMatrix<TT,!SO,false,true> TransposeType;
120  typedef ET ElementType;
121  typedef ReturnType_<MT> ReturnType;
122  typedef const This& CompositeType;
123  typedef NumericProxy<MT> Reference;
124  typedef ConstReference_<MT> ConstReference;
125  typedef ConstIterator_<MT> ConstIterator;
126  //**********************************************************************************************
127 
128  //**Rebind struct definition********************************************************************
131  template< typename NewType > // Data type of the other matrix
132  struct Rebind {
134  typedef SymmetricMatrix< typename MT::template Rebind<NewType>::Other > Other;
135  };
136  //**********************************************************************************************
137 
138  //**Resize struct definition********************************************************************
141  template< size_t NewM // Number of rows of the other matrix
142  , size_t NewN > // Number of columns of the other matrix
143  struct Resize {
145  typedef SymmetricMatrix< typename MT::template Resize<NewM,NewN>::Other > Other;
146  };
147  //**********************************************************************************************
148 
149  //**Iterator class definition*******************************************************************
152  class Iterator
153  {
154  public:
155  //**Type definitions*************************************************************************
156  typedef Iterator_<MT> IteratorType;
157 
158  typedef std::forward_iterator_tag IteratorCategory;
159  typedef SymmetricElement<MT> ValueType;
160  typedef ValueType PointerType;
161  typedef ValueType ReferenceType;
162  typedef ptrdiff_t DifferenceType;
163 
164  // STL iterator requirements
165  typedef IteratorCategory iterator_category;
166  typedef ValueType value_type;
167  typedef PointerType pointer;
168  typedef ReferenceType reference;
169  typedef DifferenceType difference_type;
170  //*******************************************************************************************
171 
172  //**Default constructor**********************************************************************
175  inline Iterator()
176  : pos_ () // Iterator to the current sparse symmetric matrix element
177  , matrix_( nullptr ) // The sparse matrix containing the iterator
178  , index_ ( 0UL ) // The row/column index of the iterator
179  {}
180  //*******************************************************************************************
181 
182  //**Constructor******************************************************************************
189  inline Iterator( IteratorType pos, MT& matrix, size_t index )
190  : pos_ ( pos ) // Iterator to the current sparse symmetric matrix element
191  , matrix_( &matrix ) // The sparse matrix containing the iterator
192  , index_ ( index ) // The row/column index of the iterator
193  {}
194  //*******************************************************************************************
195 
196  //**Prefix increment operator****************************************************************
201  inline Iterator& operator++() {
202  ++pos_;
203  return *this;
204  }
205  //*******************************************************************************************
206 
207  //**Postfix increment operator***************************************************************
212  inline const Iterator operator++( int ) {
213  const Iterator tmp( *this );
214  ++(*this);
215  return tmp;
216  }
217  //*******************************************************************************************
218 
219  //**Element access operator******************************************************************
224  inline ReferenceType operator*() const {
225  return ReferenceType( pos_, matrix_, index_ );
226  }
227  //*******************************************************************************************
228 
229  //**Element access operator******************************************************************
234  inline PointerType operator->() const {
235  return PointerType( pos_, matrix_, index_ );
236  }
237  //*******************************************************************************************
238 
239  //**Conversion operator**********************************************************************
244  inline operator ConstIterator() const {
245  return pos_;
246  }
247  //*******************************************************************************************
248 
249  //**Equality operator************************************************************************
255  inline bool operator==( const Iterator& rhs ) const {
256  return pos_ == rhs.pos_;
257  }
258  //*******************************************************************************************
259 
260  //**Inequality operator**********************************************************************
266  inline bool operator!=( const Iterator& rhs ) const {
267  return !( *this == rhs );
268  }
269  //*******************************************************************************************
270 
271  //**Subtraction operator*********************************************************************
277  inline DifferenceType operator-( const Iterator& rhs ) const {
278  return pos_ - rhs.pos_;
279  }
280  //*******************************************************************************************
281 
282  //**Base function****************************************************************************
287  inline IteratorType base() const {
288  return pos_;
289  }
290  //*******************************************************************************************
291 
292  private:
293  //**Member variables*************************************************************************
294  IteratorType pos_;
295  MT* matrix_;
296  size_t index_;
297  //*******************************************************************************************
298  };
299  //**********************************************************************************************
300 
301  //**Compilation flags***************************************************************************
303  enum : bool { smpAssignable = false };
304  //**********************************************************************************************
305 
306  //**Constructors********************************************************************************
309  explicit inline SymmetricMatrix();
310  explicit inline SymmetricMatrix( size_t n );
311  explicit inline SymmetricMatrix( size_t n, size_t nonzeros );
312  explicit inline SymmetricMatrix( size_t n, const std::vector<size_t>& nonzeros );
313 
314  inline SymmetricMatrix( const SymmetricMatrix& m );
315  inline SymmetricMatrix( SymmetricMatrix&& m ) noexcept;
316 
317  template< typename MT2 > inline SymmetricMatrix( const Matrix<MT2,SO>& m );
318  template< typename MT2 > inline SymmetricMatrix( const Matrix<MT2,!SO>& m );
320  //**********************************************************************************************
321 
322  //**Destructor**********************************************************************************
323  // No explicitly declared destructor.
324  //**********************************************************************************************
325 
326  //**Data access functions***********************************************************************
329  inline Reference operator()( size_t i, size_t j );
330  inline ConstReference operator()( size_t i, size_t j ) const;
331  inline Reference at( size_t i, size_t j );
332  inline ConstReference at( size_t i, size_t j ) const;
333  inline Iterator begin ( size_t i );
334  inline ConstIterator begin ( size_t i ) const;
335  inline ConstIterator cbegin( size_t i ) const;
336  inline Iterator end ( size_t i );
337  inline ConstIterator end ( size_t i ) const;
338  inline ConstIterator cend ( size_t i ) const;
340  //**********************************************************************************************
341 
342  //**Assignment operators************************************************************************
345  inline SymmetricMatrix& operator=( const SymmetricMatrix& rhs );
346  inline SymmetricMatrix& operator=( SymmetricMatrix&& rhs ) noexcept;
347 
348  template< typename MT2 >
349  inline DisableIf_< IsComputation<MT2>, SymmetricMatrix& > operator=( const Matrix<MT2,SO>& rhs );
350 
351  template< typename MT2 >
352  inline EnableIf_< IsComputation<MT2>, SymmetricMatrix& > operator=( const Matrix<MT2,SO>& rhs );
353 
354  template< typename MT2 >
355  inline SymmetricMatrix& operator=( const Matrix<MT2,!SO>& rhs );
356 
357  template< typename MT2 >
358  inline DisableIf_< IsComputation<MT2>, SymmetricMatrix& > operator+=( const Matrix<MT2,SO>& rhs );
359 
360  template< typename MT2 >
361  inline EnableIf_< IsComputation<MT2>, SymmetricMatrix& > operator+=( const Matrix<MT2,SO>& rhs );
362 
363  template< typename MT2 >
364  inline SymmetricMatrix& operator+=( const Matrix<MT2,!SO>& rhs );
365 
366  template< typename MT2 >
367  inline DisableIf_< IsComputation<MT2>, SymmetricMatrix& > operator-=( const Matrix<MT2,SO>& rhs );
368 
369  template< typename MT2 >
370  inline EnableIf_< IsComputation<MT2>, SymmetricMatrix& > operator-=( const Matrix<MT2,SO>& rhs );
371 
372  template< typename MT2 >
373  inline SymmetricMatrix& operator-=( const Matrix<MT2,!SO>& rhs );
374 
375  template< typename MT2, bool SO2 >
376  inline SymmetricMatrix& operator*=( const Matrix<MT2,SO2>& rhs );
377 
378  template< typename Other >
379  inline EnableIf_< IsNumeric<Other>, SymmetricMatrix >& operator*=( Other rhs );
380 
381  template< typename Other >
382  inline EnableIf_< IsNumeric<Other>, SymmetricMatrix >& operator/=( Other rhs );
384  //**********************************************************************************************
385 
386  //**Utility functions***************************************************************************
389  inline size_t rows() const noexcept;
390  inline size_t columns() const noexcept;
391  inline size_t capacity() const noexcept;
392  inline size_t capacity( size_t i ) const noexcept;
393  inline size_t nonZeros() const;
394  inline size_t nonZeros( size_t i ) const;
395  inline void reset();
396  inline void reset( size_t i );
397  inline void clear();
398  inline void resize ( size_t n, bool preserve=true );
399  inline void reserve( size_t nonzeros );
400  inline void reserve( size_t i, size_t nonzeros );
401  inline void trim();
402  inline void trim( size_t i );
403  inline void swap( SymmetricMatrix& m ) noexcept;
405  //**********************************************************************************************
406 
407  //**Insertion functions*************************************************************************
410  inline Iterator set ( size_t i, size_t j, const ElementType& value );
411  inline Iterator insert ( size_t i, size_t j, const ElementType& value );
412  inline void append ( size_t i, size_t j, const ElementType& value, bool check=false );
413  inline void finalize( size_t i );
415  //**********************************************************************************************
416 
417  //**Erase functions*****************************************************************************
420  inline void erase( size_t i, size_t j );
421  inline Iterator erase( size_t i, Iterator pos );
422  inline Iterator erase( size_t i, Iterator first, Iterator last );
423 
424  template< typename Pred >
425  inline void erase( Pred predicate );
426 
427  template< typename Pred >
428  inline void erase( size_t i, Iterator first, Iterator last, Pred predicate );
430  //**********************************************************************************************
431 
432  //**Lookup functions****************************************************************************
435  inline Iterator find ( size_t i, size_t j );
436  inline ConstIterator find ( size_t i, size_t j ) const;
437  inline Iterator lowerBound( size_t i, size_t j );
438  inline ConstIterator lowerBound( size_t i, size_t j ) const;
439  inline Iterator upperBound( size_t i, size_t j );
440  inline ConstIterator upperBound( size_t i, size_t j ) const;
442  //**********************************************************************************************
443 
444  //**Numeric functions***************************************************************************
447  inline SymmetricMatrix& transpose();
448  inline SymmetricMatrix& ctranspose();
449 
450  template< typename Other > inline SymmetricMatrix& scale( const Other& scalar );
451  template< typename Other > inline SymmetricMatrix& scaleDiagonal( const Other& scale );
453  //**********************************************************************************************
454 
455  //**Debugging functions*************************************************************************
458  inline bool isIntact() const noexcept;
460  //**********************************************************************************************
461 
462  //**Expression template evaluation functions****************************************************
465  template< typename Other > inline bool canAlias ( const Other* alias ) const noexcept;
466  template< typename Other > inline bool isAliased( const Other* alias ) const noexcept;
467 
468  inline bool canSMPAssign() const noexcept;
470  //**********************************************************************************************
471 
472  private:
473  //**Member variables****************************************************************************
476  MT matrix_;
477 
478  //**********************************************************************************************
479 
480  //**Friend declarations*************************************************************************
481  template< bool RF, typename MT2, bool SO2, bool DF2, bool NF2 >
482  friend bool isDefault( const SymmetricMatrix<MT2,SO2,DF2,NF2>& m );
483  //**********************************************************************************************
484 
485  //**Compile time checks*************************************************************************
499  BLAZE_STATIC_ASSERT( Rows<MT>::value == Columns<MT>::value );
500  //**********************************************************************************************
501 };
503 //*************************************************************************************************
504 
505 
506 
507 
508 //=================================================================================================
509 //
510 // CONSTRUCTORS
511 //
512 //=================================================================================================
513 
514 //*************************************************************************************************
518 template< typename MT // Type of the adapted sparse matrix
519  , bool SO > // Storage order of the adapted sparse matrix
520 inline SymmetricMatrix<MT,SO,false,true>::SymmetricMatrix()
521  : matrix_() // The adapted sparse matrix
522 {
523  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
524 }
526 //*************************************************************************************************
527 
528 
529 //*************************************************************************************************
537 template< typename MT // Type of the adapted sparse matrix
538  , bool SO > // Storage order of the adapted sparse matrix
539 inline SymmetricMatrix<MT,SO,false,true>::SymmetricMatrix( size_t n )
540  : matrix_( n, n ) // The adapted sparse matrix
541 {
543 
544  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
545 }
547 //*************************************************************************************************
548 
549 
550 //*************************************************************************************************
559 template< typename MT // Type of the adapted sparse matrix
560  , bool SO > // Storage order of the adapted sparse matrix
561 inline SymmetricMatrix<MT,SO,false,true>::SymmetricMatrix( size_t n, size_t nonzeros )
562  : matrix_( n, n, nonzeros ) // The adapted sparse matrix
563 {
565 
566  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
567 }
569 //*************************************************************************************************
570 
571 
572 //*************************************************************************************************
583 template< typename MT // Type of the adapted sparse matrix
584  , bool SO > // Storage order of the adapted sparse matrix
585 inline SymmetricMatrix<MT,SO,false,true>::SymmetricMatrix( size_t n, const std::vector<size_t>& nonzeros )
586  : matrix_( n, n, nonzeros ) // The adapted sparse matrix
587 {
589 
590  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
591 }
593 //*************************************************************************************************
594 
595 
596 //*************************************************************************************************
602 template< typename MT // Type of the adapted sparse matrix
603  , bool SO > // Storage order of the adapted sparse matrix
604 inline SymmetricMatrix<MT,SO,false,true>::SymmetricMatrix( const SymmetricMatrix& m )
605  : matrix_( m.matrix_ ) // The adapted sparse matrix
606 {
607  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
608  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
609 }
611 //*************************************************************************************************
612 
613 
614 //*************************************************************************************************
620 template< typename MT // Type of the adapted sparse matrix
621  , bool SO > // Storage order of the adapted sparse matrix
622 inline SymmetricMatrix<MT,SO,false,true>::SymmetricMatrix( SymmetricMatrix&& m ) noexcept
623  : matrix_( std::move( m.matrix_ ) ) // The adapted sparse matrix
624 {
625  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
626  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
627 }
629 //*************************************************************************************************
630 
631 
632 //*************************************************************************************************
642 template< typename MT // Type of the adapted sparse matrix
643  , bool SO > // Storage order of the adapted sparse matrix
644 template< typename MT2 > // Type of the foreign matrix
645 inline SymmetricMatrix<MT,SO,false,true>::SymmetricMatrix( const Matrix<MT2,SO>& m )
646  : matrix_( ~m ) // The adapted sparse matrix
647 {
648  if( !IsSymmetric<MT2>::value && !isSymmetric( matrix_ ) ) {
649  BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of symmetric matrix" );
650  }
651 
652  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
653  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
654 }
656 //*************************************************************************************************
657 
658 
659 //*************************************************************************************************
669 template< typename MT // Type of the adapted sparse matrix
670  , bool SO > // Storage order of the adapted sparse matrix
671 template< typename MT2 > // Type of the foreign matrix
672 inline SymmetricMatrix<MT,SO,false,true>::SymmetricMatrix( const Matrix<MT2,!SO>& m )
673  : matrix_( trans( ~m ) ) // The adapted sparse matrix
674 {
675  if( !IsSymmetric<MT2>::value && !isSymmetric( matrix_ ) ) {
676  BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of symmetric matrix" );
677  }
678 
679  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
680  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
681 }
683 //*************************************************************************************************
684 
685 
686 
687 
688 //=================================================================================================
689 //
690 // DATA ACCESS FUNCTIONS
691 //
692 //=================================================================================================
693 
694 //*************************************************************************************************
709 template< typename MT // Type of the adapted sparse matrix
710  , bool SO > // Storage order of the adapted sparse matrix
712  SymmetricMatrix<MT,SO,false,true>::operator()( size_t i, size_t j )
713 {
714  BLAZE_USER_ASSERT( i<rows() , "Invalid row access index" );
715  BLAZE_USER_ASSERT( j<columns(), "Invalid column access index" );
716 
717  return Reference( matrix_, i, j );
718 }
720 //*************************************************************************************************
721 
722 
723 //*************************************************************************************************
738 template< typename MT // Type of the adapted sparse matrix
739  , bool SO > // Storage order of the adapted sparse matrix
741  SymmetricMatrix<MT,SO,false,true>::operator()( size_t i, size_t j ) const
742 {
743  BLAZE_USER_ASSERT( i<rows() , "Invalid row access index" );
744  BLAZE_USER_ASSERT( j<columns(), "Invalid column access index" );
745 
746  return matrix_(i,j);
747 }
749 //*************************************************************************************************
750 
751 
752 //*************************************************************************************************
768 template< typename MT // Type of the adapted dense matrix
769  , bool SO > // Storage order of the adapted dense matrix
771  SymmetricMatrix<MT,SO,false,true>::at( size_t i, size_t j )
772 {
773  if( i >= rows() ) {
774  BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
775  }
776  if( j >= columns() ) {
777  BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
778  }
779  return (*this)(i,j);
780 }
782 //*************************************************************************************************
783 
784 
785 //*************************************************************************************************
801 template< typename MT // Type of the adapted dense matrix
802  , bool SO > // Storage order of the adapted dense matrix
804  SymmetricMatrix<MT,SO,false,true>::at( size_t i, size_t j ) const
805 {
806  if( i >= rows() ) {
807  BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
808  }
809  if( j >= columns() ) {
810  BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
811  }
812  return (*this)(i,j);
813 }
815 //*************************************************************************************************
816 
817 
818 //*************************************************************************************************
830 template< typename MT // Type of the adapted sparse matrix
831  , bool SO > // Storage order of the adapted sparse matrix
834 {
835  return Iterator( matrix_.begin(i), matrix_, i );
836 }
838 //*************************************************************************************************
839 
840 
841 //*************************************************************************************************
853 template< typename MT // Type of the adapted sparse matrix
854  , bool SO > // Storage order of the adapted sparse matrix
857 {
858  return matrix_.begin(i);
859 }
861 //*************************************************************************************************
862 
863 
864 //*************************************************************************************************
876 template< typename MT // Type of the adapted sparse matrix
877  , bool SO > // Storage order of the adapted sparse matrix
880 {
881  return matrix_.cbegin(i);
882 }
884 //*************************************************************************************************
885 
886 
887 //*************************************************************************************************
899 template< typename MT // Type of the adapted sparse matrix
900  , bool SO > // Storage order of the adapted sparse matrix
903 {
904  return Iterator( matrix_.end(i), matrix_, i );
905 }
907 //*************************************************************************************************
908 
909 
910 //*************************************************************************************************
922 template< typename MT // Type of the adapted sparse matrix
923  , bool SO > // Storage order of the adapted sparse matrix
926 {
927  return matrix_.end(i);
928 }
930 //*************************************************************************************************
931 
932 
933 //*************************************************************************************************
945 template< typename MT // Type of the adapted sparse matrix
946  , bool SO > // Storage order of the adapted sparse matrix
949 {
950  return matrix_.cend(i);
951 }
953 //*************************************************************************************************
954 
955 
956 
957 
958 //=================================================================================================
959 //
960 // ASSIGNMENT OPERATORS
961 //
962 //=================================================================================================
963 
964 //*************************************************************************************************
974 template< typename MT // Type of the adapted sparse matrix
975  , bool SO > // Storage order of the adapted sparse matrix
976 inline SymmetricMatrix<MT,SO,false,true>&
977  SymmetricMatrix<MT,SO,false,true>::operator=( const SymmetricMatrix& rhs )
978 {
979  matrix_ = rhs.matrix_;
980 
981  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
982  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
983 
984  return *this;
985 }
987 //*************************************************************************************************
988 
989 
990 //*************************************************************************************************
997 template< typename MT // Type of the adapted sparse matrix
998  , bool SO > // Storage order of the adapted sparse matrix
999 inline SymmetricMatrix<MT,SO,false,true>&
1000  SymmetricMatrix<MT,SO,false,true>::operator=( SymmetricMatrix&& rhs ) noexcept
1001 {
1002  matrix_ = std::move( rhs.matrix_ );
1003 
1004  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
1005  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1006 
1007  return *this;
1008 }
1010 //*************************************************************************************************
1011 
1012 
1013 //*************************************************************************************************
1026 template< typename MT // Type of the adapted sparse matrix
1027  , bool SO > // Storage order of the adapted sparse matrix
1028 template< typename MT2 > // Type of the right-hand side matrix
1029 inline DisableIf_< IsComputation<MT2>, SymmetricMatrix<MT,SO,false,true>& >
1030  SymmetricMatrix<MT,SO,false,true>::operator=( const Matrix<MT2,SO>& rhs )
1031 {
1032  if( !IsSymmetric<MT2>::value && !isSymmetric( ~rhs ) ) {
1033  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to symmetric matrix" );
1034  }
1035 
1036  matrix_ = ~rhs;
1037 
1038  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
1039  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1040 
1041  return *this;
1042 }
1044 //*************************************************************************************************
1045 
1046 
1047 //*************************************************************************************************
1060 template< typename MT // Type of the adapted sparse matrix
1061  , bool SO > // Storage order of the adapted sparse matrix
1062 template< typename MT2 > // Type of the right-hand side matrix
1063 inline EnableIf_< IsComputation<MT2>, SymmetricMatrix<MT,SO,false,true>& >
1064  SymmetricMatrix<MT,SO,false,true>::operator=( const Matrix<MT2,SO>& rhs )
1065 {
1066  if( !IsSquare<MT2>::value && !isSquare( ~rhs ) ) {
1067  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to symmetric matrix" );
1068  }
1069 
1070  if( IsSymmetric<MT2>::value ) {
1071  matrix_ = ~rhs;
1072  }
1073  else {
1074  MT tmp( ~rhs );
1075 
1076  if( !isSymmetric( tmp ) ) {
1077  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to symmetric matrix" );
1078  }
1079 
1080  matrix_ = std::move( tmp );
1081  }
1082 
1083  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
1084  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1085 
1086  return *this;
1087 }
1089 //*************************************************************************************************
1090 
1091 
1092 //*************************************************************************************************
1105 template< typename MT // Type of the adapted sparse matrix
1106  , bool SO > // Storage order of the adapted sparse matrix
1107 template< typename MT2 > // Type of the right-hand side matrix
1108 inline SymmetricMatrix<MT,SO,false,true>&
1109  SymmetricMatrix<MT,SO,false,true>::operator=( const Matrix<MT2,!SO>& rhs )
1110 {
1111  return this->operator=( trans( ~rhs ) );
1112 }
1114 //*************************************************************************************************
1115 
1116 
1117 //*************************************************************************************************
1130 template< typename MT // Type of the adapted sparse matrix
1131  , bool SO > // Storage order of the adapted sparse matrix
1132 template< typename MT2 > // Type of the right-hand side matrix
1133 inline DisableIf_< IsComputation<MT2>, SymmetricMatrix<MT,SO,false,true>& >
1134  SymmetricMatrix<MT,SO,false,true>::operator+=( const Matrix<MT2,SO>& rhs )
1135 {
1136  if( !IsSymmetric<MT2>::value && !isSymmetric( ~rhs ) ) {
1137  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to symmetric matrix" );
1138  }
1139 
1140  matrix_ += ~rhs;
1141 
1142  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
1143  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1144 
1145  return *this;
1146 }
1148 //*************************************************************************************************
1149 
1150 
1151 //*************************************************************************************************
1164 template< typename MT // Type of the adapted sparse matrix
1165  , bool SO > // Storage order of the adapted sparse matrix
1166 template< typename MT2 > // Type of the right-hand side matrix
1167 inline EnableIf_< IsComputation<MT2>, SymmetricMatrix<MT,SO,false,true>& >
1168  SymmetricMatrix<MT,SO,false,true>::operator+=( const Matrix<MT2,SO>& rhs )
1169 {
1170  if( !IsSquare<MT2>::value && !isSquare( ~rhs ) ) {
1171  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to symmetric matrix" );
1172  }
1173 
1174  if( IsSymmetric<MT2>::value ) {
1175  matrix_ += ~rhs;
1176  }
1177  else {
1178  const ResultType_<MT2> tmp( ~rhs );
1179 
1180  if( !isSymmetric( tmp ) ) {
1181  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to symmetric matrix" );
1182  }
1183 
1184  matrix_ += tmp;
1185  }
1186 
1187  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
1188  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1189 
1190  return *this;
1191 }
1193 //*************************************************************************************************
1194 
1195 
1196 //*************************************************************************************************
1210 template< typename MT // Type of the adapted sparse matrix
1211  , bool SO > // Storage order of the adapted sparse matrix
1212 template< typename MT2 > // Type of the right-hand side matrix
1213 inline SymmetricMatrix<MT,SO,false,true>&
1214  SymmetricMatrix<MT,SO,false,true>::operator+=( const Matrix<MT2,!SO>& rhs )
1215 {
1216  return this->operator+=( trans( ~rhs ) );
1217 }
1219 //*************************************************************************************************
1220 
1221 
1222 //*************************************************************************************************
1235 template< typename MT // Type of the adapted sparse matrix
1236  , bool SO > // Storage order of the adapted sparse matrix
1237 template< typename MT2 > // Type of the right-hand side matrix
1238 inline DisableIf_< IsComputation<MT2>, SymmetricMatrix<MT,SO,false,true>& >
1239  SymmetricMatrix<MT,SO,false,true>::operator-=( const Matrix<MT2,SO>& rhs )
1240 {
1241  if( !IsSymmetric<MT2>::value && !isSymmetric( ~rhs ) ) {
1242  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to symmetric matrix" );
1243  }
1244 
1245  matrix_ -= ~rhs;
1246 
1247  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
1248  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1249 
1250  return *this;
1251 }
1253 //*************************************************************************************************
1254 
1255 
1256 //*************************************************************************************************
1269 template< typename MT // Type of the adapted sparse matrix
1270  , bool SO > // Storage order of the adapted sparse matrix
1271 template< typename MT2 > // Type of the right-hand side matrix
1272 inline EnableIf_< IsComputation<MT2>, SymmetricMatrix<MT,SO,false,true>& >
1273  SymmetricMatrix<MT,SO,false,true>::operator-=( const Matrix<MT2,SO>& rhs )
1274 {
1275  if( !IsSquare<MT2>::value && !isSquare( ~rhs ) ) {
1276  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to symmetric matrix" );
1277  }
1278 
1279  if( IsSymmetric<MT2>::value ) {
1280  matrix_ -= ~rhs;
1281  }
1282  else {
1283  const ResultType_<MT2> tmp( ~rhs );
1284 
1285  if( !isSymmetric( tmp ) ) {
1286  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to symmetric matrix" );
1287  }
1288 
1289  matrix_ -= tmp;
1290  }
1291 
1292  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
1293  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1294 
1295  return *this;
1296 }
1298 //*************************************************************************************************
1299 
1300 
1301 //*************************************************************************************************
1315 template< typename MT // Type of the adapted sparse matrix
1316  , bool SO > // Storage order of the adapted sparse matrix
1317 template< typename MT2 > // Type of the right-hand side matrix
1318 inline SymmetricMatrix<MT,SO,false,true>&
1319  SymmetricMatrix<MT,SO,false,true>::operator-=( const Matrix<MT2,!SO>& rhs )
1320 {
1321  return this->operator-=( trans( ~rhs ) );
1322 }
1324 //*************************************************************************************************
1325 
1326 
1327 //*************************************************************************************************
1339 template< typename MT // Type of the adapted sparse matrix
1340  , bool SO > // Storage order of the adapted sparse matrix
1341 template< typename MT2 // Type of the right-hand side matrix
1342  , bool SO2 > // Storage order of the right-hand side matrix
1343 inline SymmetricMatrix<MT,SO,false,true>&
1344  SymmetricMatrix<MT,SO,false,true>::operator*=( const Matrix<MT2,SO2>& rhs )
1345 {
1346  if( matrix_.rows() != (~rhs).columns() ) {
1347  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to symmetric matrix" );
1348  }
1349 
1350  MT tmp( matrix_ * ~rhs );
1351 
1352  if( !isSymmetric( tmp ) ) {
1353  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to symmetric matrix" );
1354  }
1355 
1356  matrix_ = std::move( tmp );
1357 
1358  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
1359  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1360 
1361  return *this;
1362 }
1364 //*************************************************************************************************
1365 
1366 
1367 //*************************************************************************************************
1375 template< typename MT // Type of the adapted sparse matrix
1376  , bool SO > // Storage order of the adapted sparse matrix
1377 template< typename Other > // Data type of the right-hand side scalar
1378 inline EnableIf_< IsNumeric<Other>, SymmetricMatrix<MT,SO,false,true> >&
1380 {
1381  matrix_ *= rhs;
1382  return *this;
1383 }
1384 //*************************************************************************************************
1385 
1386 
1387 //*************************************************************************************************
1395 template< typename MT // Type of the adapted sparse matrix
1396  , bool SO > // Storage order of the adapted sparse matrix
1397 template< typename Other > // Data type of the right-hand side scalar
1398 inline EnableIf_< IsNumeric<Other>, SymmetricMatrix<MT,SO,false,true> >&
1400 {
1401  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
1402 
1403  matrix_ /= rhs;
1404  return *this;
1405 }
1407 //*************************************************************************************************
1408 
1409 
1410 
1411 
1412 //=================================================================================================
1413 //
1414 // UTILITY FUNCTIONS
1415 //
1416 //=================================================================================================
1417 
1418 //*************************************************************************************************
1424 template< typename MT // Type of the adapted sparse matrix
1425  , bool SO > // Storage order of the adapted sparse matrix
1426 inline size_t SymmetricMatrix<MT,SO,false,true>::rows() const noexcept
1427 {
1428  return matrix_.rows();
1429 }
1431 //*************************************************************************************************
1432 
1433 
1434 //*************************************************************************************************
1440 template< typename MT // Type of the adapted sparse matrix
1441  , bool SO > // Storage order of the adapted sparse matrix
1442 inline size_t SymmetricMatrix<MT,SO,false,true>::columns() const noexcept
1443 {
1444  return matrix_.columns();
1445 }
1447 //*************************************************************************************************
1448 
1449 
1450 //*************************************************************************************************
1456 template< typename MT // Type of the adapted sparse matrix
1457  , bool SO > // Storage order of the adapted sparse matrix
1458 inline size_t SymmetricMatrix<MT,SO,false,true>::capacity() const noexcept
1459 {
1460  return matrix_.capacity();
1461 }
1463 //*************************************************************************************************
1464 
1465 
1466 //*************************************************************************************************
1477 template< typename MT // Type of the adapted sparse matrix
1478  , bool SO > // Storage order of the adapted sparse matrix
1479 inline size_t SymmetricMatrix<MT,SO,false,true>::capacity( size_t i ) const noexcept
1480 {
1481  return matrix_.capacity(i);
1482 }
1484 //*************************************************************************************************
1485 
1486 
1487 //*************************************************************************************************
1493 template< typename MT // Type of the adapted sparse matrix
1494  , bool SO > // Storage order of the adapted sparse matrix
1495 inline size_t SymmetricMatrix<MT,SO,false,true>::nonZeros() const
1496 {
1497  return matrix_.nonZeros();
1498 }
1500 //*************************************************************************************************
1501 
1502 
1503 //*************************************************************************************************
1515 template< typename MT // Type of the adapted sparse matrix
1516  , bool SO > // Storage order of the adapted sparse matrix
1517 inline size_t SymmetricMatrix<MT,SO,false,true>::nonZeros( size_t i ) const
1518 {
1519  return matrix_.nonZeros(i);
1520 }
1522 //*************************************************************************************************
1523 
1524 
1525 //*************************************************************************************************
1531 template< typename MT // Type of the adapted sparse matrix
1532  , bool SO > // Storage order of the adapted sparse matrix
1534 {
1535  matrix_.reset();
1536 }
1538 //*************************************************************************************************
1539 
1540 
1541 //*************************************************************************************************
1577 template< typename MT // Type of the adapted sparse matrix
1578  , bool SO > // Storage order of the adapted sparse matrix
1579 inline void SymmetricMatrix<MT,SO,false,true>::reset( size_t i )
1580 {
1581  for( Iterator_<MT> it=matrix_.begin(i); it!=matrix_.end(i); ++it )
1582  {
1583  const size_t j( it->index() );
1584 
1585  if( i == j )
1586  continue;
1587 
1588  if( SO ) {
1589  const Iterator_<MT> pos( matrix_.find( i, j ) );
1590  BLAZE_INTERNAL_ASSERT( pos != matrix_.end( j ), "Missing element detected" );
1591  matrix_.erase( j, pos );
1592  }
1593  else {
1594  const Iterator_<MT> pos( matrix_.find( j, i ) );
1595  BLAZE_INTERNAL_ASSERT( pos != matrix_.end( j ), "Missing element detected" );
1596  matrix_.erase( j, pos );
1597  }
1598  }
1599 
1600  matrix_.reset( i );
1601 }
1603 //*************************************************************************************************
1604 
1605 
1606 //*************************************************************************************************
1614 template< typename MT // Type of the adapted sparse matrix
1615  , bool SO > // Storage order of the adapted sparse matrix
1617 {
1618  using blaze::clear;
1619 
1620  clear( matrix_ );
1621 }
1623 //*************************************************************************************************
1624 
1625 
1626 //*************************************************************************************************
1641 template< typename MT // Type of the adapted sparse matrix
1642  , bool SO > // Storage order of the adapted sparse matrix
1643 void SymmetricMatrix<MT,SO,false,true>::resize( size_t n, bool preserve )
1644 {
1646 
1647  UNUSED_PARAMETER( preserve );
1648 
1649  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square symmetric matrix detected" );
1650 
1651  matrix_.resize( n, n, true );
1652 }
1654 //*************************************************************************************************
1655 
1656 
1657 //*************************************************************************************************
1668 template< typename MT // Type of the adapted sparse matrix
1669  , bool SO > // Storage order of the adapted sparse matrix
1670 inline void SymmetricMatrix<MT,SO,false,true>::reserve( size_t nonzeros )
1671 {
1672  matrix_.reserve( nonzeros );
1673 }
1675 //*************************************************************************************************
1676 
1677 
1678 //*************************************************************************************************
1692 template< typename MT // Type of the adapted sparse matrix
1693  , bool SO > // Storage order of the adapted sparse matrix
1694 inline void SymmetricMatrix<MT,SO,false,true>::reserve( size_t i, size_t nonzeros )
1695 {
1696  matrix_.reserve( i, nonzeros );
1697 }
1699 //*************************************************************************************************
1700 
1701 
1702 //*************************************************************************************************
1713 template< typename MT // Type of the adapted sparse matrix
1714  , bool SO > // Storage order of the adapted sparse matrix
1715 inline void SymmetricMatrix<MT,SO,false,true>::trim()
1716 {
1717  matrix_.trim();
1718 }
1720 //*************************************************************************************************
1721 
1722 
1723 //*************************************************************************************************
1735 template< typename MT // Type of the adapted sparse matrix
1736  , bool SO > // Storage order of the adapted sparse matrix
1737 inline void SymmetricMatrix<MT,SO,false,true>::trim( size_t i )
1738 {
1739  matrix_.trim( i );
1740 }
1742 //*************************************************************************************************
1743 
1744 
1745 //*************************************************************************************************
1752 template< typename MT // Type of the adapted sparse matrix
1753  , bool SO > // Storage order of the adapted sparse matrix
1754 inline void SymmetricMatrix<MT,SO,false,true>::swap( SymmetricMatrix& m ) noexcept
1755 {
1756  using std::swap;
1757 
1758  swap( matrix_, m.matrix_ );
1759 }
1761 //*************************************************************************************************
1762 
1763 
1764 
1765 
1766 //=================================================================================================
1767 //
1768 // INSERTION FUNCTIONS
1769 //
1770 //=================================================================================================
1771 
1772 //*************************************************************************************************
1786 template< typename MT // Type of the adapted sparse matrix
1787  , bool SO > // Storage order of the adapted sparse matrix
1789  SymmetricMatrix<MT,SO,false,true>::set( size_t i, size_t j, const ElementType& value )
1790 {
1791  if( i != j )
1792  matrix_.set( j, i, value );
1793  return Iterator( matrix_.set( i, j, value ), matrix_, ( SO ? j : i ) );
1794 }
1796 //*************************************************************************************************
1797 
1798 
1799 //*************************************************************************************************
1814 template< typename MT // Type of the adapted sparse matrix
1815  , bool SO > // Storage order of the adapted sparse matrix
1817  SymmetricMatrix<MT,SO,false,true>::insert( size_t i, size_t j, const ElementType& value )
1818 {
1819  if( i != j )
1820  matrix_.insert( j, i, value );
1821  return Iterator( matrix_.insert( i, j, value ), matrix_, ( SO ? j : i ) );
1822 }
1824 //*************************************************************************************************
1825 
1826 
1827 //*************************************************************************************************
1882 template< typename MT // Type of the adapted sparse matrix
1883  , bool SO > // Storage order of the adapted sparse matrix
1884 inline void SymmetricMatrix<MT,SO,false,true>::append( size_t i, size_t j, const ElementType& value, bool check )
1885 {
1886  matrix_.append( i, j, value, check );
1887  if( i != j && ( !check || !isDefault( value ) ) )
1888  matrix_.insert( j, i, value );
1889 }
1891 //*************************************************************************************************
1892 
1893 
1894 //*************************************************************************************************
1908 template< typename MT // Type of the adapted sparse matrix
1909  , bool SO > // Storage order of the adapted sparse matrix
1910 inline void SymmetricMatrix<MT,SO,false,true>::finalize( size_t i )
1911 {
1912  matrix_.trim( i );
1913 }
1915 //*************************************************************************************************
1916 
1917 
1918 
1919 
1920 //=================================================================================================
1921 //
1922 // ERASE FUNCTIONS
1923 //
1924 //=================================================================================================
1925 
1926 //*************************************************************************************************
1936 template< typename MT // Type of the adapted sparse matrix
1937  , bool SO > // Storage order of the adapted sparse matrix
1938 inline void SymmetricMatrix<MT,SO,false,true>::erase( size_t i, size_t j )
1939 {
1940  matrix_.erase( i, j );
1941  if( i != j )
1942  matrix_.erase( j, i );
1943 }
1945 //*************************************************************************************************
1946 
1947 
1948 //*************************************************************************************************
1960 template< typename MT // Type of the adapted sparse matrix
1961  , bool SO > // Storage order of the adapted sparse matrix
1963  SymmetricMatrix<MT,SO,false,true>::erase( size_t i, Iterator pos )
1964 {
1965  const Iterator_<MT> base( pos.base() );
1966 
1967  if( base == matrix_.end( i ) )
1968  return pos;
1969 
1970  const size_t j( base->index() );
1971 
1972  if( i == j ) {
1973  BLAZE_INTERNAL_ASSERT( matrix_.find( i, i ) != matrix_.end( i ), "Missing element detected" );
1974  return Iterator( matrix_.erase( i, base ), matrix_, i );
1975  }
1976 
1977  if( SO ) {
1978  BLAZE_INTERNAL_ASSERT( matrix_.find( i, j ) != matrix_.end( j ), "Missing element detected" );
1979  matrix_.erase( j, matrix_.find( i, j ) );
1980  return Iterator( matrix_.erase( i, base ), matrix_, i );
1981  }
1982  else {
1983  BLAZE_INTERNAL_ASSERT( matrix_.find( j, i ) != matrix_.end( j ), "Missing element detected" );
1984  matrix_.erase( j, matrix_.find( j, i ) );
1985  return Iterator( matrix_.erase( i, base ), matrix_, i );
1986  }
1987 }
1989 //*************************************************************************************************
1990 
1991 
1992 //*************************************************************************************************
2006 template< typename MT // Type of the adapted sparse matrix
2007  , bool SO > // Storage order of the adapted sparse matrix
2009  SymmetricMatrix<MT,SO,false,true>::erase( size_t i, Iterator first, Iterator last )
2010 {
2011  for( Iterator_<MT> it=first.base(); it!=last.base(); ++it )
2012  {
2013  const size_t j( it->index() );
2014 
2015  if( i == j )
2016  continue;
2017 
2018  if( SO ) {
2019  BLAZE_INTERNAL_ASSERT( matrix_.find( i, j ) != matrix_.end( j ), "Missing element detected" );
2020  matrix_.erase( i, j );
2021  }
2022  else {
2023  BLAZE_INTERNAL_ASSERT( matrix_.find( j, i ) != matrix_.end( j ), "Missing element detected" );
2024  matrix_.erase( j, i );
2025  }
2026  }
2027 
2028  return Iterator( matrix_.erase( i, first.base(), last.base() ), matrix_, i );
2029 }
2031 //*************************************************************************************************
2032 
2033 
2034 //*************************************************************************************************
2056 template< typename MT // Type of the adapted sparse matrix
2057  , bool SO > // Storage order of the adapted sparse matrix
2058 template< typename Pred > // Type of the unary predicate
2059 inline void SymmetricMatrix<MT,SO,false,true>::erase( Pred predicate )
2060 {
2061  matrix_.erase( predicate );
2062 
2063  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
2064 }
2066 //*************************************************************************************************
2067 
2068 
2069 //*************************************************************************************************
2097 template< typename MT // Type of the adapted sparse matrix
2098  , bool SO > // Storage order of the adapted sparse matrix
2099 template< typename Pred > // Type of the unary predicate
2100 inline void
2101  SymmetricMatrix<MT,SO,false,true>::erase( size_t i, Iterator first, Iterator last, Pred predicate )
2102 {
2103  for( Iterator it=first; it!=last; ++it ) {
2104  const size_t j( it->index() );
2105  if( i != j && predicate( it->value() ) ) {
2106  if( SO )
2107  matrix_.erase( i, j );
2108  else
2109  matrix_.erase( j, i );
2110  }
2111  }
2112 
2113  matrix_.erase( i, first.base(), last.base(), predicate );
2114 
2115  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
2116 }
2118 //*************************************************************************************************
2119 
2120 
2121 
2122 
2123 //=================================================================================================
2124 //
2125 // LOOKUP FUNCTIONS
2126 //
2127 //=================================================================================================
2128 
2129 //*************************************************************************************************
2145 template< typename MT // Type of the adapted sparse matrix
2146  , bool SO > // Storage order of the adapted sparse matrix
2148  SymmetricMatrix<MT,SO,false,true>::find( size_t i, size_t j )
2149 {
2150  return Iterator( matrix_.find( i, j ), matrix_, ( SO ? j : i ) );
2151 }
2153 //*************************************************************************************************
2154 
2155 
2156 //*************************************************************************************************
2172 template< typename MT // Type of the adapted sparse matrix
2173  , bool SO > // Storage order of the adapted sparse matrix
2175  SymmetricMatrix<MT,SO,false,true>::find( size_t i, size_t j ) const
2176 {
2177  return matrix_.find( i, j );
2178 }
2180 //*************************************************************************************************
2181 
2182 
2183 //*************************************************************************************************
2199 template< typename MT // Type of the adapted sparse matrix
2200  , bool SO > // Storage order of the adapted sparse matrix
2202  SymmetricMatrix<MT,SO,false,true>::lowerBound( size_t i, size_t j )
2203 {
2204  return Iterator( matrix_.lowerBound( i, j ), matrix_, ( SO ? j : i ) );
2205 }
2207 //*************************************************************************************************
2208 
2209 
2210 //*************************************************************************************************
2226 template< typename MT // Type of the adapted sparse matrix
2227  , bool SO > // Storage order of the adapted sparse matrix
2229  SymmetricMatrix<MT,SO,false,true>::lowerBound( size_t i, size_t j ) const
2230 {
2231  return matrix_.lowerBound( i, j );
2232 }
2234 //*************************************************************************************************
2235 
2236 
2237 //*************************************************************************************************
2253 template< typename MT // Type of the adapted sparse matrix
2254  , bool SO > // Storage order of the adapted sparse matrix
2256  SymmetricMatrix<MT,SO,false,true>::upperBound( size_t i, size_t j )
2257 {
2258  return Iterator( matrix_.upperBound( i, j ), matrix_, ( SO ? j : i ) );
2259 }
2261 //*************************************************************************************************
2262 
2263 
2264 //*************************************************************************************************
2280 template< typename MT // Type of the adapted sparse matrix
2281  , bool SO > // Storage order of the adapted sparse matrix
2283  SymmetricMatrix<MT,SO,false,true>::upperBound( size_t i, size_t j ) const
2284 {
2285  return matrix_.upperBound( i, j );
2286 }
2288 //*************************************************************************************************
2289 
2290 
2291 
2292 
2293 //=================================================================================================
2294 //
2295 // NUMERIC FUNCTIONS
2296 //
2297 //=================================================================================================
2298 
2299 //*************************************************************************************************
2305 template< typename MT // Type of the adapted sparse matrix
2306  , bool SO > // Storage order of the adapted sparse matrix
2307 inline SymmetricMatrix<MT,SO,false,true>& SymmetricMatrix<MT,SO,false,true>::transpose()
2308 {
2309  return *this;
2310 }
2312 //*************************************************************************************************
2313 
2314 
2315 //*************************************************************************************************
2321 template< typename MT // Type of the adapted sparse matrix
2322  , bool SO > // Storage order of the adapted sparse matrix
2323 inline SymmetricMatrix<MT,SO,false,true>& SymmetricMatrix<MT,SO,false,true>::ctranspose()
2324 {
2325  if( !IsBuiltin<ElementType>::value )
2326  conjugate( matrix_ );
2327 
2328  return *this;
2329 }
2331 //*************************************************************************************************
2332 
2333 
2334 //*************************************************************************************************
2341 template< typename MT // Type of the adapted sparse matrix
2342  , bool SO > // Storage order of the adapted sparse matrix
2343 template< typename Other > // Data type of the scalar value
2344 inline SymmetricMatrix<MT,SO,false,true>&
2345  SymmetricMatrix<MT,SO,false,true>::scale( const Other& scalar )
2346 {
2347  matrix_.scale( scalar );
2348  return *this;
2349 }
2351 //*************************************************************************************************
2352 
2353 
2354 //*************************************************************************************************
2361 template< typename MT // Type of the adapted sparse matrix
2362  , bool SO > // Storage order of the adapted sparse matrix
2363 template< typename Other > // Data type of the scalar value
2364 inline SymmetricMatrix<MT,SO,false,true>&
2365  SymmetricMatrix<MT,SO,false,true>::scaleDiagonal( const Other& scalar )
2366 {
2367  matrix_.scaleDiagonal( scalar );
2368  return *this;
2369 }
2371 //*************************************************************************************************
2372 
2373 
2374 
2375 
2376 //=================================================================================================
2377 //
2378 // DEBUGGING FUNCTIONS
2379 //
2380 //=================================================================================================
2381 
2382 //*************************************************************************************************
2392 template< typename MT // Type of the adapted sparse matrix
2393  , bool SO > // Storage order of the adapted sparse matrix
2394 inline bool SymmetricMatrix<MT,SO,false,true>::isIntact() const noexcept
2395 {
2396  using blaze::isIntact;
2397 
2398  return ( isIntact( matrix_ ) && isSymmetric( matrix_ ) );
2399 }
2401 //*************************************************************************************************
2402 
2403 
2404 
2405 
2406 //=================================================================================================
2407 //
2408 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
2409 //
2410 //=================================================================================================
2411 
2412 //*************************************************************************************************
2423 template< typename MT // Type of the adapted sparse matrix
2424  , bool SO > // Storage order of the adapted sparse matrix
2425 template< typename Other > // Data type of the foreign expression
2426 inline bool SymmetricMatrix<MT,SO,false,true>::canAlias( const Other* alias ) const noexcept
2427 {
2428  return matrix_.canAlias( alias );
2429 }
2431 //*************************************************************************************************
2432 
2433 
2434 //*************************************************************************************************
2445 template< typename MT // Type of the adapted sparse matrix
2446  , bool SO > // Storage order of the adapted sparse matrix
2447 template< typename Other > // Data type of the foreign expression
2448 inline bool SymmetricMatrix<MT,SO,false,true>::isAliased( const Other* alias ) const noexcept
2449 {
2450  return matrix_.isAliased( alias );
2451 }
2453 //*************************************************************************************************
2454 
2455 
2456 //*************************************************************************************************
2467 template< typename MT // Type of the adapted sparse matrix
2468  , bool SO > // Storage order of the adapted sparse matrix
2469 inline bool SymmetricMatrix<MT,SO,false,true>::canSMPAssign() const noexcept
2470 {
2471  return matrix_.canSMPAssign();
2472 }
2474 //*************************************************************************************************
2475 
2476 } // namespace blaze
2477 
2478 #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:79
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.This macro encapsulates the default way o...
Definition: Exception.h:235
Header file for auxiliary alias declarations.
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 Rows type trait.
Header file for the UNUSED_PARAMETER function template.
BLAZE_ALWAYS_INLINE size_t capacity(const Matrix< MT, SO > &matrix) noexcept
Returns the maximum capacity of the matrix.
Definition: Matrix.h:352
Header file for basic type definitions.
#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:63
BLAZE_ALWAYS_INLINE T1 & operator/=(SIMDPack< T1 > &lhs, const SIMDPack< T2 > &rhs)
Division assignment operator for the division of two SIMD packs.
Definition: BasicTypes.h:1339
Constraint on the data type.
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:194
Constraint on the data type.
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:533
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2935
void clear(CompressedMatrix< Type, SO > &m)
Clearing the given compressed matrix.
Definition: CompressedMatrix.h:5556
BLAZE_ALWAYS_INLINE void ctranspose(Matrix< MT, SO > &matrix)
In-place conjugate transpose of the given matrix.
Definition: Matrix.h:596
CompressedMatrix< Type, true > This
Type of this CompressedMatrix instance.
Definition: CompressedMatrix.h:2928
#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:79
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:390
const DenseIterator< Type, AF > operator-(const DenseIterator< Type, AF > &it, ptrdiff_t inc) noexcept
Subtraction between a DenseIterator and an integral value.
Definition: DenseIterator.h:731
BLAZE_ALWAYS_INLINE T1 & operator*=(SIMDPack< T1 > &lhs, const SIMDPack< T2 > &rhs)
Multiplication assignment operator for the multiplication of two SIMD packs.
Definition: BasicTypes.h:1321
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:2931
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:304
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:238
Header file for the implementation of the base template of the SymmetricMatrix.
Constraint on the data type.
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.
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 SymmetricElement class.
void swap(CompressedMatrix< Type, SO > &a, CompressedMatrix< Type, SO > &b) noexcept
Swapping the contents of two compressed matrices.
Definition: CompressedMatrix.h:5635
Compile time assertion.
bool isIntact(const CompressedMatrix< Type, SO > &m)
Returns whether the invariants of the given compressed matrix are intact.
Definition: CompressedMatrix.h:5618
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2939
#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:79
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.This macro encapsulates the default way of Bl...
Definition: Exception.h:331
Header file for the Columns type trait.
constexpr bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value. ...
Definition: Accuracy.h:250
Constraint on the data type.
BLAZE_ALWAYS_INLINE size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:336
CompressedMatrix< Type, false > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:2932
Constraints on the storage order of matrix types.
Header file for the exception macros of the math module.
#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:81
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:544
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:260
Type ElementType
Type of the compressed matrix elements.
Definition: CompressedMatrix.h:2933
constexpr bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:290
Header file for all forward declarations for expression class templates.
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2937
Header file for the EnableIf class template.
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:553
Header file for the conjugate shim.
Header file for the IsNumeric type trait.
BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral< T >, HasSize< T, 1UL > >, If_< IsSigned< T >, SIMDint8, SIMDuint8 > > set(T value) noexcept
Sets all values in the vector to the given 1-byte integral value.
Definition: Set.h:76
#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:79
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2934
BLAZE_ALWAYS_INLINE T1 & operator+=(SIMDPack< T1 > &lhs, const SIMDPack< T2 > &rhs)
Addition assignment operator for the addition of two SIMD packs.
Definition: BasicTypes.h:1285
Header file for run time assertion macros.
Constraint on the data type.
Constraint on the data type.
#define BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE(T)
Constraint on the data type.In case the given data type T is not a numeric (integral or floating poin...
Definition: Numeric.h:61
#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:81
#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:79
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2938
Header file for the isDefault shim.
void swap(DiagonalMatrix< MT, SO, DF > &a, DiagonalMatrix< MT, SO, DF > &b) noexcept
Swapping the contents of two matrices.
Definition: DiagonalMatrix.h:267
Header file for the SymmetricValue class.
Constraint on the data type.
Constraint on the data type.
BLAZE_ALWAYS_INLINE void conjugate(T &a) noexcept(IsNumeric< T >::value)
In-place conjugation of the given value/object.
Definition: Conjugate.h:120
bool isSymmetric(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is symmetric.
Definition: DenseMatrix.h:697
BLAZE_ALWAYS_INLINE size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:320
SparseMatrix< This, true > BaseType
Base type of this CompressedMatrix instance.
Definition: CompressedMatrix.h:2929
#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 &#39;res...
Definition: Resizable.h:61
const DMatTransExpr< MT,!SO > trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:733
Header file for the IsComputation type trait class.
Header file for the IsBuiltin type trait.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_EXPRESSION_TYPE(T)
Constraint on the data type.In case the given data type T is an expression (i.e. a type derived from ...
Definition: Expression.h:81
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2930
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:249
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:573
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2936
#define BLAZE_CONSTRAINT_MUST_NOT_BE_HERMITIAN_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is an Hermitian matrix type, a compilation error is created.
Definition: Hermitian.h:79
BLAZE_ALWAYS_INLINE T1 & operator-=(SIMDPack< T1 > &lhs, const SIMDPack< T2 > &rhs)
Subtraction assignment operator for the subtraction of two SIMD packs.
Definition: BasicTypes.h:1303
void UNUSED_PARAMETER(const Args &...)
Suppression of unused parameter warnings.
Definition: Unused.h:81
#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:112
BLAZE_ALWAYS_INLINE bool isSquare(const Matrix< MT, SO > &matrix) noexcept
Checks if the given matrix is a square matrix.
Definition: Matrix.h:677
const DMatDMatMultExpr< T1, T2, false, false, false, false > 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:7505
#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:61
BLAZE_ALWAYS_INLINE void transpose(Matrix< MT, SO > &matrix)
In-place transpose of the given matrix.
Definition: Matrix.h:570