Blaze  3.6
Sparse.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_VIEWS_ROWS_SPARSE_H_
36 #define _BLAZE_MATH_VIEWS_ROWS_SPARSE_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <vector>
44 #include <blaze/math/Aliases.h>
57 #include <blaze/math/Exception.h>
78 #include <blaze/math/views/Check.h>
83 #include <blaze/util/Assert.h>
86 #include <blaze/util/MaybeUnused.h>
87 #include <blaze/util/mpl/If.h>
88 #include <blaze/util/TypeList.h>
89 #include <blaze/util/Types.h>
92 
93 
94 namespace blaze {
95 
96 //=================================================================================================
97 //
98 // CLASS TEMPLATE SPECIALIZATION FOR ROW-MAJOR SPARSE MATRICES
99 //
100 //=================================================================================================
101 
102 //*************************************************************************************************
110 template< typename MT // Type of the sparse matrix
111  , bool SF // Symmetry flag
112  , typename... CRAs > // Compile time row arguments
113 class Rows<MT,true,false,SF,CRAs...>
114  : public View< SparseMatrix< Rows<MT,true,false,SF,CRAs...>, false > >
115  , private RowsData<CRAs...>
116 {
117  private:
118  //**Type definitions****************************************************************************
119  using DataType = RowsData<CRAs...>;
120  using Operand = If_t< IsExpression_v<MT>, MT, MT& >;
121  //**********************************************************************************************
122 
123  //**Compile time flags**************************************************************************
124  using DataType::N;
125  //**********************************************************************************************
126 
127  public:
128  //**Type definitions****************************************************************************
130  using This = Rows<MT,true,false,SF,CRAs...>;
131 
132  using BaseType = SparseMatrix<This,false>;
133  using ViewedType = MT;
134  using ResultType = RowsTrait_t<MT,N>;
135  using OppositeType = OppositeType_t<ResultType>;
136  using TransposeType = TransposeType_t<ResultType>;
137  using ElementType = ElementType_t<MT>;
138  using ReturnType = ReturnType_t<MT>;
139  using CompositeType = const Rows&;
140 
142  using ConstReference = ConstReference_t<MT>;
143 
145  using Reference = If_t< IsConst_v<MT>, ConstReference, Reference_t<MT> >;
146 
148  using ConstIterator = ConstIterator_t<MT>;
149 
151  using Iterator = If_t< IsConst_v<MT>, ConstIterator, Iterator_t<MT> >;
152  //**********************************************************************************************
153 
154  //**Compilation flags***************************************************************************
156  static constexpr bool smpAssignable = MT::smpAssignable;
157 
159  static constexpr bool compileTimeArgs = DataType::compileTimeArgs;
160  //**********************************************************************************************
161 
162  //**Constructors********************************************************************************
165  template< typename... RRAs >
166  explicit inline Rows( MT& matrix, RRAs... args );
167 
168  Rows( const Rows& ) = default;
169  Rows( Rows&& ) = default;
171  //**********************************************************************************************
172 
173  //**Destructor**********************************************************************************
176  ~Rows() = default;
178  //**********************************************************************************************
179 
180  //**Data access functions***********************************************************************
183  inline Reference operator()( size_t i, size_t j );
184  inline ConstReference operator()( size_t i, size_t j ) const;
185  inline Reference at( size_t i, size_t j );
186  inline ConstReference at( size_t i, size_t j ) const;
187  inline Iterator begin ( size_t i );
188  inline ConstIterator begin ( size_t i ) const;
189  inline ConstIterator cbegin( size_t i ) const;
190  inline Iterator end ( size_t i );
191  inline ConstIterator end ( size_t i ) const;
192  inline ConstIterator cend ( size_t i ) const;
194  //**********************************************************************************************
195 
196  //**Assignment operators************************************************************************
199  inline Rows& operator=( initializer_list< initializer_list<ElementType> > list );
200  inline Rows& operator=( const Rows& rhs );
201 
202  template< typename MT2, bool SO > inline Rows& operator= ( const Matrix<MT2,SO>& rhs );
203  template< typename MT2, bool SO > inline Rows& operator+=( const Matrix<MT2,SO>& rhs );
204  template< typename MT2, bool SO > inline Rows& operator-=( const Matrix<MT2,SO>& rhs );
205  template< typename MT2, bool SO > inline Rows& operator%=( const Matrix<MT2,SO>& rhs );
207  //**********************************************************************************************
208 
209  //**Utility functions***************************************************************************
212  using DataType::idx;
213  using DataType::idces;
214  using DataType::rows;
215 
216  inline MT& operand() noexcept;
217  inline const MT& operand() const noexcept;
218 
219  inline size_t columns() const noexcept;
220  inline size_t capacity() const noexcept;
221  inline size_t capacity( size_t i ) const noexcept;
222  inline size_t nonZeros() const;
223  inline size_t nonZeros( size_t i ) const;
224  inline void reset();
225  inline void reset( size_t i );
226  inline void reserve( size_t nonzeros );
227  void reserve( size_t i, size_t nonzeros );
228  inline void trim();
229  inline void trim( size_t i );
231  //**********************************************************************************************
232 
233  //**Insertion functions*************************************************************************
236  inline Iterator set ( size_t i, size_t j, const ElementType& value );
237  inline Iterator insert ( size_t i, size_t j, const ElementType& value );
238  inline void append ( size_t i, size_t j, const ElementType& value, bool check=false );
239  inline void finalize( size_t i );
241  //**********************************************************************************************
242 
243  //**Erase functions*****************************************************************************
246  inline void erase( size_t i, size_t j );
247  inline Iterator erase( size_t i, Iterator pos );
248  inline Iterator erase( size_t i, Iterator first, Iterator last );
249 
250  template< typename Pred >
251  inline void erase( Pred predicate );
252 
253  template< typename Pred >
254  inline void erase( size_t i, Iterator first, Iterator last, Pred predicate );
256  //**********************************************************************************************
257 
258  //**Lookup functions****************************************************************************
261  inline Iterator find ( size_t i, size_t j );
262  inline ConstIterator find ( size_t i, size_t j ) const;
263  inline Iterator lowerBound( size_t i, size_t j );
264  inline ConstIterator lowerBound( size_t i, size_t j ) const;
265  inline Iterator upperBound( size_t i, size_t j );
266  inline ConstIterator upperBound( size_t i, size_t j ) const;
268  //**********************************************************************************************
269 
270  //**Numeric functions***************************************************************************
273  inline Rows& transpose();
274  inline Rows& ctranspose();
275 
276  template< typename Other > inline Rows& scale( const Other& scalar );
278  //**********************************************************************************************
279 
280  //**Expression template evaluation functions****************************************************
283  template< typename Other > inline bool canAlias ( const Other* alias ) const noexcept;
284  template< typename Other > inline bool isAliased( const Other* alias ) const noexcept;
285 
286  inline bool canSMPAssign() const noexcept;
287 
288  template< typename MT2, bool SO > inline void assign ( const DenseMatrix<MT2,SO>& rhs );
289  template< typename MT2 > inline void assign ( const SparseMatrix<MT2,false>& rhs );
290  template< typename MT2 > inline void assign ( const SparseMatrix<MT2,true>& rhs );
291  template< typename MT2, bool SO > inline void addAssign ( const Matrix<MT2,SO>& rhs );
292  template< typename MT2, bool SO > inline void subAssign ( const Matrix<MT2,SO>& rhs );
293  template< typename MT2, bool SO > inline void schurAssign( const Matrix<MT2,SO>& rhs );
295  //**********************************************************************************************
296 
297  private:
298  //**Utility functions***************************************************************************
301  inline size_t extendCapacity( size_t i ) const noexcept;
303  //**********************************************************************************************
304 
305  //**Member variables****************************************************************************
308  Operand matrix_;
309 
310  //**********************************************************************************************
311 
312  //**Compile time checks*************************************************************************
321  //**********************************************************************************************
322 };
324 //*************************************************************************************************
325 
326 
327 
328 
329 //=================================================================================================
330 //
331 // CONSTRUCTORS
332 //
333 //=================================================================================================
334 
335 //*************************************************************************************************
348 template< typename MT // Type of the sparse matrix
349  , bool SF // Symmetry flag
350  , typename... CRAs > // Compile time row arguments
351 template< typename... RRAs > // Runtime row arguments
352 inline Rows<MT,true,false,SF,CRAs...>::Rows( MT& matrix, RRAs... args )
353  : DataType( args... ) // Base class initialization
354  , matrix_ ( matrix ) // The matrix containing the rows
355 {
356  if( !Contains_v< TypeList<RRAs...>, Unchecked > ) {
357  for( size_t i=0UL; i<rows(); ++i ) {
358  if( matrix_.rows() <= idx(i) ) {
359  BLAZE_THROW_INVALID_ARGUMENT( "Invalid row access index" );
360  }
361  }
362  }
363 }
365 //*************************************************************************************************
366 
367 
368 
369 
370 //=================================================================================================
371 //
372 // DATA ACCESS FUNCTIONS
373 //
374 //=================================================================================================
375 
376 //*************************************************************************************************
387 template< typename MT // Type of the sparse matrix
388  , bool SF // Symmetry flag
389  , typename... CRAs > // Compile time row arguments
390 inline typename Rows<MT,true,false,SF,CRAs...>::Reference
391  Rows<MT,true,false,SF,CRAs...>::operator()( size_t i, size_t j )
392 {
393  BLAZE_USER_ASSERT( i < rows() , "Invalid row access index" );
394  BLAZE_USER_ASSERT( j < columns(), "Invalid column access index" );
395 
396  return matrix_(idx(i),j);
397 }
399 //*************************************************************************************************
400 
401 
402 //*************************************************************************************************
413 template< typename MT // Type of the sparse matrix
414  , bool SF // Symmetry flag
415  , typename... CRAs > // Compile time row arguments
416 inline typename Rows<MT,true,false,SF,CRAs...>::ConstReference
417  Rows<MT,true,false,SF,CRAs...>::operator()( size_t i, size_t j ) const
418 {
419  BLAZE_USER_ASSERT( i < rows() , "Invalid row access index" );
420  BLAZE_USER_ASSERT( j < columns(), "Invalid column access index" );
421 
422  return const_cast<const MT&>( matrix_ )(idx(i),j);
423 }
425 //*************************************************************************************************
426 
427 
428 //*************************************************************************************************
440 template< typename MT // Type of the sparse matrix
441  , bool SF // Symmetry flag
442  , typename... CRAs > // Compile time row arguments
443 inline typename Rows<MT,true,false,SF,CRAs...>::Reference
444  Rows<MT,true,false,SF,CRAs...>::at( size_t i, size_t j )
445 {
446  if( i >= rows() ) {
447  BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
448  }
449  if( j >= columns() ) {
450  BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
451  }
452  return (*this)(i,j);
453 }
455 //*************************************************************************************************
456 
457 
458 //*************************************************************************************************
470 template< typename MT // Type of the sparse matrix
471  , bool SF // Symmetry flag
472  , typename... CRAs > // Compile time row arguments
473 inline typename Rows<MT,true,false,SF,CRAs...>::ConstReference
474  Rows<MT,true,false,SF,CRAs...>::at( size_t i, size_t j ) const
475 {
476  if( i >= rows() ) {
477  BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
478  }
479  if( j >= columns() ) {
480  BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
481  }
482  return (*this)(i,j);
483 }
485 //*************************************************************************************************
486 
487 
488 //*************************************************************************************************
497 template< typename MT // Type of the sparse matrix
498  , bool SF // Symmetry flag
499  , typename... CRAs > // Compile time row arguments
500 inline typename Rows<MT,true,false,SF,CRAs...>::Iterator
502 {
503  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
504 
505  return matrix_.begin( idx(i) );
506 }
508 //*************************************************************************************************
509 
510 
511 //*************************************************************************************************
520 template< typename MT // Type of the sparse matrix
521  , bool SF // Symmetry flag
522  , typename... CRAs > // Compile time row arguments
523 inline typename Rows<MT,true,false,SF,CRAs...>::ConstIterator
524  Rows<MT,true,false,SF,CRAs...>::begin( size_t i ) const
525 {
526  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
527 
528  return matrix_.cbegin( idx(i) );
529 }
531 //*************************************************************************************************
532 
533 
534 //*************************************************************************************************
543 template< typename MT // Type of the sparse matrix
544  , bool SF // Symmetry flag
545  , typename... CRAs > // Compile time row arguments
546 inline typename Rows<MT,true,false,SF,CRAs...>::ConstIterator
548 {
549  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
550 
551  return matrix_.cbegin( idx(i) );
552 }
554 //*************************************************************************************************
555 
556 
557 //*************************************************************************************************
566 template< typename MT // Type of the sparse matrix
567  , bool SF // Symmetry flag
568  , typename... CRAs > // Compile time row arguments
569 inline typename Rows<MT,true,false,SF,CRAs...>::Iterator
571 {
572  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
573 
574  return matrix_.end( idx(i) );
575 }
577 //*************************************************************************************************
578 
579 
580 //*************************************************************************************************
589 template< typename MT // Type of the sparse matrix
590  , bool SF // Symmetry flag
591  , typename... CRAs > // Compile time row arguments
592 inline typename Rows<MT,true,false,SF,CRAs...>::ConstIterator
593  Rows<MT,true,false,SF,CRAs...>::end( size_t i ) const
594 {
595  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
596 
597  return matrix_.cend( idx(i) );
598 }
600 //*************************************************************************************************
601 
602 
603 //*************************************************************************************************
612 template< typename MT // Type of the sparse matrix
613  , bool SF // Symmetry flag
614  , typename... CRAs > // Compile time row arguments
615 inline typename Rows<MT,true,false,SF,CRAs...>::ConstIterator
616  Rows<MT,true,false,SF,CRAs...>::cend( size_t i ) const
617 {
618  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
619 
620  return matrix_.cend( idx(i) );
621 }
623 //*************************************************************************************************
624 
625 
626 
627 
628 //=================================================================================================
629 //
630 // ASSIGNMENT OPERATORS
631 //
632 //=================================================================================================
633 
634 //*************************************************************************************************
650 template< typename MT // Type of the sparse matrix
651  , bool SF // Symmetry flag
652  , typename... CRAs > // Compile time row arguments
653 inline Rows<MT,true,false,SF,CRAs...>&
654  Rows<MT,true,false,SF,CRAs...>::operator=( initializer_list< initializer_list<ElementType> > list )
655 {
658 
659  if( list.size() != rows() ) {
660  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to row selection" );
661  }
662 
663  const InitializerMatrix<ElementType> tmp( list, columns() );
664 
665  if( IsRestricted_v<MT> ) {
666  for( size_t i=0UL; i<rows(); ++i ) {
667  if( !tryAssign( matrix_, row( tmp, i, unchecked ), i, 0UL ) ) {
668  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
669  }
670  }
671  }
672 
673  decltype(auto) left( derestrict( *this ) );
674 
675  left.reset();
676  smpAssign( left, tmp );
677 
678  return *this;
679 }
681 //*************************************************************************************************
682 
683 
684 //*************************************************************************************************
699 template< typename MT // Type of the sparse matrix
700  , bool SF // Symmetry flag
701  , typename... CRAs > // Compile time row arguments
702 inline Rows<MT,true,false,SF,CRAs...>&
703  Rows<MT,true,false,SF,CRAs...>::operator=( const Rows& rhs )
704 {
707 
710 
711  if( this == &rhs || ( &matrix_ == &rhs.matrix_ && compareIndices( *this, rhs ) ) )
712  return *this;
713 
714  if( rows() != rhs.rows() || columns() != rhs.columns() ) {
715  BLAZE_THROW_INVALID_ARGUMENT( "Matrix sizes do not match" );
716  }
717 
718  if( IsRestricted_v<MT> ) {
719  for( size_t i=0UL; i<rows(); ++i ) {
720  if( !tryAssign( matrix_, row( rhs, i, unchecked ), idx(i), 0UL ) ) {
721  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
722  }
723  }
724  }
725 
726  decltype(auto) left( derestrict( *this ) );
727 
728  if( rhs.canAlias( &matrix_ ) ) {
729  const ResultType tmp( rhs );
730  left.reset();
731  smpAssign( left, tmp );
732  }
733  else {
734  left.reset();
735  smpAssign( left, rhs );
736  }
737 
738  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
739 
740  return *this;
741 }
743 //*************************************************************************************************
744 
745 
746 //*************************************************************************************************
761 template< typename MT // Type of the sparse matrix
762  , bool SF // Symmetry flag
763  , typename... CRAs > // Compile time row arguments
764 template< typename MT2 // Type of the right-hand side matrix
765  , bool SO > // Storage order of the right-hand side matrix
766 inline Rows<MT,true,false,SF,CRAs...>&
767  Rows<MT,true,false,SF,CRAs...>::operator=( const Matrix<MT2,SO>& rhs )
768 {
771 
773 
774  if( rows() != (~rhs).rows() || columns() != (~rhs).columns() ) {
775  BLAZE_THROW_INVALID_ARGUMENT( "Matrix sizes do not match" );
776  }
777 
778  using Right = CompositeType_t<MT2>;
779  Right right( ~rhs );
780 
781  if( IsRestricted_v<MT> ) {
782  for( size_t i=0UL; i<rows(); ++i ) {
783  if( !tryAssign( matrix_, row( right, i, unchecked ), idx(i), 0UL ) ) {
784  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
785  }
786  }
787  }
788 
789  decltype(auto) left( derestrict( *this ) );
790 
791  if( IsReference_v<Right> && right.canAlias( &matrix_ ) ) {
792  const ResultType_t<MT2> tmp( right );
793  left.reset();
794  smpAssign( left, tmp );
795  }
796  else {
797  left.reset();
798  smpAssign( left, right );
799  }
800 
801  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
802 
803  return *this;
804 }
806 //*************************************************************************************************
807 
808 
809 //*************************************************************************************************
823 template< typename MT // Type of the sparse matrix
824  , bool SF // Symmetry flag
825  , typename... CRAs > // Compile time row arguments
826 template< typename MT2 // Type of the right-hand side matrix
827  , bool SO > // Storage order of the right-hand side matrix
828 inline Rows<MT,true,false,SF,CRAs...>&
829  Rows<MT,true,false,SF,CRAs...>::operator+=( const Matrix<MT2,SO>& rhs )
830 {
833 
837 
838  using AddType = AddTrait_t< ResultType, ResultType_t<MT2> >;
839 
841 
842  if( rows() != (~rhs).rows() || columns() != (~rhs).columns() ) {
843  BLAZE_THROW_INVALID_ARGUMENT( "Matrix sizes do not match" );
844  }
845 
846  const AddType tmp( *this + (~rhs) );
847 
848  if( IsRestricted_v<MT> ) {
849  for( size_t i=0UL; i<rows(); ++i ) {
850  if( !tryAssign( matrix_, row( tmp, i, unchecked ), idx(i), 0UL ) ) {
851  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
852  }
853  }
854  }
855 
856  decltype(auto) left( derestrict( *this ) );
857 
858  left.reset();
859  smpAssign( left, tmp );
860 
861  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
862 
863  return *this;
864 }
866 //*************************************************************************************************
867 
868 
869 //*************************************************************************************************
883 template< typename MT // Type of the sparse matrix
884  , bool SF // Symmetry flag
885  , typename... CRAs > // Compile time row arguments
886 template< typename MT2 // Type of the right-hand side matrix
887  , bool SO > // Storage order of the right-hand side matrix
888 inline Rows<MT,true,false,SF,CRAs...>&
889  Rows<MT,true,false,SF,CRAs...>::operator-=( const Matrix<MT2,SO>& rhs )
890 {
893 
897 
898  using SubType = SubTrait_t< ResultType, ResultType_t<MT2> >;
899 
901 
902  if( rows() != (~rhs).rows() || columns() != (~rhs).columns() ) {
903  BLAZE_THROW_INVALID_ARGUMENT( "Matrix sizes do not match" );
904  }
905 
906  const SubType tmp( *this - (~rhs) );
907 
908  if( IsRestricted_v<MT> ) {
909  for( size_t i=0UL; i<rows(); ++i ) {
910  if( !tryAssign( matrix_, row( tmp, i, unchecked ), idx(i), 0UL ) ) {
911  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
912  }
913  }
914  }
915 
916  decltype(auto) left( derestrict( *this ) );
917 
918  left.reset();
919  smpAssign( left, tmp );
920 
921  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
922 
923  return *this;
924 }
926 //*************************************************************************************************
927 
928 
929 //*************************************************************************************************
943 template< typename MT // Type of the sparse matrix
944  , bool SF // Symmetry flag
945  , typename... CRAs > // Compile time row arguments
946 template< typename MT2 // Type of the right-hand side matrix
947  , bool SO > // Storage order of the right-hand side matrix
948 inline Rows<MT,true,false,SF,CRAs...>&
949  Rows<MT,true,false,SF,CRAs...>::operator%=( const Matrix<MT2,SO>& rhs )
950 {
953 
957 
958  using SchurType = SchurTrait_t< ResultType, ResultType_t<MT2> >;
959 
961 
962  if( rows() != (~rhs).rows() || columns() != (~rhs).columns() ) {
963  BLAZE_THROW_INVALID_ARGUMENT( "Matrix sizes do not match" );
964  }
965 
966  const SchurType tmp( *this % (~rhs) );
967 
968  if( IsRestricted_v<MT> ) {
969  for( size_t i=0UL; i<rows(); ++i ) {
970  if( !tryAssign( matrix_, row( tmp, i, unchecked ), idx(i), 0UL ) ) {
971  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
972  }
973  }
974  }
975 
976  decltype(auto) left( derestrict( *this ) );
977 
978  left.reset();
979  smpAssign( left, tmp );
980 
981  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
982 
983  return *this;
984 }
986 //*************************************************************************************************
987 
988 
989 
990 
991 //=================================================================================================
992 //
993 // UTILITY FUNCTIONS
994 //
995 //=================================================================================================
996 
997 //*************************************************************************************************
1003 template< typename MT // Type of the sparse matrix
1004  , bool SF // Symmetry flag
1005  , typename... CRAs > // Compile time row arguments
1006 inline MT& Rows<MT,true,false,SF,CRAs...>::operand() noexcept
1007 {
1008  return matrix_;
1009 }
1011 //*************************************************************************************************
1012 
1013 
1014 //*************************************************************************************************
1020 template< typename MT // Type of the sparse matrix
1021  , bool SF // Symmetry flag
1022  , typename... CRAs > // Compile time row arguments
1023 inline const MT& Rows<MT,true,false,SF,CRAs...>::operand() const noexcept
1024 {
1025  return matrix_;
1026 }
1028 //*************************************************************************************************
1029 
1030 
1031 //*************************************************************************************************
1037 template< typename MT // Type of the sparse matrix
1038  , bool SF // Symmetry flag
1039  , typename... CRAs > // Compile time row arguments
1040 inline size_t Rows<MT,true,false,SF,CRAs...>::columns() const noexcept
1041 {
1042  return matrix_.columns();
1043 }
1045 //*************************************************************************************************
1046 
1047 
1048 //*************************************************************************************************
1054 template< typename MT // Type of the sparse matrix
1055  , bool SF // Symmetry flag
1056  , typename... CRAs > // Compile time row arguments
1057 inline size_t Rows<MT,true,false,SF,CRAs...>::capacity() const noexcept
1058 {
1059  return nonZeros() + matrix_.capacity() - matrix_.nonZeros();
1060 }
1062 //*************************************************************************************************
1063 
1064 
1065 //*************************************************************************************************
1074 template< typename MT // Type of the sparse matrix
1075  , bool SF // Symmetry flag
1076  , typename... CRAs > // Compile time row arguments
1077 inline size_t Rows<MT,true,false,SF,CRAs...>::capacity( size_t i ) const noexcept
1078 {
1079  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
1080 
1081  return matrix_.capacity( idx(i) );
1082 }
1084 //*************************************************************************************************
1085 
1086 
1087 //*************************************************************************************************
1093 template< typename MT // Type of the sparse matrix
1094  , bool SF // Symmetry flag
1095  , typename... CRAs > // Compile time row arguments
1096 inline size_t Rows<MT,true,false,SF,CRAs...>::nonZeros() const
1097 {
1098  size_t nonzeros( 0UL );
1099 
1100  for( size_t i=0UL; i<rows(); ++i )
1101  nonzeros += nonZeros( i );
1102 
1103  return nonzeros;
1104 }
1106 //*************************************************************************************************
1107 
1108 
1109 //*************************************************************************************************
1118 template< typename MT // Type of the sparse matrix
1119  , bool SF // Symmetry flag
1120  , typename... CRAs > // Compile time row arguments
1121 inline size_t Rows<MT,true,false,SF,CRAs...>::nonZeros( size_t i ) const
1122 {
1123  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
1124 
1125  return matrix_.nonZeros( idx(i) );
1126 }
1128 //*************************************************************************************************
1129 
1130 
1131 //*************************************************************************************************
1137 template< typename MT // Type of the sparse matrix
1138  , bool SF // Symmetry flag
1139  , typename... CRAs > // Compile time row arguments
1141 {
1142  for( size_t i=0UL; i<rows(); ++i ) {
1143  matrix_.reset( idx(i) );
1144  }
1145 }
1147 //*************************************************************************************************
1148 
1149 
1150 //*************************************************************************************************
1160 template< typename MT // Type of the sparse matrix
1161  , bool SF // Symmetry flag
1162  , typename... CRAs > // Compile time row arguments
1163 inline void Rows<MT,true,false,SF,CRAs...>::reset( size_t i )
1164 {
1165  matrix_.reset( idx(i) );
1166 }
1168 //*************************************************************************************************
1169 
1170 
1171 //*************************************************************************************************
1182 template< typename MT // Type of the sparse matrix
1183  , bool SF // Symmetry flag
1184  , typename... CRAs > // Compile time row arguments
1185 inline void Rows<MT,true,false,SF,CRAs...>::reserve( size_t nonzeros )
1186 {
1187  const size_t current( capacity() );
1188 
1189  if( nonzeros > current ) {
1190  matrix_.reserve( matrix_.capacity() + nonzeros - current );
1191  }
1192 }
1194 //*************************************************************************************************
1195 
1196 
1197 //*************************************************************************************************
1210 template< typename MT // Type of the sparse matrix
1211  , bool SF // Symmetry flag
1212  , typename... CRAs > // Compile time row arguments
1213 void Rows<MT,true,false,SF,CRAs...>::reserve( size_t i, size_t nonzeros )
1214 {
1215  matrix_.reserve( idx(i), nonzeros );
1216 }
1218 //*************************************************************************************************
1219 
1220 
1221 //*************************************************************************************************
1231 template< typename MT // Type of the sparse matrix
1232  , bool SF // Symmetry flag
1233  , typename... CRAs > // Compile time row arguments
1234 void Rows<MT,true,false,SF,CRAs...>::trim()
1235 {
1236  for( size_t i=0UL; i<rows(); ++i ) {
1237  trim( i );
1238  }
1239 }
1241 //*************************************************************************************************
1242 
1243 
1244 //*************************************************************************************************
1255 template< typename MT // Type of the sparse matrix
1256  , bool SF // Symmetry flag
1257  , typename... CRAs > // Compile time row arguments
1258 void Rows<MT,true,false,SF,CRAs...>::trim( size_t i )
1259 {
1260  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
1261 
1262  matrix_.trim( idx(i) );
1263 }
1265 //*************************************************************************************************
1266 
1267 
1268 //*************************************************************************************************
1278 template< typename MT // Type of the sparse matrix
1279  , bool SF // Symmetry flag
1280  , typename... CRAs > // Compile time row arguments
1281 inline size_t Rows<MT,true,false,SF,CRAs...>::extendCapacity( size_t i ) const noexcept
1282 {
1283  using blaze::max;
1284  using blaze::min;
1285 
1286  size_t nonzeros( 2UL*capacity( i )+1UL );
1287  nonzeros = max( nonzeros, 7UL );
1288  nonzeros = min( nonzeros, columns() );
1289 
1290  BLAZE_INTERNAL_ASSERT( nonzeros > capacity( i ), "Invalid capacity value" );
1291 
1292  return nonzeros;
1293 }
1295 //*************************************************************************************************
1296 
1297 
1298 
1299 
1300 //=================================================================================================
1301 //
1302 // INSERTION FUNCTIONS
1303 //
1304 //=================================================================================================
1305 
1306 //*************************************************************************************************
1319 template< typename MT // Type of the sparse matrix
1320  , bool SF // Symmetry flag
1321  , typename... CRAs > // Compile time row arguments
1322 inline typename Rows<MT,true,false,SF,CRAs...>::Iterator
1323  Rows<MT,true,false,SF,CRAs...>::set( size_t i, size_t j, const ElementType& value )
1324 {
1325  return matrix_.set( idx(i), j, value );
1326 }
1328 //*************************************************************************************************
1329 
1330 
1331 //*************************************************************************************************
1345 template< typename MT // Type of the sparse matrix
1346  , bool SF // Symmetry flag
1347  , typename... CRAs > // Compile time row arguments
1348 inline typename Rows<MT,true,false,SF,CRAs...>::Iterator
1349  Rows<MT,true,false,SF,CRAs...>::insert( size_t i, size_t j, const ElementType& value )
1350 {
1351  return matrix_.insert( idx(i), j, value );
1352 }
1354 //*************************************************************************************************
1355 
1356 
1357 //*************************************************************************************************
1401 template< typename MT // Type of the sparse matrix
1402  , bool SF // Symmetry flag
1403  , typename... CRAs > // Compile time row arguments
1404 inline void Rows<MT,true,false,SF,CRAs...>::append( size_t i, size_t j, const ElementType& value, bool check )
1405 {
1406  if( !check || !isDefault<strict>( value ) )
1407  matrix_.insert( idx(i), j, value );
1408 }
1410 //*************************************************************************************************
1411 
1412 
1413 //*************************************************************************************************
1427 template< typename MT // Type of the sparse matrix
1428  , bool SF // Symmetry flag
1429  , typename... CRAs > // Compile time row arguments
1430 inline void Rows<MT,true,false,SF,CRAs...>::finalize( size_t i )
1431 {
1432  MAYBE_UNUSED( i );
1433 
1434  return;
1435 }
1437 //*************************************************************************************************
1438 
1439 
1440 
1441 
1442 //=================================================================================================
1443 //
1444 // ERASE FUNCTIONS
1445 //
1446 //=================================================================================================
1447 
1448 //*************************************************************************************************
1458 template< typename MT // Type of the sparse matrix
1459  , bool SF // Symmetry flag
1460  , typename... CRAs > // Compile time row arguments
1461 inline void Rows<MT,true,false,SF,CRAs...>::erase( size_t i, size_t j )
1462 {
1463  BLAZE_USER_ASSERT( i < rows() , "Invalid row access index" );
1464  BLAZE_USER_ASSERT( j < columns(), "Invalid column access index" );
1465 
1466  matrix_.erase( idx(i), j );
1467 }
1469 //*************************************************************************************************
1470 
1471 
1472 //*************************************************************************************************
1482 template< typename MT // Type of the sparse matrix
1483  , bool SF // Symmetry flag
1484  , typename... CRAs > // Compile time row arguments
1485 inline typename Rows<MT,true,false,SF,CRAs...>::Iterator
1486  Rows<MT,true,false,SF,CRAs...>::erase( size_t i, Iterator pos )
1487 {
1488  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
1489 
1490  return matrix_.erase( idx(i), pos );
1491 }
1493 //*************************************************************************************************
1494 
1495 
1496 //*************************************************************************************************
1507 template< typename MT // Type of the sparse matrix
1508  , bool SF // Symmetry flag
1509  , typename... CRAs > // Compile time row arguments
1510 inline typename Rows<MT,true,false,SF,CRAs...>::Iterator
1511  Rows<MT,true,false,SF,CRAs...>::erase( size_t i, Iterator first, Iterator last )
1512 {
1513  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
1514 
1515  return matrix_.erase( idx(i), first, last );
1516 }
1518 //*************************************************************************************************
1519 
1520 
1521 //*************************************************************************************************
1544 template< typename MT // Type of the sparse matrix
1545  , bool SF // Symmetry flag
1546  , typename... CRAs > // Compile time row arguments
1547 template< typename Pred > // Type of the unary predicate
1548 inline void Rows<MT,true,false,SF,CRAs...>::erase( Pred predicate )
1549 {
1550  for( size_t i=0UL; i<rows(); ++i ) {
1551  matrix_.erase( idx(i), begin(i), end(i), predicate );
1552  }
1553 }
1555 //*************************************************************************************************
1556 
1557 
1558 //*************************************************************************************************
1585 template< typename MT // Type of the sparse matrix
1586  , bool SF // Symmetry flag
1587  , typename... CRAs > // Compile time row arguments
1588 template< typename Pred > // Type of the unary predicate
1589 inline void Rows<MT,true,false,SF,CRAs...>::erase( size_t i, Iterator first, Iterator last, Pred predicate )
1590 {
1591  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
1592 
1593  matrix_.erase( idx(i), first, last, predicate );
1594 }
1596 //*************************************************************************************************
1597 
1598 
1599 
1600 
1601 //=================================================================================================
1602 //
1603 // LOOKUP FUNCTIONS
1604 //
1605 //=================================================================================================
1606 
1607 //*************************************************************************************************
1622 template< typename MT // Type of the sparse matrix
1623  , bool SF // Symmetry flag
1624  , typename... CRAs > // Compile time row arguments
1625 inline typename Rows<MT,true,false,SF,CRAs...>::Iterator
1626  Rows<MT,true,false,SF,CRAs...>::find( size_t i, size_t j )
1627 {
1628  return matrix_.find( idx(i), j );
1629 }
1631 //*************************************************************************************************
1632 
1633 
1634 //*************************************************************************************************
1649 template< typename MT // Type of the sparse matrix
1650  , bool SF // Symmetry flag
1651  , typename... CRAs > // Compile time row arguments
1652 inline typename Rows<MT,true,false,SF,CRAs...>::ConstIterator
1653  Rows<MT,true,false,SF,CRAs...>::find( size_t i, size_t j ) const
1654 {
1655  return matrix_.find( idx(i), j );
1656 }
1658 //*************************************************************************************************
1659 
1660 
1661 //*************************************************************************************************
1675 template< typename MT // Type of the sparse matrix
1676  , bool SF // Symmetry flag
1677  , typename... CRAs > // Compile time row arguments
1678 inline typename Rows<MT,true,false,SF,CRAs...>::Iterator
1679  Rows<MT,true,false,SF,CRAs...>::lowerBound( size_t i, size_t j )
1680 {
1681  return matrix_.lowerBound( idx(i), j );
1682 }
1684 //*************************************************************************************************
1685 
1686 
1687 //*************************************************************************************************
1701 template< typename MT // Type of the sparse matrix
1702  , bool SF // Symmetry flag
1703  , typename... CRAs > // Compile time row arguments
1704 inline typename Rows<MT,true,false,SF,CRAs...>::ConstIterator
1705  Rows<MT,true,false,SF,CRAs...>::lowerBound( size_t i, size_t j ) const
1706 {
1707  return matrix_.lowerBound( idx(i), j );
1708 }
1710 //*************************************************************************************************
1711 
1712 
1713 //*************************************************************************************************
1727 template< typename MT // Type of the sparse matrix
1728  , bool SF // Symmetry flag
1729  , typename... CRAs > // Compile time row arguments
1730 inline typename Rows<MT,true,false,SF,CRAs...>::Iterator
1731  Rows<MT,true,false,SF,CRAs...>::upperBound( size_t i, size_t j )
1732 {
1733  return matrix_.upperBound( idx(i), j );
1734 }
1736 //*************************************************************************************************
1737 
1738 
1739 //*************************************************************************************************
1753 template< typename MT // Type of the sparse matrix
1754  , bool SF // Symmetry flag
1755  , typename... CRAs > // Compile time row arguments
1756 inline typename Rows<MT,true,false,SF,CRAs...>::ConstIterator
1757  Rows<MT,true,false,SF,CRAs...>::upperBound( size_t i, size_t j ) const
1758 {
1759  return matrix_.upperBound( idx(i), j );
1760 }
1762 //*************************************************************************************************
1763 
1764 
1765 
1766 
1767 //=================================================================================================
1768 //
1769 // NUMERIC FUNCTIONS
1770 //
1771 //=================================================================================================
1772 
1773 //*************************************************************************************************
1786 template< typename MT // Type of the sparse matrix
1787  , bool SF // Symmetry flag
1788  , typename... CRAs > // Compile time row arguments
1789 inline Rows<MT,true,false,SF,CRAs...>&
1791 {
1794 
1795  if( rows() != columns() ) {
1796  BLAZE_THROW_LOGIC_ERROR( "Invalid transpose of a non-quadratic matrix" );
1797  }
1798 
1799  const ResultType tmp( trans( *this ) );
1800 
1801  if( IsRestricted_v<MT> ) {
1802  for( size_t i=0UL; i<rows(); ++i ) {
1803  if( !tryAssign( matrix_, row( tmp, i, unchecked ), idx(i), 0UL ) ) {
1804  BLAZE_THROW_LOGIC_ERROR( "Invalid transpose operation" );
1805  }
1806  }
1807  }
1808 
1809  decltype(auto) left( derestrict( *this ) );
1810 
1811  left.reset();
1812  smpAssign( left, tmp );
1813 
1814  return *this;
1815 }
1817 //*************************************************************************************************
1818 
1819 
1820 //*************************************************************************************************
1833 template< typename MT // Type of the sparse matrix
1834  , bool SF // Symmetry flag
1835  , typename... CRAs > // Compile time row arguments
1836 inline Rows<MT,true,false,SF,CRAs...>&
1837  Rows<MT,true,false,SF,CRAs...>::ctranspose()
1838 {
1841 
1842  if( rows() != columns() ) {
1843  BLAZE_THROW_LOGIC_ERROR( "Invalid transpose of a non-quadratic matrix" );
1844  }
1845 
1846  const ResultType tmp( ctrans( *this ) );
1847 
1848  if( IsRestricted_v<MT> ) {
1849  for( size_t i=0UL; i<rows(); ++i ) {
1850  if( !tryAssign( matrix_, row( tmp, i, unchecked ), idx(i), 0UL ) ) {
1851  BLAZE_THROW_LOGIC_ERROR( "Invalid transpose operation" );
1852  }
1853  }
1854  }
1855 
1856  decltype(auto) left( derestrict( *this ) );
1857 
1858  left.reset();
1859  smpAssign( left, tmp );
1860 
1861  return *this;
1862 }
1864 //*************************************************************************************************
1865 
1866 
1867 //*************************************************************************************************
1880 template< typename MT // Type of the sparse matrix
1881  , bool SF // Symmetry flag
1882  , typename... CRAs > // Compile time row arguments
1883 template< typename Other > // Data type of the scalar value
1884 inline Rows<MT,true,false,SF,CRAs...>&
1885  Rows<MT,true,false,SF,CRAs...>::scale( const Other& scalar )
1886 {
1890 
1891  for( size_t i=0UL; i<rows(); ++i ) {
1892  const Iterator last( end(i) );
1893  for( Iterator element=begin(i); element!=last; ++element )
1894  element->value() *= scalar;
1895  }
1896 
1897  return *this;
1898 }
1900 //*************************************************************************************************
1901 
1902 
1903 
1904 
1905 //=================================================================================================
1906 //
1907 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1908 //
1909 //=================================================================================================
1910 
1911 //*************************************************************************************************
1922 template< typename MT // Type of the sparse matrix
1923  , bool SF // Symmetry flag
1924  , typename... CRAs > // Compile time row arguments
1925 template< typename Other > // Data type of the foreign expression
1926 inline bool Rows<MT,true,false,SF,CRAs...>::canAlias( const Other* alias ) const noexcept
1927 {
1928  return matrix_.isAliased( alias );
1929 }
1931 //*************************************************************************************************
1932 
1933 
1934 //*************************************************************************************************
1945 template< typename MT // Type of the sparse matrix
1946  , bool SF // Symmetry flag
1947  , typename... CRAs > // Compile time row arguments
1948 template< typename Other > // Data type of the foreign expression
1949 inline bool Rows<MT,true,false,SF,CRAs...>::isAliased( const Other* alias ) const noexcept
1950 {
1951  return matrix_.isAliased( alias );
1952 }
1954 //*************************************************************************************************
1955 
1956 
1957 //*************************************************************************************************
1968 template< typename MT // Type of the sparse matrix
1969  , bool SF // Symmetry flag
1970  , typename... CRAs > // Compile time row arguments
1971 inline bool Rows<MT,true,false,SF,CRAs...>::canSMPAssign() const noexcept
1972 {
1973  return false;
1974 }
1976 //*************************************************************************************************
1977 
1978 
1979 //*************************************************************************************************
1991 template< typename MT // Type of the sparse matrix
1992  , bool SF // Symmetry flag
1993  , typename... CRAs > // Compile time row arguments
1994 template< typename MT2 // Type of the right-hand side dense matrix
1995  , bool SO > // Storage order of the right-hand side dense matrix
1996 inline void Rows<MT,true,false,SF,CRAs...>::assign( const DenseMatrix<MT2,SO>& rhs )
1997 {
2000 
2001  BLAZE_INTERNAL_ASSERT( rows() == (~rhs).rows() , "Invalid number of rows" );
2002  BLAZE_INTERNAL_ASSERT( columns() == (~rhs).columns(), "Invalid number of columns" );
2003  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
2004 
2005  for( size_t i=0UL; i<rows(); ++i )
2006  {
2007  const size_t index( idx(i) );
2008  size_t remaining( matrix_.capacity( index ) );
2009 
2010  for( size_t j=0UL; j<columns(); ++j )
2011  {
2012  if( remaining == 0UL ) {
2013  matrix_.reserve( index, extendCapacity( i ) );
2014  remaining = matrix_.capacity( index ) - matrix_.nonZeros( index );
2015  }
2016 
2017  matrix_.append( index, j, (~rhs)(i,j), true );
2018  --remaining;
2019  }
2020  }
2021 }
2023 //*************************************************************************************************
2024 
2025 
2026 //*************************************************************************************************
2038 template< typename MT // Type of the sparse matrix
2039  , bool SF // Symmetry flag
2040  , typename... CRAs > // Compile time row arguments
2041 template< typename MT2 > // Type of the right-hand side sparse matrix
2042 inline void Rows<MT,true,false,SF,CRAs...>::assign( const SparseMatrix<MT2,false>& rhs )
2043 {
2046 
2047  BLAZE_INTERNAL_ASSERT( rows() == (~rhs).rows() , "Invalid number of rows" );
2048  BLAZE_INTERNAL_ASSERT( columns() == (~rhs).columns(), "Invalid number of columns" );
2049  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
2050 
2051  for( size_t i=0UL; i<rows(); ++i )
2052  {
2053  const size_t index( idx(i) );
2054  size_t remaining( matrix_.capacity( index ) );
2055 
2056  for( ConstIterator_t<MT2> element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
2057  {
2058  if( remaining == 0UL ) {
2059  matrix_.reserve( index, extendCapacity( i ) );
2060  remaining = matrix_.capacity( index ) - matrix_.nonZeros( index );
2061  }
2062 
2063  matrix_.append( index, element->index(), element->value(), true );
2064  --remaining;
2065  }
2066  }
2067 }
2069 //*************************************************************************************************
2070 
2071 
2072 //*************************************************************************************************
2084 template< typename MT // Type of the sparse matrix
2085  , bool SF // Symmetry flag
2086  , typename... CRAs > // Compile time row arguments
2087 template< typename MT2 > // Type of the right-hand side sparse matrix
2088 inline void Rows<MT,true,false,SF,CRAs...>::assign( const SparseMatrix<MT2,true>& rhs )
2089 {
2092 
2094 
2095  BLAZE_INTERNAL_ASSERT( rows() == (~rhs).rows() , "Invalid number of rows" );
2096  BLAZE_INTERNAL_ASSERT( columns() == (~rhs).columns(), "Invalid number of columns" );
2097  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
2098 
2099  // Counting the number of elements per row
2100  std::vector<size_t> rowLengths( rows(), 0UL );
2101  for( size_t j=0UL; j<columns(); ++j ) {
2102  for( auto element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
2103  ++rowLengths[element->index()];
2104  }
2105 
2106  // Resizing the sparse matrix
2107  for( size_t i=0UL; i<rows(); ++i ) {
2108  reserve( i, rowLengths[i] );
2109  }
2110 
2111  // Appending the elements to the rows of the sparse row selection
2112  for( size_t j=0UL; j<columns(); ++j ) {
2113  for( auto element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
2114  append( element->index(), j, element->value(), true );
2115  }
2116 }
2118 //*************************************************************************************************
2119 
2120 
2121 //*************************************************************************************************
2133 template< typename MT // Type of the sparse matrix
2134  , bool SF // Symmetry flag
2135  , typename... CRAs > // Compile time row arguments
2136 template< typename MT2 // Type of the right-hand side matrix
2137  , bool SO > // Storage order of the right-hand side matrix
2138 inline void Rows<MT,true,false,SF,CRAs...>::addAssign( const Matrix<MT2,SO>& rhs )
2139 {
2142 
2143  using AddType = AddTrait_t< ResultType, ResultType_t<MT2> >;
2144 
2146 
2147  BLAZE_INTERNAL_ASSERT( rows() == (~rhs).rows() , "Invalid number of rows" );
2148  BLAZE_INTERNAL_ASSERT( columns() == (~rhs).columns(), "Invalid number of columns" );
2149 
2150  const AddType tmp( serial( *this + (~rhs) ) );
2151  reset();
2152  assign( tmp );
2153 }
2155 //*************************************************************************************************
2156 
2157 
2158 //*************************************************************************************************
2170 template< typename MT // Type of the sparse matrix
2171  , bool SF // Symmetry flag
2172  , typename... CRAs > // Compile time row arguments
2173 template< typename MT2 // Type of the right-hand side matrix
2174  , bool SO > // Storage order of the right-hand side matrix
2175 inline void Rows<MT,true,false,SF,CRAs...>::subAssign( const Matrix<MT2,SO>& rhs )
2176 {
2179 
2180  using SubType = SubTrait_t< ResultType, ResultType_t<MT2> >;
2181 
2183 
2184  BLAZE_INTERNAL_ASSERT( rows() == (~rhs).rows() , "Invalid number of rows" );
2185  BLAZE_INTERNAL_ASSERT( columns() == (~rhs).columns(), "Invalid number of columns" );
2186 
2187  const SubType tmp( serial( *this - (~rhs) ) );
2188  reset();
2189  assign( tmp );
2190 }
2192 //*************************************************************************************************
2193 
2194 
2195 //*************************************************************************************************
2207 template< typename MT // Type of the sparse matrix
2208  , bool SF // Symmetry flag
2209  , typename... CRAs > // Compile time row arguments
2210 template< typename MT2 // Type of the right-hand side matrix
2211  , bool SO > // Storage order of the right-hand side matrix
2212 inline void Rows<MT,true,false,SF,CRAs...>::schurAssign( const Matrix<MT2,SO>& rhs )
2213 {
2216 
2217  using SchurType = SchurTrait_t< ResultType, ResultType_t<MT2> >;
2218 
2221 
2222  BLAZE_INTERNAL_ASSERT( rows() == (~rhs).rows() , "Invalid number of rows" );
2223  BLAZE_INTERNAL_ASSERT( columns() == (~rhs).columns(), "Invalid number of columns" );
2224 
2225  const SchurType tmp( serial( *this % (~rhs) ) );
2226  reset();
2227  assign( tmp );
2228 }
2230 //*************************************************************************************************
2231 
2232 
2233 
2234 
2235 
2236 
2237 
2238 
2239 //=================================================================================================
2240 //
2241 // CLASS TEMPLATE SPECIALIZATION FOR GENERAL COLUMN-MAJOR SPARSE MATRICES
2242 //
2243 //=================================================================================================
2244 
2245 //*************************************************************************************************
2253 template< typename MT // Type of the sparse matrix
2254  , typename... CRAs > // Compile time row arguments
2255 class Rows<MT,false,false,false,CRAs...>
2256  : public View< SparseMatrix< Rows<MT,false,false,false,CRAs...>, false > >
2257  , private RowsData<CRAs...>
2258 {
2259  private:
2260  //**Type definitions****************************************************************************
2261  using DataType = RowsData<CRAs...>;
2262  using Operand = If_t< IsExpression_v<MT>, MT, MT& >;
2263  //**********************************************************************************************
2264 
2265  //**Compile time flags**************************************************************************
2266  using DataType::N;
2267  //**********************************************************************************************
2268 
2269  public:
2270  //**Type definitions****************************************************************************
2272  using This = Rows<MT,false,false,false,CRAs...>;
2273 
2274  using BaseType = SparseMatrix<This,false>;
2275  using ViewedType = MT;
2276  using ResultType = RowsTrait_t<MT,N>;
2277  using OppositeType = OppositeType_t<ResultType>;
2278  using TransposeType = TransposeType_t<ResultType>;
2279  using ElementType = ElementType_t<MT>;
2280  using ReturnType = ReturnType_t<MT>;
2281  using CompositeType = const Rows&;
2282 
2284  using ConstReference = ConstReference_t<MT>;
2285 
2287  using Reference = If_t< IsConst_v<MT>, ConstReference, Reference_t<MT> >;
2288  //**********************************************************************************************
2289 
2290  //**RowsElement class definition****************************************************************
2293  template< typename MatrixType // Type of the sparse matrix
2294  , typename IteratorType > // Type of the sparse matrix iterator
2295  class RowsElement
2296  : private SparseElement
2297  {
2298  public:
2299  //**Constructor******************************************************************************
2305  inline RowsElement( IteratorType pos, size_t column )
2306  : pos_ ( pos ) // Iterator to the current position of the sparse row element
2307  , column_( column ) // Index of the according column
2308  {}
2309  //*******************************************************************************************
2310 
2311  //**Assignment operator**********************************************************************
2317  template< typename T > inline RowsElement& operator=( const T& v ) {
2318  *pos_ = v;
2319  return *this;
2320  }
2321  //*******************************************************************************************
2322 
2323  //**Addition assignment operator*************************************************************
2329  template< typename T > inline RowsElement& operator+=( const T& v ) {
2330  *pos_ += v;
2331  return *this;
2332  }
2333  //*******************************************************************************************
2334 
2335  //**Subtraction assignment operator**********************************************************
2341  template< typename T > inline RowsElement& operator-=( const T& v ) {
2342  *pos_ -= v;
2343  return *this;
2344  }
2345  //*******************************************************************************************
2346 
2347  //**Multiplication assignment operator*******************************************************
2353  template< typename T > inline RowsElement& operator*=( const T& v ) {
2354  *pos_ *= v;
2355  return *this;
2356  }
2357  //*******************************************************************************************
2358 
2359  //**Division assignment operator*************************************************************
2365  template< typename T > inline RowsElement& operator/=( const T& v ) {
2366  *pos_ /= v;
2367  return *this;
2368  }
2369  //*******************************************************************************************
2370 
2371  //**Element access operator******************************************************************
2376  inline const RowsElement* operator->() const {
2377  return this;
2378  }
2379  //*******************************************************************************************
2380 
2381  //**Value function***************************************************************************
2386  inline decltype(auto) value() const {
2387  return pos_->value();
2388  }
2389  //*******************************************************************************************
2390 
2391  //**Index function***************************************************************************
2396  inline size_t index() const {
2397  return column_;
2398  }
2399  //*******************************************************************************************
2400 
2401  private:
2402  //**Member variables*************************************************************************
2403  IteratorType pos_;
2404  size_t column_;
2405  //*******************************************************************************************
2406  };
2407  //**********************************************************************************************
2408 
2409  //**RowsIterator class definition***************************************************************
2412  template< typename MatrixType // Type of the sparse matrix
2413  , typename IteratorType > // Type of the sparse matrix iterator
2414  class RowsIterator
2415  {
2416  public:
2417  //**Type definitions*************************************************************************
2418  using IteratorCategory = std::forward_iterator_tag;
2419  using ValueType = RowsElement<MatrixType,IteratorType>;
2420  using PointerType = ValueType;
2421  using ReferenceType = ValueType;
2422  using DifferenceType = ptrdiff_t;
2423 
2424  // STL iterator requirements
2425  using iterator_category = IteratorCategory;
2426  using value_type = ValueType;
2427  using pointer = PointerType;
2428  using reference = ReferenceType;
2429  using difference_type = DifferenceType;
2430  //*******************************************************************************************
2431 
2432  //**Constructor******************************************************************************
2435  inline RowsIterator()
2436  : matrix_( nullptr ) // The sparse matrix containing the selected row
2437  , row_ ( 0UL ) // The current row index
2438  , column_( 0UL ) // The current column index
2439  , pos_ () // Iterator to the current sparse element
2440  {}
2441  //*******************************************************************************************
2442 
2443  //**Constructor******************************************************************************
2450  inline RowsIterator( MatrixType& matrix, size_t row, size_t column )
2451  : matrix_( &matrix ) // The sparse matrix containing the selected row
2452  , row_ ( row ) // The current row index
2453  , column_( column ) // The current column index
2454  , pos_ () // Iterator to the current sparse element
2455  {
2456  for( ; column_<matrix_->columns(); ++column_ ) {
2457  pos_ = matrix_->find( row_, column_ );
2458  if( pos_ != matrix_->end( column_ ) ) break;
2459  }
2460  }
2461  //*******************************************************************************************
2462 
2463  //**Constructor******************************************************************************
2471  inline RowsIterator( MatrixType& matrix, size_t row, size_t column, IteratorType pos )
2472  : matrix_( &matrix ) // The sparse matrix containing the selected row
2473  , row_ ( row ) // The current row index
2474  , column_( column ) // The current column index
2475  , pos_ ( pos ) // Iterator to the current sparse element
2476  {
2477  BLAZE_INTERNAL_ASSERT( matrix.find( row, column ) == pos, "Invalid initial iterator position" );
2478  }
2479  //*******************************************************************************************
2480 
2481  //**Constructor******************************************************************************
2486  template< typename MatrixType2, typename IteratorType2 >
2487  inline RowsIterator( const RowsIterator<MatrixType2,IteratorType2>& it )
2488  : matrix_( it.matrix_ ) // The sparse matrix containing the selected row
2489  , row_ ( it.row_ ) // The current row index
2490  , column_( it.column_ ) // The current column index
2491  , pos_ ( it.pos_ ) // Iterator to the current sparse element
2492  {}
2493  //*******************************************************************************************
2494 
2495  //**Prefix increment operator****************************************************************
2500  inline RowsIterator& operator++() {
2501  ++column_;
2502  for( ; column_<matrix_->columns(); ++column_ ) {
2503  pos_ = matrix_->find( row_, column_ );
2504  if( pos_ != matrix_->end( column_ ) ) break;
2505  }
2506 
2507  return *this;
2508  }
2509  //*******************************************************************************************
2510 
2511  //**Postfix increment operator***************************************************************
2516  inline const RowsIterator operator++( int ) {
2517  const RowsIterator tmp( *this );
2518  ++(*this);
2519  return tmp;
2520  }
2521  //*******************************************************************************************
2522 
2523  //**Element access operator******************************************************************
2528  inline ReferenceType operator*() const {
2529  return ReferenceType( pos_, column_ );
2530  }
2531  //*******************************************************************************************
2532 
2533  //**Element access operator******************************************************************
2538  inline PointerType operator->() const {
2539  return PointerType( pos_, column_ );
2540  }
2541  //*******************************************************************************************
2542 
2543  //**Equality operator************************************************************************
2549  template< typename MatrixType2, typename IteratorType2 >
2550  inline bool operator==( const RowsIterator<MatrixType2,IteratorType2>& rhs ) const noexcept {
2551  return column_ == rhs.column_;
2552  }
2553  //*******************************************************************************************
2554 
2555  //**Inequality operator**********************************************************************
2561  template< typename MatrixType2, typename IteratorType2 >
2562  inline bool operator!=( const RowsIterator<MatrixType2,IteratorType2>& rhs ) const noexcept {
2563  return !( *this == rhs );
2564  }
2565  //*******************************************************************************************
2566 
2567  //**Subtraction operator*********************************************************************
2573  inline DifferenceType operator-( const RowsIterator& rhs ) const {
2574  size_t counter( 0UL );
2575  for( size_t j=rhs.column_; j<column_; ++j ) {
2576  if( matrix_->find( row_, j ) != matrix_->end( j ) )
2577  ++counter;
2578  }
2579  return counter;
2580  }
2581  //*******************************************************************************************
2582 
2583  private:
2584  //**Member variables*************************************************************************
2585  MatrixType* matrix_;
2586  size_t row_;
2587  size_t column_;
2588  IteratorType pos_;
2589  //*******************************************************************************************
2590 
2591  //**Friend declarations**********************************************************************
2592  template< typename MatrixType2, typename IteratorType2 > friend class RowsIterator;
2593  template< typename MT2, bool SO2, bool DF2, bool SF2, typename... CRAs2 > friend class Rows;
2594  //*******************************************************************************************
2595  };
2596  //**********************************************************************************************
2597 
2598  //**Type definitions****************************************************************************
2600  using ConstIterator = RowsIterator< const MT, ConstIterator_t<MT> >;
2601 
2603  using Iterator = If_t< IsConst_v<MT>, ConstIterator, RowsIterator< MT, Iterator_t<MT> > >;
2604  //**********************************************************************************************
2605 
2606  //**Compilation flags***************************************************************************
2608  static constexpr bool smpAssignable = MT::smpAssignable;
2609 
2611  static constexpr bool compileTimeArgs = DataType::compileTimeArgs;
2612  //**********************************************************************************************
2613 
2614  //**Constructors********************************************************************************
2617  template< typename... RRAs >
2618  explicit inline Rows( MT& matrix, RRAs... args );
2619 
2620  Rows( const Rows& ) = default;
2621  Rows( Rows&& ) = default;
2623  //**********************************************************************************************
2624 
2625  //**Destructor**********************************************************************************
2628  ~Rows() = default;
2630  //**********************************************************************************************
2631 
2632  //**Data access functions***********************************************************************
2635  inline Reference operator()( size_t i, size_t j );
2636  inline ConstReference operator()( size_t i, size_t j ) const;
2637  inline Reference at( size_t i, size_t j );
2638  inline ConstReference at( size_t i, size_t j ) const;
2639  inline Iterator begin ( size_t i );
2640  inline ConstIterator begin ( size_t i ) const;
2641  inline ConstIterator cbegin( size_t i ) const;
2642  inline Iterator end ( size_t i );
2643  inline ConstIterator end ( size_t i ) const;
2644  inline ConstIterator cend ( size_t i ) const;
2646  //**********************************************************************************************
2647 
2648  //**Assignment operators************************************************************************
2651  inline Rows& operator=( initializer_list< initializer_list<ElementType> > list );
2652  inline Rows& operator=( const Rows& rhs );
2653 
2654  template< typename MT2, bool SO > inline Rows& operator= ( const Matrix<MT2,SO>& rhs );
2655  template< typename MT2, bool SO > inline Rows& operator+=( const Matrix<MT2,SO>& rhs );
2656  template< typename MT2, bool SO > inline Rows& operator-=( const Matrix<MT2,SO>& rhs );
2657  template< typename MT2, bool SO > inline Rows& operator%=( const Matrix<MT2,SO>& rhs );
2659  //**********************************************************************************************
2660 
2661  //**Utility functions***************************************************************************
2664  using DataType::idx;
2665  using DataType::idces;
2666  using DataType::rows;
2667 
2668  inline MT& operand() noexcept;
2669  inline const MT& operand() const noexcept;
2670 
2671  inline size_t columns() const noexcept;
2672  inline size_t capacity() const noexcept;
2673  inline size_t capacity( size_t i ) const noexcept;
2674  inline size_t nonZeros() const;
2675  inline size_t nonZeros( size_t i ) const;
2676  inline void reset();
2677  inline void reset( size_t i );
2678  inline void reserve( size_t nonzeros );
2679  void reserve( size_t i, size_t nonzeros );
2680  inline void trim();
2681  inline void trim( size_t j );
2683  //**********************************************************************************************
2684 
2685  //**Insertion functions*************************************************************************
2688  inline Iterator set ( size_t i, size_t j, const ElementType& value );
2689  inline Iterator insert ( size_t i, size_t j, const ElementType& value );
2690  inline void append ( size_t i, size_t j, const ElementType& value, bool check=false );
2691  inline void finalize( size_t i );
2693  //**********************************************************************************************
2694 
2695  //**Erase functions*****************************************************************************
2698  inline void erase( size_t i, size_t j );
2699  inline Iterator erase( size_t i, Iterator pos );
2700  inline Iterator erase( size_t i, Iterator first, Iterator last );
2701 
2702  template< typename Pred >
2703  inline void erase( Pred predicate );
2704 
2705  template< typename Pred >
2706  inline void erase( size_t i, Iterator first, Iterator last, Pred predicate );
2708  //**********************************************************************************************
2709 
2710  //**Lookup functions****************************************************************************
2713  inline Iterator find ( size_t i, size_t j );
2714  inline ConstIterator find ( size_t i, size_t j ) const;
2715  inline Iterator lowerBound( size_t i, size_t j );
2716  inline ConstIterator lowerBound( size_t i, size_t j ) const;
2717  inline Iterator upperBound( size_t i, size_t j );
2718  inline ConstIterator upperBound( size_t i, size_t j ) const;
2720  //**********************************************************************************************
2721 
2722  //**Numeric functions***************************************************************************
2725  inline Rows& transpose();
2726  inline Rows& ctranspose();
2727 
2728  template< typename Other > inline Rows& scale( const Other& scalar );
2730  //**********************************************************************************************
2731 
2732  //**Expression template evaluation functions****************************************************
2735  template< typename Other > inline bool canAlias ( const Other* alias ) const noexcept;
2736  template< typename Other > inline bool isAliased( const Other* alias ) const noexcept;
2737 
2738  inline bool canSMPAssign() const noexcept;
2739 
2740  template< typename MT2, bool SO > inline void assign ( const DenseMatrix<MT2,SO>& rhs );
2741  template< typename MT2 > inline void assign ( const SparseMatrix<MT2,true>& rhs );
2742  template< typename MT2 > inline void assign ( const SparseMatrix<MT2,false>& rhs );
2743  template< typename MT2, bool SO > inline void addAssign ( const Matrix<MT2,SO>& rhs );
2744  template< typename MT2, bool SO > inline void subAssign ( const Matrix<MT2,SO>& rhs );
2745  template< typename MT2, bool SO > inline void schurAssign( const Matrix<MT2,SO>& rhs );
2747  //**********************************************************************************************
2748 
2749  private:
2750  //**Member variables****************************************************************************
2753  Operand matrix_;
2754 
2755  //**********************************************************************************************
2756 
2757  //**Compile time checks*************************************************************************
2767  //**********************************************************************************************
2768 };
2770 //*************************************************************************************************
2771 
2772 
2773 
2774 
2775 //=================================================================================================
2776 //
2777 // CONSTRUCTORS
2778 //
2779 //=================================================================================================
2780 
2781 //*************************************************************************************************
2794 template< typename MT // Type of the sparse matrix
2795  , typename... CRAs > // Compile time row arguments
2796 template< typename... RRAs > // Runtime row arguments
2797 inline Rows<MT,false,false,false,CRAs...>::Rows( MT& matrix, RRAs... args )
2798  : DataType( args... ) // Base class initialization
2799  , matrix_ ( matrix ) // The matrix containing the rows
2800 {
2801  if( !Contains_v< TypeList<RRAs...>, Unchecked > ) {
2802  for( size_t i=0UL; i<rows(); ++i ) {
2803  if( matrix_.rows() <= idx(i) ) {
2804  BLAZE_THROW_INVALID_ARGUMENT( "Invalid row access index" );
2805  }
2806  }
2807  }
2808 }
2810 //*************************************************************************************************
2811 
2812 
2813 
2814 
2815 //=================================================================================================
2816 //
2817 // DATA ACCESS FUNCTIONS
2818 //
2819 //=================================================================================================
2820 
2821 //*************************************************************************************************
2832 template< typename MT // Type of the sparse matrix
2833  , typename... CRAs > // Compile time row arguments
2834 inline typename Rows<MT,false,false,false,CRAs...>::Reference
2835  Rows<MT,false,false,false,CRAs...>::operator()( size_t i, size_t j )
2836 {
2837  BLAZE_USER_ASSERT( i < rows() , "Invalid row access index" );
2838  BLAZE_USER_ASSERT( j < columns(), "Invalid column access index" );
2839 
2840  return matrix_(idx(i),j);
2841 }
2843 //*************************************************************************************************
2844 
2845 
2846 //*************************************************************************************************
2857 template< typename MT // Type of the sparse matrix
2858  , typename... CRAs > // Compile time row arguments
2859 inline typename Rows<MT,false,false,false,CRAs...>::ConstReference
2860  Rows<MT,false,false,false,CRAs...>::operator()( size_t i, size_t j ) const
2861 {
2862  BLAZE_USER_ASSERT( i < rows() , "Invalid row access index" );
2863  BLAZE_USER_ASSERT( j < columns(), "Invalid column access index" );
2864 
2865  return const_cast<const MT&>( matrix_ )(idx(i),j);
2866 }
2868 //*************************************************************************************************
2869 
2870 
2871 //*************************************************************************************************
2883 template< typename MT // Type of the sparse matrix
2884  , typename... CRAs > // Compile time row arguments
2885 inline typename Rows<MT,false,false,false,CRAs...>::Reference
2886  Rows<MT,false,false,false,CRAs...>::at( size_t i, size_t j )
2887 {
2888  if( i >= rows() ) {
2889  BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
2890  }
2891  if( j >= columns() ) {
2892  BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
2893  }
2894  return (*this)(i,j);
2895 }
2897 //*************************************************************************************************
2898 
2899 
2900 //*************************************************************************************************
2912 template< typename MT // Type of the sparse matrix
2913  , typename... CRAs > // Compile time row arguments
2914 inline typename Rows<MT,false,false,false,CRAs...>::ConstReference
2915  Rows<MT,false,false,false,CRAs...>::at( size_t i, size_t j ) const
2916 {
2917  if( i >= rows() ) {
2918  BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
2919  }
2920  if( j >= columns() ) {
2921  BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
2922  }
2923  return (*this)(i,j);
2924 }
2926 //*************************************************************************************************
2927 
2928 
2929 //*************************************************************************************************
2938 template< typename MT // Type of the sparse matrix
2939  , typename... CRAs > // Compile time row arguments
2940 inline typename Rows<MT,false,false,false,CRAs...>::Iterator
2942 {
2943  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
2944 
2945  return Iterator( matrix_, idx(i), 0UL );
2946 }
2948 //*************************************************************************************************
2949 
2950 
2951 //*************************************************************************************************
2960 template< typename MT // Type of the sparse matrix
2961  , typename... CRAs > // Compile time row arguments
2962 inline typename Rows<MT,false,false,false,CRAs...>::ConstIterator
2964 {
2965  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
2966 
2967  return ConstIterator( matrix_, idx(i), 0UL );
2968 }
2970 //*************************************************************************************************
2971 
2972 
2973 //*************************************************************************************************
2982 template< typename MT // Type of the sparse matrix
2983  , typename... CRAs > // Compile time row arguments
2984 inline typename Rows<MT,false,false,false,CRAs...>::ConstIterator
2986 {
2987  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
2988 
2989  return ConstIterator( matrix_, idx(i), 0UL );
2990 }
2992 //*************************************************************************************************
2993 
2994 
2995 //*************************************************************************************************
3004 template< typename MT // Type of the sparse matrix
3005  , typename... CRAs > // Compile time row arguments
3006 inline typename Rows<MT,false,false,false,CRAs...>::Iterator
3008 {
3009  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
3010 
3011  return Iterator( matrix_, idx(i), columns() );
3012 }
3014 //*************************************************************************************************
3015 
3016 
3017 //*************************************************************************************************
3026 template< typename MT // Type of the sparse matrix
3027  , typename... CRAs > // Compile time row arguments
3028 inline typename Rows<MT,false,false,false,CRAs...>::ConstIterator
3029  Rows<MT,false,false,false,CRAs...>::end( size_t i ) const
3030 {
3031  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
3032 
3033  return ConstIterator( matrix_, idx(i), columns() );
3034 }
3036 //*************************************************************************************************
3037 
3038 
3039 //*************************************************************************************************
3048 template< typename MT // Type of the sparse matrix
3049  , typename... CRAs > // Compile time row arguments
3050 inline typename Rows<MT,false,false,false,CRAs...>::ConstIterator
3052 {
3053  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
3054 
3055  return ConstIterator( matrix_, idx(i), columns() );
3056 }
3058 //*************************************************************************************************
3059 
3060 
3061 
3062 
3063 //=================================================================================================
3064 //
3065 // ASSIGNMENT OPERATORS
3066 //
3067 //=================================================================================================
3068 
3069 //*************************************************************************************************
3085 template< typename MT // Type of the sparse matrix
3086  , typename... CRAs > // Compile time row arguments
3087 inline Rows<MT,false,false,false,CRAs...>&
3088  Rows<MT,false,false,false,CRAs...>::operator=( initializer_list< initializer_list<ElementType> > list )
3089 {
3092 
3093  if( list.size() != rows() ) {
3094  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to row selection" );
3095  }
3096 
3097  const InitializerMatrix<ElementType> tmp( list, columns() );
3098 
3099  if( IsRestricted_v<MT> ) {
3100  for( size_t i=0UL; i<rows(); ++i ) {
3101  if( !tryAssign( matrix_, row( tmp, i, unchecked ), i, 0UL ) ) {
3102  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
3103  }
3104  }
3105  }
3106 
3107  decltype(auto) left( derestrict( *this ) );
3108 
3109  smpAssign( left, tmp );
3110 
3111  return *this;
3112 }
3114 //*************************************************************************************************
3115 
3116 
3117 //*************************************************************************************************
3132 template< typename MT // Type of the sparse matrix
3133  , typename... CRAs > // Compile time row arguments
3134 inline Rows<MT,false,false,false,CRAs...>&
3135  Rows<MT,false,false,false,CRAs...>::operator=( const Rows& rhs )
3136 {
3139 
3142 
3143  if( this == &rhs || ( &matrix_ == &rhs.matrix_ && compareIndices( *this, rhs ) ) )
3144  return *this;
3145 
3146  if( rows() != rhs.rows() || columns() != rhs.columns() ) {
3147  BLAZE_THROW_INVALID_ARGUMENT( "Matrix sizes do not match" );
3148  }
3149 
3150  if( IsRestricted_v<MT> ) {
3151  for( size_t i=0UL; i<rows(); ++i ) {
3152  if( !tryAssign( matrix_, row( rhs, i, unchecked ), idx(i), 0UL ) ) {
3153  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
3154  }
3155  }
3156  }
3157 
3158  decltype(auto) left( derestrict( *this ) );
3159 
3160  if( rhs.canAlias( &matrix_ ) ) {
3161  const ResultType tmp( rhs );
3162  left.reset();
3163  smpAssign( left, tmp );
3164  }
3165  else {
3166  left.reset();
3167  smpAssign( left, rhs );
3168  }
3169 
3170  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
3171 
3172  return *this;
3173 }
3175 //*************************************************************************************************
3176 
3177 
3178 //*************************************************************************************************
3193 template< typename MT // Type of the sparse matrix
3194  , typename... CRAs > // Compile time row arguments
3195 template< typename MT2 // Type of the right-hand side matrix
3196  , bool SO > // Storage order of the right-hand side matrix
3197 inline Rows<MT,false,false,false,CRAs...>&
3198  Rows<MT,false,false,false,CRAs...>::operator=( const Matrix<MT2,SO>& rhs )
3199 {
3202 
3203  BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( ResultType_t<MT2> );
3204 
3205  if( rows() != (~rhs).rows() || columns() != (~rhs).columns() ) {
3206  BLAZE_THROW_INVALID_ARGUMENT( "Matrix sizes do not match" );
3207  }
3208 
3209  using Right = CompositeType_t<MT2>;
3210  Right right( ~rhs );
3211 
3212  if( IsRestricted_v<MT> ) {
3213  for( size_t i=0UL; i<rows(); ++i ) {
3214  if( !tryAssign( matrix_, row( right, i, unchecked ), idx(i), 0UL ) ) {
3215  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
3216  }
3217  }
3218  }
3219 
3220  decltype(auto) left( derestrict( *this ) );
3221 
3222  if( IsReference_v<Right> && right.canAlias( &matrix_ ) ) {
3223  const ResultType_t<MT2> tmp( right );
3224  if( IsSparseMatrix_v< ResultType_t<MT2> > )
3225  left.reset();
3226  smpAssign( left, tmp );
3227  }
3228  else {
3229  if( IsSparseMatrix_v<MT2> )
3230  left.reset();
3231  smpAssign( left, right );
3232  }
3233 
3234  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
3235 
3236  return *this;
3237 }
3239 //*************************************************************************************************
3240 
3241 
3242 //*************************************************************************************************
3256 template< typename MT // Type of the sparse matrix
3257  , typename... CRAs > // Compile time row arguments
3258 template< typename MT2 // Type of the right-hand side matrix
3259  , bool SO > // Storage order of the right-hand side matrix
3260 inline Rows<MT,false,false,false,CRAs...>&
3261  Rows<MT,false,false,false,CRAs...>::operator+=( const Matrix<MT2,SO>& rhs )
3262 {
3265 
3268  BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( ResultType_t<MT2> );
3269 
3270  using AddType = AddTrait_t< ResultType, ResultType_t<MT2> >;
3271 
3273 
3274  if( rows() != (~rhs).rows() || columns() != (~rhs).columns() ) {
3275  BLAZE_THROW_INVALID_ARGUMENT( "Matrix sizes do not match" );
3276  }
3277 
3278  const AddType tmp( *this + (~rhs) );
3279 
3280  if( IsRestricted_v<MT> ) {
3281  for( size_t i=0UL; i<rows(); ++i ) {
3282  if( !tryAssign( matrix_, row( tmp, i, unchecked ), idx(i), 0UL ) ) {
3283  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
3284  }
3285  }
3286  }
3287 
3288  decltype(auto) left( derestrict( *this ) );
3289 
3290  if( IsSparseMatrix_v<AddType> ) {
3291  left.reset();
3292  }
3293 
3294  smpAssign( left, tmp );
3295 
3296  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
3297 
3298  return *this;
3299 }
3301 //*************************************************************************************************
3302 
3303 
3304 //*************************************************************************************************
3318 template< typename MT // Type of the sparse matrix
3319  , typename... CRAs > // Compile time row arguments
3320 template< typename MT2 // Type of the right-hand side matrix
3321  , bool SO > // Storage order of the right-hand side matrix
3322 inline Rows<MT,false,false,false,CRAs...>&
3323  Rows<MT,false,false,false,CRAs...>::operator-=( const Matrix<MT2,SO>& rhs )
3324 {
3327 
3330  BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( ResultType_t<MT2> );
3331 
3332  using SubType = SubTrait_t< ResultType, ResultType_t<MT2> >;
3333 
3335 
3336  if( rows() != (~rhs).rows() || columns() != (~rhs).columns() ) {
3337  BLAZE_THROW_INVALID_ARGUMENT( "Matrix sizes do not match" );
3338  }
3339 
3340  const SubType tmp( *this - (~rhs) );
3341 
3342  if( IsRestricted_v<MT> ) {
3343  for( size_t i=0UL; i<rows(); ++i ) {
3344  if( !tryAssign( matrix_, row( tmp, i, unchecked ), idx(i), 0UL ) ) {
3345  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
3346  }
3347  }
3348  }
3349 
3350  decltype(auto) left( derestrict( *this ) );
3351 
3352  if( IsSparseMatrix_v<SubType> ) {
3353  left.reset();
3354  }
3355 
3356  smpAssign( left, tmp );
3357 
3358  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
3359 
3360  return *this;
3361 }
3363 //*************************************************************************************************
3364 
3365 
3366 //*************************************************************************************************
3380 template< typename MT // Type of the sparse matrix
3381  , typename... CRAs > // Compile time row arguments
3382 template< typename MT2 // Type of the right-hand side matrix
3383  , bool SO > // Storage order of the right-hand side matrix
3384 inline Rows<MT,false,false,false,CRAs...>&
3385  Rows<MT,false,false,false,CRAs...>::operator%=( const Matrix<MT2,SO>& rhs )
3386 {
3389 
3392  BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( ResultType_t<MT2> );
3393 
3394  using SchurType = SchurTrait_t< ResultType, ResultType_t<MT2> >;
3395 
3397 
3398  if( rows() != (~rhs).rows() || columns() != (~rhs).columns() ) {
3399  BLAZE_THROW_INVALID_ARGUMENT( "Matrix sizes do not match" );
3400  }
3401 
3402  const SchurType tmp( *this % (~rhs) );
3403 
3404  if( IsRestricted_v<MT> ) {
3405  for( size_t i=0UL; i<rows(); ++i ) {
3406  if( !tryAssign( matrix_, row( tmp, i, unchecked ), idx(i), 0UL ) ) {
3407  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
3408  }
3409  }
3410  }
3411 
3412  decltype(auto) left( derestrict( *this ) );
3413 
3414  if( IsSparseMatrix_v<SchurType> ) {
3415  left.reset();
3416  }
3417 
3418  smpAssign( left, tmp );
3419 
3420  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
3421 
3422  return *this;
3423 }
3425 //*************************************************************************************************
3426 
3427 
3428 
3429 
3430 //=================================================================================================
3431 //
3432 // UTILITY FUNCTIONS
3433 //
3434 //=================================================================================================
3435 
3436 //*************************************************************************************************
3442 template< typename MT // Type of the sparse matrix
3443  , typename... CRAs > // Compile time row arguments
3444 inline MT& Rows<MT,false,false,false,CRAs...>::operand() noexcept
3445 {
3446  return matrix_;
3447 }
3449 //*************************************************************************************************
3450 
3451 
3452 //*************************************************************************************************
3458 template< typename MT // Type of the sparse matrix
3459  , typename... CRAs > // Compile time row arguments
3460 inline const MT& Rows<MT,false,false,false,CRAs...>::operand() const noexcept
3461 {
3462  return matrix_;
3463 }
3465 //*************************************************************************************************
3466 
3467 
3468 //*************************************************************************************************
3474 template< typename MT // Type of the sparse matrix
3475  , typename... CRAs > // Compile time row arguments
3476 inline size_t Rows<MT,false,false,false,CRAs...>::columns() const noexcept
3477 {
3478  return matrix_.columns();
3479 }
3481 //*************************************************************************************************
3482 
3483 
3484 //*************************************************************************************************
3490 template< typename MT // Type of the sparse matrix
3491  , typename... CRAs > // Compile time row arguments
3492 inline size_t Rows<MT,false,false,false,CRAs...>::capacity() const noexcept
3493 {
3494  return rows() * columns();
3495 }
3497 //*************************************************************************************************
3498 
3499 
3500 //*************************************************************************************************
3509 template< typename MT // Type of the sparse matrix
3510  , typename... CRAs > // Compile time row arguments
3511 inline size_t Rows<MT,false,false,false,CRAs...>::capacity( size_t i ) const noexcept
3512 {
3513  MAYBE_UNUSED( i );
3514 
3515  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
3516 
3517  return columns();
3518 }
3520 //*************************************************************************************************
3521 
3522 
3523 //*************************************************************************************************
3529 template< typename MT // Type of the sparse matrix
3530  , typename... CRAs > // Compile time row arguments
3532 {
3533  size_t nonzeros( 0UL );
3534 
3535  for( size_t j=0UL; j<columns(); ++j ) {
3536  const auto end( matrix_.end( j ) );
3537  for( size_t i=0UL; i<rows(); ++i ) {
3538  auto pos = matrix_.find( idx(i), j );
3539  if( pos != end ) {
3540  ++nonzeros;
3541  }
3542  }
3543  }
3544 
3545  return nonzeros;
3546 }
3548 //*************************************************************************************************
3549 
3550 
3551 //*************************************************************************************************
3560 template< typename MT // Type of the sparse matrix
3561  , typename... CRAs > // Compile time row arguments
3562 inline size_t Rows<MT,false,false,false,CRAs...>::nonZeros( size_t i ) const
3563 {
3564  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
3565 
3566  size_t counter( 0UL );
3567 
3568  const ConstIterator last( end(i) );
3569  for( ConstIterator element=begin(i); element!=last; ++element ) {
3570  ++counter;
3571  }
3572 
3573  return counter;
3574 }
3576 //*************************************************************************************************
3577 
3578 
3579 //*************************************************************************************************
3585 template< typename MT // Type of the sparse matrix
3586  , typename... CRAs > // Compile time row arguments
3588 {
3589  for( size_t i=0UL; i<rows(); ++i ) {
3590  reset( i );
3591  }
3592 }
3594 //*************************************************************************************************
3595 
3596 
3597 //*************************************************************************************************
3607 template< typename MT // Type of the sparse matrix
3608  , typename... CRAs > // Compile time row arguments
3609 inline void Rows<MT,false,false,false,CRAs...>::reset( size_t i )
3610 {
3611  const size_t index( idx(i) );
3612 
3613  const size_t jbegin( ( IsUpper_v<MT> )
3614  ?( ( IsUniUpper_v<MT> || IsStrictlyUpper_v<MT> )
3615  ?( index+1UL )
3616  :( index ) )
3617  :( 0UL ) );
3618  const size_t jend ( ( IsLower_v<MT> )
3619  ?( ( IsUniLower_v<MT> || IsStrictlyLower_v<MT> )
3620  ?( index )
3621  :( index+1UL ) )
3622  :( columns() ) );
3623 
3624  for( size_t j=jbegin; j<jend; ++j ) {
3625  matrix_.erase( index, j );
3626  }
3627 }
3629 //*************************************************************************************************
3630 
3631 
3632 //*************************************************************************************************
3643 template< typename MT // Type of the sparse matrix
3644  , typename... CRAs > // Compile time row arguments
3645 inline void Rows<MT,false,false,false,CRAs...>::reserve( size_t nonzeros )
3646 {
3647  MAYBE_UNUSED( nonzeros );
3648 
3649  return;
3650 }
3652 //*************************************************************************************************
3653 
3654 
3655 //*************************************************************************************************
3668 template< typename MT // Type of the sparse matrix
3669  , typename... CRAs > // Compile time row arguments
3670 void Rows<MT,false,false,false,CRAs...>::reserve( size_t i, size_t nonzeros )
3671 {
3672  MAYBE_UNUSED( i, nonzeros );
3673 
3674  return;
3675 }
3677 //*************************************************************************************************
3678 
3679 
3680 //*************************************************************************************************
3690 template< typename MT // Type of the sparse matrix
3691  , typename... CRAs > // Compile time row arguments
3692 void Rows<MT,false,false,false,CRAs...>::trim()
3693 {
3694  return;
3695 }
3697 //*************************************************************************************************
3698 
3699 
3700 //*************************************************************************************************
3711 template< typename MT // Type of the sparse matrix
3712  , typename... CRAs > // Compile time row arguments
3713 void Rows<MT,false,false,false,CRAs...>::trim( size_t i )
3714 {
3715  MAYBE_UNUSED( i );
3716 
3717  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
3718 
3719  return;
3720 }
3722 //*************************************************************************************************
3723 
3724 
3725 
3726 
3727 //=================================================================================================
3728 //
3729 // INSERTION FUNCTIONS
3730 //
3731 //=================================================================================================
3732 
3733 //*************************************************************************************************
3746 template< typename MT // Type of the sparse matrix
3747  , typename... CRAs > // Compile time row arguments
3748 inline typename Rows<MT,false,false,false,CRAs...>::Iterator
3749  Rows<MT,false,false,false,CRAs...>::set( size_t i, size_t j, const ElementType& value )
3750 {
3751  return Iterator( matrix_, idx(i), j, matrix_.set( idx(i), j, value ) );
3752 }
3754 //*************************************************************************************************
3755 
3756 
3757 //*************************************************************************************************
3771 template< typename MT // Type of the sparse matrix
3772  , typename... CRAs > // Compile time row arguments
3773 inline typename Rows<MT,false,false,false,CRAs...>::Iterator
3774  Rows<MT,false,false,false,CRAs...>::insert( size_t i, size_t j, const ElementType& value )
3775 {
3776  return Iterator( matrix_, idx(i), j, matrix_.insert( idx(i), j, value ) );
3777 }
3779 //*************************************************************************************************
3780 
3781 
3782 //*************************************************************************************************
3826 template< typename MT // Type of the sparse matrix
3827  , typename... CRAs > // Compile time row arguments
3828 inline void Rows<MT,false,false,false,CRAs...>::append( size_t i, size_t j, const ElementType& value, bool check )
3829 {
3830  if( !check || !isDefault<strict>( value ) )
3831  matrix_.insert( idx(i), j, value );
3832 }
3834 //*************************************************************************************************
3835 
3836 
3837 //*************************************************************************************************
3851 template< typename MT // Type of the sparse matrix
3852  , typename... CRAs > // Compile time row arguments
3853 inline void Rows<MT,false,false,false,CRAs...>::finalize( size_t i )
3854 {
3855  MAYBE_UNUSED( i );
3856 
3857  return;
3858 }
3860 //*************************************************************************************************
3861 
3862 
3863 
3864 
3865 //=================================================================================================
3866 //
3867 // ERASE FUNCTIONS
3868 //
3869 //=================================================================================================
3870 
3871 //*************************************************************************************************
3881 template< typename MT // Type of the sparse matrix
3882  , typename... CRAs > // Compile time row arguments
3883 inline void Rows<MT,false,false,false,CRAs...>::erase( size_t i, size_t j )
3884 {
3885  BLAZE_USER_ASSERT( i < rows() , "Invalid row access index" );
3886  BLAZE_USER_ASSERT( j < columns(), "Invalid column access index" );
3887 
3888  matrix_.erase( idx(i), j );
3889 }
3891 //*************************************************************************************************
3892 
3893 
3894 //*************************************************************************************************
3904 template< typename MT // Type of the sparse matrix
3905  , typename... CRAs > // Compile time row arguments
3906 inline typename Rows<MT,false,false,false,CRAs...>::Iterator
3907  Rows<MT,false,false,false,CRAs...>::erase( size_t i, Iterator pos )
3908 {
3909  const size_t column( pos.column_ );
3910 
3911  if( column == columns() )
3912  return pos;
3913 
3914  matrix_.erase( column, pos.pos_ );
3915  return Iterator( matrix_, idx(i), column+1UL );
3916 }
3918 //*************************************************************************************************
3919 
3920 
3921 //*************************************************************************************************
3932 template< typename MT // Type of the sparse matrix
3933  , typename... CRAs > // Compile time row arguments
3934 inline typename Rows<MT,false,false,false,CRAs...>::Iterator
3935  Rows<MT,false,false,false,CRAs...>::erase( size_t i, Iterator first, Iterator last )
3936 {
3937  MAYBE_UNUSED( i );
3938 
3939  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
3940 
3941  for( ; first!=last; ++first ) {
3942  matrix_.erase( first.column_, first.pos_ );
3943  }
3944 
3945  return last;
3946 }
3948 //*************************************************************************************************
3949 
3950 
3951 //*************************************************************************************************
3974 template< typename MT // Type of the sparse matrix
3975  , typename... CRAs > // Compile time row arguments
3976 template< typename Pred > // Type of the unary predicate
3977 inline void Rows<MT,false,false,false,CRAs...>::erase( Pred predicate )
3978 {
3979  for( size_t i=0UL; i<rows(); ++i ) {
3980  for( Iterator element=begin(i); element!=end(i); ++element ) {
3981  if( predicate( element->value() ) )
3982  matrix_.erase( element.column_, element.pos_ );
3983  }
3984  }
3985 }
3987 //*************************************************************************************************
3988 
3989 
3990 //*************************************************************************************************
4017 template< typename MT // Type of the sparse matrix
4018  , typename... CRAs > // Compile time row arguments
4019 template< typename Pred > // Type of the unary predicate
4020 inline void Rows<MT,false,false,false,CRAs...>::erase( size_t i, Iterator first, Iterator last, Pred predicate )
4021 {
4022  MAYBE_UNUSED( i );
4023 
4024  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
4025 
4026  for( ; first!=last; ++first ) {
4027  if( predicate( first->value() ) )
4028  matrix_.erase( first.column_, first.pos_ );
4029  }
4030 }
4032 //*************************************************************************************************
4033 
4034 
4035 
4036 
4037 //=================================================================================================
4038 //
4039 // LOOKUP FUNCTIONS
4040 //
4041 //=================================================================================================
4042 
4043 //*************************************************************************************************
4058 template< typename MT // Type of the sparse matrix
4059  , typename... CRAs > // Compile time row arguments
4060 inline typename Rows<MT,false,false,false,CRAs...>::Iterator
4061  Rows<MT,false,false,false,CRAs...>::find( size_t i, size_t j )
4062 {
4063  const size_t index( idx(i) );
4064  const Iterator_t<MT> pos( matrix_.find( index, j ) );
4065 
4066  if( pos != matrix_.end( j ) )
4067  return Iterator( matrix_, index, j, pos );
4068  else
4069  return end( i );
4070 }
4072 //*************************************************************************************************
4073 
4074 
4075 //*************************************************************************************************
4090 template< typename MT // Type of the sparse matrix
4091  , typename... CRAs > // Compile time row arguments
4092 inline typename Rows<MT,false,false,false,CRAs...>::ConstIterator
4093  Rows<MT,false,false,false,CRAs...>::find( size_t i, size_t j ) const
4094 {
4095  const size_t index( idx(i) );
4096  const ConstIterator_t<MT> pos( matrix_.find( index, j ) );
4097 
4098  if( pos != matrix_.end( j ) )
4099  return ConstIterator( matrix_, index, j, pos );
4100  else
4101  return end( i );
4102 }
4104 //*************************************************************************************************
4105 
4106 
4107 //*************************************************************************************************
4121 template< typename MT // Type of the sparse matrix
4122  , typename... CRAs > // Compile time row arguments
4123 inline typename Rows<MT,false,false,false,CRAs...>::Iterator
4124  Rows<MT,false,false,false,CRAs...>::lowerBound( size_t i, size_t j )
4125 {
4126  const size_t index( idx(i) );
4127 
4128  for( ; j<columns(); ++j )
4129  {
4130  const Iterator_t<MT> pos( matrix_.find( index, j ) );
4131 
4132  if( pos != matrix_.end( j ) )
4133  return Iterator( matrix_, index, j, pos );
4134  }
4135 
4136  return end( i );
4137 }
4139 //*************************************************************************************************
4140 
4141 
4142 //*************************************************************************************************
4156 template< typename MT // Type of the sparse matrix
4157  , typename... CRAs > // Compile time row arguments
4158 inline typename Rows<MT,false,false,false,CRAs...>::ConstIterator
4159  Rows<MT,false,false,false,CRAs...>::lowerBound( size_t i, size_t j ) const
4160 {
4161  const size_t index( idx(i) );
4162 
4163  for( ; j<columns(); ++j )
4164  {
4165  const ConstIterator_t<MT> pos( matrix_.find( index, j ) );
4166 
4167  if( pos != matrix_.end( j ) )
4168  return ConstIterator( matrix_, index, j, pos );
4169  }
4170 
4171  return end( i );
4172 }
4174 //*************************************************************************************************
4175 
4176 
4177 //*************************************************************************************************
4191 template< typename MT // Type of the sparse matrix
4192  , typename... CRAs > // Compile time row arguments
4193 inline typename Rows<MT,false,false,false,CRAs...>::Iterator
4194  Rows<MT,false,false,false,CRAs...>::upperBound( size_t i, size_t j )
4195 {
4196  return lowerBound( i, j+1UL );
4197 }
4199 //*************************************************************************************************
4200 
4201 
4202 //*************************************************************************************************
4216 template< typename MT // Type of the sparse matrix
4217  , typename... CRAs > // Compile time row arguments
4218 inline typename Rows<MT,false,false,false,CRAs...>::ConstIterator
4219  Rows<MT,false,false,false,CRAs...>::upperBound( size_t i, size_t j ) const
4220 {
4221  return lowerBound( i, j+1UL );
4222 }
4224 //*************************************************************************************************
4225 
4226 
4227 
4228 
4229 //=================================================================================================
4230 //
4231 // NUMERIC FUNCTIONS
4232 //
4233 //=================================================================================================
4234 
4235 //*************************************************************************************************
4248 template< typename MT // Type of the sparse matrix
4249  , typename... CRAs > // Compile time row arguments
4250 inline Rows<MT,false,false,false,CRAs...>&
4252 {
4255 
4256  if( rows() != columns() ) {
4257  BLAZE_THROW_LOGIC_ERROR( "Invalid transpose of a non-quadratic matrix" );
4258  }
4259 
4260  const ResultType tmp( trans( *this ) );
4261 
4262  if( IsRestricted_v<MT> ) {
4263  for( size_t i=0UL; i<rows(); ++i ) {
4264  if( !tryAssign( matrix_, row( tmp, i, unchecked ), idx(i), 0UL ) ) {
4265  BLAZE_THROW_LOGIC_ERROR( "Invalid transpose operation" );
4266  }
4267  }
4268  }
4269 
4270  decltype(auto) left( derestrict( *this ) );
4271 
4272  left.reset();
4273  smpAssign( left, tmp );
4274 
4275  return *this;
4276 }
4278 //*************************************************************************************************
4279 
4280 
4281 //*************************************************************************************************
4294 template< typename MT // Type of the sparse matrix
4295  , typename... CRAs > // Compile time row arguments
4296 inline Rows<MT,false,false,false,CRAs...>&
4297  Rows<MT,false,false,false,CRAs...>::ctranspose()
4298 {
4301 
4302  if( rows() != columns() ) {
4303  BLAZE_THROW_LOGIC_ERROR( "Invalid transpose of a non-quadratic matrix" );
4304  }
4305 
4306  const ResultType tmp( ctrans( *this ) );
4307 
4308  if( IsRestricted_v<MT> ) {
4309  for( size_t i=0UL; i<rows(); ++i ) {
4310  if( !tryAssign( matrix_, row( tmp, i, unchecked ), idx(i), 0UL ) ) {
4311  BLAZE_THROW_LOGIC_ERROR( "Invalid transpose operation" );
4312  }
4313  }
4314  }
4315 
4316  decltype(auto) left( derestrict( *this ) );
4317 
4318  left.reset();
4319  smpAssign( left, tmp );
4320 
4321  return *this;
4322 }
4324 //*************************************************************************************************
4325 
4326 
4327 //*************************************************************************************************
4340 template< typename MT // Type of the sparse matrix
4341  , typename... CRAs > // Compile time row arguments
4342 template< typename Other > // Data type of the scalar value
4343 inline Rows<MT,false,false,false,CRAs...>&
4344  Rows<MT,false,false,false,CRAs...>::scale( const Other& scalar )
4345 {
4349 
4350  for( size_t j=0UL; j<columns(); ++j ) {
4351  const auto end( matrix_.end( j ) );
4352  for( size_t i=0UL; i<rows(); ++i ) {
4353  auto pos = matrix_.find( idx(i), j );
4354  if( pos != end ) {
4355  pos->value() *= scalar;
4356  }
4357  }
4358  }
4359 
4360  return *this;
4361 }
4363 //*************************************************************************************************
4364 
4365 
4366 
4367 
4368 //=================================================================================================
4369 //
4370 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
4371 //
4372 //=================================================================================================
4373 
4374 //*************************************************************************************************
4385 template< typename MT // Type of the sparse matrix
4386  , typename... CRAs > // Compile time row arguments
4387 template< typename Other > // Data type of the foreign expression
4388 inline bool Rows<MT,false,false,false,CRAs...>::canAlias( const Other* alias ) const noexcept
4389 {
4390  return matrix_.isAliased( alias );
4391 }
4393 //*************************************************************************************************
4394 
4395 
4396 //*************************************************************************************************
4407 template< typename MT // Type of the sparse matrix
4408  , typename... CRAs > // Compile time row arguments
4409 template< typename Other > // Data type of the foreign expression
4410 inline bool Rows<MT,false,false,false,CRAs...>::isAliased( const Other* alias ) const noexcept
4411 {
4412  return matrix_.isAliased( alias );
4413 }
4415 //*************************************************************************************************
4416 
4417 
4418 //*************************************************************************************************
4429 template< typename MT // Type of the sparse matrix
4430  , typename... CRAs > // Compile time row arguments
4431 inline bool Rows<MT,false,false,false,CRAs...>::canSMPAssign() const noexcept
4432 {
4433  return false;
4434 }
4436 //*************************************************************************************************
4437 
4438 
4439 //*************************************************************************************************
4451 template< typename MT // Type of the sparse matrix
4452  , typename... CRAs > // Compile time row arguments
4453 template< typename MT2 // Type of the right-hand side dense matrix
4454  , bool SO > // Storage order of the right-hand side dense matrix
4455 inline void Rows<MT,false,false,false,CRAs...>::assign( const DenseMatrix<MT2,SO>& rhs )
4456 {
4459 
4460  using RT = If_t< IsComputation_v<MT2>, ElementType_t<MT>, const ElementType_t<MT2>& >;
4461 
4462  BLAZE_INTERNAL_ASSERT( rows() == (~rhs).rows() , "Invalid number of rows" );
4463  BLAZE_INTERNAL_ASSERT( columns() == (~rhs).columns(), "Invalid number of columns" );
4464 
4465  for( size_t j=0UL; j<columns(); ++j ) {
4466  for( size_t i=0UL; i<rows(); ++i ) {
4467  RT value( (~rhs)(i,j) );
4468  if( !isDefault<strict>( value ) )
4469  matrix_.set( idx(i), j, std::move( value ) );
4470  else matrix_.erase( idx(i), j );
4471  }
4472  }
4473 }
4475 //*************************************************************************************************
4476 
4477 
4478 //*************************************************************************************************
4490 template< typename MT // Type of the sparse matrix
4491  , typename... CRAs > // Compile time row arguments
4492 template< typename MT2 > // Type of the right-hand side sparse matrix
4493 inline void Rows<MT,false,false,false,CRAs...>::assign( const SparseMatrix<MT2,false>& rhs )
4494 {
4497 
4498  using RT = If_t< IsComputation_v<MT2>, ElementType_t<MT>, const ElementType_t<MT2>& >;
4499 
4500  BLAZE_INTERNAL_ASSERT( rows() == (~rhs).rows() , "Invalid number of rows" );
4501  BLAZE_INTERNAL_ASSERT( columns() == (~rhs).columns(), "Invalid number of columns" );
4502  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
4503 
4504  for( size_t i=0UL; i<rows(); ++i ) {
4505  const size_t index( idx(i) );
4506  for( ConstIterator_t<MT2> element=(~rhs).begin(i); element!=(~rhs).end(i); ++element ) {
4507  RT value( element->value() );
4508  if( !isDefault<strict>( value ) )
4509  matrix_.set( index, element->index(), std::move( value ) );
4510  else matrix_.erase( index, element->index() );
4511  }
4512  }
4513 }
4515 //*************************************************************************************************
4516 
4517 
4518 //*************************************************************************************************
4530 template< typename MT // Type of the sparse matrix
4531  , typename... CRAs > // Compile time row arguments
4532 template< typename MT2 > // Type of the right-hand side sparse matrix
4533 inline void Rows<MT,false,false,false,CRAs...>::assign( const SparseMatrix<MT2,true>& rhs )
4534 {
4537 
4539 
4540  using RT = If_t< IsComputation_v<MT2>, ElementType_t<MT>, const ElementType_t<MT2>& >;
4541 
4542  BLAZE_INTERNAL_ASSERT( rows() == (~rhs).rows() , "Invalid number of rows" );
4543  BLAZE_INTERNAL_ASSERT( columns() == (~rhs).columns(), "Invalid number of columns" );
4544  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
4545 
4546  for( size_t j=0UL; j<columns(); ++j ) {
4547  for( ConstIterator_t<MT2> element=(~rhs).begin(j); element!=(~rhs).end(j); ++element ) {
4548  RT value( element->value() );
4549  if( !isDefault<strict>( value ) )
4550  matrix_.set( idx( element->index() ), j, std::move( value ) );
4551  else matrix_.erase( idx( element->index() ), j );
4552  }
4553  }
4554 }
4556 //*************************************************************************************************
4557 
4558 
4559 //*************************************************************************************************
4571 template< typename MT // Type of the sparse matrix
4572  , typename... CRAs > // Compile time row arguments
4573 template< typename MT2 // Type of the right-hand side matrix
4574  , bool SO > // Storage order of the right-hand side matrix
4575 inline void Rows<MT,false,false,false,CRAs...>::addAssign( const Matrix<MT2,SO>& rhs )
4576 {
4579 
4580  using AddType = AddTrait_t< ResultType, ResultType_t<MT2> >;
4581 
4583 
4584  BLAZE_INTERNAL_ASSERT( rows() == (~rhs).rows() , "Invalid number of rows" );
4585  BLAZE_INTERNAL_ASSERT( columns() == (~rhs).columns(), "Invalid number of columns" );
4586 
4587  const AddType tmp( serial( *this + (~rhs) ) );
4588  reset();
4589  assign( tmp );
4590 }
4592 //*************************************************************************************************
4593 
4594 
4595 //*************************************************************************************************
4607 template< typename MT // Type of the sparse matrix
4608  , typename... CRAs > // Compile time row arguments
4609 template< typename MT2 // Type of the right-hand side matrix
4610  , bool SO > // Storage order of the right-hand side matrix
4611 inline void Rows<MT,false,false,false,CRAs...>::subAssign( const Matrix<MT2,SO>& rhs )
4612 {
4615 
4616  using SubType = SubTrait_t< ResultType, ResultType_t<MT2> >;
4617 
4619 
4620  BLAZE_INTERNAL_ASSERT( rows() == (~rhs).rows() , "Invalid number of rows" );
4621  BLAZE_INTERNAL_ASSERT( columns() == (~rhs).columns(), "Invalid number of columns" );
4622 
4623  const SubType tmp( serial( *this - (~rhs) ) );
4624  reset();
4625  assign( tmp );
4626 }
4628 //*************************************************************************************************
4629 
4630 
4631 //*************************************************************************************************
4643 template< typename MT // Type of the sparse matrix
4644  , typename... CRAs > // Compile time row arguments
4645 template< typename MT2 // Type of the right-hand side matrix
4646  , bool SO > // Storage order of the right-hand side matrix
4647 inline void Rows<MT,false,false,false,CRAs...>::schurAssign( const Matrix<MT2,SO>& rhs )
4648 {
4651 
4652  using SchurType = SchurTrait_t< ResultType, ResultType_t<MT2> >;
4653 
4656 
4657  BLAZE_INTERNAL_ASSERT( rows() == (~rhs).rows() , "Invalid number of rows" );
4658  BLAZE_INTERNAL_ASSERT( columns() == (~rhs).columns(), "Invalid number of columns" );
4659 
4660  const SchurType tmp( serial( *this % (~rhs) ) );
4661  reset();
4662  assign( tmp );
4663 }
4665 //*************************************************************************************************
4666 
4667 
4668 
4669 
4670 
4671 
4672 
4673 
4674 //=================================================================================================
4675 //
4676 // CLASS TEMPLATE SPECIALIZATION FOR SYMMETRIC COLUMN-MAJOR SPARSE MATRICES
4677 //
4678 //=================================================================================================
4679 
4680 //*************************************************************************************************
4688 template< typename MT // Type of the sparse matrix
4689  , typename... CRAs > // Compile time row arguments
4690 class Rows<MT,false,false,true,CRAs...>
4691  : public View< SparseMatrix< Rows<MT,false,false,true,CRAs...>, false > >
4692  , private RowsData<CRAs...>
4693 {
4694  private:
4695  //**Type definitions****************************************************************************
4696  using DataType = RowsData<CRAs...>;
4697  using Operand = If_t< IsExpression_v<MT>, MT, MT& >;
4698  //**********************************************************************************************
4699 
4700  //**Compile time flags**************************************************************************
4701  using DataType::N;
4702  //**********************************************************************************************
4703 
4704  public:
4705  //**Type definitions****************************************************************************
4707  using This = Rows<MT,false,false,true,CRAs...>;
4708 
4709  using BaseType = SparseMatrix<This,false>;
4710  using ViewedType = MT;
4711  using ResultType = RowsTrait_t<MT,N>;
4712  using OppositeType = OppositeType_t<ResultType>;
4713  using TransposeType = TransposeType_t<ResultType>;
4714  using ElementType = ElementType_t<MT>;
4715  using ReturnType = ReturnType_t<MT>;
4716  using CompositeType = const Rows&;
4717 
4719  using ConstReference = ConstReference_t<MT>;
4720 
4722  using Reference = If_t< IsConst_v<MT>, ConstReference, Reference_t<MT> >;
4723 
4725  using ConstIterator = ConstIterator_t<MT>;
4726 
4728  using Iterator = If_t< IsConst_v<MT>, ConstIterator, Iterator_t<MT> >;
4729  //**********************************************************************************************
4730 
4731  //**Compilation flags***************************************************************************
4733  static constexpr bool smpAssignable = MT::smpAssignable;
4734 
4736  static constexpr bool compileTimeArgs = DataType::compileTimeArgs;
4737  //**********************************************************************************************
4738 
4739  //**Constructors********************************************************************************
4742  template< typename... RRAs >
4743  explicit inline Rows( MT& matrix, RRAs... args );
4744 
4745  Rows( const Rows& ) = default;
4746  Rows( Rows&& ) = default;
4748  //**********************************************************************************************
4749 
4750  //**Destructor**********************************************************************************
4753  ~Rows() = default;
4755  //**********************************************************************************************
4756 
4757  //**Data access functions***********************************************************************
4760  inline Reference operator()( size_t i, size_t j );
4761  inline ConstReference operator()( size_t i, size_t j ) const;
4762  inline Reference at( size_t i, size_t j );
4763  inline ConstReference at( size_t i, size_t j ) const;
4764  inline Iterator begin ( size_t i );
4765  inline ConstIterator begin ( size_t i ) const;
4766  inline ConstIterator cbegin( size_t i ) const;
4767  inline Iterator end ( size_t i );
4768  inline ConstIterator end ( size_t i ) const;
4769  inline ConstIterator cend ( size_t i ) const;
4771  //**********************************************************************************************
4772 
4773  //**Assignment operators************************************************************************
4776  Rows& operator=( const Rows& ) = delete;
4778  //**********************************************************************************************
4779 
4780  //**Utility functions***************************************************************************
4783  using DataType::idx;
4784  using DataType::idces;
4785  using DataType::rows;
4786 
4787  inline MT& operand() noexcept;
4788  inline const MT& operand() const noexcept;
4789 
4790  inline size_t columns() const noexcept;
4791  inline size_t capacity() const noexcept;
4792  inline size_t capacity( size_t i ) const noexcept;
4793  inline size_t nonZeros() const;
4794  inline size_t nonZeros( size_t i ) const;
4795  inline void reset();
4796  inline void reset( size_t i );
4797  inline void reserve( size_t nonzeros );
4798  void reserve( size_t i, size_t nonzeros );
4799  inline void trim();
4800  inline void trim( size_t i );
4802  //**********************************************************************************************
4803 
4804  //**Insertion functions*************************************************************************
4807  inline Iterator set ( size_t i, size_t j, const ElementType& value );
4808  inline Iterator insert ( size_t i, size_t j, const ElementType& value );
4809  inline void append ( size_t i, size_t j, const ElementType& value, bool check=false );
4810  inline void finalize( size_t i );
4812  //**********************************************************************************************
4813 
4814  //**Erase functions*****************************************************************************
4817  inline void erase( size_t i, size_t j );
4818  inline Iterator erase( size_t i, Iterator pos );
4819  inline Iterator erase( size_t i, Iterator first, Iterator last );
4820 
4821  template< typename Pred >
4822  inline void erase( Pred predicate );
4823 
4824  template< typename Pred >
4825  inline void erase( size_t i, Iterator first, Iterator last, Pred predicate );
4827  //**********************************************************************************************
4828 
4829  //**Lookup functions****************************************************************************
4832  inline Iterator find ( size_t i, size_t j );
4833  inline ConstIterator find ( size_t i, size_t j ) const;
4834  inline Iterator lowerBound( size_t i, size_t j );
4835  inline ConstIterator lowerBound( size_t i, size_t j ) const;
4836  inline Iterator upperBound( size_t i, size_t j );
4837  inline ConstIterator upperBound( size_t i, size_t j ) const;
4839  //**********************************************************************************************
4840 
4841  //**Expression template evaluation functions****************************************************
4844  template< typename Other > inline bool canAlias ( const Other* alias ) const noexcept;
4845  template< typename Other > inline bool isAliased( const Other* alias ) const noexcept;
4846 
4847  inline bool canSMPAssign() const noexcept;
4849  //**********************************************************************************************
4850 
4851  private:
4852  //**Member variables****************************************************************************
4855  Operand matrix_;
4856 
4857  //**********************************************************************************************
4858 
4859  //**Compile time checks*************************************************************************
4869  //**********************************************************************************************
4870 };
4872 //*************************************************************************************************
4873 
4874 
4875 
4876 
4877 //=================================================================================================
4878 //
4879 // CONSTRUCTORS
4880 //
4881 //=================================================================================================
4882 
4883 //*************************************************************************************************
4896 template< typename MT // Type of the sparse matrix
4897  , typename... CRAs > // Compile time row arguments
4898 template< typename... RRAs > // Runtime row arguments
4899 inline Rows<MT,false,false,true,CRAs...>::Rows( MT& matrix, RRAs... args )
4900  : DataType( args... ) // Base class initialization
4901  , matrix_ ( matrix ) // The matrix containing the rows
4902 {
4903  if( !Contains_v< TypeList<RRAs...>, Unchecked > ) {
4904  for( size_t i=0UL; i<rows(); ++i ) {
4905  if( matrix_.rows() <= idx(i) ) {
4906  BLAZE_THROW_INVALID_ARGUMENT( "Invalid row access index" );
4907  }
4908  }
4909  }
4910 }
4912 //*************************************************************************************************
4913 
4914 
4915 
4916 
4917 //=================================================================================================
4918 //
4919 // DATA ACCESS FUNCTIONS
4920 //
4921 //=================================================================================================
4922 
4923 //*************************************************************************************************
4934 template< typename MT // Type of the sparse matrix
4935  , typename... CRAs > // Compile time row arguments
4936 inline typename Rows<MT,false,false,true,CRAs...>::Reference
4937  Rows<MT,false,false,true,CRAs...>::operator()( size_t i, size_t j )
4938 {
4939  BLAZE_USER_ASSERT( i < rows() , "Invalid row access index" );
4940  BLAZE_USER_ASSERT( j < columns(), "Invalid column access index" );
4941 
4942  return matrix_(j,idx(i));
4943 }
4945 //*************************************************************************************************
4946 
4947 
4948 //*************************************************************************************************
4959 template< typename MT // Type of the sparse matrix
4960  , typename... CRAs > // Compile time row arguments
4961 inline typename Rows<MT,false,false,true,CRAs...>::ConstReference
4962  Rows<MT,false,false,true,CRAs...>::operator()( size_t i, size_t j ) const
4963 {
4964  BLAZE_USER_ASSERT( i < rows() , "Invalid row access index" );
4965  BLAZE_USER_ASSERT( j < columns(), "Invalid column access index" );
4966 
4967  return const_cast<const MT&>( matrix_ )(j,idx(i));
4968 }
4970 //*************************************************************************************************
4971 
4972 
4973 //*************************************************************************************************
4985 template< typename MT // Type of the sparse matrix
4986  , typename... CRAs > // Compile time row arguments
4987 inline typename Rows<MT,false,false,true,CRAs...>::Reference
4988  Rows<MT,false,false,true,CRAs...>::at( size_t i, size_t j )
4989 {
4990  if( i >= rows() ) {
4991  BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
4992  }
4993  if( j >= columns() ) {
4994  BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
4995  }
4996  return (*this)(i,j);
4997 }
4999 //*************************************************************************************************
5000 
5001 
5002 //*************************************************************************************************
5014 template< typename MT // Type of the sparse matrix
5015  , typename... CRAs > // Compile time row arguments
5016 inline typename Rows<MT,false,false,true,CRAs...>::ConstReference
5017  Rows<MT,false,false,true,CRAs...>::at( size_t i, size_t j ) const
5018 {
5019  if( i >= rows() ) {
5020  BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
5021  }
5022  if( j >= columns() ) {
5023  BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
5024  }
5025  return (*this)(i,j);
5026 }
5028 //*************************************************************************************************
5029 
5030 
5031 //*************************************************************************************************
5040 template< typename MT // Type of the sparse matrix
5041  , typename... CRAs > // Compile time row arguments
5042 inline typename Rows<MT,false,false,true,CRAs...>::Iterator
5044 {
5045  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
5046 
5047  return matrix_.begin( idx(i) );
5048 }
5050 //*************************************************************************************************
5051 
5052 
5053 //*************************************************************************************************
5062 template< typename MT // Type of the sparse matrix
5063  , typename... CRAs > // Compile time row arguments
5064 inline typename Rows<MT,false,false,true,CRAs...>::ConstIterator
5066 {
5067  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
5068 
5069  return matrix_.cbegin( idx(i) );
5070 }
5072 //*************************************************************************************************
5073 
5074 
5075 //*************************************************************************************************
5084 template< typename MT // Type of the sparse matrix
5085  , typename... CRAs > // Compile time row arguments
5086 inline typename Rows<MT,false,false,true,CRAs...>::ConstIterator
5088 {
5089  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
5090 
5091  return matrix_.cbegin( idx(i) );
5092 }
5094 //*************************************************************************************************
5095 
5096 
5097 //*************************************************************************************************
5106 template< typename MT // Type of the sparse matrix
5107  , typename... CRAs > // Compile time row arguments
5108 inline typename Rows<MT,false,false,true,CRAs...>::Iterator
5110 {
5111  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
5112 
5113  return matrix_.end( idx(i) );
5114 }
5116 //*************************************************************************************************
5117 
5118 
5119 //*************************************************************************************************
5128 template< typename MT // Type of the sparse matrix
5129  , typename... CRAs > // Compile time row arguments
5130 inline typename Rows<MT,false,false,true,CRAs...>::ConstIterator
5131  Rows<MT,false,false,true,CRAs...>::end( size_t i ) const
5132 {
5133  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
5134 
5135  return matrix_.cend( idx(i) );
5136 }
5138 //*************************************************************************************************
5139 
5140 
5141 //*************************************************************************************************
5150 template< typename MT // Type of the sparse matrix
5151  , typename... CRAs > // Compile time row arguments
5152 inline typename Rows<MT,false,false,true,CRAs...>::ConstIterator
5153  Rows<MT,false,false,true,CRAs...>::cend( size_t i ) const
5154 {
5155  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
5156 
5157  return matrix_.cend( idx(i) );
5158 }
5160 //*************************************************************************************************
5161 
5162 
5163 
5164 
5165 //=================================================================================================
5166 //
5167 // UTILITY FUNCTIONS
5168 //
5169 //=================================================================================================
5170 
5171 //*************************************************************************************************
5177 template< typename MT // Type of the sparse matrix
5178  , typename... CRAs > // Compile time row arguments
5179 inline MT& Rows<MT,false,false,true,CRAs...>::operand() noexcept
5180 {
5181  return matrix_;
5182 }
5184 //*************************************************************************************************
5185 
5186 
5187 //*************************************************************************************************
5193 template< typename MT // Type of the sparse matrix
5194  , typename... CRAs > // Compile time row arguments
5195 inline const MT& Rows<MT,false,false,true,CRAs...>::operand() const noexcept
5196 {
5197  return matrix_;
5198 }
5200 //*************************************************************************************************
5201 
5202 
5203 //*************************************************************************************************
5209 template< typename MT // Type of the sparse matrix
5210  , typename... CRAs > // Compile time row arguments
5211 inline size_t Rows<MT,false,false,true,CRAs...>::columns() const noexcept
5212 {
5213  return matrix_.columns();
5214 }
5216 //*************************************************************************************************
5217 
5218 
5219 //*************************************************************************************************
5225 template< typename MT // Type of the sparse matrix
5226  , typename... CRAs > // Compile time row arguments
5227 inline size_t Rows<MT,false,false,true,CRAs...>::capacity() const noexcept
5228 {
5229  return nonZeros() + matrix_.capacity() - matrix_.nonZeros();
5230 }
5232 //*************************************************************************************************
5233 
5234 
5235 //*************************************************************************************************
5244 template< typename MT // Type of the sparse matrix
5245  , typename... CRAs > // Compile time row arguments
5246 inline size_t Rows<MT,false,false,true,CRAs...>::capacity( size_t i ) const noexcept
5247 {
5248  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
5249 
5250  return matrix_.capacity( idx(i) );
5251 }
5253 //*************************************************************************************************
5254 
5255 
5256 //*************************************************************************************************
5262 template< typename MT // Type of the sparse matrix
5263  , typename... CRAs > // Compile time row arguments
5264 inline size_t Rows<MT,false,false,true,CRAs...>::nonZeros() const
5265 {
5266  size_t nonzeros( 0UL );
5267 
5268  for( size_t i=0UL; i<rows(); ++i )
5269  nonzeros += nonZeros( i );
5270 
5271  return nonzeros;
5272 }
5274 //*************************************************************************************************
5275 
5276 
5277 //*************************************************************************************************
5286 template< typename MT // Type of the sparse matrix
5287  , typename... CRAs > // Compile time row arguments
5288 inline size_t Rows<MT,false,false,true,CRAs...>::nonZeros( size_t i ) const
5289 {
5290  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
5291 
5292  return matrix_.nonZeros( idx(i) );
5293 }
5295 //*************************************************************************************************
5296 
5297 
5298 //*************************************************************************************************
5304 template< typename MT // Type of the sparse matrix
5305  , typename... CRAs > // Compile time row arguments
5307 {
5308  for( size_t i=0UL; i<rows(); ++i ) {
5309  matrix_.reset( idx(i) );
5310  }
5311 }
5313 //*************************************************************************************************
5314 
5315 
5316 //*************************************************************************************************
5326 template< typename MT // Type of the sparse matrix
5327  , typename... CRAs > // Compile time row arguments
5328 inline void Rows<MT,false,false,true,CRAs...>::reset( size_t i )
5329 {
5330  matrix_.reset( idx(i) );
5331 }
5333 //*************************************************************************************************
5334 
5335 
5336 //*************************************************************************************************
5347 template< typename MT // Type of the sparse matrix
5348  , typename... CRAs > // Compile time row arguments
5349 inline void Rows<MT,false,false,true,CRAs...>::reserve( size_t nonzeros )
5350 {
5351  const size_t current( capacity() );
5352 
5353  if( nonzeros > current ) {
5354  matrix_.reserve( matrix_.capacity() + nonzeros - current );
5355  }
5356 }
5358 //*************************************************************************************************
5359 
5360 
5361 //*************************************************************************************************
5374 template< typename MT // Type of the sparse matrix
5375  , typename... CRAs > // Compile time row arguments
5376 void Rows<MT,false,false,true,CRAs...>::reserve( size_t i, size_t nonzeros )
5377 {
5378  matrix_.reserve( idx(i), nonzeros );
5379 }
5381 //*************************************************************************************************
5382 
5383 
5384 //*************************************************************************************************
5394 template< typename MT // Type of the sparse matrix
5395  , typename... CRAs > // Compile time row arguments
5396 void Rows<MT,false,false,true,CRAs...>::trim()
5397 {
5398  for( size_t i=0UL; i<rows(); ++i ) {
5399  trim( i );
5400  }
5401 }
5403 //*************************************************************************************************
5404 
5405 
5406 //*************************************************************************************************
5417 template< typename MT // Type of the sparse matrix
5418  , typename... CRAs > // Compile time row arguments
5419 void Rows<MT,false,false,true,CRAs...>::trim( size_t i )
5420 {
5421  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
5422 
5423  matrix_.trim( idx(i) );
5424 }
5426 //*************************************************************************************************
5427 
5428 
5429 
5430 
5431 //=================================================================================================
5432 //
5433 // INSERTION FUNCTIONS
5434 //
5435 //=================================================================================================
5436 
5437 //*************************************************************************************************
5450 template< typename MT // Type of the sparse matrix
5451  , typename... CRAs > // Compile time row arguments
5452 inline typename Rows<MT,false,false,true,CRAs...>::Iterator
5453  Rows<MT,false,false,true,CRAs...>::set( size_t i, size_t j, const ElementType& value )
5454 {
5455  return matrix_.set( j, idx(i), value );
5456 }
5458 //*************************************************************************************************
5459 
5460 
5461 //*************************************************************************************************
5475 template< typename MT // Type of the sparse matrix
5476  , typename... CRAs > // Compile time row arguments
5477 inline typename Rows<MT,false,false,true,CRAs...>::Iterator
5478  Rows<MT,false,false,true,CRAs...>::insert( size_t i, size_t j, const ElementType& value )
5479 {
5480  return matrix_.insert( j, idx(i), value );
5481 }
5483 //*************************************************************************************************
5484 
5485 
5486 //*************************************************************************************************
5530 template< typename MT // Type of the sparse matrix
5531  , typename... CRAs > // Compile time row arguments
5532 inline void Rows<MT,false,false,true,CRAs...>::append( size_t i, size_t j, const ElementType& value, bool check )
5533 {
5534  if( !check || !isDefault<strict>( value ) )
5535  matrix_.insert( j, idx(i), value );
5536 }
5538 //*************************************************************************************************
5539 
5540 
5541 //*************************************************************************************************
5555 template< typename MT // Type of the sparse matrix
5556  , typename... CRAs > // Compile time row arguments
5557 inline void Rows<MT,false,false,true,CRAs...>::finalize( size_t i )
5558 {
5559  MAYBE_UNUSED( i );
5560 
5561  return;
5562 }
5564 //*************************************************************************************************
5565 
5566 
5567 
5568 
5569 //=================================================================================================
5570 //
5571 // ERASE FUNCTIONS
5572 //
5573 //=================================================================================================
5574 
5575 //*************************************************************************************************
5585 template< typename MT // Type of the sparse matrix
5586  , typename... CRAs > // Compile time row arguments
5587 inline void Rows<MT,false,false,true,CRAs...>::erase( size_t i, size_t j )
5588 {
5589  BLAZE_USER_ASSERT( i < rows() , "Invalid row access index" );
5590  BLAZE_USER_ASSERT( j < columns(), "Invalid column access index" );
5591 
5592  matrix_.erase( j, idx(i) );
5593 }
5595 //*************************************************************************************************
5596 
5597 
5598 //*************************************************************************************************
5608 template< typename MT // Type of the sparse matrix
5609  , typename... CRAs > // Compile time row arguments
5610 inline typename Rows<MT,false,false,true,CRAs...>::Iterator
5611  Rows<MT,false,false,true,CRAs...>::erase( size_t i, Iterator pos )
5612 {
5613  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
5614 
5615  return matrix_.erase( idx(i), pos );
5616 }
5618 //*************************************************************************************************
5619 
5620 
5621 //*************************************************************************************************
5632 template< typename MT // Type of the sparse matrix
5633  , typename... CRAs > // Compile time row arguments
5634 inline typename Rows<MT,false,false,true,CRAs...>::Iterator
5635  Rows<MT,false,false,true,CRAs...>::erase( size_t i, Iterator first, Iterator last )
5636 {
5637  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
5638 
5639  return matrix_.erase( idx(i), first, last );
5640 }
5642 //*************************************************************************************************
5643 
5644 
5645 //*************************************************************************************************
5668 template< typename MT // Type of the sparse matrix
5669  , typename... CRAs > // Compile time row arguments
5670 template< typename Pred > // Type of the unary predicate
5671 inline void Rows<MT,false,false,true,CRAs...>::erase( Pred predicate )
5672 {
5673  for( size_t i=0UL; i<rows(); ++i ) {
5674  matrix_.erase( idx(i), begin(i), end(i), predicate );
5675  }
5676 }
5678 //*************************************************************************************************
5679 
5680 
5681 //*************************************************************************************************
5708 template< typename MT // Type of the sparse matrix
5709  , typename... CRAs > // Compile time row arguments
5710 template< typename Pred > // Type of the unary predicate
5711 inline void Rows<MT,false,false,true,CRAs...>::erase( size_t i, Iterator first, Iterator last, Pred predicate )
5712 {
5713  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
5714 
5715  matrix_.erase( idx(i), first, last, predicate );
5716 }
5718 //*************************************************************************************************
5719 
5720 
5721 
5722 
5723 //=================================================================================================
5724 //
5725 // LOOKUP FUNCTIONS
5726 //
5727 //=================================================================================================
5728 
5729 //*************************************************************************************************
5744 template< typename MT // Type of the sparse matrix
5745  , typename... CRAs > // Compile time row arguments
5746 inline typename Rows<MT,false,false,true,CRAs...>::Iterator
5747  Rows<MT,false,false,true,CRAs...>::find( size_t i, size_t j )
5748 {
5749  return matrix_.find( j, idx(i) );
5750 }
5752 //*************************************************************************************************
5753 
5754 
5755 //*************************************************************************************************
5770 template< typename MT // Type of the sparse matrix
5771  , typename... CRAs > // Compile time row arguments
5772 inline typename Rows<MT,false,false,true,CRAs...>::ConstIterator
5773  Rows<MT,false,false,true,CRAs...>::find( size_t i, size_t j ) const
5774 {
5775  return matrix_.find( j, idx(i) );
5776 }
5778 //*************************************************************************************************
5779 
5780 
5781 //*************************************************************************************************
5795 template< typename MT // Type of the sparse matrix
5796  , typename... CRAs > // Compile time row arguments
5797 inline typename Rows<MT,false,false,true,CRAs...>::Iterator
5798  Rows<MT,false,false,true,CRAs...>::lowerBound( size_t i, size_t j )
5799 {
5800  return matrix_.lowerBound( j, idx(i) );
5801 }
5803 //*************************************************************************************************
5804 
5805 
5806 //*************************************************************************************************
5820 template< typename MT // Type of the sparse matrix
5821  , typename... CRAs > // Compile time row arguments
5822 inline typename Rows<MT,false,false,true,CRAs...>::ConstIterator
5823  Rows<MT,false,false,true,CRAs...>::lowerBound( size_t i, size_t j ) const
5824 {
5825  return matrix_.lowerBound( j, idx(i) );
5826 }
5828 //*************************************************************************************************
5829 
5830 
5831 //*************************************************************************************************
5845 template< typename MT // Type of the sparse matrix
5846  , typename... CRAs > // Compile time row arguments
5847 inline typename Rows<MT,false,false,true,CRAs...>::Iterator
5848  Rows<MT,false,false,true,CRAs...>::upperBound( size_t i, size_t j )
5849 {
5850  return matrix_.upperBound( j, idx(i) );
5851 }
5853 //*************************************************************************************************
5854 
5855 
5856 //*************************************************************************************************
5870 template< typename MT // Type of the sparse matrix
5871  , typename... CRAs > // Compile time row arguments
5872 inline typename Rows<MT,false,false,true,CRAs...>::ConstIterator
5873  Rows<MT,false,false,true,CRAs...>::upperBound( size_t i, size_t j ) const
5874 {
5875  return matrix_.upperBound( j, idx(i) );
5876 }
5878 //*************************************************************************************************
5879 
5880 
5881 
5882 
5883 //=================================================================================================
5884 //
5885 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
5886 //
5887 //=================================================================================================
5888 
5889 //*************************************************************************************************
5900 template< typename MT // Type of the sparse matrix
5901  , typename... CRAs > // Compile time row arguments
5902 template< typename Other > // Data type of the foreign expression
5903 inline bool Rows<MT,false,false,true,CRAs...>::canAlias( const Other* alias ) const noexcept
5904 {
5905  return matrix_.isAliased( alias );
5906 }
5908 //*************************************************************************************************
5909 
5910 
5911 //*************************************************************************************************
5922 template< typename MT // Type of the sparse matrix
5923  , typename... CRAs > // Compile time row arguments
5924 template< typename Other > // Data type of the foreign expression
5925 inline bool Rows<MT,false,false,true,CRAs...>::isAliased( const Other* alias ) const noexcept
5926 {
5927  return matrix_.isAliased( alias );
5928 }
5930 //*************************************************************************************************
5931 
5932 
5933 //*************************************************************************************************
5944 template< typename MT // Type of the sparse matrix
5945  , typename... CRAs > // Compile time row arguments
5946 inline bool Rows<MT,false,false,true,CRAs...>::canSMPAssign() const noexcept
5947 {
5948  return false;
5949 }
5951 //*************************************************************************************************
5952 
5953 } // namespace blaze
5954 
5955 #endif
#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
Constraint on the data type.
Header file for auxiliary alias declarations.
decltype(auto) column(Matrix< MT, SO > &matrix, RCAs... args)
Creating a view on a specific column of the given matrix.
Definition: Column.h:133
Headerfile for the generic min algorithm.
Header file for the blaze::checked and blaze::unchecked instances.
auto operator-=(DenseMatrix< MT, SO > &mat, ST scalar) -> EnableIf_t< IsNumeric_v< ST >, MT & >
Subtraction assignment operator for the subtraction of a dense matrix and a scalar value ( ).
Definition: DenseMatrix.h:432
Header file for the Schur product trait.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_ROWS_TYPE(T)
Constraint on the data type.In case the given data type T is a row selection type (i....
Definition: Rows.h:81
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.In case of an invalid run time expression,...
Definition: Assert.h:117
Header file for the IsUniUpper type trait.
Header file for the subtraction trait.
size_t capacity(const Matrix< MT, SO > &matrix) noexcept
Returns the maximum capacity of the matrix.
Definition: Matrix.h:546
Header file for basic type definitions.
constexpr 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:750
Header file for the View base class.
Header file for the IsSparseMatrix type trait.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE(T)
Constraint on the data type.In case the given data type T is a computational expression (i....
Definition: Computation.h:81
MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:372
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:595
constexpr Unchecked unchecked
Global Unchecked instance.The blaze::unchecked instance is an optional token for the creation of view...
Definition: Check.h:138
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SUBMATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a submatrix type (i.e....
Definition: Submatrix.h:81
void ctranspose(Matrix< MT, SO > &matrix)
In-place conjugate transpose of the given matrix.
Definition: Matrix.h:851
#define BLAZE_CONSTRAINT_MUST_NOT_BE_UNITRIANGULAR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a lower or upper unitriangular matrix ty...
Definition: UniTriangular.h:81
Header file for the MAYBE_UNUSED function template.
constexpr bool IsReference_v
Auxiliary variable template for the IsReference type trait.The IsReference_v variable template provid...
Definition: IsReference.h:95
size_t nonZeros(const Matrix< MT, SO > &matrix)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:584
#define BLAZE_CONSTRAINT_MUST_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a symmetric matrix type,...
Definition: Symmetric.h:60
Constraints on the storage order of matrix types.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_TRANSEXPR_TYPE(T)
Constraint on the data type.In case the given data type T is a transposition expression (i....
Definition: TransExpr.h:81
Header file for the extended initializer_list functionality.
Header file for the IsUniLower type trait.
constexpr size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:514
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:482
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:416
Constraint on the data type.
Constraint on the data type.
Header file for the SparseMatrix base class.
Constraint on the data type.
Header file for the implementation of a matrix representation of an initializer list.
Headerfile for the generic max algorithm.
Header file for the IsStrictlyUpper type trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
decltype(auto) ctrans(const DenseMatrix< MT, SO > &dm)
Returns the conjugate transpose matrix of dm.
Definition: DMatMapExpr.h:1361
Header file for the If class template.
#define BLAZE_CONSTRAINT_MUST_BE_COLUMN_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a column-major dense or sparse matri...
Definition: ColumnMajorMatrix.h:61
decltype(auto) operator *(const DenseMatrix< MT1, false > &lhs, const DenseMatrix< MT2, false > &rhs)
Multiplication operator for the multiplication of two row-major dense matrices ( ).
Definition: DMatDMatMultExpr.h:9091
#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
decltype(auto) min(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the componentwise minimum of the dense matrices lhs and rhs.
Definition: DMatDMatMapExpr.h:1162
#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
auto operator+=(DenseMatrix< MT, SO > &mat, ST scalar) -> EnableIf_t< IsNumeric_v< ST >, MT & >
Addition assignment operator for the addition of a dense matrix and a scalar value ( ).
Definition: DenseMatrix.h:370
constexpr bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:253
constexpr bool Contains_v
Auxiliary variable template for the Contains type trait.The Contains_v variable template provides a c...
Definition: Contains.h:138
Header file for the IsLower type trait.
constexpr void MAYBE_UNUSED(const Args &...)
Suppression of unused parameter warnings.
Definition: MaybeUnused.h:81
Header file for the SparseElement base class.
Constraint on the data type.
Header file for the exception macros of the math module.
decltype(auto) max(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the componentwise maximum of the dense matrices lhs and rhs.
Definition: DMatDMatMapExpr.h:1198
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:438
constexpr bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:293
Constraint on the data type.
Header file for the IsStrictlyLower type trait.
Constraint on the data type.
auto operator/=(DenseMatrix< MT, SO > &mat, ST scalar) -> EnableIf_t< IsNumeric_v< ST >, MT & >
Division assignment operator for the division of a dense matrix by a scalar value ( ).
Definition: DenseMatrix.h:558
#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,...
Definition: Symmetric.h:79
#define BLAZE_CONSTRAINT_MUST_BE_ROW_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a row-major dense or sparse matrix t...
Definition: RowMajorMatrix.h:61
Header file for the IsConst type trait.
Header file for run time assertion macros.
Header file for the relaxation flag types.
Header file for the addition trait.
Header file for the Unique class template.
Check< false > Unchecked
Type of the blaze::unchecked instance.blaze::Unchecked is the type of the blaze::unchecked instance,...
Definition: Check.h:96
decltype(auto) row(Matrix< MT, SO > &, RRAs...)
Creating a view on a specific row of the given matrix.
Definition: Row.h:133
#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,...
Definition: Reference.h:79
Header file for the isDefault shim.
BLAZE_ALWAYS_INLINE const EnableIf_t< IsIntegral_v< T > &&HasSize_v< T, 1UL >, If_t< IsSigned_v< T >, SIMDint8, SIMDuint8 > > set(T value) noexcept
Sets all values in the vector to the given 1-byte integral value.
Definition: Set.h:75
auto smpAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:100
Constraint on the data type.
Constraint on the data type.
Constraints on the storage order of matrix types.
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:808
#define BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION(T)
Constraint on the data type.In case the given data type T requires an intermediate evaluation within ...
Definition: RequiresEvaluation.h:81
Header file for the IsReference type trait.
constexpr size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:498
Header file for the rows trait.
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:765
Constraint on the data type.
Header file for the implementation of the RowsData class template.
Header file for the IsComputation type trait class.
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:264
auto operator *=(DenseMatrix< MT, SO > &mat, ST scalar) -> EnableIf_t< IsNumeric_v< ST >, MT & >
Multiplication assignment operator for the multiplication of a dense matrix and a scalar value ( ).
Definition: DenseMatrix.h:494
#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,...
Definition: Hermitian.h:79
#define BLAZE_THROW_LOGIC_ERROR(MESSAGE)
Macro for the emission of a std::logic_error exception.This macro encapsulates the default way of Bla...
Definition: Exception.h:187
Header file for the IsUpper type trait.
Header file for the implementation of the Rows base template.
Header file for the IsRestricted type trait.
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression,...
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
constexpr bool IsSparseMatrix_v
Auxiliary variable template for the IsSparseMatrix type trait.The IsSparseMatrix_v variable template ...
Definition: IsSparseMatrix.h:138
Header file for the IsExpression type trait class.
Constraint on the data type.
void transpose(Matrix< MT, SO > &matrix)
In-place transpose of the given matrix.
Definition: Matrix.h:825