Sparse.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_ADAPTORS_UPPERMATRIX_SPARSE_H_
36 #define _BLAZE_MATH_ADAPTORS_UPPERMATRIX_SPARSE_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <algorithm>
44 #include <stdexcept>
45 #include <vector>
57 #include <blaze/math/shims/Clear.h>
59 #include <blaze/math/shims/Move.h>
66 #include <blaze/util/Assert.h>
71 #include <blaze/util/DisableIf.h>
72 #include <blaze/util/EnableIf.h>
74 #include <blaze/util/Types.h>
75 
76 
77 namespace blaze {
78 
79 //=================================================================================================
80 //
81 // CLASS TEMPLATE SPECIALIZATION FOR SPARSE MATRICES
82 //
83 //=================================================================================================
84 
85 //*************************************************************************************************
93 template< typename MT // Type of the adapted sparse matrix
94  , bool SO > // Storage order of the adapted sparse matrix
95 class UpperMatrix<MT,SO,false>
96  : public SparseMatrix< UpperMatrix<MT,SO,false>, SO >
97 {
98  private:
99  //**Type definitions****************************************************************************
100  typedef typename MT::OppositeType OT;
101  typedef typename MT::TransposeType TT;
102  typedef typename MT::ElementType ET;
103  //**********************************************************************************************
104 
105  public:
106  //**Type definitions****************************************************************************
107  typedef UpperMatrix<MT,SO,false> This;
108  typedef This ResultType;
109  typedef UpperMatrix<OT,!SO,false> OppositeType;
110  typedef LowerMatrix<TT,!SO,false> TransposeType;
111  typedef ET ElementType;
112  typedef typename MT::ReturnType ReturnType;
113  typedef const This& CompositeType;
114  typedef UpperProxy<MT> Reference;
115  typedef typename MT::ConstReference ConstReference;
116  typedef typename MT::Iterator Iterator;
117  typedef typename MT::ConstIterator ConstIterator;
118  //**********************************************************************************************
119 
120  //**Rebind struct definition********************************************************************
123  template< typename ET > // Data type of the other matrix
124  struct Rebind {
126  typedef UpperMatrix< typename MT::template Rebind<ET>::Other > Other;
127  };
128  //**********************************************************************************************
129 
130  //**Compilation flags***************************************************************************
132  enum { smpAssignable = 0 };
133  //**********************************************************************************************
134 
135  //**Constructors********************************************************************************
138  explicit inline UpperMatrix();
139  explicit inline UpperMatrix( size_t n );
140  explicit inline UpperMatrix( size_t n, size_t nonzeros );
141  explicit inline UpperMatrix( size_t n, const std::vector<size_t>& nonzeros );
142 
143  inline UpperMatrix( const UpperMatrix& m );
144  template< typename MT2, bool SO2 > inline UpperMatrix( const Matrix<MT2,SO2>& m );
146  //**********************************************************************************************
147 
148  //**Destructor**********************************************************************************
149  // No explicitly declared destructor.
150  //**********************************************************************************************
151 
152  //**Data access functions***********************************************************************
155  inline Reference operator()( size_t i, size_t j );
156  inline ConstReference operator()( size_t i, size_t j ) const;
157  inline Iterator begin ( size_t i );
158  inline ConstIterator begin ( size_t i ) const;
159  inline ConstIterator cbegin( size_t i ) const;
160  inline Iterator end ( size_t i );
161  inline ConstIterator end ( size_t i ) const;
162  inline ConstIterator cend ( size_t i ) const;
164  //**********************************************************************************************
165 
166  //**Assignment operators************************************************************************
169  inline UpperMatrix& operator=( const UpperMatrix& rhs );
170 
171  template< typename MT2, bool SO2 >
172  inline typename DisableIf< IsComputation<MT2>, UpperMatrix& >::Type
173  operator=( const Matrix<MT2,SO2>& rhs );
174 
175  template< typename MT2, bool SO2 >
176  inline typename EnableIf< IsComputation<MT2>, UpperMatrix& >::Type
177  operator=( const Matrix<MT2,SO2>& rhs );
178 
179  template< typename MT2, bool SO2 >
180  inline typename DisableIf< IsComputation<MT2>, UpperMatrix& >::Type
181  operator+=( const Matrix<MT2,SO2>& rhs );
182 
183  template< typename MT2, bool SO2 >
184  inline typename EnableIf< IsComputation<MT2>, UpperMatrix& >::Type
185  operator+=( const Matrix<MT2,SO2>& rhs );
186 
187  template< typename MT2, bool SO2 >
188  inline typename DisableIf< IsComputation<MT2>, UpperMatrix& >::Type
189  operator-=( const Matrix<MT2,SO2>& rhs );
190 
191  template< typename MT2, bool SO2 >
192  inline typename EnableIf< IsComputation<MT2>, UpperMatrix& >::Type
193  operator-=( const Matrix<MT2,SO2>& rhs );
194 
195  template< typename MT2, bool SO2 >
196  inline UpperMatrix& operator*=( const Matrix<MT2,SO2>& rhs );
197 
198  template< typename Other >
199  inline typename EnableIf< IsNumeric<Other>, UpperMatrix >::Type&
200  operator*=( Other rhs );
201 
202  template< typename Other >
203  inline typename EnableIf< IsNumeric<Other>, UpperMatrix >::Type&
204  operator/=( Other rhs );
206  //**********************************************************************************************
207 
208  //**Utility functions***************************************************************************
211  inline size_t rows() const;
212  inline size_t columns() const;
213  inline size_t capacity() const;
214  inline size_t capacity( size_t i ) const;
215  inline size_t nonZeros() const;
216  inline size_t nonZeros( size_t i ) const;
217  inline void reset();
218  inline void reset( size_t i );
219  inline void clear();
220  inline Iterator set( size_t i, size_t j, const ElementType& value );
221  inline Iterator insert( size_t i, size_t j, const ElementType& value );
222  inline void erase( size_t i, size_t j );
223  inline Iterator erase( size_t i, Iterator pos );
224  inline Iterator erase( size_t i, Iterator first, Iterator last );
225  inline void resize ( size_t n, bool preserve=true );
226  inline void reserve( size_t nonzeros );
227  inline void reserve( size_t i, size_t nonzeros );
228  inline void trim();
229  inline void trim( size_t i );
230  template< typename Other > inline UpperMatrix& scale( const Other& scalar );
231  template< typename Other > inline UpperMatrix& scaleDiagonal( Other scale );
232  inline void swap( UpperMatrix& m ) /* throw() */;
233 
234  static inline size_t maxNonZeros();
235  static inline size_t maxNonZeros( size_t n );
237  //**********************************************************************************************
238 
239  //**Lookup functions****************************************************************************
242  inline Iterator find ( size_t i, size_t j );
243  inline ConstIterator find ( size_t i, size_t j ) const;
244  inline Iterator lowerBound( size_t i, size_t j );
245  inline ConstIterator lowerBound( size_t i, size_t j ) const;
246  inline Iterator upperBound( size_t i, size_t j );
247  inline ConstIterator upperBound( size_t i, size_t j ) const;
249  //**********************************************************************************************
250 
251  //**Low-level utility functions*****************************************************************
254  inline void append ( size_t i, size_t j, const ElementType& value, bool check=false );
255  inline void finalize( size_t i );
257  //**********************************************************************************************
258 
259  //**Expression template evaluation functions****************************************************
262  template< typename Other > inline bool canAlias ( const Other* alias ) const;
263  template< typename Other > inline bool isAliased( const Other* alias ) const;
264 
265  inline bool canSMPAssign() const;
267  //**********************************************************************************************
268 
269  private:
270  //**Utility functions***************************************************************************
273  inline void resetLower();
275  //**********************************************************************************************
276 
277  //**Member variables****************************************************************************
280  MT matrix_;
281 
282  //**********************************************************************************************
283 
284  //**Friend declarations*************************************************************************
285  template< typename MT2, bool SO2, bool DF2 >
286  friend bool isDefault( const UpperMatrix<MT2,SO2,DF2>& m );
287 
288  template< typename MT2, bool SO2, bool DF2 >
289  friend MT2& derestrict( UpperMatrix<MT2,SO2,DF2>& m );
290  //**********************************************************************************************
291 
292  //**Compile time checks*************************************************************************
304  BLAZE_STATIC_ASSERT( IsResizable<MT>::value || IsSquare<MT>::value );
305  //**********************************************************************************************
306 };
308 //*************************************************************************************************
309 
310 
311 
312 
313 //=================================================================================================
314 //
315 // CONSTRUCTORS
316 //
317 //=================================================================================================
318 
319 //*************************************************************************************************
323 template< typename MT // Type of the adapted sparse matrix
324  , bool SO > // Storage order of the adapted sparse matrix
325 inline UpperMatrix<MT,SO,false>::UpperMatrix()
326  : matrix_() // The adapted sparse matrix
327 {
328  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square upper matrix detected" );
329 }
331 //*************************************************************************************************
332 
333 
334 //*************************************************************************************************
342 template< typename MT // Type of the adapted sparse matrix
343  , bool SO > // Storage order of the adapted sparse matrix
344 inline UpperMatrix<MT,SO,false>::UpperMatrix( size_t n )
345  : matrix_( n, n ) // The adapted sparse matrix
346 {
348 
349  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square upper matrix detected" );
350 }
352 //*************************************************************************************************
353 
354 
355 //*************************************************************************************************
364 template< typename MT // Type of the adapted sparse matrix
365  , bool SO > // Storage order of the adapted sparse matrix
366 inline UpperMatrix<MT,SO,false>::UpperMatrix( size_t n, size_t nonzeros )
367  : matrix_( n, n, nonzeros ) // The adapted sparse matrix
368 {
370 
371  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square upper matrix detected" );
372 }
374 //*************************************************************************************************
375 
376 
377 //*************************************************************************************************
388 template< typename MT // Type of the adapted sparse matrix
389  , bool SO > // Storage order of the adapted sparse matrix
390 inline UpperMatrix<MT,SO,false>::UpperMatrix( size_t n, const std::vector<size_t>& nonzeros )
391  : matrix_( n, n, nonzeros ) // The adapted sparse matrix
392 {
394 
395  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square upper matrix detected" );
396 }
398 //*************************************************************************************************
399 
400 
401 //*************************************************************************************************
407 template< typename MT // Type of the adapted sparse matrix
408  , bool SO > // Storage order of the adapted sparse matrix
409 inline UpperMatrix<MT,SO,false>::UpperMatrix( const UpperMatrix& m )
410  : matrix_( m.matrix_ ) // The adapted sparse matrix
411 {
412  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square upper matrix detected" );
413 }
415 //*************************************************************************************************
416 
417 
418 //*************************************************************************************************
428 template< typename MT // Type of the adapted sparse matrix
429  , bool SO > // Storage order of the adapted sparse matrix
430 template< typename MT2 // Type of the foreign matrix
431  , bool SO2 > // Storage order of the foreign matrix
432 inline UpperMatrix<MT,SO,false>::UpperMatrix( const Matrix<MT2,SO2>& m )
433  : matrix_( ~m ) // The adapted sparse matrix
434 {
435  if( !IsUpper<MT2>::value && !isUpper( matrix_ ) )
436  throw std::invalid_argument( "Invalid setup of upper matrix" );
437 
438  if( !IsUpper<MT2>::value )
439  resetLower();
440 
441  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square upper matrix detected" );
442 }
444 //*************************************************************************************************
445 
446 
447 
448 
449 //=================================================================================================
450 //
451 // DATA ACCESS FUNCTIONS
452 //
453 //=================================================================================================
454 
455 //*************************************************************************************************
467 template< typename MT // Type of the adapted sparse matrix
468  , bool SO > // Storage order of the adapted sparse matrix
470  UpperMatrix<MT,SO,false>::operator()( size_t i, size_t j )
471 {
472  BLAZE_USER_ASSERT( i<rows() , "Invalid row access index" );
473  BLAZE_USER_ASSERT( j<columns(), "Invalid column access index" );
474 
475  return Reference( matrix_, i, j );
476 }
478 //*************************************************************************************************
479 
480 
481 //*************************************************************************************************
493 template< typename MT // Type of the adapted sparse matrix
494  , bool SO > // Storage order of the adapted sparse matrix
496  UpperMatrix<MT,SO,false>::operator()( size_t i, size_t j ) const
497 {
498  BLAZE_USER_ASSERT( i<rows() , "Invalid row access index" );
499  BLAZE_USER_ASSERT( j<columns(), "Invalid column access index" );
500 
501  return matrix_(i,j);
502 }
504 //*************************************************************************************************
505 
506 
507 //*************************************************************************************************
519 template< typename MT // Type of the adapted sparse matrix
520  , bool SO > // Storage order of the adapted sparse matrix
523 {
524  return matrix_.begin(i);
525 }
527 //*************************************************************************************************
528 
529 
530 //*************************************************************************************************
542 template< typename MT // Type of the adapted sparse matrix
543  , bool SO > // Storage order of the adapted sparse matrix
545  UpperMatrix<MT,SO,false>::begin( size_t i ) const
546 {
547  return matrix_.begin(i);
548 }
550 //*************************************************************************************************
551 
552 
553 //*************************************************************************************************
565 template< typename MT // Type of the adapted sparse matrix
566  , bool SO > // Storage order of the adapted sparse matrix
568  UpperMatrix<MT,SO,false>::cbegin( size_t i ) const
569 {
570  return matrix_.cbegin(i);
571 }
573 //*************************************************************************************************
574 
575 
576 //*************************************************************************************************
588 template< typename MT // Type of the adapted sparse matrix
589  , bool SO > // Storage order of the adapted sparse matrix
592 {
593  return matrix_.end(i);
594 }
596 //*************************************************************************************************
597 
598 
599 //*************************************************************************************************
611 template< typename MT // Type of the adapted sparse matrix
612  , bool SO > // Storage order of the adapted sparse matrix
614  UpperMatrix<MT,SO,false>::end( size_t i ) const
615 {
616  return matrix_.end(i);
617 }
619 //*************************************************************************************************
620 
621 
622 //*************************************************************************************************
634 template< typename MT // Type of the adapted sparse matrix
635  , bool SO > // Storage order of the adapted sparse matrix
637  UpperMatrix<MT,SO,false>::cend( size_t i ) const
638 {
639  return matrix_.cend(i);
640 }
642 //*************************************************************************************************
643 
644 
645 
646 
647 //=================================================================================================
648 //
649 // ASSIGNMENT OPERATORS
650 //
651 //=================================================================================================
652 
653 //*************************************************************************************************
663 template< typename MT // Type of the adapted sparse matrix
664  , bool SO > // Storage order of the adapted sparse matrix
665 inline UpperMatrix<MT,SO,false>&
666  UpperMatrix<MT,SO,false>::operator=( const UpperMatrix& rhs )
667 {
668  matrix_ = rhs.matrix_;
669 
670  return *this;
671 }
673 //*************************************************************************************************
674 
675 
676 //*************************************************************************************************
689 template< typename MT // Type of the adapted sparse matrix
690  , bool SO > // Storage order of the adapted sparse matrix
691 template< typename MT2 // Type of the right-hand side matrix
692  , bool SO2 > // Storage order of the right-hand side matrix
693 inline typename DisableIf< IsComputation<MT2>, UpperMatrix<MT,SO,false>& >::Type
694  UpperMatrix<MT,SO,false>::operator=( const Matrix<MT2,SO2>& rhs )
695 {
696  if( !IsUpper<MT2>::value && !isUpper( ~rhs ) )
697  throw std::invalid_argument( "Invalid assignment to upper matrix" );
698 
699  matrix_ = ~rhs;
700 
701  if( !IsUpper<MT2>::value )
702  resetLower();
703 
704  return *this;
705 }
707 //*************************************************************************************************
708 
709 
710 //*************************************************************************************************
723 template< typename MT // Type of the adapted sparse matrix
724  , bool SO > // Storage order of the adapted sparse matrix
725 template< typename MT2 // Type of the right-hand side matrix
726  , bool SO2 > // Storage order of the right-hand side matrix
727 inline typename EnableIf< IsComputation<MT2>, UpperMatrix<MT,SO,false>& >::Type
728  UpperMatrix<MT,SO,false>::operator=( const Matrix<MT2,SO2>& rhs )
729 {
730  if( !IsSquare<MT2>::value && !isSquare( ~rhs ) )
731  throw std::invalid_argument( "Invalid assignment to upper matrix" );
732 
733  if( IsUpper<MT2>::value ) {
734  matrix_ = ~rhs;
735  }
736  else {
737  MT tmp( ~rhs );
738 
739  if( !isUpper( tmp ) )
740  throw std::invalid_argument( "Invalid assignment to upper matrix" );
741 
742  move( matrix_, tmp );
743  }
744 
745  if( !IsUpper<MT2>::value )
746  resetLower();
747 
748  return *this;
749 }
751 //*************************************************************************************************
752 
753 
754 //*************************************************************************************************
767 template< typename MT // Type of the adapted sparse matrix
768  , bool SO > // Storage order of the adapted sparse matrix
769 template< typename MT2 // Type of the right-hand side matrix
770  , bool SO2 > // Storage order of the right-hand side matrix
771 inline typename DisableIf< IsComputation<MT2>, UpperMatrix<MT,SO,false>& >::Type
772  UpperMatrix<MT,SO,false>::operator+=( const Matrix<MT2,SO2>& rhs )
773 {
774  if( !IsUpper<MT2>::value && !isUpper( ~rhs ) )
775  throw std::invalid_argument( "Invalid assignment to upper matrix" );
776 
777  matrix_ += ~rhs;
778 
779  if( !IsUpper<MT2>::value )
780  resetLower();
781 
782  return *this;
783 }
785 //*************************************************************************************************
786 
787 
788 //*************************************************************************************************
801 template< typename MT // Type of the adapted sparse matrix
802  , bool SO > // Storage order of the adapted sparse matrix
803 template< typename MT2 // Type of the right-hand side matrix
804  , bool SO2 > // Storage order of the right-hand side matrix
805 inline typename EnableIf< IsComputation<MT2>, UpperMatrix<MT,SO,false>& >::Type
806  UpperMatrix<MT,SO,false>::operator+=( const Matrix<MT2,SO2>& rhs )
807 {
808  if( IsSquare<MT2>::value && !isSquare( ~rhs ) )
809  throw std::invalid_argument( "Invalid assignment to upper matrix" );
810 
811  if( IsUpper<MT2>::value ) {
812  matrix_ += ~rhs;
813  }
814  else {
815  typename MT2::ResultType tmp( ~rhs );
816 
817  if( !isUpper( tmp ) )
818  throw std::invalid_argument( "Invalid assignment to upper matrix" );
819 
820  matrix_ += tmp;
821  }
822 
823  if( !IsUpper<MT2>::value )
824  resetLower();
825 
826  return *this;
827 }
829 //*************************************************************************************************
830 
831 
832 //*************************************************************************************************
845 template< typename MT // Type of the adapted sparse matrix
846  , bool SO > // Storage order of the adapted sparse matrix
847 template< typename MT2 // Type of the right-hand side matrix
848  , bool SO2 > // Storage order of the right-hand side matrix
849 inline typename DisableIf< IsComputation<MT2>, UpperMatrix<MT,SO,false>& >::Type
850  UpperMatrix<MT,SO,false>::operator-=( const Matrix<MT2,SO2>& rhs )
851 {
852  if( !IsUpper<MT2>::value && !isUpper( ~rhs ) )
853  throw std::invalid_argument( "Invalid assignment to upper matrix" );
854 
855  matrix_ -= ~rhs;
856 
857  if( !IsUpper<MT2>::value )
858  resetLower();
859 
860  return *this;
861 }
863 //*************************************************************************************************
864 
865 
866 //*************************************************************************************************
879 template< typename MT // Type of the adapted sparse matrix
880  , bool SO > // Storage order of the adapted sparse matrix
881 template< typename MT2 // Type of the right-hand side matrix
882  , bool SO2 > // Storage order of the right-hand side matrix
883 inline typename EnableIf< IsComputation<MT2>, UpperMatrix<MT,SO,false>& >::Type
884  UpperMatrix<MT,SO,false>::operator-=( const Matrix<MT2,SO2>& rhs )
885 {
886  if( !IsSquare<MT2>::value && !isSquare( ~rhs ) )
887  throw std::invalid_argument( "Invalid assignment to upper matrix" );
888 
889  if( IsUpper<MT2>::value ) {
890  matrix_ -= ~rhs;
891  }
892  else {
893  typename MT2::ResultType tmp( ~rhs );
894 
895  if( !isUpper( tmp ) )
896  throw std::invalid_argument( "Invalid assignment to upper matrix" );
897 
898  matrix_ -= tmp;
899  }
900 
901  if( !IsUpper<MT2>::value )
902  resetLower();
903 
904  return *this;
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
924 template< typename MT2 // Type of the right-hand side matrix
925  , bool SO2 > // Storage order of the right-hand side matrix
926 inline UpperMatrix<MT,SO,false>&
927  UpperMatrix<MT,SO,false>::operator*=( const Matrix<MT2,SO2>& rhs )
928 {
929  if( matrix_.rows() != (~rhs).columns() )
930  throw std::invalid_argument( "Invalid assignment to upper matrix" );
931 
932  MT tmp( matrix_ * ~rhs );
933 
934  if( !isUpper( tmp ) )
935  throw std::invalid_argument( "Invalid assignment to upper matrix" );
936 
937  move( matrix_, tmp );
938 
939  if( !IsUpper<MT2>::value )
940  resetLower();
941 
942  return *this;
943 }
945 //*************************************************************************************************
946 
947 
948 //*************************************************************************************************
956 template< typename MT // Type of the adapted sparse matrix
957  , bool SO > // Storage order of the adapted sparse matrix
958 template< typename Other > // Data type of the right-hand side scalar
959 inline typename EnableIf< IsNumeric<Other>, UpperMatrix<MT,SO,false> >::Type&
960  UpperMatrix<MT,SO,false>::operator*=( Other rhs )
961 {
962  matrix_ *= rhs;
963  return *this;
964 }
965 //*************************************************************************************************
966 
967 
968 //*************************************************************************************************
976 template< typename MT // Type of the adapted sparse matrix
977  , bool SO > // Storage order of the adapted sparse matrix
978 template< typename Other > // Data type of the right-hand side scalar
979 inline typename EnableIf< IsNumeric<Other>, UpperMatrix<MT,SO,false> >::Type&
980  UpperMatrix<MT,SO,false>::operator/=( Other rhs )
981 {
982  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
983 
984  matrix_ /= rhs;
985  return *this;
986 }
988 //*************************************************************************************************
989 
990 
991 
992 
993 //=================================================================================================
994 //
995 // UTILITY FUNCTIONS
996 //
997 //=================================================================================================
998 
999 //*************************************************************************************************
1005 template< typename MT // Type of the adapted sparse matrix
1006  , bool SO > // Storage order of the adapted sparse matrix
1007 inline size_t UpperMatrix<MT,SO,false>::rows() const
1008 {
1009  return matrix_.rows();
1010 }
1012 //*************************************************************************************************
1013 
1014 
1015 //*************************************************************************************************
1021 template< typename MT // Type of the adapted sparse matrix
1022  , bool SO > // Storage order of the adapted sparse matrix
1023 inline size_t UpperMatrix<MT,SO,false>::columns() const
1024 {
1025  return matrix_.columns();
1026 }
1028 //*************************************************************************************************
1029 
1030 
1031 //*************************************************************************************************
1037 template< typename MT // Type of the adapted sparse matrix
1038  , bool SO > // Storage order of the adapted sparse matrix
1039 inline size_t UpperMatrix<MT,SO,false>::capacity() const
1040 {
1041  return matrix_.capacity();
1042 }
1044 //*************************************************************************************************
1045 
1046 
1047 //*************************************************************************************************
1059 template< typename MT // Type of the adapted sparse matrix
1060  , bool SO > // Storage order of the adapted sparse matrix
1061 inline size_t UpperMatrix<MT,SO,false>::capacity( size_t i ) const
1062 {
1063  return matrix_.capacity(i);
1064 }
1066 //*************************************************************************************************
1067 
1068 
1069 //*************************************************************************************************
1075 template< typename MT // Type of the adapted sparse matrix
1076  , bool SO > // Storage order of the adapted sparse matrix
1077 inline size_t UpperMatrix<MT,SO,false>::nonZeros() const
1078 {
1079  return matrix_.nonZeros();
1080 }
1082 //*************************************************************************************************
1083 
1084 
1085 //*************************************************************************************************
1097 template< typename MT // Type of the adapted sparse matrix
1098  , bool SO > // Storage order of the adapted sparse matrix
1099 inline size_t UpperMatrix<MT,SO,false>::nonZeros( size_t i ) const
1100 {
1101  return matrix_.nonZeros(i);
1102 }
1104 //*************************************************************************************************
1105 
1106 
1107 //*************************************************************************************************
1113 template< typename MT // Type of the adapted sparse matrix
1114  , bool SO > // Storage order of the adapted sparse matrix
1115 inline void UpperMatrix<MT,SO,false>::reset()
1116 {
1117  matrix_.reset();
1118 }
1120 //*************************************************************************************************
1121 
1122 
1123 //*************************************************************************************************
1136 template< typename MT // Type of the adapted sparse matrix
1137  , bool SO > // Storage order of the adapted sparse matrix
1138 inline void UpperMatrix<MT,SO,false>::reset( size_t i )
1139 {
1140  matrix_.reset( i );
1141 }
1143 //*************************************************************************************************
1144 
1145 
1146 //*************************************************************************************************
1154 template< typename MT // Type of the adapted sparse matrix
1155  , bool SO > // Storage order of the adapted sparse matrix
1156 inline void UpperMatrix<MT,SO,false>::clear()
1157 {
1158  using blaze::clear;
1159 
1160  clear( matrix_ );
1161 }
1163 //*************************************************************************************************
1164 
1165 
1166 //*************************************************************************************************
1182 template< typename MT // Type of the adapted sparse matrix
1183  , bool SO > // Storage order of the adapted sparse matrix
1184 inline typename UpperMatrix<MT,SO,false>::Iterator
1185  UpperMatrix<MT,SO,false>::set( size_t i, size_t j, const ElementType& value )
1186 {
1187  if( i > j )
1188  throw std::invalid_argument( "Invalid access to lower matrix element" );
1189 
1190  return matrix_.set( i, j, value );
1191 }
1193 //*************************************************************************************************
1194 
1195 
1196 //*************************************************************************************************
1213 template< typename MT // Type of the adapted sparse matrix
1214  , bool SO > // Storage order of the adapted sparse matrix
1215 inline typename UpperMatrix<MT,SO,false>::Iterator
1216  UpperMatrix<MT,SO,false>::insert( size_t i, size_t j, const ElementType& value )
1217 {
1218  if( i > j )
1219  throw std::invalid_argument( "Invalid access to lower matrix element" );
1220 
1221  return matrix_.insert( i, j, value );
1222 }
1224 //*************************************************************************************************
1225 
1226 
1227 //*************************************************************************************************
1237 template< typename MT // Type of the adapted sparse matrix
1238  , bool SO > // Storage order of the adapted sparse matrix
1239 inline void UpperMatrix<MT,SO,false>::erase( size_t i, size_t j )
1240 {
1241  matrix_.erase( i, j );
1242 }
1244 //*************************************************************************************************
1245 
1246 
1247 //*************************************************************************************************
1259 template< typename MT // Type of the adapted sparse matrix
1260  , bool SO > // Storage order of the adapted sparse matrix
1261 inline typename UpperMatrix<MT,SO,false>::Iterator
1262  UpperMatrix<MT,SO,false>::erase( size_t i, Iterator pos )
1263 {
1264  return matrix_.erase( i, pos );
1265 }
1267 //*************************************************************************************************
1268 
1269 
1270 //*************************************************************************************************
1283 template< typename MT // Type of the adapted sparse matrix
1284  , bool SO > // Storage order of the adapted sparse matrix
1285 inline typename UpperMatrix<MT,SO,false>::Iterator
1286  UpperMatrix<MT,SO,false>::erase( size_t i, Iterator first, Iterator last )
1287 {
1288  return matrix_.erase( i, first, last );
1289 }
1291 //*************************************************************************************************
1292 
1293 
1294 //*************************************************************************************************
1309 template< typename MT // Type of the adapted sparse matrix
1310  , bool SO > // Storage order of the adapted sparse matrix
1311 void UpperMatrix<MT,SO,false>::resize( size_t n, bool preserve )
1312 {
1314 
1315  BLAZE_INTERNAL_ASSERT( isSquare( matrix_ ), "Non-square upper matrix detected" );
1316 
1317  matrix_.resize( n, n, preserve );
1318 }
1320 //*************************************************************************************************
1321 
1322 
1323 //*************************************************************************************************
1334 template< typename MT // Type of the adapted sparse matrix
1335  , bool SO > // Storage order of the adapted sparse matrix
1336 inline void UpperMatrix<MT,SO,false>::reserve( size_t nonzeros )
1337 {
1338  matrix_.reserve( nonzeros );
1339 }
1341 //*************************************************************************************************
1342 
1343 
1344 //*************************************************************************************************
1358 template< typename MT // Type of the adapted sparse matrix
1359  , bool SO > // Storage order of the adapted sparse matrix
1360 inline void UpperMatrix<MT,SO,false>::reserve( size_t i, size_t nonzeros )
1361 {
1362  matrix_.reserve( i, nonzeros );
1363 }
1365 //*************************************************************************************************
1366 
1367 
1368 //*************************************************************************************************
1379 template< typename MT // Type of the adapted sparse matrix
1380  , bool SO > // Storage order of the adapted sparse matrix
1381 inline void UpperMatrix<MT,SO,false>::trim()
1382 {
1383  matrix_.trim();
1384 }
1386 //*************************************************************************************************
1387 
1388 
1389 //*************************************************************************************************
1401 template< typename MT // Type of the adapted sparse matrix
1402  , bool SO > // Storage order of the adapted sparse matrix
1403 inline void UpperMatrix<MT,SO,false>::trim( size_t i )
1404 {
1405  matrix_.trim( i );
1406 }
1408 //*************************************************************************************************
1409 
1410 
1411 //*************************************************************************************************
1418 template< typename MT // Type of the adapted sparse matrix
1419  , bool SO > // Storage order of the adapted sparse matrix
1420 template< typename Other > // Data type of the scalar value
1421 inline UpperMatrix<MT,SO,false>&
1422  UpperMatrix<MT,SO,false>::scale( const Other& scalar )
1423 {
1424  matrix_.scale( scalar );
1425  return *this;
1426 }
1428 //*************************************************************************************************
1429 
1430 
1431 //*************************************************************************************************
1438 template< typename MT // Type of the adapted sparse matrix
1439  , bool SO > // Storage order of the adapted sparse matrix
1440 template< typename Other > // Data type of the scalar value
1441 inline UpperMatrix<MT,SO,false>&
1442  UpperMatrix<MT,SO,false>::scaleDiagonal( Other scalar )
1443 {
1444  matrix_.scaleDiagonal( scalar );
1445  return *this;
1446 }
1448 //*************************************************************************************************
1449 
1450 
1451 //*************************************************************************************************
1459 template< typename MT // Type of the adapted sparse matrix
1460  , bool SO > // Storage order of the adapted sparse matrix
1461 inline void UpperMatrix<MT,SO,false>::swap( UpperMatrix& m ) /* throw() */
1462 {
1463  using std::swap;
1464 
1465  swap( matrix_, m.matrix_ );
1466 }
1468 //*************************************************************************************************
1469 
1470 
1471 //*************************************************************************************************
1482 template< typename MT // Type of the adapted dense matrix
1483  , bool SO > // Storage order of the adapted dense matrix
1484 inline size_t UpperMatrix<MT,SO,false>::maxNonZeros()
1485 {
1487 
1488  return maxNonZeros( Rows<MT>::value );
1489 }
1491 //*************************************************************************************************
1492 
1493 
1494 //*************************************************************************************************
1504 template< typename MT // Type of the adapted dense matrix
1505  , bool SO > // Storage order of the adapted dense matrix
1506 inline size_t UpperMatrix<MT,SO,false>::maxNonZeros( size_t n )
1507 {
1508  return ( ( n + 1UL ) * n ) / 2UL;
1509 }
1511 //*************************************************************************************************
1512 
1513 
1514 //*************************************************************************************************
1520 template< typename MT // Type of the adapted dense matrix
1521  , bool SO > // Storage order of the adapted dense matrix
1522 inline void UpperMatrix<MT,SO,false>::resetLower()
1523 {
1524  if( SO ) {
1525  for( size_t j=0UL; j<columns(); ++j )
1526  matrix_.erase( j, matrix_.upperBound( j, j ), matrix_.end( j ) );
1527  }
1528  else {
1529  for( size_t i=1UL; i<rows(); ++i )
1530  matrix_.erase( i, matrix_.begin( i ), matrix_.lowerBound( i, i ) );
1531  }
1532 }
1534 //*************************************************************************************************
1535 
1536 
1537 
1538 
1539 //=================================================================================================
1540 //
1541 // LOOKUP FUNCTIONS
1542 //
1543 //=================================================================================================
1544 
1545 //*************************************************************************************************
1561 template< typename MT // Type of the adapted sparse matrix
1562  , bool SO > // Storage order of the adapted sparse matrix
1563 inline typename UpperMatrix<MT,SO,false>::Iterator
1564  UpperMatrix<MT,SO,false>::find( size_t i, size_t j )
1565 {
1566  return matrix_.find( i, j );
1567 }
1569 //*************************************************************************************************
1570 
1571 
1572 //*************************************************************************************************
1588 template< typename MT // Type of the adapted sparse matrix
1589  , bool SO > // Storage order of the adapted sparse matrix
1591  UpperMatrix<MT,SO,false>::find( size_t i, size_t j ) const
1592 {
1593  return matrix_.find( i, j );
1594 }
1596 //*************************************************************************************************
1597 
1598 
1599 //*************************************************************************************************
1615 template< typename MT // Type of the adapted sparse matrix
1616  , bool SO > // Storage order of the adapted sparse matrix
1617 inline typename UpperMatrix<MT,SO,false>::Iterator
1618  UpperMatrix<MT,SO,false>::lowerBound( size_t i, size_t j )
1619 {
1620  return matrix_.lowerBound( i, j );
1621 }
1623 //*************************************************************************************************
1624 
1625 
1626 //*************************************************************************************************
1642 template< typename MT // Type of the adapted sparse matrix
1643  , bool SO > // Storage order of the adapted sparse matrix
1645  UpperMatrix<MT,SO,false>::lowerBound( size_t i, size_t j ) const
1646 {
1647  return matrix_.lowerBound( i, j );
1648 }
1650 //*************************************************************************************************
1651 
1652 
1653 //*************************************************************************************************
1669 template< typename MT // Type of the adapted sparse matrix
1670  , bool SO > // Storage order of the adapted sparse matrix
1671 inline typename UpperMatrix<MT,SO,false>::Iterator
1672  UpperMatrix<MT,SO,false>::upperBound( size_t i, size_t j )
1673 {
1674  return matrix_.upperBound( i, j );
1675 }
1677 //*************************************************************************************************
1678 
1679 
1680 //*************************************************************************************************
1696 template< typename MT // Type of the adapted sparse matrix
1697  , bool SO > // Storage order of the adapted sparse matrix
1699  UpperMatrix<MT,SO,false>::upperBound( size_t i, size_t j ) const
1700 {
1701  return matrix_.upperBound( i, j );
1702 }
1704 //*************************************************************************************************
1705 
1706 
1707 
1708 
1709 //=================================================================================================
1710 //
1711 // LOW-LEVEL UTILITY FUNCTIONS
1712 //
1713 //=================================================================================================
1714 
1715 //*************************************************************************************************
1765 template< typename MT // Type of the adapted sparse matrix
1766  , bool SO > // Storage order of the adapted sparse matrix
1767 inline void UpperMatrix<MT,SO,false>::append( size_t i, size_t j, const ElementType& value, bool check )
1768 {
1769  if( i > j )
1770  throw std::invalid_argument( "Invalid access to lower matrix element" );
1771 
1772  matrix_.append( i, j, value, check );
1773 }
1775 //*************************************************************************************************
1776 
1777 
1778 //*************************************************************************************************
1792 template< typename MT // Type of the adapted sparse matrix
1793  , bool SO > // Storage order of the adapted sparse matrix
1794 inline void UpperMatrix<MT,SO,false>::finalize( size_t i )
1795 {
1796  matrix_.finalize( i );
1797 }
1799 //*************************************************************************************************
1800 
1801 
1802 
1803 
1804 //=================================================================================================
1805 //
1806 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1807 //
1808 //=================================================================================================
1809 
1810 //*************************************************************************************************
1821 template< typename MT // Type of the adapted sparse matrix
1822  , bool SO > // Storage order of the adapted sparse matrix
1823 template< typename Other > // Data type of the foreign expression
1824 inline bool UpperMatrix<MT,SO,false>::canAlias( const Other* alias ) const
1825 {
1826  return matrix_.canAlias( alias );
1827 }
1829 //*************************************************************************************************
1830 
1831 
1832 //*************************************************************************************************
1843 template< typename MT // Type of the adapted sparse matrix
1844  , bool SO > // Storage order of the adapted sparse matrix
1845 template< typename Other > // Data type of the foreign expression
1846 inline bool UpperMatrix<MT,SO,false>::isAliased( const Other* alias ) const
1847 {
1848  return matrix_.isAliased( alias );
1849 }
1851 //*************************************************************************************************
1852 
1853 
1854 //*************************************************************************************************
1865 template< typename MT // Type of the adapted sparse matrix
1866  , bool SO > // Storage order of the adapted sparse matrix
1867 inline bool UpperMatrix<MT,SO,false>::canSMPAssign() const
1868 {
1869  return matrix_.canSMPAssign();
1870 }
1872 //*************************************************************************************************
1873 
1874 } // namespace blaze
1875 
1876 #endif
#define BLAZE_CONSTRAINT_MUST_NOT_BE_CONST(T)
Constraint on the data type.In case the given data type is a const-qualified type, a compilation error is created.
Definition: Const.h:116
#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 basic type definitions.
BLAZE_ALWAYS_INLINE bool isSquare(const Matrix< MT, SO > &matrix)
Checks if the given matrix is a square matrix.
Definition: Matrix.h:902
BLAZE_ALWAYS_INLINE MT::ConstIterator cbegin(const Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:237
void move(CompressedMatrix< Type, SO > &dst, CompressedMatrix< Type, SO > &src)
Moving the contents of one compressed matrix to another.
Definition: CompressedMatrix.h:4825
BLAZE_ALWAYS_INLINE MT::ConstIterator cend(const Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:300
BLAZE_ALWAYS_INLINE MT::Iterator end(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:258
#define BLAZE_CONSTRAINT_MUST_BE_MATRIX_WITH_STORAGE_ORDER(T, SO)
Constraint on the data type.In case the given data type T is not a dense or sparse matrix type and in...
Definition: StorageOrder.h:242
Constraint on the data type.
Constraint on the data type.
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:821
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2507
BLAZE_ALWAYS_INLINE size_t capacity(const Matrix< MT, SO > &matrix)
Returns the maximum capacity of the matrix.
Definition: Matrix.h:348
BLAZE_ALWAYS_INLINE size_t rows(const Matrix< MT, SO > &matrix)
Returns the current number of rows of the matrix.
Definition: Matrix.h:316
void clear(CompressedMatrix< Type, SO > &m)
Clearing the given compressed matrix.
Definition: CompressedMatrix.h:4762
CompressedMatrix< Type, true > This
Type of this CompressedMatrix instance.
Definition: CompressedMatrix.h:2501
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE(T)
Constraint on the data type.In case the given data type is a volatile-qualified type, a compilation error is created.
Definition: Volatile.h:116
BLAZE_ALWAYS_INLINE size_t nonZeros(const Matrix< MT, SO > &matrix)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:386
Constraint on the data type.
CompressedMatrix< Type, false > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: CompressedMatrix.h:2503
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:861
Constraint on the data type.
Header file for the implementation of the base template of the UpperMatrix.
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 clear shim.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
void swap(CompressedMatrix< Type, SO > &a, CompressedMatrix< Type, SO > &b)
Swapping the contents of two compressed matrices.
Definition: CompressedMatrix.h:4807
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2511
#define BLAZE_CONSTRAINT_MUST_NOT_BE_POINTER_TYPE(T)
Constraint on the data type.In case the given data type T is not a pointer type, a compilation error ...
Definition: Pointer.h:116
Constraint on the data type.
CompressedMatrix< Type, false > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:2504
bool isUpper(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is an upper triangular matrix.
Definition: DenseMatrix.h:1197
Constraints on the storage order of matrix types.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_UPPER_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a upper triangular matrix type...
Definition: Upper.h:118
BLAZE_ALWAYS_INLINE MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:195
BLAZE_ALWAYS_INLINE void resize(Matrix< MT, SO > &matrix, size_t rows, size_t columns, bool preserve=true)
Changing the size of the matrix.
Definition: Matrix.h:535
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2505
Header file for the UpperProxy class.
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2509
Header file for the EnableIf class template.
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:841
Header file for the IsNumeric type trait.
Header file for all adaptor forward declarations.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a symmetric matrix type, a compilation error is created.
Definition: Symmetric.h:116
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2506
Header file for run time assertion macros.
Constraint on the data type.
Constraint on the data type.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_LOWER_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a lower triangular matrix type...
Definition: Lower.h:118
#define BLAZE_CONSTRAINT_MUST_NOT_BE_REFERENCE_TYPE(T)
Constraint on the data type.In case the given data type T is not a reference type, a compilation error is created.
Definition: Reference.h:116
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2510
Header file for the isDefault shim.
Constraint on the data type.
Constraint on the data type.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_RESIZABLE(T)
Constraint on the data type.In case the given data type T is resizable, i.e. has a 'resize' member fu...
Definition: Resizable.h:118
void swap(DiagonalMatrix< MT, SO, DF > &a, DiagonalMatrix< MT, SO, DF > &b)
Swapping the contents of two matrices.
Definition: DiagonalMatrix.h:200
BLAZE_ALWAYS_INLINE EnableIf< And< IsIntegral< T >, HasSize< T, 2UL > >, sse_int16_t >::Type set(T value)
Sets all values in the vector to the given 2-byte integral value.
Definition: Set.h:73
Header file for the move shim.
#define BLAZE_CONSTRAINT_MUST_BE_RESIZABLE(T)
Constraint on the data type.In case the given data type T is not resizable, i.e. does not have a 'res...
Definition: Resizable.h:79
Header file for the IsComputation type trait class.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_EXPRESSION_TYPE(T)
Constraint on the data type.In case the given data type T is an expression (i.e. a type derived from ...
Definition: Expression.h:118
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2502
BLAZE_ALWAYS_INLINE size_t columns(const Matrix< MT, SO > &matrix)
Returns the current number of columns of the matrix.
Definition: Matrix.h:332
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2508
Header file for the IsUpper type trait.
#define BLAZE_STATIC_ASSERT(expr)
Compile time assertion macro.In case of an invalid compile time expression, a compilation error is cr...
Definition: StaticAssert.h:143
Header file for the IsResizable type trait.
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_INTERNAL_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERTION flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:101
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a sparse, N-dimensional matrix type...
Definition: SparseMatrix.h:79