Sparse.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_ADAPTORS_HERMITIANMATRIX_SPARSE_H_
36 #define _BLAZE_MATH_ADAPTORS_HERMITIANMATRIX_SPARSE_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <iterator>
44 #include <utility>
45 #include <vector>
49 #include <blaze/math/Aliases.h>
58 #include <blaze/math/Exception.h>
61 #include <blaze/math/shims/Clear.h>
72 #include <blaze/util/Assert.h>
78 #include <blaze/util/DisableIf.h>
79 #include <blaze/util/EnableIf.h>
81 #include <blaze/util/TrueType.h>
82 #include <blaze/util/Types.h>
86 #include <blaze/util/Unused.h>
87 
88 
89 namespace blaze {
90 
91 //=================================================================================================
92 //
93 // CLASS TEMPLATE SPECIALIZATION FOR SPARSE MATRICES
94 //
95 //=================================================================================================
96 
97 //*************************************************************************************************
105 template< typename MT // Type of the adapted sparse matrix
106  , bool SO > // Storage order of the adapted sparse matrix
107 class HermitianMatrix<MT,SO,false>
108  : public SparseMatrix< HermitianMatrix<MT,SO,false>, SO >
109 {
110  private:
111  //**Type definitions****************************************************************************
112  typedef OppositeType_<MT> OT;
113  typedef TransposeType_<MT> TT;
114  typedef ElementType_<MT> ET;
115  //**********************************************************************************************
116 
117  public:
118  //**Type definitions****************************************************************************
119  typedef HermitianMatrix<MT,SO,false> This;
120  typedef SparseMatrix<This,SO> BaseType;
121  typedef This ResultType;
122  typedef HermitianMatrix<OT,!SO,false> OppositeType;
123  typedef HermitianMatrix<TT,!SO,false> TransposeType;
124  typedef ET ElementType;
125  typedef ReturnType_<MT> ReturnType;
126  typedef const This& CompositeType;
127  typedef HermitianProxy<MT> Reference;
128  typedef ConstReference_<MT> ConstReference;
129  typedef ConstIterator_<MT> ConstIterator;
130  //**********************************************************************************************
131 
132  //**Rebind struct definition********************************************************************
135  template< typename NewType > // Data type of the other matrix
136  struct Rebind {
138  typedef HermitianMatrix< typename MT::template Rebind<NewType>::Other > Other;
139  };
140  //**********************************************************************************************
141 
142  //**Resize struct definition********************************************************************
145  template< size_t NewM // Number of rows of the other matrix
146  , size_t NewN > // Number of columns of the other matrix
147  struct Resize {
149  typedef HermitianMatrix< typename MT::template Resize<NewM,NewN>::Other > Other;
150  };
151  //**********************************************************************************************
152 
153  //**Iterator class definition*******************************************************************
156  class Iterator
157  {
158  public:
159  //**Type definitions*************************************************************************
160  typedef Iterator_<MT> IteratorType;
161 
162  typedef std::forward_iterator_tag IteratorCategory;
163  typedef HermitianElement<MT> ValueType;
164  typedef ValueType PointerType;
165  typedef ValueType ReferenceType;
166  typedef ptrdiff_t DifferenceType;
167 
168  // STL iterator requirements
169  typedef IteratorCategory iterator_category;
170  typedef ValueType value_type;
171  typedef PointerType pointer;
172  typedef ReferenceType reference;
173  typedef DifferenceType difference_type;
174  //*******************************************************************************************
175 
176  //**Default constructor**********************************************************************
179  inline Iterator()
180  : pos_ () // Iterator to the current sparse Hermitian matrix element
181  , matrix_( nullptr ) // The sparse matrix containing the iterator
182  , index_ ( 0UL ) // The row/column index of the iterator
183  {}
184  //*******************************************************************************************
185 
186  //**Constructor******************************************************************************
193  inline Iterator( IteratorType pos, MT& matrix, size_t index )
194  : pos_ ( pos ) // Iterator to the current sparse Hermitian matrix element
195  , matrix_( &matrix ) // The sparse matrix containing the iterator
196  , index_ ( index ) // The row/column index of the iterator
197  {}
198  //*******************************************************************************************
199 
200  //**Prefix increment operator****************************************************************
205  inline Iterator& operator++() {
206  ++pos_;
207  return *this;
208  }
209  //*******************************************************************************************
210 
211  //**Postfix increment operator***************************************************************
216  inline const Iterator operator++( int ) {
217  const Iterator tmp( *this );
218  ++(*this);
219  return tmp;
220  }
221  //*******************************************************************************************
222 
223  //**Element access operator******************************************************************
228  inline ReferenceType operator*() const {
229  return ReferenceType( pos_, matrix_, index_ );
230  }
231  //*******************************************************************************************
232 
233  //**Element access operator******************************************************************
238  inline PointerType operator->() const {
239  return PointerType( pos_, matrix_, index_ );
240  }
241  //*******************************************************************************************
242 
243  //**Conversion operator**********************************************************************
248  inline operator ConstIterator() const {
249  return pos_;
250  }
251  //*******************************************************************************************
252 
253  //**Equality operator************************************************************************
259  inline bool operator==( const Iterator& rhs ) const {
260  return pos_ == rhs.pos_;
261  }
262  //*******************************************************************************************
263 
264  //**Inequality operator**********************************************************************
270  inline bool operator!=( const Iterator& rhs ) const {
271  return !( *this == rhs );
272  }
273  //*******************************************************************************************
274 
275  //**Subtraction operator*********************************************************************
281  inline DifferenceType operator-( const Iterator& rhs ) const {
282  return pos_ - rhs.pos_;
283  }
284  //*******************************************************************************************
285 
286  //**Base function****************************************************************************
291  inline IteratorType base() const {
292  return pos_;
293  }
294  //*******************************************************************************************
295 
296  private:
297  //**Member variables*************************************************************************
298  IteratorType pos_;
299  MT* matrix_;
300  size_t index_;
301  //*******************************************************************************************
302  };
303  //**********************************************************************************************
304 
305  //**Compilation flags***************************************************************************
307  enum : bool { smpAssignable = false };
308  //**********************************************************************************************
309 
310  //**Constructors********************************************************************************
313  explicit inline HermitianMatrix();
314  explicit inline HermitianMatrix( size_t n );
315  explicit inline HermitianMatrix( size_t n, size_t nonzeros );
316  explicit inline HermitianMatrix( size_t n, const std::vector<size_t>& nonzeros );
317 
318  inline HermitianMatrix( const HermitianMatrix& m );
319  inline HermitianMatrix( HermitianMatrix&& m ) noexcept;
320 
321  template< typename MT2, bool SO2 >
322  inline HermitianMatrix( const Matrix<MT2,SO2>& m );
324  //**********************************************************************************************
325 
326  //**Destructor**********************************************************************************
327  // No explicitly declared destructor.
328  //**********************************************************************************************
329 
330  //**Data access functions***********************************************************************
333  inline Reference operator()( size_t i, size_t j );
334  inline ConstReference operator()( size_t i, size_t j ) const;
335  inline Reference at( size_t i, size_t j );
336  inline ConstReference at( size_t i, size_t j ) const;
337  inline Iterator begin ( size_t i );
338  inline ConstIterator begin ( size_t i ) const;
339  inline ConstIterator cbegin( size_t i ) const;
340  inline Iterator end ( size_t i );
341  inline ConstIterator end ( size_t i ) const;
342  inline ConstIterator cend ( size_t i ) const;
344  //**********************************************************************************************
345 
346  //**Assignment operators************************************************************************
349  inline HermitianMatrix& operator=( const HermitianMatrix& rhs );
350  inline HermitianMatrix& operator=( HermitianMatrix&& rhs ) noexcept;
351 
352  template< typename MT2, bool SO2 >
353  inline DisableIf_< IsComputation<MT2>, HermitianMatrix& > operator=( const Matrix<MT2,SO2>& rhs );
354 
355  template< typename MT2, bool SO2 >
356  inline EnableIf_< IsComputation<MT2>, HermitianMatrix& > operator=( const Matrix<MT2,SO2>& rhs );
357 
358  template< typename MT2 >
359  inline EnableIf_< IsBuiltin< ElementType_<MT2> >, HermitianMatrix& >
360  operator=( const Matrix<MT2,!SO>& rhs );
361 
362  template< typename MT2, bool SO2 >
363  inline DisableIf_< IsComputation<MT2>, HermitianMatrix& > operator+=( const Matrix<MT2,SO2>& rhs );
364 
365  template< typename MT2, bool SO2 >
366  inline EnableIf_< IsComputation<MT2>, HermitianMatrix& > operator+=( const Matrix<MT2,SO2>& rhs );
367 
368  template< typename MT2 >
369  inline EnableIf_< IsBuiltin< ElementType_<MT2> >, HermitianMatrix& >
370  operator+=( const Matrix<MT2,!SO>& rhs );
371 
372  template< typename MT2, bool SO2 >
373  inline DisableIf_< IsComputation<MT2>, HermitianMatrix& > operator-=( const Matrix<MT2,SO2>& rhs );
374 
375  template< typename MT2, bool SO2 >
376  inline EnableIf_< IsComputation<MT2>, HermitianMatrix& > operator-=( const Matrix<MT2,SO2>& rhs );
377 
378  template< typename MT2 >
379  inline EnableIf_< IsBuiltin< ElementType_<MT2> >, HermitianMatrix& >
380  operator-=( const Matrix<MT2,!SO>& rhs );
381 
382  template< typename MT2, bool SO2 >
383  inline HermitianMatrix& operator*=( const Matrix<MT2,SO2>& rhs );
384 
385  template< typename Other >
386  inline EnableIf_< IsNumeric<Other>, HermitianMatrix >& operator*=( Other rhs );
387 
388  template< typename Other >
389  inline EnableIf_< IsNumeric<Other>, HermitianMatrix >& operator/=( Other rhs );
391  //**********************************************************************************************
392 
393  //**Utility functions***************************************************************************
396  inline size_t rows() const noexcept;
397  inline size_t columns() const noexcept;
398  inline size_t capacity() const noexcept;
399  inline size_t capacity( size_t i ) const noexcept;
400  inline size_t nonZeros() const;
401  inline size_t nonZeros( size_t i ) const;
402  inline void reset();
403  inline void reset( size_t i );
404  inline void clear();
405  inline void resize ( size_t n, bool preserve=true );
406  inline void reserve( size_t nonzeros );
407  inline void reserve( size_t i, size_t nonzeros );
408  inline void trim();
409  inline void trim( size_t i );
410  inline void swap( HermitianMatrix& m ) noexcept;
412  //**********************************************************************************************
413 
414  //**Insertion functions*************************************************************************
417  inline Iterator set ( size_t i, size_t j, const ElementType& value );
418  inline Iterator insert ( size_t i, size_t j, const ElementType& value );
419  inline void append ( size_t i, size_t j, const ElementType& value, bool check=false );
420  inline void finalize( size_t i );
422  //**********************************************************************************************
423 
424  //**Erase functions*****************************************************************************
427  inline void erase( size_t i, size_t j );
428  inline Iterator erase( size_t i, Iterator pos );
429  inline Iterator erase( size_t i, Iterator first, Iterator last );
430 
431  template< typename Pred >
432  inline void erase( Pred predicate );
433 
434  template< typename Pred >
435  inline void erase( size_t i, Iterator first, Iterator last, Pred predicate );
437  //**********************************************************************************************
438 
439  //**Lookup functions****************************************************************************
442  inline Iterator find ( size_t i, size_t j );
443  inline ConstIterator find ( size_t i, size_t j ) const;
444  inline Iterator lowerBound( size_t i, size_t j );
445  inline ConstIterator lowerBound( size_t i, size_t j ) const;
446  inline Iterator upperBound( size_t i, size_t j );
447  inline ConstIterator upperBound( size_t i, size_t j ) const;
449  //**********************************************************************************************
450 
451  //**Numeric functions***************************************************************************
454  inline HermitianMatrix& transpose();
455  inline HermitianMatrix& ctranspose();
456 
457  template< typename Other > inline HermitianMatrix& scale( const Other& scalar );
458  template< typename Other > inline HermitianMatrix& scaleDiagonal( const Other& scale );
460  //**********************************************************************************************
461 
462  //**Debugging functions*************************************************************************
465  inline bool isIntact() const noexcept;
467  //**********************************************************************************************
468 
469  //**Expression template evaluation functions****************************************************
472  template< typename Other > inline bool canAlias ( const Other* alias ) const noexcept;
473  template< typename Other > inline bool isAliased( const Other* alias ) const noexcept;
474 
475  inline bool canSMPAssign() const noexcept;
477  //**********************************************************************************************
478 
479  private:
480  //**Construction functions**********************************************************************
483  template< typename MT2, bool SO2, typename T >
484  inline const MT2& construct( const Matrix<MT2,SO2>& m, T );
485 
486  template< typename MT2 >
487  inline TransExprTrait_<MT2> construct( const Matrix<MT2,!SO>& m, TrueType );
489  //**********************************************************************************************
490 
491  //**Member variables****************************************************************************
494  MT matrix_;
495 
496  //**********************************************************************************************
497 
498  //**Friend declarations*************************************************************************
499  template< bool RF, typename MT2, bool SO2, bool DF2 >
500  friend bool isDefault( const HermitianMatrix<MT2,SO2,DF2>& m );
501  //**********************************************************************************************
502 
503  //**Compile time checks*************************************************************************
517  BLAZE_STATIC_ASSERT( Rows<MT>::value == Columns<MT>::value );
518  //**********************************************************************************************
519 };
521 //*************************************************************************************************
522 
523 
524 
525 
526 //=================================================================================================
527 //
528 // CONSTRUCTORS
529 //
530 //=================================================================================================
531 
532 //*************************************************************************************************
536 template< typename MT // Type of the adapted sparse matrix
537  , bool SO > // Storage order of the adapted sparse matrix
538 inline HermitianMatrix<MT,SO,false>::HermitianMatrix()
539  : matrix_() // The adapted sparse matrix
540 {
541  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square Hermitian matrix detected" );
542 }
544 //*************************************************************************************************
545 
546 
547 //*************************************************************************************************
555 template< typename MT // Type of the adapted sparse matrix
556  , bool SO > // Storage order of the adapted sparse matrix
557 inline HermitianMatrix<MT,SO,false>::HermitianMatrix( size_t n )
558  : matrix_( n, n ) // The adapted sparse matrix
559 {
561 
562  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square Hermitian matrix detected" );
563 }
565 //*************************************************************************************************
566 
567 
568 //*************************************************************************************************
577 template< typename MT // Type of the adapted sparse matrix
578  , bool SO > // Storage order of the adapted sparse matrix
579 inline HermitianMatrix<MT,SO,false>::HermitianMatrix( size_t n, size_t nonzeros )
580  : matrix_( n, n, nonzeros ) // The adapted sparse matrix
581 {
583 
584  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square Hermitian matrix detected" );
585 }
587 //*************************************************************************************************
588 
589 
590 //*************************************************************************************************
601 template< typename MT // Type of the adapted sparse matrix
602  , bool SO > // Storage order of the adapted sparse matrix
603 inline HermitianMatrix<MT,SO,false>::HermitianMatrix( size_t n, const std::vector<size_t>& nonzeros )
604  : matrix_( n, n, nonzeros ) // The adapted sparse matrix
605 {
607 
608  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square Hermitian matrix 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 HermitianMatrix<MT,SO,false>::HermitianMatrix( const HermitianMatrix& m )
623  : matrix_( m.matrix_ ) // The adapted sparse matrix
624 {
625  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square Hermitian matrix detected" );
626  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
627 }
629 //*************************************************************************************************
630 
631 
632 //*************************************************************************************************
638 template< typename MT // Type of the adapted sparse matrix
639  , bool SO > // Storage order of the adapted sparse matrix
640 inline HermitianMatrix<MT,SO,false>::HermitianMatrix( HermitianMatrix&& m ) noexcept
641  : matrix_( std::move( m.matrix_ ) ) // The adapted sparse matrix
642 {
643  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square Hermitian matrix detected" );
644  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
645 }
647 //*************************************************************************************************
648 
649 
650 //*************************************************************************************************
660 template< typename MT // Type of the adapted sparse matrix
661  , bool SO > // Storage order of the adapted sparse matrix
662 template< typename MT2 // Type of the foreign matrix
663  , bool SO2 > // Storage order of the foreign matrix
664 inline HermitianMatrix<MT,SO,false>::HermitianMatrix( const Matrix<MT2,SO2>& m )
665  : matrix_( construct( m, typename IsBuiltin< ElementType_<MT2> >::Type() ) ) // The adapted sparse matrix
666 {
667  if( !IsHermitian<MT2>::value && !isHermitian( matrix_ ) ) {
668  BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of Hermitian matrix" );
669  }
670 }
672 //*************************************************************************************************
673 
674 
675 
676 
677 //=================================================================================================
678 //
679 // DATA ACCESS FUNCTIONS
680 //
681 //=================================================================================================
682 
683 //*************************************************************************************************
699 template< typename MT // Type of the adapted sparse matrix
700  , bool SO > // Storage order of the adapted sparse matrix
702  HermitianMatrix<MT,SO,false>::operator()( size_t i, size_t j )
703 {
704  BLAZE_USER_ASSERT( i<rows() , "Invalid row access index" );
705  BLAZE_USER_ASSERT( j<columns(), "Invalid column access index" );
706 
707  return Reference( matrix_, i, j );
708 }
710 //*************************************************************************************************
711 
712 
713 //*************************************************************************************************
729 template< typename MT // Type of the adapted sparse matrix
730  , bool SO > // Storage order of the adapted sparse matrix
732  HermitianMatrix<MT,SO,false>::operator()( size_t i, size_t j ) const
733 {
734  BLAZE_USER_ASSERT( i<rows() , "Invalid row access index" );
735  BLAZE_USER_ASSERT( j<columns(), "Invalid column access index" );
736 
737  return matrix_(i,j);
738 }
740 //*************************************************************************************************
741 
742 
743 //*************************************************************************************************
760 template< typename MT // Type of the adapted sparse matrix
761  , bool SO > // Storage order of the adapted sparse matrix
763  HermitianMatrix<MT,SO,false>::at( size_t i, size_t j )
764 {
765  if( i >= rows() ) {
766  BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
767  }
768  if( j >= columns() ) {
769  BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
770  }
771  return (*this)(i,j);
772 }
774 //*************************************************************************************************
775 
776 
777 //*************************************************************************************************
794 template< typename MT // Type of the adapted sparse matrix
795  , bool SO > // Storage order of the adapted sparse matrix
797  HermitianMatrix<MT,SO,false>::at( size_t i, size_t j ) const
798 {
799  if( i >= rows() ) {
800  BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
801  }
802  if( j >= columns() ) {
803  BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
804  }
805  return (*this)(i,j);
806 }
808 //*************************************************************************************************
809 
810 
811 //*************************************************************************************************
823 template< typename MT // Type of the adapted sparse matrix
824  , bool SO > // Storage order of the adapted sparse matrix
827 {
828  return Iterator( matrix_.begin(i), matrix_, i );
829 }
831 //*************************************************************************************************
832 
833 
834 //*************************************************************************************************
846 template< typename MT // Type of the adapted sparse matrix
847  , bool SO > // Storage order of the adapted sparse matrix
849  HermitianMatrix<MT,SO,false>::begin( size_t i ) const
850 {
851  return matrix_.begin(i);
852 }
854 //*************************************************************************************************
855 
856 
857 //*************************************************************************************************
869 template< typename MT // Type of the adapted sparse matrix
870  , bool SO > // Storage order of the adapted sparse matrix
872  HermitianMatrix<MT,SO,false>::cbegin( size_t i ) const
873 {
874  return matrix_.cbegin(i);
875 }
877 //*************************************************************************************************
878 
879 
880 //*************************************************************************************************
892 template< typename MT // Type of the adapted sparse matrix
893  , bool SO > // Storage order of the adapted sparse matrix
896 {
897  return Iterator( matrix_.end(i), matrix_, i );
898 }
900 //*************************************************************************************************
901 
902 
903 //*************************************************************************************************
915 template< typename MT // Type of the adapted sparse matrix
916  , bool SO > // Storage order of the adapted sparse matrix
918  HermitianMatrix<MT,SO,false>::end( size_t i ) const
919 {
920  return matrix_.end(i);
921 }
923 //*************************************************************************************************
924 
925 
926 //*************************************************************************************************
938 template< typename MT // Type of the adapted sparse matrix
939  , bool SO > // Storage order of the adapted sparse matrix
941  HermitianMatrix<MT,SO,false>::cend( size_t i ) const
942 {
943  return matrix_.cend(i);
944 }
946 //*************************************************************************************************
947 
948 
949 
950 
951 //=================================================================================================
952 //
953 // ASSIGNMENT OPERATORS
954 //
955 //=================================================================================================
956 
957 //*************************************************************************************************
967 template< typename MT // Type of the adapted sparse matrix
968  , bool SO > // Storage order of the adapted sparse matrix
969 inline HermitianMatrix<MT,SO,false>&
970  HermitianMatrix<MT,SO,false>::operator=( const HermitianMatrix& rhs )
971 {
972  matrix_ = rhs.matrix_;
973 
974  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square Hermitian matrix detected" );
975  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
976 
977  return *this;
978 }
980 //*************************************************************************************************
981 
982 
983 //*************************************************************************************************
990 template< typename MT // Type of the adapted sparse matrix
991  , bool SO > // Storage order of the adapted sparse matrix
992 inline HermitianMatrix<MT,SO,false>&
993  HermitianMatrix<MT,SO,false>::operator=( HermitianMatrix&& rhs ) noexcept
994 {
995  matrix_ = std::move( rhs.matrix_ );
996 
997  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square Hermitian matrix detected" );
998  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
999 
1000  return *this;
1001 }
1003 //*************************************************************************************************
1004 
1005 
1006 //*************************************************************************************************
1019 template< typename MT // Type of the adapted sparse matrix
1020  , bool SO > // Storage order of the adapted sparse matrix
1021 template< typename MT2 // Type of the right-hand side matrix
1022  , bool SO2 > // Storage order of the right-hand side matrix
1023 inline DisableIf_< IsComputation<MT2>, HermitianMatrix<MT,SO,false>& >
1024  HermitianMatrix<MT,SO,false>::operator=( const Matrix<MT2,SO2>& rhs )
1025 {
1026  if( !IsHermitian<MT2>::value && !isHermitian( ~rhs ) ) {
1027  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to Hermitian matrix" );
1028  }
1029 
1030  matrix_ = ~rhs;
1031 
1032  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square Hermitian matrix detected" );
1033  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1034 
1035  return *this;
1036 }
1038 //*************************************************************************************************
1039 
1040 
1041 //*************************************************************************************************
1054 template< typename MT // Type of the adapted sparse matrix
1055  , bool SO > // Storage order of the adapted sparse matrix
1056 template< typename MT2 // Type of the right-hand side matrix
1057  , bool SO2 > // Storage order of the right-hand side matrix
1058 inline EnableIf_< IsComputation<MT2>, HermitianMatrix<MT,SO,false>& >
1059  HermitianMatrix<MT,SO,false>::operator=( const Matrix<MT2,SO2>& rhs )
1060 {
1061  if( !IsSquare<MT2>::value && !isSquare( ~rhs ) ) {
1062  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to Hermitian matrix" );
1063  }
1064 
1065  if( IsHermitian<MT2>::value ) {
1066  matrix_ = ~rhs;
1067  }
1068  else {
1069  MT tmp( ~rhs );
1070 
1071  if( !isHermitian( tmp ) ) {
1072  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to Hermitian matrix" );
1073  }
1074 
1075  matrix_ = std::move( tmp );
1076  }
1077 
1078  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square Hermitian matrix detected" );
1079  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1080 
1081  return *this;
1082 }
1084 //*************************************************************************************************
1085 
1086 
1087 //*************************************************************************************************
1100 template< typename MT // Type of the adapted sparse matrix
1101  , bool SO > // Storage order of the adapted sparse matrix
1102 template< typename MT2 > // Type of the right-hand side matrix
1103 inline EnableIf_< IsBuiltin< ElementType_<MT2> >, HermitianMatrix<MT,SO,false>& >
1104  HermitianMatrix<MT,SO,false>::operator=( const Matrix<MT2,!SO>& rhs )
1105 {
1106  return this->operator=( trans( ~rhs ) );
1107 }
1109 //*************************************************************************************************
1110 
1111 
1112 //*************************************************************************************************
1125 template< typename MT // Type of the adapted sparse matrix
1126  , bool SO > // Storage order of the adapted sparse matrix
1127 template< typename MT2 // Type of the right-hand side matrix
1128  , bool SO2 > // Storage order of the right-hand side matrix
1129 inline DisableIf_< IsComputation<MT2>, HermitianMatrix<MT,SO,false>& >
1130  HermitianMatrix<MT,SO,false>::operator+=( const Matrix<MT2,SO2>& rhs )
1131 {
1132  if( !IsHermitian<MT2>::value && !isHermitian( ~rhs ) ) {
1133  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to Hermitian matrix" );
1134  }
1135 
1136  matrix_ += ~rhs;
1137 
1138  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square Hermitian matrix detected" );
1139  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1140 
1141  return *this;
1142 }
1144 //*************************************************************************************************
1145 
1146 
1147 //*************************************************************************************************
1160 template< typename MT // Type of the adapted sparse matrix
1161  , bool SO > // Storage order of the adapted sparse matrix
1162 template< typename MT2 // Type of the right-hand side matrix
1163  , bool SO2 > // Storage order of the right-hand side matrix
1164 inline EnableIf_< IsComputation<MT2>, HermitianMatrix<MT,SO,false>& >
1165  HermitianMatrix<MT,SO,false>::operator+=( const Matrix<MT2,SO2>& rhs )
1166 {
1167  if( !IsSquare<MT2>::value && !isSquare( ~rhs ) ) {
1168  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to Hermitian matrix" );
1169  }
1170 
1171  if( IsHermitian<MT2>::value ) {
1172  matrix_ += ~rhs;
1173  }
1174  else {
1175  const ResultType_<MT2> tmp( ~rhs );
1176 
1177  if( !isHermitian( tmp ) ) {
1178  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to Hermitian matrix" );
1179  }
1180 
1181  matrix_ += tmp;
1182  }
1183 
1184  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square Hermitian matrix detected" );
1185  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1186 
1187  return *this;
1188 }
1190 //*************************************************************************************************
1191 
1192 
1193 //*************************************************************************************************
1207 template< typename MT // Type of the adapted sparse matrix
1208  , bool SO > // Storage order of the adapted sparse matrix
1209 template< typename MT2 > // Type of the right-hand side matrix
1210 inline EnableIf_< IsBuiltin< ElementType_<MT2> >, HermitianMatrix<MT,SO,false>& >
1211  HermitianMatrix<MT,SO,false>::operator+=( const Matrix<MT2,!SO>& rhs )
1212 {
1213  return this->operator+=( trans( ~rhs ) );
1214 }
1216 //*************************************************************************************************
1217 
1218 
1219 //*************************************************************************************************
1232 template< typename MT // Type of the adapted sparse matrix
1233  , bool SO > // Storage order of the adapted sparse matrix
1234 template< typename MT2 // Type of the right-hand side matrix
1235  , bool SO2 > // Storage order of the right-hand side matrix
1236 inline DisableIf_< IsComputation<MT2>, HermitianMatrix<MT,SO,false>& >
1237  HermitianMatrix<MT,SO,false>::operator-=( const Matrix<MT2,SO2>& rhs )
1238 {
1239  if( !IsHermitian<MT2>::value && !isHermitian( ~rhs ) ) {
1240  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to Hermitian matrix" );
1241  }
1242 
1243  matrix_ -= ~rhs;
1244 
1245  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square Hermitian matrix detected" );
1246  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1247 
1248  return *this;
1249 }
1251 //*************************************************************************************************
1252 
1253 
1254 //*************************************************************************************************
1267 template< typename MT // Type of the adapted sparse matrix
1268  , bool SO > // Storage order of the adapted sparse matrix
1269 template< typename MT2 // Type of the right-hand side matrix
1270  , bool SO2 > // Storage order of the right-hand side matrix
1271 inline EnableIf_< IsComputation<MT2>, HermitianMatrix<MT,SO,false>& >
1272  HermitianMatrix<MT,SO,false>::operator-=( const Matrix<MT2,SO2>& rhs )
1273 {
1274  if( !IsSquare<MT2>::value && !isSquare( ~rhs ) ) {
1275  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to Hermitian matrix" );
1276  }
1277 
1278  if( IsHermitian<MT2>::value ) {
1279  matrix_ -= ~rhs;
1280  }
1281  else {
1282  const ResultType_<MT2> tmp( ~rhs );
1283 
1284  if( !isHermitian( tmp ) ) {
1285  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to Hermitian matrix" );
1286  }
1287 
1288  matrix_ -= tmp;
1289  }
1290 
1291  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square Hermitian matrix detected" );
1292  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1293 
1294  return *this;
1295 }
1297 //*************************************************************************************************
1298 
1299 
1300 //*************************************************************************************************
1314 template< typename MT // Type of the adapted sparse matrix
1315  , bool SO > // Storage order of the adapted sparse matrix
1316 template< typename MT2 > // Type of the right-hand side matrix
1317 inline EnableIf_< IsBuiltin< ElementType_<MT2> >, HermitianMatrix<MT,SO,false>& >
1318  HermitianMatrix<MT,SO,false>::operator-=( const Matrix<MT2,!SO>& rhs )
1319 {
1320  return this->operator-=( trans( ~rhs ) );
1321 }
1323 //*************************************************************************************************
1324 
1325 
1326 //*************************************************************************************************
1338 template< typename MT // Type of the adapted sparse matrix
1339  , bool SO > // Storage order of the adapted sparse matrix
1340 template< typename MT2 // Type of the right-hand side matrix
1341  , bool SO2 > // Storage order of the right-hand side matrix
1342 inline HermitianMatrix<MT,SO,false>&
1343  HermitianMatrix<MT,SO,false>::operator*=( const Matrix<MT2,SO2>& rhs )
1344 {
1345  if( matrix_.rows() != (~rhs).columns() ) {
1346  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to Hermitian matrix" );
1347  }
1348 
1349  MT tmp( matrix_ * ~rhs );
1350 
1351  if( !isHermitian( tmp ) ) {
1352  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to Hermitian matrix" );
1353  }
1354 
1355  matrix_ = std::move( tmp );
1356 
1357  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square Hermitian matrix detected" );
1358  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
1359 
1360  return *this;
1361 }
1363 //*************************************************************************************************
1364 
1365 
1366 //*************************************************************************************************
1374 template< typename MT // Type of the adapted sparse matrix
1375  , bool SO > // Storage order of the adapted sparse matrix
1376 template< typename Other > // Data type of the right-hand side scalar
1377 inline EnableIf_< IsNumeric<Other>, HermitianMatrix<MT,SO,false> >&
1379 {
1380  matrix_ *= rhs;
1381  return *this;
1382 }
1383 //*************************************************************************************************
1384 
1385 
1386 //*************************************************************************************************
1394 template< typename MT // Type of the adapted sparse matrix
1395  , bool SO > // Storage order of the adapted sparse matrix
1396 template< typename Other > // Data type of the right-hand side scalar
1397 inline EnableIf_< IsNumeric<Other>, HermitianMatrix<MT,SO,false> >&
1399 {
1400  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
1401 
1402  matrix_ /= rhs;
1403  return *this;
1404 }
1406 //*************************************************************************************************
1407 
1408 
1409 
1410 
1411 //=================================================================================================
1412 //
1413 // UTILITY FUNCTIONS
1414 //
1415 //=================================================================================================
1416 
1417 //*************************************************************************************************
1423 template< typename MT // Type of the adapted sparse matrix
1424  , bool SO > // Storage order of the adapted sparse matrix
1425 inline size_t HermitianMatrix<MT,SO,false>::rows() const noexcept
1426 {
1427  return matrix_.rows();
1428 }
1430 //*************************************************************************************************
1431 
1432 
1433 //*************************************************************************************************
1439 template< typename MT // Type of the adapted sparse matrix
1440  , bool SO > // Storage order of the adapted sparse matrix
1441 inline size_t HermitianMatrix<MT,SO,false>::columns() const noexcept
1442 {
1443  return matrix_.columns();
1444 }
1446 //*************************************************************************************************
1447 
1448 
1449 //*************************************************************************************************
1455 template< typename MT // Type of the adapted sparse matrix
1456  , bool SO > // Storage order of the adapted sparse matrix
1457 inline size_t HermitianMatrix<MT,SO,false>::capacity() const noexcept
1458 {
1459  return matrix_.capacity();
1460 }
1462 //*************************************************************************************************
1463 
1464 
1465 //*************************************************************************************************
1476 template< typename MT // Type of the adapted sparse matrix
1477  , bool SO > // Storage order of the adapted sparse matrix
1478 inline size_t HermitianMatrix<MT,SO,false>::capacity( size_t i ) const noexcept
1479 {
1480  return matrix_.capacity(i);
1481 }
1483 //*************************************************************************************************
1484 
1485 
1486 //*************************************************************************************************
1492 template< typename MT // Type of the adapted sparse matrix
1493  , bool SO > // Storage order of the adapted sparse matrix
1494 inline size_t HermitianMatrix<MT,SO,false>::nonZeros() const
1495 {
1496  return matrix_.nonZeros();
1497 }
1499 //*************************************************************************************************
1500 
1501 
1502 //*************************************************************************************************
1514 template< typename MT // Type of the adapted sparse matrix
1515  , bool SO > // Storage order of the adapted sparse matrix
1516 inline size_t HermitianMatrix<MT,SO,false>::nonZeros( size_t i ) const
1517 {
1518  return matrix_.nonZeros(i);
1519 }
1521 //*************************************************************************************************
1522 
1523 
1524 //*************************************************************************************************
1530 template< typename MT // Type of the adapted sparse matrix
1531  , bool SO > // Storage order of the adapted sparse matrix
1533 {
1534  matrix_.reset();
1535 }
1537 //*************************************************************************************************
1538 
1539 
1540 //*************************************************************************************************
1576 template< typename MT // Type of the adapted sparse matrix
1577  , bool SO > // Storage order of the adapted sparse matrix
1578 inline void HermitianMatrix<MT,SO,false>::reset( size_t i )
1579 {
1580  for( Iterator_<MT> it=matrix_.begin(i); it!=matrix_.end(i); ++it )
1581  {
1582  const size_t j( it->index() );
1583 
1584  if( i == j )
1585  continue;
1586 
1587  if( SO ) {
1588  const Iterator_<MT> pos( matrix_.find( i, j ) );
1589  BLAZE_INTERNAL_ASSERT( pos != matrix_.end( j ), "Missing element detected" );
1590  matrix_.erase( j, pos );
1591  }
1592  else {
1593  const Iterator_<MT> pos( matrix_.find( j, i ) );
1594  BLAZE_INTERNAL_ASSERT( pos != matrix_.end( j ), "Missing element detected" );
1595  matrix_.erase( j, pos );
1596  }
1597  }
1598 
1599  matrix_.reset( i );
1600 }
1602 //*************************************************************************************************
1603 
1604 
1605 //*************************************************************************************************
1613 template< typename MT // Type of the adapted sparse matrix
1614  , bool SO > // Storage order of the adapted sparse matrix
1616 {
1617  using blaze::clear;
1618 
1619  clear( matrix_ );
1620 }
1622 //*************************************************************************************************
1623 
1624 
1625 //*************************************************************************************************
1640 template< typename MT // Type of the adapted sparse matrix
1641  , bool SO > // Storage order of the adapted sparse matrix
1642 void HermitianMatrix<MT,SO,false>::resize( size_t n, bool preserve )
1643 {
1645 
1646  UNUSED_PARAMETER( preserve );
1647 
1648  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square Hermitian matrix detected" );
1649 
1650  matrix_.resize( n, n, true );
1651 }
1653 //*************************************************************************************************
1654 
1655 
1656 //*************************************************************************************************
1667 template< typename MT // Type of the adapted sparse matrix
1668  , bool SO > // Storage order of the adapted sparse matrix
1669 inline void HermitianMatrix<MT,SO,false>::reserve( size_t nonzeros )
1670 {
1671  matrix_.reserve( nonzeros );
1672 }
1674 //*************************************************************************************************
1675 
1676 
1677 //*************************************************************************************************
1691 template< typename MT // Type of the adapted sparse matrix
1692  , bool SO > // Storage order of the adapted sparse matrix
1693 inline void HermitianMatrix<MT,SO,false>::reserve( size_t i, size_t nonzeros )
1694 {
1695  matrix_.reserve( i, nonzeros );
1696 }
1698 //*************************************************************************************************
1699 
1700 
1701 //*************************************************************************************************
1712 template< typename MT // Type of the adapted sparse matrix
1713  , bool SO > // Storage order of the adapted sparse matrix
1714 inline void HermitianMatrix<MT,SO,false>::trim()
1715 {
1716  matrix_.trim();
1717 }
1719 //*************************************************************************************************
1720 
1721 
1722 //*************************************************************************************************
1734 template< typename MT // Type of the adapted sparse matrix
1735  , bool SO > // Storage order of the adapted sparse matrix
1736 inline void HermitianMatrix<MT,SO,false>::trim( size_t i )
1737 {
1738  matrix_.trim( i );
1739 }
1741 //*************************************************************************************************
1742 
1743 
1744 //*************************************************************************************************
1751 template< typename MT // Type of the adapted sparse matrix
1752  , bool SO > // Storage order of the adapted sparse matrix
1753 inline void HermitianMatrix<MT,SO,false>::swap( HermitianMatrix& m ) noexcept
1754 {
1755  using std::swap;
1756 
1757  swap( matrix_, m.matrix_ );
1758 }
1760 //*************************************************************************************************
1761 
1762 
1763 
1764 
1765 //=================================================================================================
1766 //
1767 // INSERTION FUNCTIONS
1768 //
1769 //=================================================================================================
1770 
1771 //*************************************************************************************************
1786 template< typename MT // Type of the adapted sparse matrix
1787  , bool SO > // Storage order of the adapted sparse matrix
1789  HermitianMatrix<MT,SO,false>::set( size_t i, size_t j, const ElementType& value )
1790 {
1791  const bool isDiagonal( i == j );
1792 
1793  if( IsComplex<ElementType>::value && isDiagonal && !isReal( value ) ) {
1794  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to diagonal matrix element" );
1795  }
1796 
1797  if( !isDiagonal )
1798  matrix_.set( j, i, conj( value ) );
1799  return Iterator( matrix_.set( i, j, value ), matrix_, ( SO ? j : i ) );
1800 }
1802 //*************************************************************************************************
1803 
1804 
1805 //*************************************************************************************************
1821 template< typename MT // Type of the adapted sparse matrix
1822  , bool SO > // Storage order of the adapted sparse matrix
1824  HermitianMatrix<MT,SO,false>::insert( size_t i, size_t j, const ElementType& value )
1825 {
1826  const bool isDiagonal( i == j );
1827 
1828  if( IsComplex<ElementType>::value && isDiagonal && !isReal( value ) ) {
1829  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to diagonal matrix element" );
1830  }
1831 
1832  if( !isDiagonal )
1833  matrix_.insert( j, i, conj( value ) );
1834  return Iterator( matrix_.insert( i, j, value ), matrix_, ( SO ? j : i ) );
1835 }
1837 //*************************************************************************************************
1838 
1839 
1840 //*************************************************************************************************
1899 template< typename MT // Type of the adapted sparse matrix
1900  , bool SO > // Storage order of the adapted sparse matrix
1901 inline void HermitianMatrix<MT,SO,false>::append( size_t i, size_t j, const ElementType& value, bool check )
1902 {
1903  const bool isDiagonal( i == j );
1904 
1905  if( IsComplex<ElementType>::value && isDiagonal && !isReal( value ) ) {
1906  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to diagonal matrix element" );
1907  }
1908 
1909  matrix_.append( i, j, value, check );
1910  if( !isDiagonal && ( !check || !isDefault( value ) ) )
1911  matrix_.insert( j, i, conj( value ) );
1912 }
1914 //*************************************************************************************************
1915 
1916 
1917 //*************************************************************************************************
1931 template< typename MT // Type of the adapted sparse matrix
1932  , bool SO > // Storage order of the adapted sparse matrix
1933 inline void HermitianMatrix<MT,SO,false>::finalize( size_t i )
1934 {
1935  matrix_.trim( i );
1936 }
1938 //*************************************************************************************************
1939 
1940 
1941 
1942 
1943 //=================================================================================================
1944 //
1945 // ERASE FUNCTIONS
1946 //
1947 //=================================================================================================
1948 
1949 //*************************************************************************************************
1959 template< typename MT // Type of the adapted sparse matrix
1960  , bool SO > // Storage order of the adapted sparse matrix
1961 inline void HermitianMatrix<MT,SO,false>::erase( size_t i, size_t j )
1962 {
1963  matrix_.erase( i, j );
1964  if( i != j )
1965  matrix_.erase( j, i );
1966 }
1968 //*************************************************************************************************
1969 
1970 
1971 //*************************************************************************************************
1983 template< typename MT // Type of the adapted sparse matrix
1984  , bool SO > // Storage order of the adapted sparse matrix
1986  HermitianMatrix<MT,SO,false>::erase( size_t i, Iterator pos )
1987 {
1988  const Iterator_<MT> base( pos.base() );
1989 
1990  if( base == matrix_.end( i ) )
1991  return pos;
1992 
1993  const size_t j( base->index() );
1994 
1995  if( i == j ) {
1996  BLAZE_INTERNAL_ASSERT( matrix_.find( i, i ) != matrix_.end( i ), "Missing element detected" );
1997  return Iterator( matrix_.erase( i, base ), matrix_, i );
1998  }
1999 
2000  if( SO ) {
2001  BLAZE_INTERNAL_ASSERT( matrix_.find( i, j ) != matrix_.end( j ), "Missing element detected" );
2002  matrix_.erase( j, matrix_.find( i, j ) );
2003  return Iterator( matrix_.erase( i, base ), matrix_, i );
2004  }
2005  else {
2006  BLAZE_INTERNAL_ASSERT( matrix_.find( j, i ) != matrix_.end( j ), "Missing element detected" );
2007  matrix_.erase( j, matrix_.find( j, i ) );
2008  return Iterator( matrix_.erase( i, base ), matrix_, i );
2009  }
2010 }
2012 //*************************************************************************************************
2013 
2014 
2015 //*************************************************************************************************
2029 template< typename MT // Type of the adapted sparse matrix
2030  , bool SO > // Storage order of the adapted sparse matrix
2032  HermitianMatrix<MT,SO,false>::erase( size_t i, Iterator first, Iterator last )
2033 {
2034  for( Iterator_<MT> it=first.base(); it!=last.base(); ++it )
2035  {
2036  const size_t j( it->index() );
2037 
2038  if( i == j )
2039  continue;
2040 
2041  if( SO ) {
2042  BLAZE_INTERNAL_ASSERT( matrix_.find( i, j ) != matrix_.end( j ), "Missing element detected" );
2043  matrix_.erase( i, j );
2044  }
2045  else {
2046  BLAZE_INTERNAL_ASSERT( matrix_.find( j, i ) != matrix_.end( j ), "Missing element detected" );
2047  matrix_.erase( j, i );
2048  }
2049  }
2050 
2051  return Iterator( matrix_.erase( i, first.base(), last.base() ), matrix_, i );
2052 }
2054 //*************************************************************************************************
2055 
2056 
2057 //*************************************************************************************************
2079 template< typename MT // Type of the adapted sparse matrix
2080  , bool SO > // Storage order of the adapted sparse matrix
2081 template< typename Pred > // Type of the unary predicate
2082 inline void HermitianMatrix<MT,SO,false>::erase( Pred predicate )
2083 {
2084  matrix_.erase( [predicate=predicate]( const ElementType& value ) {
2085  return predicate( value ) || predicate( conj( value ) );
2086  } );
2087 
2088  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
2089 }
2091 //*************************************************************************************************
2092 
2093 
2094 //*************************************************************************************************
2122 template< typename MT // Type of the adapted sparse matrix
2123  , bool SO > // Storage order of the adapted sparse matrix
2124 template< typename Pred > // Type of the unary predicate
2125 inline void
2126  HermitianMatrix<MT,SO,false>::erase( size_t i, Iterator first, Iterator last, Pred predicate )
2127 {
2128  for( Iterator it=first; it!=last; ++it ) {
2129  const size_t j( it->index() );
2130  if( i != j && predicate( it->value() ) ) {
2131  if( SO )
2132  matrix_.erase( i, j );
2133  else
2134  matrix_.erase( j, i );
2135  }
2136  }
2137 
2138  matrix_.erase( i, first.base(), last.base(), predicate );
2139 
2140  BLAZE_INTERNAL_ASSERT( isIntact(), "Broken invariant detected" );
2141 }
2143 //*************************************************************************************************
2144 
2145 
2146 
2147 
2148 //=================================================================================================
2149 //
2150 // LOOKUP FUNCTIONS
2151 //
2152 //=================================================================================================
2153 
2154 //*************************************************************************************************
2170 template< typename MT // Type of the adapted sparse matrix
2171  , bool SO > // Storage order of the adapted sparse matrix
2173  HermitianMatrix<MT,SO,false>::find( size_t i, size_t j )
2174 {
2175  return Iterator( matrix_.find( i, j ), matrix_, ( SO ? j : i ) );
2176 }
2178 //*************************************************************************************************
2179 
2180 
2181 //*************************************************************************************************
2197 template< typename MT // Type of the adapted sparse matrix
2198  , bool SO > // Storage order of the adapted sparse matrix
2200  HermitianMatrix<MT,SO,false>::find( size_t i, size_t j ) const
2201 {
2202  return matrix_.find( i, j );
2203 }
2205 //*************************************************************************************************
2206 
2207 
2208 //*************************************************************************************************
2224 template< typename MT // Type of the adapted sparse matrix
2225  , bool SO > // Storage order of the adapted sparse matrix
2227  HermitianMatrix<MT,SO,false>::lowerBound( size_t i, size_t j )
2228 {
2229  return Iterator( matrix_.lowerBound( i, j ), matrix_, ( SO ? j : i ) );
2230 }
2232 //*************************************************************************************************
2233 
2234 
2235 //*************************************************************************************************
2251 template< typename MT // Type of the adapted sparse matrix
2252  , bool SO > // Storage order of the adapted sparse matrix
2254  HermitianMatrix<MT,SO,false>::lowerBound( size_t i, size_t j ) const
2255 {
2256  return matrix_.lowerBound( i, j );
2257 }
2259 //*************************************************************************************************
2260 
2261 
2262 //*************************************************************************************************
2278 template< typename MT // Type of the adapted sparse matrix
2279  , bool SO > // Storage order of the adapted sparse matrix
2281  HermitianMatrix<MT,SO,false>::upperBound( size_t i, size_t j )
2282 {
2283  return Iterator( matrix_.upperBound( i, j ), matrix_, ( SO ? j : i ) );
2284 }
2286 //*************************************************************************************************
2287 
2288 
2289 //*************************************************************************************************
2305 template< typename MT // Type of the adapted sparse matrix
2306  , bool SO > // Storage order of the adapted sparse matrix
2308  HermitianMatrix<MT,SO,false>::upperBound( size_t i, size_t j ) const
2309 {
2310  return matrix_.upperBound( i, j );
2311 }
2313 //*************************************************************************************************
2314 
2315 
2316 
2317 
2318 //=================================================================================================
2319 //
2320 // NUMERIC FUNCTIONS
2321 //
2322 //=================================================================================================
2323 
2324 //*************************************************************************************************
2330 template< typename MT // Type of the adapted sparse matrix
2331  , bool SO > // Storage order of the adapted sparse matrix
2332 inline HermitianMatrix<MT,SO,false>& HermitianMatrix<MT,SO,false>::transpose()
2333 {
2334  if( IsComplex<ElementType>::value )
2335  matrix_.transpose();
2336  return *this;
2337 }
2339 //*************************************************************************************************
2340 
2341 
2342 //*************************************************************************************************
2348 template< typename MT // Type of the adapted sparse matrix
2349  , bool SO > // Storage order of the adapted sparse matrix
2350 inline HermitianMatrix<MT,SO,false>& HermitianMatrix<MT,SO,false>::ctranspose()
2351 {
2352  return *this;
2353 }
2355 //*************************************************************************************************
2356 
2357 
2358 //*************************************************************************************************
2365 template< typename MT // Type of the adapted sparse matrix
2366  , bool SO > // Storage order of the adapted sparse matrix
2367 template< typename Other > // Data type of the scalar value
2368 inline HermitianMatrix<MT,SO,false>&
2369  HermitianMatrix<MT,SO,false>::scale( const Other& scalar )
2370 {
2371  matrix_.scale( scalar );
2372  return *this;
2373 }
2375 //*************************************************************************************************
2376 
2377 
2378 //*************************************************************************************************
2385 template< typename MT // Type of the adapted sparse matrix
2386  , bool SO > // Storage order of the adapted sparse matrix
2387 template< typename Other > // Data type of the scalar value
2388 inline HermitianMatrix<MT,SO,false>&
2389  HermitianMatrix<MT,SO,false>::scaleDiagonal( const Other& scalar )
2390 {
2391  matrix_.scaleDiagonal( scalar );
2392  return *this;
2393 }
2395 //*************************************************************************************************
2396 
2397 
2398 
2399 
2400 //=================================================================================================
2401 //
2402 // DEBUGGING FUNCTIONS
2403 //
2404 //=================================================================================================
2405 
2406 //*************************************************************************************************
2416 template< typename MT // Type of the adapted sparse matrix
2417  , bool SO > // Storage order of the adapted sparse matrix
2418 inline bool HermitianMatrix<MT,SO,false>::isIntact() const noexcept
2419 {
2420  using blaze::isIntact;
2421 
2422  return ( isIntact( matrix_ ) && isHermitian( matrix_ ) );
2423 }
2425 //*************************************************************************************************
2426 
2427 
2428 
2429 
2430 //=================================================================================================
2431 //
2432 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
2433 //
2434 //=================================================================================================
2435 
2436 //*************************************************************************************************
2447 template< typename MT // Type of the adapted sparse matrix
2448  , bool SO > // Storage order of the adapted sparse matrix
2449 template< typename Other > // Data type of the foreign expression
2450 inline bool HermitianMatrix<MT,SO,false>::canAlias( const Other* alias ) const noexcept
2451 {
2452  return matrix_.canAlias( alias );
2453 }
2455 //*************************************************************************************************
2456 
2457 
2458 //*************************************************************************************************
2469 template< typename MT // Type of the adapted sparse matrix
2470  , bool SO > // Storage order of the adapted sparse matrix
2471 template< typename Other > // Data type of the foreign expression
2472 inline bool HermitianMatrix<MT,SO,false>::isAliased( const Other* alias ) const noexcept
2473 {
2474  return matrix_.isAliased( alias );
2475 }
2477 //*************************************************************************************************
2478 
2479 
2480 //*************************************************************************************************
2491 template< typename MT // Type of the adapted sparse matrix
2492  , bool SO > // Storage order of the adapted sparse matrix
2493 inline bool HermitianMatrix<MT,SO,false>::canSMPAssign() const noexcept
2494 {
2495  return matrix_.canSMPAssign();
2496 }
2498 //*************************************************************************************************
2499 
2500 
2501 
2502 
2503 //=================================================================================================
2504 //
2505 // CONSTRUCTION FUNCTIONS
2506 //
2507 //=================================================================================================
2508 
2509 //*************************************************************************************************
2511 template< typename MT // Type of the adapted dense matrix
2512  , bool SO > // Storage order of the adapted dense matrix
2513 template< typename MT2 // Type of the foreign matrix
2514  , bool SO2 // Storage order of the foreign matrix
2515  , typename T > // Type of the third argument
2516 inline const MT2& HermitianMatrix<MT,SO,false>::construct( const Matrix<MT2,SO2>& m, T )
2517 {
2518  return ~m;
2519 }
2521 //*************************************************************************************************
2522 
2523 
2524 //*************************************************************************************************
2526 template< typename MT // Type of the adapted dense matrix
2527  , bool SO > // Storage order of the adapted dense matrix
2528 template< typename MT2 > // Type of the foreign matrix
2529 inline TransExprTrait_<MT2>
2530  HermitianMatrix<MT,SO,false>::construct( const Matrix<MT2,!SO>& m, TrueType )
2531 {
2532  return trans( ~m );
2533 }
2535 //*************************************************************************************************
2536 
2537 } // namespace blaze
2538 
2539 #endif
bool isReal(const DiagonalProxy< MT > &proxy)
Returns whether the matrix element represents a real number.
Definition: DiagonalProxy.h:595
#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
const DMatForEachExpr< MT, Conj, SO > conj(const DenseMatrix< MT, SO > &dm)
Returns a matrix containing the complex conjugate of each single element of dm.
Definition: DMatForEachExpr.h:1214
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
bool isDiagonal(const DenseMatrix< MT, SO > &dm)
Checks if the give dense matrix is diagonal.
Definition: DenseMatrix.h:1577
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
BoolConstant< true > TrueType
Type traits base class.The TrueType class is used as base class for type traits and value traits that...
Definition: TrueType.h:61
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.
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
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.
typename TransExprTrait< T >::Type TransExprTrait_
Auxiliary alias declaration for the TransExprTrait class template.The TransExprTrait_ alias declarati...
Definition: TransExprTrait.h:143
Header file for the DisableIf class template.
Header file for the clear shim.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
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
typename T::ElementType ElementType_
Alias declaration for nested ElementType type definitions.The ElementType_ alias declaration provides...
Definition: Aliases.h:163
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 the implementation of the base template of the HeritianMatrix.
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 HermitianElement class.
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
bool isHermitian(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is Hermitian.
Definition: DenseMatrix.h:775
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 TransExprTrait class template.
Constraint on the data type.
Constraint on the data type.
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
Header file for the HermitianProxy class.
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
Header file for the IsComplex type trait.
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
Header file for the IsHermitian type trait.
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
Header file for the isReal shim.
#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
Header file for the TrueType type/value trait base class.
BLAZE_ALWAYS_INLINE void transpose(Matrix< MT, SO > &matrix)
In-place transpose of the given matrix.
Definition: Matrix.h:570