Blaze 3.9
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>
82#include <blaze/util/Assert.h>
86#include <blaze/util/mpl/If.h>
87#include <blaze/util/Types.h>
90
91
92namespace blaze {
93
94//=================================================================================================
95//
96// CLASS TEMPLATE SPECIALIZATION FOR ROW-MAJOR SPARSE MATRICES
97//
98//=================================================================================================
99
100//*************************************************************************************************
108template< typename MT // Type of the sparse matrix
109 , bool SF // Symmetry flag
110 , typename... CRAs > // Compile time row arguments
111class Rows<MT,true,false,SF,CRAs...>
112 : public View< SparseMatrix< Rows<MT,true,false,SF,CRAs...>, false > >
113 , private RowsData<CRAs...>
114{
115 private:
116 //**Type definitions****************************************************************************
117 using DataType = RowsData<CRAs...>;
118 using Operand = If_t< IsExpression_v<MT>, MT, MT& >;
119 //**********************************************************************************************
120
121 //**Compile time flags**************************************************************************
122 using DataType::N;
123 //**********************************************************************************************
124
125 public:
126 //**Type definitions****************************************************************************
128 using This = Rows<MT,true,false,SF,CRAs...>;
129
131 using BaseType = View< SparseMatrix<This,false> >;
132
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_;
310 //**********************************************************************************************
311
312 //**Compile time checks*************************************************************************
321 //**********************************************************************************************
322};
324//*************************************************************************************************
325
326
327
328
329//=================================================================================================
330//
331// CONSTRUCTORS
332//
333//=================================================================================================
334
335//*************************************************************************************************
348template< typename MT // Type of the sparse matrix
349 , bool SF // Symmetry flag
350 , typename... CRAs > // Compile time row arguments
351template< typename... RRAs > // Runtime row arguments
352inline 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( isChecked( args... ) ) {
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//*************************************************************************************************
387template< typename MT // Type of the sparse matrix
388 , bool SF // Symmetry flag
389 , typename... CRAs > // Compile time row arguments
390inline 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//*************************************************************************************************
413template< typename MT // Type of the sparse matrix
414 , bool SF // Symmetry flag
415 , typename... CRAs > // Compile time row arguments
416inline 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//*************************************************************************************************
440template< typename MT // Type of the sparse matrix
441 , bool SF // Symmetry flag
442 , typename... CRAs > // Compile time row arguments
443inline 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//*************************************************************************************************
470template< typename MT // Type of the sparse matrix
471 , bool SF // Symmetry flag
472 , typename... CRAs > // Compile time row arguments
473inline 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//*************************************************************************************************
497template< typename MT // Type of the sparse matrix
498 , bool SF // Symmetry flag
499 , typename... CRAs > // Compile time row arguments
500inline 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//*************************************************************************************************
520template< typename MT // Type of the sparse matrix
521 , bool SF // Symmetry flag
522 , typename... CRAs > // Compile time row arguments
523inline typename Rows<MT,true,false,SF,CRAs...>::ConstIterator
525{
526 BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
527
528 return matrix_.cbegin( idx(i) );
529}
531//*************************************************************************************************
532
533
534//*************************************************************************************************
543template< typename MT // Type of the sparse matrix
544 , bool SF // Symmetry flag
545 , typename... CRAs > // Compile time row arguments
546inline 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//*************************************************************************************************
566template< typename MT // Type of the sparse matrix
567 , bool SF // Symmetry flag
568 , typename... CRAs > // Compile time row arguments
569inline 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//*************************************************************************************************
589template< typename MT // Type of the sparse matrix
590 , bool SF // Symmetry flag
591 , typename... CRAs > // Compile time row arguments
592inline typename Rows<MT,true,false,SF,CRAs...>::ConstIterator
594{
595 BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
596
597 return matrix_.cend( idx(i) );
598}
600//*************************************************************************************************
601
602
603//*************************************************************************************************
612template< typename MT // Type of the sparse matrix
613 , bool SF // Symmetry flag
614 , typename... CRAs > // Compile time row arguments
615inline typename Rows<MT,true,false,SF,CRAs...>::ConstIterator
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//*************************************************************************************************
650template< typename MT // Type of the sparse matrix
651 , bool SF // Symmetry flag
652 , typename... CRAs > // Compile time row arguments
653inline 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//*************************************************************************************************
699template< typename MT // Type of the sparse matrix
700 , bool SF // Symmetry flag
701 , typename... CRAs > // Compile time row arguments
702inline 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( this ) ) {
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//*************************************************************************************************
761template< typename MT // Type of the sparse matrix
762 , bool SF // Symmetry flag
763 , typename... CRAs > // Compile time row arguments
764template< typename MT2 // Type of the right-hand side matrix
765 , bool SO > // Storage order of the right-hand side matrix
766inline 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( this ) ) {
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//*************************************************************************************************
823template< typename MT // Type of the sparse matrix
824 , bool SF // Symmetry flag
825 , typename... CRAs > // Compile time row arguments
826template< typename MT2 // Type of the right-hand side matrix
827 , bool SO > // Storage order of the right-hand side matrix
828inline 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//*************************************************************************************************
883template< typename MT // Type of the sparse matrix
884 , bool SF // Symmetry flag
885 , typename... CRAs > // Compile time row arguments
886template< typename MT2 // Type of the right-hand side matrix
887 , bool SO > // Storage order of the right-hand side matrix
888inline 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//*************************************************************************************************
943template< typename MT // Type of the sparse matrix
944 , bool SF // Symmetry flag
945 , typename... CRAs > // Compile time row arguments
946template< typename MT2 // Type of the right-hand side matrix
947 , bool SO > // Storage order of the right-hand side matrix
948inline 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//*************************************************************************************************
1003template< typename MT // Type of the sparse matrix
1004 , bool SF // Symmetry flag
1005 , typename... CRAs > // Compile time row arguments
1006inline MT& Rows<MT,true,false,SF,CRAs...>::operand() noexcept
1007{
1008 return matrix_;
1009}
1011//*************************************************************************************************
1012
1013
1014//*************************************************************************************************
1020template< typename MT // Type of the sparse matrix
1021 , bool SF // Symmetry flag
1022 , typename... CRAs > // Compile time row arguments
1023inline const MT& Rows<MT,true,false,SF,CRAs...>::operand() const noexcept
1024{
1025 return matrix_;
1026}
1028//*************************************************************************************************
1029
1030
1031//*************************************************************************************************
1037template< typename MT // Type of the sparse matrix
1038 , bool SF // Symmetry flag
1039 , typename... CRAs > // Compile time row arguments
1040inline size_t Rows<MT,true,false,SF,CRAs...>::columns() const noexcept
1041{
1042 return matrix_.columns();
1043}
1045//*************************************************************************************************
1046
1047
1048//*************************************************************************************************
1054template< typename MT // Type of the sparse matrix
1055 , bool SF // Symmetry flag
1056 , typename... CRAs > // Compile time row arguments
1057inline size_t Rows<MT,true,false,SF,CRAs...>::capacity() const noexcept
1058{
1059 return nonZeros() + matrix_.capacity() - matrix_.nonZeros();
1060}
1062//*************************************************************************************************
1063
1064
1065//*************************************************************************************************
1074template< typename MT // Type of the sparse matrix
1075 , bool SF // Symmetry flag
1076 , typename... CRAs > // Compile time row arguments
1077inline 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//*************************************************************************************************
1093template< typename MT // Type of the sparse matrix
1094 , bool SF // Symmetry flag
1095 , typename... CRAs > // Compile time row arguments
1096inline 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//*************************************************************************************************
1118template< typename MT // Type of the sparse matrix
1119 , bool SF // Symmetry flag
1120 , typename... CRAs > // Compile time row arguments
1121inline 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//*************************************************************************************************
1137template< 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//*************************************************************************************************
1160template< typename MT // Type of the sparse matrix
1161 , bool SF // Symmetry flag
1162 , typename... CRAs > // Compile time row arguments
1163inline void Rows<MT,true,false,SF,CRAs...>::reset( size_t i )
1164{
1165 matrix_.reset( idx(i) );
1166}
1168//*************************************************************************************************
1169
1170
1171//*************************************************************************************************
1182template< typename MT // Type of the sparse matrix
1183 , bool SF // Symmetry flag
1184 , typename... CRAs > // Compile time row arguments
1185inline 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//*************************************************************************************************
1210template< typename MT // Type of the sparse matrix
1211 , bool SF // Symmetry flag
1212 , typename... CRAs > // Compile time row arguments
1213void 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//*************************************************************************************************
1231template< typename MT // Type of the sparse matrix
1232 , bool SF // Symmetry flag
1233 , typename... CRAs > // Compile time row arguments
1234void 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//*************************************************************************************************
1255template< typename MT // Type of the sparse matrix
1256 , bool SF // Symmetry flag
1257 , typename... CRAs > // Compile time row arguments
1258void 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//*************************************************************************************************
1278template< typename MT // Type of the sparse matrix
1279 , bool SF // Symmetry flag
1280 , typename... CRAs > // Compile time row arguments
1281inline 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//*************************************************************************************************
1319template< typename MT // Type of the sparse matrix
1320 , bool SF // Symmetry flag
1321 , typename... CRAs > // Compile time row arguments
1322inline 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//*************************************************************************************************
1345template< typename MT // Type of the sparse matrix
1346 , bool SF // Symmetry flag
1347 , typename... CRAs > // Compile time row arguments
1348inline 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//*************************************************************************************************
1401template< typename MT // Type of the sparse matrix
1402 , bool SF // Symmetry flag
1403 , typename... CRAs > // Compile time row arguments
1404inline 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//*************************************************************************************************
1427template< typename MT // Type of the sparse matrix
1428 , bool SF // Symmetry flag
1429 , typename... CRAs > // Compile time row arguments
1430inline 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//*************************************************************************************************
1458template< typename MT // Type of the sparse matrix
1459 , bool SF // Symmetry flag
1460 , typename... CRAs > // Compile time row arguments
1461inline 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//*************************************************************************************************
1482template< typename MT // Type of the sparse matrix
1483 , bool SF // Symmetry flag
1484 , typename... CRAs > // Compile time row arguments
1485inline 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//*************************************************************************************************
1507template< typename MT // Type of the sparse matrix
1508 , bool SF // Symmetry flag
1509 , typename... CRAs > // Compile time row arguments
1510inline 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//*************************************************************************************************
1544template< typename MT // Type of the sparse matrix
1545 , bool SF // Symmetry flag
1546 , typename... CRAs > // Compile time row arguments
1547template< typename Pred > // Type of the unary predicate
1548inline 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//*************************************************************************************************
1585template< typename MT // Type of the sparse matrix
1586 , bool SF // Symmetry flag
1587 , typename... CRAs > // Compile time row arguments
1588template< typename Pred > // Type of the unary predicate
1589inline 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//*************************************************************************************************
1622template< typename MT // Type of the sparse matrix
1623 , bool SF // Symmetry flag
1624 , typename... CRAs > // Compile time row arguments
1625inline 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//*************************************************************************************************
1649template< typename MT // Type of the sparse matrix
1650 , bool SF // Symmetry flag
1651 , typename... CRAs > // Compile time row arguments
1652inline 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//*************************************************************************************************
1675template< typename MT // Type of the sparse matrix
1676 , bool SF // Symmetry flag
1677 , typename... CRAs > // Compile time row arguments
1678inline 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//*************************************************************************************************
1701template< typename MT // Type of the sparse matrix
1702 , bool SF // Symmetry flag
1703 , typename... CRAs > // Compile time row arguments
1704inline 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//*************************************************************************************************
1727template< typename MT // Type of the sparse matrix
1728 , bool SF // Symmetry flag
1729 , typename... CRAs > // Compile time row arguments
1730inline 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//*************************************************************************************************
1753template< typename MT // Type of the sparse matrix
1754 , bool SF // Symmetry flag
1755 , typename... CRAs > // Compile time row arguments
1756inline 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//*************************************************************************************************
1786template< typename MT // Type of the sparse matrix
1787 , bool SF // Symmetry flag
1788 , typename... CRAs > // Compile time row arguments
1789inline 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//*************************************************************************************************
1833template< typename MT // Type of the sparse matrix
1834 , bool SF // Symmetry flag
1835 , typename... CRAs > // Compile time row arguments
1836inline Rows<MT,true,false,SF,CRAs...>&
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//*************************************************************************************************
1880template< typename MT // Type of the sparse matrix
1881 , bool SF // Symmetry flag
1882 , typename... CRAs > // Compile time row arguments
1883template< typename Other > // Data type of the scalar value
1884inline 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//*************************************************************************************************
1922template< typename MT // Type of the sparse matrix
1923 , bool SF // Symmetry flag
1924 , typename... CRAs > // Compile time row arguments
1925template< typename Other > // Data type of the foreign expression
1926inline bool Rows<MT,true,false,SF,CRAs...>::canAlias( const Other* alias ) const noexcept
1927{
1928 return matrix_.isAliased( &unview( *alias ) );
1929}
1931//*************************************************************************************************
1932
1933
1934//*************************************************************************************************
1945template< typename MT // Type of the sparse matrix
1946 , bool SF // Symmetry flag
1947 , typename... CRAs > // Compile time row arguments
1948template< typename Other > // Data type of the foreign expression
1949inline bool Rows<MT,true,false,SF,CRAs...>::isAliased( const Other* alias ) const noexcept
1950{
1951 return matrix_.isAliased( &unview( *alias ) );
1952}
1954//*************************************************************************************************
1955
1956
1957//*************************************************************************************************
1968template< typename MT // Type of the sparse matrix
1969 , bool SF // Symmetry flag
1970 , typename... CRAs > // Compile time row arguments
1971inline bool Rows<MT,true,false,SF,CRAs...>::canSMPAssign() const noexcept
1972{
1973 return false;
1974}
1976//*************************************************************************************************
1977
1978
1979//*************************************************************************************************
1991template< typename MT // Type of the sparse matrix
1992 , bool SF // Symmetry flag
1993 , typename... CRAs > // Compile time row arguments
1994template< typename MT2 // Type of the right-hand side dense matrix
1995 , bool SO > // Storage order of the right-hand side dense matrix
1996inline 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//*************************************************************************************************
2038template< typename MT // Type of the sparse matrix
2039 , bool SF // Symmetry flag
2040 , typename... CRAs > // Compile time row arguments
2041template< typename MT2 > // Type of the right-hand side sparse matrix
2042inline 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//*************************************************************************************************
2084template< typename MT // Type of the sparse matrix
2085 , bool SF // Symmetry flag
2086 , typename... CRAs > // Compile time row arguments
2087template< typename MT2 > // Type of the right-hand side sparse matrix
2088inline 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//*************************************************************************************************
2133template< typename MT // Type of the sparse matrix
2134 , bool SF // Symmetry flag
2135 , typename... CRAs > // Compile time row arguments
2136template< typename MT2 // Type of the right-hand side matrix
2137 , bool SO > // Storage order of the right-hand side matrix
2138inline 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//*************************************************************************************************
2170template< typename MT // Type of the sparse matrix
2171 , bool SF // Symmetry flag
2172 , typename... CRAs > // Compile time row arguments
2173template< typename MT2 // Type of the right-hand side matrix
2174 , bool SO > // Storage order of the right-hand side matrix
2175inline 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//*************************************************************************************************
2207template< typename MT // Type of the sparse matrix
2208 , bool SF // Symmetry flag
2209 , typename... CRAs > // Compile time row arguments
2210template< typename MT2 // Type of the right-hand side matrix
2211 , bool SO > // Storage order of the right-hand side matrix
2212inline 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//*************************************************************************************************
2253template< typename MT // Type of the sparse matrix
2254 , typename... CRAs > // Compile time row arguments
2255class 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
2275 using BaseType = View< SparseMatrix<This,false> >;
2276
2277 using ViewedType = MT;
2278 using ResultType = RowsTrait_t<MT,N>;
2279 using OppositeType = OppositeType_t<ResultType>;
2280 using TransposeType = TransposeType_t<ResultType>;
2281 using ElementType = ElementType_t<MT>;
2282 using ReturnType = ReturnType_t<MT>;
2283 using CompositeType = const Rows&;
2284
2286 using ConstReference = ConstReference_t<MT>;
2287
2289 using Reference = If_t< IsConst_v<MT>, ConstReference, Reference_t<MT> >;
2290 //**********************************************************************************************
2291
2292 //**RowsElement class definition****************************************************************
2295 template< typename MatrixType // Type of the sparse matrix
2296 , typename IteratorType > // Type of the sparse matrix iterator
2297 class RowsElement
2298 : private SparseElement
2299 {
2300 public:
2301 //**Constructor******************************************************************************
2307 inline RowsElement( IteratorType pos, size_t column )
2308 : pos_ ( pos ) // Iterator to the current position of the sparse row element
2309 , column_( column ) // Index of the according column
2310 {}
2311 //*******************************************************************************************
2312
2313 //**Assignment operator**********************************************************************
2319 template< typename T > inline RowsElement& operator=( const T& v ) {
2320 *pos_ = v;
2321 return *this;
2322 }
2323 //*******************************************************************************************
2324
2325 //**Addition assignment operator*************************************************************
2331 template< typename T > inline RowsElement& operator+=( const T& v ) {
2332 *pos_ += v;
2333 return *this;
2334 }
2335 //*******************************************************************************************
2336
2337 //**Subtraction assignment operator**********************************************************
2343 template< typename T > inline RowsElement& operator-=( const T& v ) {
2344 *pos_ -= v;
2345 return *this;
2346 }
2347 //*******************************************************************************************
2348
2349 //**Multiplication assignment operator*******************************************************
2355 template< typename T > inline RowsElement& operator*=( const T& v ) {
2356 *pos_ *= v;
2357 return *this;
2358 }
2359 //*******************************************************************************************
2360
2361 //**Division assignment operator*************************************************************
2367 template< typename T > inline RowsElement& operator/=( const T& v ) {
2368 *pos_ /= v;
2369 return *this;
2370 }
2371 //*******************************************************************************************
2372
2373 //**Element access operator******************************************************************
2378 inline const RowsElement* operator->() const {
2379 return this;
2380 }
2381 //*******************************************************************************************
2382
2383 //**Value function***************************************************************************
2388 inline decltype(auto) value() const {
2389 return pos_->value();
2390 }
2391 //*******************************************************************************************
2392
2393 //**Index function***************************************************************************
2398 inline size_t index() const {
2399 return column_;
2400 }
2401 //*******************************************************************************************
2402
2403 private:
2404 //**Member variables*************************************************************************
2405 IteratorType pos_;
2406 size_t column_;
2407 //*******************************************************************************************
2408 };
2409 //**********************************************************************************************
2410
2411 //**RowsIterator class definition***************************************************************
2414 template< typename MatrixType // Type of the sparse matrix
2415 , typename IteratorType > // Type of the sparse matrix iterator
2416 class RowsIterator
2417 {
2418 public:
2419 //**Type definitions*************************************************************************
2420 using IteratorCategory = std::forward_iterator_tag;
2421 using ValueType = RowsElement<MatrixType,IteratorType>;
2422 using PointerType = ValueType;
2423 using ReferenceType = ValueType;
2424 using DifferenceType = ptrdiff_t;
2425
2426 // STL iterator requirements
2427 using iterator_category = IteratorCategory;
2428 using value_type = ValueType;
2429 using pointer = PointerType;
2430 using reference = ReferenceType;
2431 using difference_type = DifferenceType;
2432 //*******************************************************************************************
2433
2434 //**Constructor******************************************************************************
2437 inline RowsIterator()
2438 : matrix_( nullptr ) // The sparse matrix containing the selected row
2439 , row_ ( 0UL ) // The current row index
2440 , column_( 0UL ) // The current column index
2441 , pos_ () // Iterator to the current sparse element
2442 {}
2443 //*******************************************************************************************
2444
2445 //**Constructor******************************************************************************
2452 inline RowsIterator( MatrixType& matrix, size_t row, size_t column )
2453 : matrix_( &matrix ) // The sparse matrix containing the selected row
2454 , row_ ( row ) // The current row index
2455 , column_( column ) // The current column index
2456 , pos_ () // Iterator to the current sparse element
2457 {
2458 for( ; column_<matrix_->columns(); ++column_ ) {
2459 pos_ = matrix_->find( row_, column_ );
2460 if( pos_ != matrix_->end( column_ ) ) break;
2461 }
2462 }
2463 //*******************************************************************************************
2464
2465 //**Constructor******************************************************************************
2473 inline RowsIterator( MatrixType& matrix, size_t row, size_t column, IteratorType pos )
2474 : matrix_( &matrix ) // The sparse matrix containing the selected row
2475 , row_ ( row ) // The current row index
2476 , column_( column ) // The current column index
2477 , pos_ ( pos ) // Iterator to the current sparse element
2478 {
2479 BLAZE_INTERNAL_ASSERT( matrix.find( row, column ) == pos, "Invalid initial iterator position" );
2480 }
2481 //*******************************************************************************************
2482
2483 //**Constructor******************************************************************************
2488 template< typename MatrixType2, typename IteratorType2 >
2489 inline RowsIterator( const RowsIterator<MatrixType2,IteratorType2>& it )
2490 : matrix_( it.matrix_ ) // The sparse matrix containing the selected row
2491 , row_ ( it.row_ ) // The current row index
2492 , column_( it.column_ ) // The current column index
2493 , pos_ ( it.pos_ ) // Iterator to the current sparse element
2494 {}
2495 //*******************************************************************************************
2496
2497 //**Prefix increment operator****************************************************************
2502 inline RowsIterator& operator++() {
2503 ++column_;
2504 for( ; column_<matrix_->columns(); ++column_ ) {
2505 pos_ = matrix_->find( row_, column_ );
2506 if( pos_ != matrix_->end( column_ ) ) break;
2507 }
2508
2509 return *this;
2510 }
2511 //*******************************************************************************************
2512
2513 //**Postfix increment operator***************************************************************
2518 inline const RowsIterator operator++( int ) {
2519 const RowsIterator tmp( *this );
2520 ++(*this);
2521 return tmp;
2522 }
2523 //*******************************************************************************************
2524
2525 //**Element access operator******************************************************************
2530 inline ReferenceType operator*() const {
2531 return ReferenceType( pos_, column_ );
2532 }
2533 //*******************************************************************************************
2534
2535 //**Element access operator******************************************************************
2540 inline PointerType operator->() const {
2541 return PointerType( pos_, column_ );
2542 }
2543 //*******************************************************************************************
2544
2545 //**Equality operator************************************************************************
2551 template< typename MatrixType2, typename IteratorType2 >
2552 inline bool operator==( const RowsIterator<MatrixType2,IteratorType2>& rhs ) const noexcept {
2553 return column_ == rhs.column_;
2554 }
2555 //*******************************************************************************************
2556
2557 //**Inequality operator**********************************************************************
2563 template< typename MatrixType2, typename IteratorType2 >
2564 inline bool operator!=( const RowsIterator<MatrixType2,IteratorType2>& rhs ) const noexcept {
2565 return !( *this == rhs );
2566 }
2567 //*******************************************************************************************
2568
2569 //**Subtraction operator*********************************************************************
2575 inline DifferenceType operator-( const RowsIterator& rhs ) const {
2576 size_t counter( 0UL );
2577 for( size_t j=rhs.column_; j<column_; ++j ) {
2578 if( matrix_->find( row_, j ) != matrix_->end( j ) )
2579 ++counter;
2580 }
2581 return counter;
2582 }
2583 //*******************************************************************************************
2584
2585 private:
2586 //**Member variables*************************************************************************
2587 MatrixType* matrix_;
2588 size_t row_;
2589 size_t column_;
2590 IteratorType pos_;
2591 //*******************************************************************************************
2592
2593 //**Friend declarations**********************************************************************
2594 template< typename MatrixType2, typename IteratorType2 > friend class RowsIterator;
2595 template< typename MT2, bool SO2, bool DF2, bool SF2, typename... CRAs2 > friend class Rows;
2596 //*******************************************************************************************
2597 };
2598 //**********************************************************************************************
2599
2600 //**Type definitions****************************************************************************
2602 using ConstIterator = RowsIterator< const MT, ConstIterator_t<MT> >;
2603
2605 using Iterator = If_t< IsConst_v<MT>, ConstIterator, RowsIterator< MT, Iterator_t<MT> > >;
2606 //**********************************************************************************************
2607
2608 //**Compilation flags***************************************************************************
2610 static constexpr bool smpAssignable = MT::smpAssignable;
2611
2613 static constexpr bool compileTimeArgs = DataType::compileTimeArgs;
2614 //**********************************************************************************************
2615
2616 //**Constructors********************************************************************************
2619 template< typename... RRAs >
2620 explicit inline Rows( MT& matrix, RRAs... args );
2621
2622 Rows( const Rows& ) = default;
2623 Rows( Rows&& ) = default;
2625 //**********************************************************************************************
2626
2627 //**Destructor**********************************************************************************
2630 ~Rows() = default;
2632 //**********************************************************************************************
2633
2634 //**Data access functions***********************************************************************
2637 inline Reference operator()( size_t i, size_t j );
2638 inline ConstReference operator()( size_t i, size_t j ) const;
2639 inline Reference at( size_t i, size_t j );
2640 inline ConstReference at( size_t i, size_t j ) const;
2641 inline Iterator begin ( size_t i );
2642 inline ConstIterator begin ( size_t i ) const;
2643 inline ConstIterator cbegin( size_t i ) const;
2644 inline Iterator end ( size_t i );
2645 inline ConstIterator end ( size_t i ) const;
2646 inline ConstIterator cend ( size_t i ) const;
2648 //**********************************************************************************************
2649
2650 //**Assignment operators************************************************************************
2653 inline Rows& operator=( initializer_list< initializer_list<ElementType> > list );
2654 inline Rows& operator=( const Rows& rhs );
2655
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 );
2658 template< typename MT2, bool SO > inline Rows& operator-=( const Matrix<MT2,SO>& rhs );
2659 template< typename MT2, bool SO > inline Rows& operator%=( const Matrix<MT2,SO>& rhs );
2661 //**********************************************************************************************
2662
2663 //**Utility functions***************************************************************************
2666 using DataType::idx;
2667 using DataType::idces;
2668 using DataType::rows;
2669
2670 inline MT& operand() noexcept;
2671 inline const MT& operand() const noexcept;
2672
2673 inline size_t columns() const noexcept;
2674 inline size_t capacity() const noexcept;
2675 inline size_t capacity( size_t i ) const noexcept;
2676 inline size_t nonZeros() const;
2677 inline size_t nonZeros( size_t i ) const;
2678 inline void reset();
2679 inline void reset( size_t i );
2680 inline void reserve( size_t nonzeros );
2681 void reserve( size_t i, size_t nonzeros );
2682 inline void trim();
2683 inline void trim( size_t j );
2685 //**********************************************************************************************
2686
2687 //**Insertion functions*************************************************************************
2690 inline Iterator set ( size_t i, size_t j, const ElementType& value );
2691 inline Iterator insert ( size_t i, size_t j, const ElementType& value );
2692 inline void append ( size_t i, size_t j, const ElementType& value, bool check=false );
2693 inline void finalize( size_t i );
2695 //**********************************************************************************************
2696
2697 //**Erase functions*****************************************************************************
2700 inline void erase( size_t i, size_t j );
2701 inline Iterator erase( size_t i, Iterator pos );
2702 inline Iterator erase( size_t i, Iterator first, Iterator last );
2703
2704 template< typename Pred >
2705 inline void erase( Pred predicate );
2706
2707 template< typename Pred >
2708 inline void erase( size_t i, Iterator first, Iterator last, Pred predicate );
2710 //**********************************************************************************************
2711
2712 //**Lookup functions****************************************************************************
2715 inline Iterator find ( size_t i, size_t j );
2716 inline ConstIterator find ( size_t i, size_t j ) const;
2717 inline Iterator lowerBound( size_t i, size_t j );
2718 inline ConstIterator lowerBound( size_t i, size_t j ) const;
2719 inline Iterator upperBound( size_t i, size_t j );
2720 inline ConstIterator upperBound( size_t i, size_t j ) const;
2722 //**********************************************************************************************
2723
2724 //**Numeric functions***************************************************************************
2727 inline Rows& transpose();
2728 inline Rows& ctranspose();
2729
2730 template< typename Other > inline Rows& scale( const Other& scalar );
2732 //**********************************************************************************************
2733
2734 //**Expression template evaluation functions****************************************************
2737 template< typename Other > inline bool canAlias ( const Other* alias ) const noexcept;
2738 template< typename Other > inline bool isAliased( const Other* alias ) const noexcept;
2739
2740 inline bool canSMPAssign() const noexcept;
2741
2742 template< typename MT2, bool SO > inline void assign ( const DenseMatrix<MT2,SO>& rhs );
2743 template< typename MT2 > inline void assign ( const SparseMatrix<MT2,true>& rhs );
2744 template< typename MT2 > inline void assign ( const SparseMatrix<MT2,false>& rhs );
2745 template< typename MT2, bool SO > inline void addAssign ( const Matrix<MT2,SO>& rhs );
2746 template< typename MT2, bool SO > inline void subAssign ( const Matrix<MT2,SO>& rhs );
2747 template< typename MT2, bool SO > inline void schurAssign( const Matrix<MT2,SO>& rhs );
2749 //**********************************************************************************************
2750
2751 private:
2752 //**Member variables****************************************************************************
2755 Operand matrix_;
2757 //**********************************************************************************************
2758
2759 //**Compile time checks*************************************************************************
2769 //**********************************************************************************************
2770};
2772//*************************************************************************************************
2773
2774
2775
2776
2777//=================================================================================================
2778//
2779// CONSTRUCTORS
2780//
2781//=================================================================================================
2782
2783//*************************************************************************************************
2796template< typename MT // Type of the sparse matrix
2797 , typename... CRAs > // Compile time row arguments
2798template< typename... RRAs > // Runtime row arguments
2799inline Rows<MT,false,false,false,CRAs...>::Rows( MT& matrix, RRAs... args )
2800 : DataType( args... ) // Base class initialization
2801 , matrix_ ( matrix ) // The matrix containing the rows
2802{
2803 if( isChecked( args... ) ) {
2804 for( size_t i=0UL; i<rows(); ++i ) {
2805 if( matrix_.rows() <= idx(i) ) {
2806 BLAZE_THROW_INVALID_ARGUMENT( "Invalid row access index" );
2807 }
2808 }
2809 }
2810}
2812//*************************************************************************************************
2813
2814
2815
2816
2817//=================================================================================================
2818//
2819// DATA ACCESS FUNCTIONS
2820//
2821//=================================================================================================
2822
2823//*************************************************************************************************
2834template< typename MT // Type of the sparse matrix
2835 , typename... CRAs > // Compile time row arguments
2836inline typename Rows<MT,false,false,false,CRAs...>::Reference
2837 Rows<MT,false,false,false,CRAs...>::operator()( size_t i, size_t j )
2838{
2839 BLAZE_USER_ASSERT( i < rows() , "Invalid row access index" );
2840 BLAZE_USER_ASSERT( j < columns(), "Invalid column access index" );
2841
2842 return matrix_(idx(i),j);
2843}
2845//*************************************************************************************************
2846
2847
2848//*************************************************************************************************
2859template< typename MT // Type of the sparse matrix
2860 , typename... CRAs > // Compile time row arguments
2861inline typename Rows<MT,false,false,false,CRAs...>::ConstReference
2862 Rows<MT,false,false,false,CRAs...>::operator()( size_t i, size_t j ) const
2863{
2864 BLAZE_USER_ASSERT( i < rows() , "Invalid row access index" );
2865 BLAZE_USER_ASSERT( j < columns(), "Invalid column access index" );
2866
2867 return const_cast<const MT&>( matrix_ )(idx(i),j);
2868}
2870//*************************************************************************************************
2871
2872
2873//*************************************************************************************************
2885template< typename MT // Type of the sparse matrix
2886 , typename... CRAs > // Compile time row arguments
2887inline typename Rows<MT,false,false,false,CRAs...>::Reference
2888 Rows<MT,false,false,false,CRAs...>::at( size_t i, size_t j )
2889{
2890 if( i >= rows() ) {
2891 BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
2892 }
2893 if( j >= columns() ) {
2894 BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
2895 }
2896 return (*this)(i,j);
2897}
2899//*************************************************************************************************
2900
2901
2902//*************************************************************************************************
2914template< typename MT // Type of the sparse matrix
2915 , typename... CRAs > // Compile time row arguments
2916inline typename Rows<MT,false,false,false,CRAs...>::ConstReference
2917 Rows<MT,false,false,false,CRAs...>::at( size_t i, size_t j ) const
2918{
2919 if( i >= rows() ) {
2920 BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
2921 }
2922 if( j >= columns() ) {
2923 BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
2924 }
2925 return (*this)(i,j);
2926}
2928//*************************************************************************************************
2929
2930
2931//*************************************************************************************************
2940template< typename MT // Type of the sparse matrix
2941 , typename... CRAs > // Compile time row arguments
2942inline typename Rows<MT,false,false,false,CRAs...>::Iterator
2944{
2945 BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
2946
2947 return Iterator( matrix_, idx(i), 0UL );
2948}
2950//*************************************************************************************************
2951
2952
2953//*************************************************************************************************
2962template< typename MT // Type of the sparse matrix
2963 , typename... CRAs > // Compile time row arguments
2964inline typename Rows<MT,false,false,false,CRAs...>::ConstIterator
2966{
2967 BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
2968
2969 return ConstIterator( matrix_, idx(i), 0UL );
2970}
2972//*************************************************************************************************
2973
2974
2975//*************************************************************************************************
2984template< typename MT // Type of the sparse matrix
2985 , typename... CRAs > // Compile time row arguments
2986inline typename Rows<MT,false,false,false,CRAs...>::ConstIterator
2988{
2989 BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
2990
2991 return ConstIterator( matrix_, idx(i), 0UL );
2992}
2994//*************************************************************************************************
2995
2996
2997//*************************************************************************************************
3006template< typename MT // Type of the sparse matrix
3007 , typename... CRAs > // Compile time row arguments
3008inline typename Rows<MT,false,false,false,CRAs...>::Iterator
3010{
3011 BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
3012
3013 return Iterator( matrix_, idx(i), columns() );
3014}
3016//*************************************************************************************************
3017
3018
3019//*************************************************************************************************
3028template< typename MT // Type of the sparse matrix
3029 , typename... CRAs > // Compile time row arguments
3030inline typename Rows<MT,false,false,false,CRAs...>::ConstIterator
3032{
3033 BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
3034
3035 return ConstIterator( matrix_, idx(i), columns() );
3036}
3038//*************************************************************************************************
3039
3040
3041//*************************************************************************************************
3050template< typename MT // Type of the sparse matrix
3051 , typename... CRAs > // Compile time row arguments
3052inline typename Rows<MT,false,false,false,CRAs...>::ConstIterator
3054{
3055 BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
3056
3057 return ConstIterator( matrix_, idx(i), columns() );
3058}
3060//*************************************************************************************************
3061
3062
3063
3064
3065//=================================================================================================
3066//
3067// ASSIGNMENT OPERATORS
3068//
3069//=================================================================================================
3070
3071//*************************************************************************************************
3087template< typename MT // Type of the sparse matrix
3088 , typename... CRAs > // Compile time row arguments
3089inline Rows<MT,false,false,false,CRAs...>&
3090 Rows<MT,false,false,false,CRAs...>::operator=( initializer_list< initializer_list<ElementType> > list )
3091{
3094
3095 if( list.size() != rows() ) {
3096 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to row selection" );
3097 }
3098
3099 const InitializerMatrix<ElementType> tmp( list, columns() );
3100
3101 if( IsRestricted_v<MT> ) {
3102 for( size_t i=0UL; i<rows(); ++i ) {
3103 if( !tryAssign( matrix_, row( tmp, i, unchecked ), i, 0UL ) ) {
3104 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
3105 }
3106 }
3107 }
3108
3109 decltype(auto) left( derestrict( *this ) );
3110
3111 smpAssign( left, tmp );
3112
3113 return *this;
3114}
3116//*************************************************************************************************
3117
3118
3119//*************************************************************************************************
3134template< typename MT // Type of the sparse matrix
3135 , typename... CRAs > // Compile time row arguments
3136inline Rows<MT,false,false,false,CRAs...>&
3137 Rows<MT,false,false,false,CRAs...>::operator=( const Rows& rhs )
3138{
3141
3144
3145 if( this == &rhs || ( &matrix_ == &rhs.matrix_ && compareIndices( *this, rhs ) ) )
3146 return *this;
3147
3148 if( rows() != rhs.rows() || columns() != rhs.columns() ) {
3149 BLAZE_THROW_INVALID_ARGUMENT( "Matrix sizes do not match" );
3150 }
3151
3152 if( IsRestricted_v<MT> ) {
3153 for( size_t i=0UL; i<rows(); ++i ) {
3154 if( !tryAssign( matrix_, row( rhs, i, unchecked ), idx(i), 0UL ) ) {
3155 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
3156 }
3157 }
3158 }
3159
3160 decltype(auto) left( derestrict( *this ) );
3161
3162 if( rhs.canAlias( this ) ) {
3163 const ResultType tmp( rhs );
3164 left.reset();
3165 smpAssign( left, tmp );
3166 }
3167 else {
3168 left.reset();
3169 smpAssign( left, rhs );
3170 }
3171
3172 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
3173
3174 return *this;
3175}
3177//*************************************************************************************************
3178
3179
3180//*************************************************************************************************
3195template< typename MT // Type of the sparse matrix
3196 , typename... CRAs > // Compile time row arguments
3197template< typename MT2 // Type of the right-hand side matrix
3198 , bool SO > // Storage order of the right-hand side matrix
3199inline Rows<MT,false,false,false,CRAs...>&
3200 Rows<MT,false,false,false,CRAs...>::operator=( const Matrix<MT2,SO>& rhs )
3201{
3204
3206
3207 if( rows() != (*rhs).rows() || columns() != (*rhs).columns() ) {
3208 BLAZE_THROW_INVALID_ARGUMENT( "Matrix sizes do not match" );
3209 }
3210
3211 using Right = CompositeType_t<MT2>;
3212 Right right( *rhs );
3213
3214 if( IsRestricted_v<MT> ) {
3215 for( size_t i=0UL; i<rows(); ++i ) {
3216 if( !tryAssign( matrix_, row( right, i, unchecked ), idx(i), 0UL ) ) {
3217 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
3218 }
3219 }
3220 }
3221
3222 decltype(auto) left( derestrict( *this ) );
3223
3224 if( IsReference_v<Right> && right.canAlias( this ) ) {
3225 const ResultType_t<MT2> tmp( right );
3226 if( IsSparseMatrix_v< ResultType_t<MT2> > )
3227 left.reset();
3228 smpAssign( left, tmp );
3229 }
3230 else {
3231 if( IsSparseMatrix_v<MT2> )
3232 left.reset();
3233 smpAssign( left, right );
3234 }
3235
3236 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
3237
3238 return *this;
3239}
3241//*************************************************************************************************
3242
3243
3244//*************************************************************************************************
3258template< typename MT // Type of the sparse matrix
3259 , typename... CRAs > // Compile time row arguments
3260template< typename MT2 // Type of the right-hand side matrix
3261 , bool SO > // Storage order of the right-hand side matrix
3262inline Rows<MT,false,false,false,CRAs...>&
3263 Rows<MT,false,false,false,CRAs...>::operator+=( const Matrix<MT2,SO>& rhs )
3264{
3267
3271
3272 using AddType = AddTrait_t< ResultType, ResultType_t<MT2> >;
3273
3275
3276 if( rows() != (*rhs).rows() || columns() != (*rhs).columns() ) {
3277 BLAZE_THROW_INVALID_ARGUMENT( "Matrix sizes do not match" );
3278 }
3279
3280 const AddType tmp( *this + (*rhs) );
3281
3282 if( IsRestricted_v<MT> ) {
3283 for( size_t i=0UL; i<rows(); ++i ) {
3284 if( !tryAssign( matrix_, row( tmp, i, unchecked ), idx(i), 0UL ) ) {
3285 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
3286 }
3287 }
3288 }
3289
3290 decltype(auto) left( derestrict( *this ) );
3291
3292 if( IsSparseMatrix_v<AddType> ) {
3293 left.reset();
3294 }
3295
3296 smpAssign( left, tmp );
3297
3298 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
3299
3300 return *this;
3301}
3303//*************************************************************************************************
3304
3305
3306//*************************************************************************************************
3320template< typename MT // Type of the sparse matrix
3321 , typename... CRAs > // Compile time row arguments
3322template< typename MT2 // Type of the right-hand side matrix
3323 , bool SO > // Storage order of the right-hand side matrix
3324inline Rows<MT,false,false,false,CRAs...>&
3325 Rows<MT,false,false,false,CRAs...>::operator-=( const Matrix<MT2,SO>& rhs )
3326{
3329
3333
3334 using SubType = SubTrait_t< ResultType, ResultType_t<MT2> >;
3335
3337
3338 if( rows() != (*rhs).rows() || columns() != (*rhs).columns() ) {
3339 BLAZE_THROW_INVALID_ARGUMENT( "Matrix sizes do not match" );
3340 }
3341
3342 const SubType tmp( *this - (*rhs) );
3343
3344 if( IsRestricted_v<MT> ) {
3345 for( size_t i=0UL; i<rows(); ++i ) {
3346 if( !tryAssign( matrix_, row( tmp, i, unchecked ), idx(i), 0UL ) ) {
3347 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
3348 }
3349 }
3350 }
3351
3352 decltype(auto) left( derestrict( *this ) );
3353
3354 if( IsSparseMatrix_v<SubType> ) {
3355 left.reset();
3356 }
3357
3358 smpAssign( left, tmp );
3359
3360 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
3361
3362 return *this;
3363}
3365//*************************************************************************************************
3366
3367
3368//*************************************************************************************************
3382template< typename MT // Type of the sparse matrix
3383 , typename... CRAs > // Compile time row arguments
3384template< typename MT2 // Type of the right-hand side matrix
3385 , bool SO > // Storage order of the right-hand side matrix
3386inline Rows<MT,false,false,false,CRAs...>&
3387 Rows<MT,false,false,false,CRAs...>::operator%=( const Matrix<MT2,SO>& rhs )
3388{
3391
3395
3396 using SchurType = SchurTrait_t< ResultType, ResultType_t<MT2> >;
3397
3399
3400 if( rows() != (*rhs).rows() || columns() != (*rhs).columns() ) {
3401 BLAZE_THROW_INVALID_ARGUMENT( "Matrix sizes do not match" );
3402 }
3403
3404 const SchurType tmp( *this % (*rhs) );
3405
3406 if( IsRestricted_v<MT> ) {
3407 for( size_t i=0UL; i<rows(); ++i ) {
3408 if( !tryAssign( matrix_, row( tmp, i, unchecked ), idx(i), 0UL ) ) {
3409 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
3410 }
3411 }
3412 }
3413
3414 decltype(auto) left( derestrict( *this ) );
3415
3416 if( IsSparseMatrix_v<SchurType> ) {
3417 left.reset();
3418 }
3419
3420 smpAssign( left, tmp );
3421
3422 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
3423
3424 return *this;
3425}
3427//*************************************************************************************************
3428
3429
3430
3431
3432//=================================================================================================
3433//
3434// UTILITY FUNCTIONS
3435//
3436//=================================================================================================
3437
3438//*************************************************************************************************
3444template< typename MT // Type of the sparse matrix
3445 , typename... CRAs > // Compile time row arguments
3446inline MT& Rows<MT,false,false,false,CRAs...>::operand() noexcept
3447{
3448 return matrix_;
3449}
3451//*************************************************************************************************
3452
3453
3454//*************************************************************************************************
3460template< typename MT // Type of the sparse matrix
3461 , typename... CRAs > // Compile time row arguments
3462inline const MT& Rows<MT,false,false,false,CRAs...>::operand() const noexcept
3463{
3464 return matrix_;
3465}
3467//*************************************************************************************************
3468
3469
3470//*************************************************************************************************
3476template< typename MT // Type of the sparse matrix
3477 , typename... CRAs > // Compile time row arguments
3478inline size_t Rows<MT,false,false,false,CRAs...>::columns() const noexcept
3479{
3480 return matrix_.columns();
3481}
3483//*************************************************************************************************
3484
3485
3486//*************************************************************************************************
3492template< typename MT // Type of the sparse matrix
3493 , typename... CRAs > // Compile time row arguments
3494inline size_t Rows<MT,false,false,false,CRAs...>::capacity() const noexcept
3495{
3496 return rows() * columns();
3497}
3499//*************************************************************************************************
3500
3501
3502//*************************************************************************************************
3511template< typename MT // Type of the sparse matrix
3512 , typename... CRAs > // Compile time row arguments
3513inline size_t Rows<MT,false,false,false,CRAs...>::capacity( size_t i ) const noexcept
3514{
3515 MAYBE_UNUSED( i );
3516
3517 BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
3518
3519 return columns();
3520}
3522//*************************************************************************************************
3523
3524
3525//*************************************************************************************************
3531template< typename MT // Type of the sparse matrix
3532 , typename... CRAs > // Compile time row arguments
3534{
3535 size_t nonzeros( 0UL );
3536
3537 for( size_t j=0UL; j<columns(); ++j ) {
3538 const auto end( matrix_.end( j ) );
3539 for( size_t i=0UL; i<rows(); ++i ) {
3540 auto pos = matrix_.find( idx(i), j );
3541 if( pos != end ) {
3542 ++nonzeros;
3543 }
3544 }
3545 }
3546
3547 return nonzeros;
3548}
3550//*************************************************************************************************
3551
3552
3553//*************************************************************************************************
3562template< typename MT // Type of the sparse matrix
3563 , typename... CRAs > // Compile time row arguments
3564inline size_t Rows<MT,false,false,false,CRAs...>::nonZeros( size_t i ) const
3565{
3566 BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
3567
3568 size_t counter( 0UL );
3569
3570 const ConstIterator last( end(i) );
3571 for( ConstIterator element=begin(i); element!=last; ++element ) {
3572 ++counter;
3573 }
3574
3575 return counter;
3576}
3578//*************************************************************************************************
3579
3580
3581//*************************************************************************************************
3587template< typename MT // Type of the sparse matrix
3588 , typename... CRAs > // Compile time row arguments
3590{
3591 for( size_t i=0UL; i<rows(); ++i ) {
3592 reset( i );
3593 }
3594}
3596//*************************************************************************************************
3597
3598
3599//*************************************************************************************************
3609template< typename MT // Type of the sparse matrix
3610 , typename... CRAs > // Compile time row arguments
3611inline void Rows<MT,false,false,false,CRAs...>::reset( size_t i )
3612{
3613 const size_t index( idx(i) );
3614
3615 const size_t jbegin( ( IsUpper_v<MT> )
3616 ?( ( IsUniUpper_v<MT> || IsStrictlyUpper_v<MT> )
3617 ?( index+1UL )
3618 :( index ) )
3619 :( 0UL ) );
3620 const size_t jend ( ( IsLower_v<MT> )
3621 ?( ( IsUniLower_v<MT> || IsStrictlyLower_v<MT> )
3622 ?( index )
3623 :( index+1UL ) )
3624 :( columns() ) );
3625
3626 for( size_t j=jbegin; j<jend; ++j ) {
3627 matrix_.erase( index, j );
3628 }
3629}
3631//*************************************************************************************************
3632
3633
3634//*************************************************************************************************
3645template< typename MT // Type of the sparse matrix
3646 , typename... CRAs > // Compile time row arguments
3647inline void Rows<MT,false,false,false,CRAs...>::reserve( size_t nonzeros )
3648{
3649 MAYBE_UNUSED( nonzeros );
3650
3651 return;
3652}
3654//*************************************************************************************************
3655
3656
3657//*************************************************************************************************
3670template< typename MT // Type of the sparse matrix
3671 , typename... CRAs > // Compile time row arguments
3672void Rows<MT,false,false,false,CRAs...>::reserve( size_t i, size_t nonzeros )
3673{
3674 MAYBE_UNUSED( i, nonzeros );
3675
3676 return;
3677}
3679//*************************************************************************************************
3680
3681
3682//*************************************************************************************************
3692template< typename MT // Type of the sparse matrix
3693 , typename... CRAs > // Compile time row arguments
3694void Rows<MT,false,false,false,CRAs...>::trim()
3695{
3696 return;
3697}
3699//*************************************************************************************************
3700
3701
3702//*************************************************************************************************
3713template< typename MT // Type of the sparse matrix
3714 , typename... CRAs > // Compile time row arguments
3715void Rows<MT,false,false,false,CRAs...>::trim( size_t i )
3716{
3717 MAYBE_UNUSED( i );
3718
3719 BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
3720
3721 return;
3722}
3724//*************************************************************************************************
3725
3726
3727
3728
3729//=================================================================================================
3730//
3731// INSERTION FUNCTIONS
3732//
3733//=================================================================================================
3734
3735//*************************************************************************************************
3748template< typename MT // Type of the sparse matrix
3749 , typename... CRAs > // Compile time row arguments
3750inline typename Rows<MT,false,false,false,CRAs...>::Iterator
3751 Rows<MT,false,false,false,CRAs...>::set( size_t i, size_t j, const ElementType& value )
3752{
3753 return Iterator( matrix_, idx(i), j, matrix_.set( idx(i), j, value ) );
3754}
3756//*************************************************************************************************
3757
3758
3759//*************************************************************************************************
3773template< typename MT // Type of the sparse matrix
3774 , typename... CRAs > // Compile time row arguments
3775inline typename Rows<MT,false,false,false,CRAs...>::Iterator
3776 Rows<MT,false,false,false,CRAs...>::insert( size_t i, size_t j, const ElementType& value )
3777{
3778 return Iterator( matrix_, idx(i), j, matrix_.insert( idx(i), j, value ) );
3779}
3781//*************************************************************************************************
3782
3783
3784//*************************************************************************************************
3828template< typename MT // Type of the sparse matrix
3829 , typename... CRAs > // Compile time row arguments
3830inline void Rows<MT,false,false,false,CRAs...>::append( size_t i, size_t j, const ElementType& value, bool check )
3831{
3832 if( !check || !isDefault<strict>( value ) )
3833 matrix_.insert( idx(i), j, value );
3834}
3836//*************************************************************************************************
3837
3838
3839//*************************************************************************************************
3853template< typename MT // Type of the sparse matrix
3854 , typename... CRAs > // Compile time row arguments
3855inline void Rows<MT,false,false,false,CRAs...>::finalize( size_t i )
3856{
3857 MAYBE_UNUSED( i );
3858
3859 return;
3860}
3862//*************************************************************************************************
3863
3864
3865
3866
3867//=================================================================================================
3868//
3869// ERASE FUNCTIONS
3870//
3871//=================================================================================================
3872
3873//*************************************************************************************************
3883template< typename MT // Type of the sparse matrix
3884 , typename... CRAs > // Compile time row arguments
3885inline void Rows<MT,false,false,false,CRAs...>::erase( size_t i, size_t j )
3886{
3887 BLAZE_USER_ASSERT( i < rows() , "Invalid row access index" );
3888 BLAZE_USER_ASSERT( j < columns(), "Invalid column access index" );
3889
3890 matrix_.erase( idx(i), j );
3891}
3893//*************************************************************************************************
3894
3895
3896//*************************************************************************************************
3906template< typename MT // Type of the sparse matrix
3907 , typename... CRAs > // Compile time row arguments
3908inline typename Rows<MT,false,false,false,CRAs...>::Iterator
3909 Rows<MT,false,false,false,CRAs...>::erase( size_t i, Iterator pos )
3910{
3911 const size_t column( pos.column_ );
3912
3913 if( column == columns() )
3914 return pos;
3915
3916 matrix_.erase( column, pos.pos_ );
3917 return Iterator( matrix_, idx(i), column+1UL );
3918}
3920//*************************************************************************************************
3921
3922
3923//*************************************************************************************************
3934template< typename MT // Type of the sparse matrix
3935 , typename... CRAs > // Compile time row arguments
3936inline typename Rows<MT,false,false,false,CRAs...>::Iterator
3937 Rows<MT,false,false,false,CRAs...>::erase( size_t i, Iterator first, Iterator last )
3938{
3939 MAYBE_UNUSED( i );
3940
3941 BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
3942
3943 for( ; first!=last; ++first ) {
3944 matrix_.erase( first.column_, first.pos_ );
3945 }
3946
3947 return last;
3948}
3950//*************************************************************************************************
3951
3952
3953//*************************************************************************************************
3976template< typename MT // Type of the sparse matrix
3977 , typename... CRAs > // Compile time row arguments
3978template< typename Pred > // Type of the unary predicate
3979inline void Rows<MT,false,false,false,CRAs...>::erase( Pred predicate )
3980{
3981 for( size_t i=0UL; i<rows(); ++i ) {
3982 for( Iterator element=begin(i); element!=end(i); ++element ) {
3983 if( predicate( element->value() ) )
3984 matrix_.erase( element.column_, element.pos_ );
3985 }
3986 }
3987}
3989//*************************************************************************************************
3990
3991
3992//*************************************************************************************************
4019template< typename MT // Type of the sparse matrix
4020 , typename... CRAs > // Compile time row arguments
4021template< typename Pred > // Type of the unary predicate
4022inline void Rows<MT,false,false,false,CRAs...>::erase( size_t i, Iterator first, Iterator last, Pred predicate )
4023{
4024 MAYBE_UNUSED( i );
4025
4026 BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
4027
4028 for( ; first!=last; ++first ) {
4029 if( predicate( first->value() ) )
4030 matrix_.erase( first.column_, first.pos_ );
4031 }
4032}
4034//*************************************************************************************************
4035
4036
4037
4038
4039//=================================================================================================
4040//
4041// LOOKUP FUNCTIONS
4042//
4043//=================================================================================================
4044
4045//*************************************************************************************************
4060template< typename MT // Type of the sparse matrix
4061 , typename... CRAs > // Compile time row arguments
4062inline typename Rows<MT,false,false,false,CRAs...>::Iterator
4063 Rows<MT,false,false,false,CRAs...>::find( size_t i, size_t j )
4064{
4065 const size_t index( idx(i) );
4066 const Iterator_t<MT> pos( matrix_.find( index, j ) );
4067
4068 if( pos != matrix_.end( j ) )
4069 return Iterator( matrix_, index, j, pos );
4070 else
4071 return end( i );
4072}
4074//*************************************************************************************************
4075
4076
4077//*************************************************************************************************
4092template< typename MT // Type of the sparse matrix
4093 , typename... CRAs > // Compile time row arguments
4094inline typename Rows<MT,false,false,false,CRAs...>::ConstIterator
4095 Rows<MT,false,false,false,CRAs...>::find( size_t i, size_t j ) const
4096{
4097 const size_t index( idx(i) );
4098 const ConstIterator_t<MT> pos( matrix_.find( index, j ) );
4099
4100 if( pos != matrix_.end( j ) )
4101 return ConstIterator( matrix_, index, j, pos );
4102 else
4103 return end( i );
4104}
4106//*************************************************************************************************
4107
4108
4109//*************************************************************************************************
4123template< typename MT // Type of the sparse matrix
4124 , typename... CRAs > // Compile time row arguments
4125inline typename Rows<MT,false,false,false,CRAs...>::Iterator
4127{
4128 const size_t index( idx(i) );
4129
4130 for( ; j<columns(); ++j )
4131 {
4132 const Iterator_t<MT> pos( matrix_.find( index, j ) );
4133
4134 if( pos != matrix_.end( j ) )
4135 return Iterator( matrix_, index, j, pos );
4136 }
4137
4138 return end( i );
4139}
4141//*************************************************************************************************
4142
4143
4144//*************************************************************************************************
4158template< typename MT // Type of the sparse matrix
4159 , typename... CRAs > // Compile time row arguments
4160inline typename Rows<MT,false,false,false,CRAs...>::ConstIterator
4161 Rows<MT,false,false,false,CRAs...>::lowerBound( size_t i, size_t j ) const
4162{
4163 const size_t index( idx(i) );
4164
4165 for( ; j<columns(); ++j )
4166 {
4167 const ConstIterator_t<MT> pos( matrix_.find( index, j ) );
4168
4169 if( pos != matrix_.end( j ) )
4170 return ConstIterator( matrix_, index, j, pos );
4171 }
4172
4173 return end( i );
4174}
4176//*************************************************************************************************
4177
4178
4179//*************************************************************************************************
4193template< typename MT // Type of the sparse matrix
4194 , typename... CRAs > // Compile time row arguments
4195inline typename Rows<MT,false,false,false,CRAs...>::Iterator
4197{
4198 return lowerBound( i, j+1UL );
4199}
4201//*************************************************************************************************
4202
4203
4204//*************************************************************************************************
4218template< typename MT // Type of the sparse matrix
4219 , typename... CRAs > // Compile time row arguments
4220inline typename Rows<MT,false,false,false,CRAs...>::ConstIterator
4221 Rows<MT,false,false,false,CRAs...>::upperBound( size_t i, size_t j ) const
4222{
4223 return lowerBound( i, j+1UL );
4224}
4226//*************************************************************************************************
4227
4228
4229
4230
4231//=================================================================================================
4232//
4233// NUMERIC FUNCTIONS
4234//
4235//=================================================================================================
4236
4237//*************************************************************************************************
4250template< typename MT // Type of the sparse matrix
4251 , typename... CRAs > // Compile time row arguments
4252inline Rows<MT,false,false,false,CRAs...>&
4254{
4257
4258 if( rows() != columns() ) {
4259 BLAZE_THROW_LOGIC_ERROR( "Invalid transpose of a non-quadratic matrix" );
4260 }
4261
4262 const ResultType tmp( trans( *this ) );
4263
4264 if( IsRestricted_v<MT> ) {
4265 for( size_t i=0UL; i<rows(); ++i ) {
4266 if( !tryAssign( matrix_, row( tmp, i, unchecked ), idx(i), 0UL ) ) {
4267 BLAZE_THROW_LOGIC_ERROR( "Invalid transpose operation" );
4268 }
4269 }
4270 }
4271
4272 decltype(auto) left( derestrict( *this ) );
4273
4274 left.reset();
4275 smpAssign( left, tmp );
4276
4277 return *this;
4278}
4280//*************************************************************************************************
4281
4282
4283//*************************************************************************************************
4296template< typename MT // Type of the sparse matrix
4297 , typename... CRAs > // Compile time row arguments
4298inline Rows<MT,false,false,false,CRAs...>&
4300{
4303
4304 if( rows() != columns() ) {
4305 BLAZE_THROW_LOGIC_ERROR( "Invalid transpose of a non-quadratic matrix" );
4306 }
4307
4308 const ResultType tmp( ctrans( *this ) );
4309
4310 if( IsRestricted_v<MT> ) {
4311 for( size_t i=0UL; i<rows(); ++i ) {
4312 if( !tryAssign( matrix_, row( tmp, i, unchecked ), idx(i), 0UL ) ) {
4313 BLAZE_THROW_LOGIC_ERROR( "Invalid transpose operation" );
4314 }
4315 }
4316 }
4317
4318 decltype(auto) left( derestrict( *this ) );
4319
4320 left.reset();
4321 smpAssign( left, tmp );
4322
4323 return *this;
4324}
4326//*************************************************************************************************
4327
4328
4329//*************************************************************************************************
4342template< typename MT // Type of the sparse matrix
4343 , typename... CRAs > // Compile time row arguments
4344template< typename Other > // Data type of the scalar value
4345inline Rows<MT,false,false,false,CRAs...>&
4346 Rows<MT,false,false,false,CRAs...>::scale( const Other& scalar )
4347{
4351
4352 for( size_t j=0UL; j<columns(); ++j ) {
4353 const auto end( matrix_.end( j ) );
4354 for( size_t i=0UL; i<rows(); ++i ) {
4355 auto pos = matrix_.find( idx(i), j );
4356 if( pos != end ) {
4357 pos->value() *= scalar;
4358 }
4359 }
4360 }
4361
4362 return *this;
4363}
4365//*************************************************************************************************
4366
4367
4368
4369
4370//=================================================================================================
4371//
4372// EXPRESSION TEMPLATE EVALUATION FUNCTIONS
4373//
4374//=================================================================================================
4375
4376//*************************************************************************************************
4387template< typename MT // Type of the sparse matrix
4388 , typename... CRAs > // Compile time row arguments
4389template< typename Other > // Data type of the foreign expression
4390inline bool Rows<MT,false,false,false,CRAs...>::canAlias( const Other* alias ) const noexcept
4391{
4392 return matrix_.isAliased( &unview( *alias ) );
4393}
4395//*************************************************************************************************
4396
4397
4398//*************************************************************************************************
4409template< typename MT // Type of the sparse matrix
4410 , typename... CRAs > // Compile time row arguments
4411template< typename Other > // Data type of the foreign expression
4412inline bool Rows<MT,false,false,false,CRAs...>::isAliased( const Other* alias ) const noexcept
4413{
4414 return matrix_.isAliased( &unview( *alias ) );
4415}
4417//*************************************************************************************************
4418
4419
4420//*************************************************************************************************
4431template< typename MT // Type of the sparse matrix
4432 , typename... CRAs > // Compile time row arguments
4433inline bool Rows<MT,false,false,false,CRAs...>::canSMPAssign() const noexcept
4434{
4435 return false;
4436}
4438//*************************************************************************************************
4439
4440
4441//*************************************************************************************************
4453template< typename MT // Type of the sparse matrix
4454 , typename... CRAs > // Compile time row arguments
4455template< typename MT2 // Type of the right-hand side dense matrix
4456 , bool SO > // Storage order of the right-hand side dense matrix
4457inline void Rows<MT,false,false,false,CRAs...>::assign( const DenseMatrix<MT2,SO>& rhs )
4458{
4461
4462 using RT = If_t< IsComputation_v<MT2>, ElementType_t<MT>, const ElementType_t<MT2>& >;
4463
4464 BLAZE_INTERNAL_ASSERT( rows() == (*rhs).rows() , "Invalid number of rows" );
4465 BLAZE_INTERNAL_ASSERT( columns() == (*rhs).columns(), "Invalid number of columns" );
4466
4467 for( size_t j=0UL; j<columns(); ++j ) {
4468 for( size_t i=0UL; i<rows(); ++i ) {
4469 RT value( (*rhs)(i,j) );
4470 if( !isDefault<strict>( value ) )
4471 matrix_.set( idx(i), j, std::move( value ) );
4472 else matrix_.erase( idx(i), j );
4473 }
4474 }
4475}
4477//*************************************************************************************************
4478
4479
4480//*************************************************************************************************
4492template< typename MT // Type of the sparse matrix
4493 , typename... CRAs > // Compile time row arguments
4494template< typename MT2 > // Type of the right-hand side sparse matrix
4495inline void Rows<MT,false,false,false,CRAs...>::assign( const SparseMatrix<MT2,false>& rhs )
4496{
4499
4500 using RT = If_t< IsComputation_v<MT2>, ElementType_t<MT>, const ElementType_t<MT2>& >;
4501
4502 BLAZE_INTERNAL_ASSERT( rows() == (*rhs).rows() , "Invalid number of rows" );
4503 BLAZE_INTERNAL_ASSERT( columns() == (*rhs).columns(), "Invalid number of columns" );
4504 BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
4505
4506 for( size_t i=0UL; i<rows(); ++i ) {
4507 const size_t index( idx(i) );
4508 for( ConstIterator_t<MT2> element=(*rhs).begin(i); element!=(*rhs).end(i); ++element ) {
4509 RT value( element->value() );
4510 if( !isDefault<strict>( value ) )
4511 matrix_.set( index, element->index(), std::move( value ) );
4512 else matrix_.erase( index, element->index() );
4513 }
4514 }
4515}
4517//*************************************************************************************************
4518
4519
4520//*************************************************************************************************
4532template< typename MT // Type of the sparse matrix
4533 , typename... CRAs > // Compile time row arguments
4534template< typename MT2 > // Type of the right-hand side sparse matrix
4535inline void Rows<MT,false,false,false,CRAs...>::assign( const SparseMatrix<MT2,true>& rhs )
4536{
4539
4541
4542 using RT = If_t< IsComputation_v<MT2>, ElementType_t<MT>, const ElementType_t<MT2>& >;
4543
4544 BLAZE_INTERNAL_ASSERT( rows() == (*rhs).rows() , "Invalid number of rows" );
4545 BLAZE_INTERNAL_ASSERT( columns() == (*rhs).columns(), "Invalid number of columns" );
4546 BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
4547
4548 for( size_t j=0UL; j<columns(); ++j ) {
4549 for( ConstIterator_t<MT2> element=(*rhs).begin(j); element!=(*rhs).end(j); ++element ) {
4550 RT value( element->value() );
4551 if( !isDefault<strict>( value ) )
4552 matrix_.set( idx( element->index() ), j, std::move( value ) );
4553 else matrix_.erase( idx( element->index() ), j );
4554 }
4555 }
4556}
4558//*************************************************************************************************
4559
4560
4561//*************************************************************************************************
4573template< typename MT // Type of the sparse matrix
4574 , typename... CRAs > // Compile time row arguments
4575template< typename MT2 // Type of the right-hand side matrix
4576 , bool SO > // Storage order of the right-hand side matrix
4577inline void Rows<MT,false,false,false,CRAs...>::addAssign( const Matrix<MT2,SO>& rhs )
4578{
4581
4582 using AddType = AddTrait_t< ResultType, ResultType_t<MT2> >;
4583
4585
4586 BLAZE_INTERNAL_ASSERT( rows() == (*rhs).rows() , "Invalid number of rows" );
4587 BLAZE_INTERNAL_ASSERT( columns() == (*rhs).columns(), "Invalid number of columns" );
4588
4589 const AddType tmp( serial( *this + (*rhs) ) );
4590 reset();
4591 assign( tmp );
4592}
4594//*************************************************************************************************
4595
4596
4597//*************************************************************************************************
4609template< typename MT // Type of the sparse matrix
4610 , typename... CRAs > // Compile time row arguments
4611template< typename MT2 // Type of the right-hand side matrix
4612 , bool SO > // Storage order of the right-hand side matrix
4613inline void Rows<MT,false,false,false,CRAs...>::subAssign( const Matrix<MT2,SO>& rhs )
4614{
4617
4618 using SubType = SubTrait_t< ResultType, ResultType_t<MT2> >;
4619
4621
4622 BLAZE_INTERNAL_ASSERT( rows() == (*rhs).rows() , "Invalid number of rows" );
4623 BLAZE_INTERNAL_ASSERT( columns() == (*rhs).columns(), "Invalid number of columns" );
4624
4625 const SubType tmp( serial( *this - (*rhs) ) );
4626 reset();
4627 assign( tmp );
4628}
4630//*************************************************************************************************
4631
4632
4633//*************************************************************************************************
4645template< typename MT // Type of the sparse matrix
4646 , typename... CRAs > // Compile time row arguments
4647template< typename MT2 // Type of the right-hand side matrix
4648 , bool SO > // Storage order of the right-hand side matrix
4649inline void Rows<MT,false,false,false,CRAs...>::schurAssign( const Matrix<MT2,SO>& rhs )
4650{
4653
4654 using SchurType = SchurTrait_t< ResultType, ResultType_t<MT2> >;
4655
4658
4659 BLAZE_INTERNAL_ASSERT( rows() == (*rhs).rows() , "Invalid number of rows" );
4660 BLAZE_INTERNAL_ASSERT( columns() == (*rhs).columns(), "Invalid number of columns" );
4661
4662 const SchurType tmp( serial( *this % (*rhs) ) );
4663 reset();
4664 assign( tmp );
4665}
4667//*************************************************************************************************
4668
4669
4670
4671
4672
4673
4674
4675
4676//=================================================================================================
4677//
4678// CLASS TEMPLATE SPECIALIZATION FOR SYMMETRIC COLUMN-MAJOR SPARSE MATRICES
4679//
4680//=================================================================================================
4681
4682//*************************************************************************************************
4690template< typename MT // Type of the sparse matrix
4691 , typename... CRAs > // Compile time row arguments
4692class Rows<MT,false,false,true,CRAs...>
4693 : public View< SparseMatrix< Rows<MT,false,false,true,CRAs...>, false > >
4694 , private RowsData<CRAs...>
4695{
4696 private:
4697 //**Type definitions****************************************************************************
4698 using DataType = RowsData<CRAs...>;
4699 using Operand = If_t< IsExpression_v<MT>, MT, MT& >;
4700 //**********************************************************************************************
4701
4702 //**Compile time flags**************************************************************************
4703 using DataType::N;
4704 //**********************************************************************************************
4705
4706 public:
4707 //**Type definitions****************************************************************************
4709 using This = Rows<MT,false,false,true,CRAs...>;
4710
4712 using BaseType = View< SparseMatrix<This,false> >;
4713
4714 using ViewedType = MT;
4715 using ResultType = RowsTrait_t<MT,N>;
4716 using OppositeType = OppositeType_t<ResultType>;
4717 using TransposeType = TransposeType_t<ResultType>;
4718 using ElementType = ElementType_t<MT>;
4719 using ReturnType = ReturnType_t<MT>;
4720 using CompositeType = const Rows&;
4721
4723 using ConstReference = ConstReference_t<MT>;
4724
4726 using Reference = If_t< IsConst_v<MT>, ConstReference, Reference_t<MT> >;
4727
4729 using ConstIterator = ConstIterator_t<MT>;
4730
4732 using Iterator = If_t< IsConst_v<MT>, ConstIterator, Iterator_t<MT> >;
4733 //**********************************************************************************************
4734
4735 //**Compilation flags***************************************************************************
4737 static constexpr bool smpAssignable = MT::smpAssignable;
4738
4740 static constexpr bool compileTimeArgs = DataType::compileTimeArgs;
4741 //**********************************************************************************************
4742
4743 //**Constructors********************************************************************************
4746 template< typename... RRAs >
4747 explicit inline Rows( MT& matrix, RRAs... args );
4748
4749 Rows( const Rows& ) = default;
4750 Rows( Rows&& ) = default;
4752 //**********************************************************************************************
4753
4754 //**Destructor**********************************************************************************
4757 ~Rows() = default;
4759 //**********************************************************************************************
4760
4761 //**Data access functions***********************************************************************
4764 inline Reference operator()( size_t i, size_t j );
4765 inline ConstReference operator()( size_t i, size_t j ) const;
4766 inline Reference at( size_t i, size_t j );
4767 inline ConstReference at( size_t i, size_t j ) const;
4768 inline Iterator begin ( size_t i );
4769 inline ConstIterator begin ( size_t i ) const;
4770 inline ConstIterator cbegin( size_t i ) const;
4771 inline Iterator end ( size_t i );
4772 inline ConstIterator end ( size_t i ) const;
4773 inline ConstIterator cend ( size_t i ) const;
4775 //**********************************************************************************************
4776
4777 //**Assignment operators************************************************************************
4780 Rows& operator=( const Rows& ) = delete;
4782 //**********************************************************************************************
4783
4784 //**Utility functions***************************************************************************
4787 using DataType::idx;
4788 using DataType::idces;
4789 using DataType::rows;
4790
4791 inline MT& operand() noexcept;
4792 inline const MT& operand() const noexcept;
4793
4794 inline size_t columns() const noexcept;
4795 inline size_t capacity() const noexcept;
4796 inline size_t capacity( size_t i ) const noexcept;
4797 inline size_t nonZeros() const;
4798 inline size_t nonZeros( size_t i ) const;
4799 inline void reset();
4800 inline void reset( size_t i );
4801 inline void reserve( size_t nonzeros );
4802 void reserve( size_t i, size_t nonzeros );
4803 inline void trim();
4804 inline void trim( size_t i );
4806 //**********************************************************************************************
4807
4808 //**Insertion functions*************************************************************************
4811 inline Iterator set ( size_t i, size_t j, const ElementType& value );
4812 inline Iterator insert ( size_t i, size_t j, const ElementType& value );
4813 inline void append ( size_t i, size_t j, const ElementType& value, bool check=false );
4814 inline void finalize( size_t i );
4816 //**********************************************************************************************
4817
4818 //**Erase functions*****************************************************************************
4821 inline void erase( size_t i, size_t j );
4822 inline Iterator erase( size_t i, Iterator pos );
4823 inline Iterator erase( size_t i, Iterator first, Iterator last );
4824
4825 template< typename Pred >
4826 inline void erase( Pred predicate );
4827
4828 template< typename Pred >
4829 inline void erase( size_t i, Iterator first, Iterator last, Pred predicate );
4831 //**********************************************************************************************
4832
4833 //**Lookup functions****************************************************************************
4836 inline Iterator find ( size_t i, size_t j );
4837 inline ConstIterator find ( size_t i, size_t j ) const;
4838 inline Iterator lowerBound( size_t i, size_t j );
4839 inline ConstIterator lowerBound( size_t i, size_t j ) const;
4840 inline Iterator upperBound( size_t i, size_t j );
4841 inline ConstIterator upperBound( size_t i, size_t j ) const;
4843 //**********************************************************************************************
4844
4845 //**Expression template evaluation functions****************************************************
4848 template< typename Other > inline bool canAlias ( const Other* alias ) const noexcept;
4849 template< typename Other > inline bool isAliased( const Other* alias ) const noexcept;
4850
4851 inline bool canSMPAssign() const noexcept;
4853 //**********************************************************************************************
4854
4855 private:
4856 //**Member variables****************************************************************************
4859 Operand matrix_;
4861 //**********************************************************************************************
4862
4863 //**Compile time checks*************************************************************************
4873 //**********************************************************************************************
4874};
4876//*************************************************************************************************
4877
4878
4879
4880
4881//=================================================================================================
4882//
4883// CONSTRUCTORS
4884//
4885//=================================================================================================
4886
4887//*************************************************************************************************
4900template< typename MT // Type of the sparse matrix
4901 , typename... CRAs > // Compile time row arguments
4902template< typename... RRAs > // Runtime row arguments
4903inline Rows<MT,false,false,true,CRAs...>::Rows( MT& matrix, RRAs... args )
4904 : DataType( args... ) // Base class initialization
4905 , matrix_ ( matrix ) // The matrix containing the rows
4906{
4907 if( isChecked( args... ) ) {
4908 for( size_t i=0UL; i<rows(); ++i ) {
4909 if( matrix_.rows() <= idx(i) ) {
4910 BLAZE_THROW_INVALID_ARGUMENT( "Invalid row access index" );
4911 }
4912 }
4913 }
4914}
4916//*************************************************************************************************
4917
4918
4919
4920
4921//=================================================================================================
4922//
4923// DATA ACCESS FUNCTIONS
4924//
4925//=================================================================================================
4926
4927//*************************************************************************************************
4938template< typename MT // Type of the sparse matrix
4939 , typename... CRAs > // Compile time row arguments
4940inline typename Rows<MT,false,false,true,CRAs...>::Reference
4941 Rows<MT,false,false,true,CRAs...>::operator()( size_t i, size_t j )
4942{
4943 BLAZE_USER_ASSERT( i < rows() , "Invalid row access index" );
4944 BLAZE_USER_ASSERT( j < columns(), "Invalid column access index" );
4945
4946 return matrix_(j,idx(i));
4947}
4949//*************************************************************************************************
4950
4951
4952//*************************************************************************************************
4963template< typename MT // Type of the sparse matrix
4964 , typename... CRAs > // Compile time row arguments
4965inline typename Rows<MT,false,false,true,CRAs...>::ConstReference
4966 Rows<MT,false,false,true,CRAs...>::operator()( size_t i, size_t j ) const
4967{
4968 BLAZE_USER_ASSERT( i < rows() , "Invalid row access index" );
4969 BLAZE_USER_ASSERT( j < columns(), "Invalid column access index" );
4970
4971 return const_cast<const MT&>( matrix_ )(j,idx(i));
4972}
4974//*************************************************************************************************
4975
4976
4977//*************************************************************************************************
4989template< typename MT // Type of the sparse matrix
4990 , typename... CRAs > // Compile time row arguments
4991inline typename Rows<MT,false,false,true,CRAs...>::Reference
4992 Rows<MT,false,false,true,CRAs...>::at( size_t i, size_t j )
4993{
4994 if( i >= rows() ) {
4995 BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
4996 }
4997 if( j >= columns() ) {
4998 BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
4999 }
5000 return (*this)(i,j);
5001}
5003//*************************************************************************************************
5004
5005
5006//*************************************************************************************************
5018template< typename MT // Type of the sparse matrix
5019 , typename... CRAs > // Compile time row arguments
5020inline typename Rows<MT,false,false,true,CRAs...>::ConstReference
5021 Rows<MT,false,false,true,CRAs...>::at( size_t i, size_t j ) const
5022{
5023 if( i >= rows() ) {
5024 BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
5025 }
5026 if( j >= columns() ) {
5027 BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
5028 }
5029 return (*this)(i,j);
5030}
5032//*************************************************************************************************
5033
5034
5035//*************************************************************************************************
5044template< typename MT // Type of the sparse matrix
5045 , typename... CRAs > // Compile time row arguments
5046inline typename Rows<MT,false,false,true,CRAs...>::Iterator
5048{
5049 BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
5050
5051 return matrix_.begin( idx(i) );
5052}
5054//*************************************************************************************************
5055
5056
5057//*************************************************************************************************
5066template< typename MT // Type of the sparse matrix
5067 , typename... CRAs > // Compile time row arguments
5068inline typename Rows<MT,false,false,true,CRAs...>::ConstIterator
5070{
5071 BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
5072
5073 return matrix_.cbegin( idx(i) );
5074}
5076//*************************************************************************************************
5077
5078
5079//*************************************************************************************************
5088template< typename MT // Type of the sparse matrix
5089 , typename... CRAs > // Compile time row arguments
5090inline typename Rows<MT,false,false,true,CRAs...>::ConstIterator
5092{
5093 BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
5094
5095 return matrix_.cbegin( idx(i) );
5096}
5098//*************************************************************************************************
5099
5100
5101//*************************************************************************************************
5110template< typename MT // Type of the sparse matrix
5111 , typename... CRAs > // Compile time row arguments
5112inline typename Rows<MT,false,false,true,CRAs...>::Iterator
5114{
5115 BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
5116
5117 return matrix_.end( idx(i) );
5118}
5120//*************************************************************************************************
5121
5122
5123//*************************************************************************************************
5132template< typename MT // Type of the sparse matrix
5133 , typename... CRAs > // Compile time row arguments
5134inline typename Rows<MT,false,false,true,CRAs...>::ConstIterator
5136{
5137 BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
5138
5139 return matrix_.cend( idx(i) );
5140}
5142//*************************************************************************************************
5143
5144
5145//*************************************************************************************************
5154template< typename MT // Type of the sparse matrix
5155 , typename... CRAs > // Compile time row arguments
5156inline typename Rows<MT,false,false,true,CRAs...>::ConstIterator
5158{
5159 BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
5160
5161 return matrix_.cend( idx(i) );
5162}
5164//*************************************************************************************************
5165
5166
5167
5168
5169//=================================================================================================
5170//
5171// UTILITY FUNCTIONS
5172//
5173//=================================================================================================
5174
5175//*************************************************************************************************
5181template< typename MT // Type of the sparse matrix
5182 , typename... CRAs > // Compile time row arguments
5183inline MT& Rows<MT,false,false,true,CRAs...>::operand() noexcept
5184{
5185 return matrix_;
5186}
5188//*************************************************************************************************
5189
5190
5191//*************************************************************************************************
5197template< typename MT // Type of the sparse matrix
5198 , typename... CRAs > // Compile time row arguments
5199inline const MT& Rows<MT,false,false,true,CRAs...>::operand() const noexcept
5200{
5201 return matrix_;
5202}
5204//*************************************************************************************************
5205
5206
5207//*************************************************************************************************
5213template< typename MT // Type of the sparse matrix
5214 , typename... CRAs > // Compile time row arguments
5215inline size_t Rows<MT,false,false,true,CRAs...>::columns() const noexcept
5216{
5217 return matrix_.columns();
5218}
5220//*************************************************************************************************
5221
5222
5223//*************************************************************************************************
5229template< typename MT // Type of the sparse matrix
5230 , typename... CRAs > // Compile time row arguments
5231inline size_t Rows<MT,false,false,true,CRAs...>::capacity() const noexcept
5232{
5233 return nonZeros() + matrix_.capacity() - matrix_.nonZeros();
5234}
5236//*************************************************************************************************
5237
5238
5239//*************************************************************************************************
5248template< typename MT // Type of the sparse matrix
5249 , typename... CRAs > // Compile time row arguments
5250inline size_t Rows<MT,false,false,true,CRAs...>::capacity( size_t i ) const noexcept
5251{
5252 BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
5253
5254 return matrix_.capacity( idx(i) );
5255}
5257//*************************************************************************************************
5258
5259
5260//*************************************************************************************************
5266template< typename MT // Type of the sparse matrix
5267 , typename... CRAs > // Compile time row arguments
5269{
5270 size_t nonzeros( 0UL );
5271
5272 for( size_t i=0UL; i<rows(); ++i )
5273 nonzeros += nonZeros( i );
5274
5275 return nonzeros;
5276}
5278//*************************************************************************************************
5279
5280
5281//*************************************************************************************************
5290template< typename MT // Type of the sparse matrix
5291 , typename... CRAs > // Compile time row arguments
5292inline size_t Rows<MT,false,false,true,CRAs...>::nonZeros( size_t i ) const
5293{
5294 BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
5295
5296 return matrix_.nonZeros( idx(i) );
5297}
5299//*************************************************************************************************
5300
5301
5302//*************************************************************************************************
5308template< typename MT // Type of the sparse matrix
5309 , typename... CRAs > // Compile time row arguments
5311{
5312 for( size_t i=0UL; i<rows(); ++i ) {
5313 matrix_.reset( idx(i) );
5314 }
5315}
5317//*************************************************************************************************
5318
5319
5320//*************************************************************************************************
5330template< typename MT // Type of the sparse matrix
5331 , typename... CRAs > // Compile time row arguments
5332inline void Rows<MT,false,false,true,CRAs...>::reset( size_t i )
5333{
5334 matrix_.reset( idx(i) );
5335}
5337//*************************************************************************************************
5338
5339
5340//*************************************************************************************************
5351template< typename MT // Type of the sparse matrix
5352 , typename... CRAs > // Compile time row arguments
5353inline void Rows<MT,false,false,true,CRAs...>::reserve( size_t nonzeros )
5354{
5355 const size_t current( capacity() );
5356
5357 if( nonzeros > current ) {
5358 matrix_.reserve( matrix_.capacity() + nonzeros - current );
5359 }
5360}
5362//*************************************************************************************************
5363
5364
5365//*************************************************************************************************
5378template< typename MT // Type of the sparse matrix
5379 , typename... CRAs > // Compile time row arguments
5380void Rows<MT,false,false,true,CRAs...>::reserve( size_t i, size_t nonzeros )
5381{
5382 matrix_.reserve( idx(i), nonzeros );
5383}
5385//*************************************************************************************************
5386
5387
5388//*************************************************************************************************
5398template< typename MT // Type of the sparse matrix
5399 , typename... CRAs > // Compile time row arguments
5400void Rows<MT,false,false,true,CRAs...>::trim()
5401{
5402 for( size_t i=0UL; i<rows(); ++i ) {
5403 trim( i );
5404 }
5405}
5407//*************************************************************************************************
5408
5409
5410//*************************************************************************************************
5421template< typename MT // Type of the sparse matrix
5422 , typename... CRAs > // Compile time row arguments
5423void Rows<MT,false,false,true,CRAs...>::trim( size_t i )
5424{
5425 BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
5426
5427 matrix_.trim( idx(i) );
5428}
5430//*************************************************************************************************
5431
5432
5433
5434
5435//=================================================================================================
5436//
5437// INSERTION FUNCTIONS
5438//
5439//=================================================================================================
5440
5441//*************************************************************************************************
5454template< typename MT // Type of the sparse matrix
5455 , typename... CRAs > // Compile time row arguments
5456inline typename Rows<MT,false,false,true,CRAs...>::Iterator
5457 Rows<MT,false,false,true,CRAs...>::set( size_t i, size_t j, const ElementType& value )
5458{
5459 return matrix_.set( j, idx(i), value );
5460}
5462//*************************************************************************************************
5463
5464
5465//*************************************************************************************************
5479template< typename MT // Type of the sparse matrix
5480 , typename... CRAs > // Compile time row arguments
5481inline typename Rows<MT,false,false,true,CRAs...>::Iterator
5482 Rows<MT,false,false,true,CRAs...>::insert( size_t i, size_t j, const ElementType& value )
5483{
5484 return matrix_.insert( j, idx(i), value );
5485}
5487//*************************************************************************************************
5488
5489
5490//*************************************************************************************************
5534template< typename MT // Type of the sparse matrix
5535 , typename... CRAs > // Compile time row arguments
5536inline void Rows<MT,false,false,true,CRAs...>::append( size_t i, size_t j, const ElementType& value, bool check )
5537{
5538 if( !check || !isDefault<strict>( value ) )
5539 matrix_.insert( j, idx(i), value );
5540}
5542//*************************************************************************************************
5543
5544
5545//*************************************************************************************************
5559template< typename MT // Type of the sparse matrix
5560 , typename... CRAs > // Compile time row arguments
5561inline void Rows<MT,false,false,true,CRAs...>::finalize( size_t i )
5562{
5563 MAYBE_UNUSED( i );
5564
5565 return;
5566}
5568//*************************************************************************************************
5569
5570
5571
5572
5573//=================================================================================================
5574//
5575// ERASE FUNCTIONS
5576//
5577//=================================================================================================
5578
5579//*************************************************************************************************
5589template< typename MT // Type of the sparse matrix
5590 , typename... CRAs > // Compile time row arguments
5591inline void Rows<MT,false,false,true,CRAs...>::erase( size_t i, size_t j )
5592{
5593 BLAZE_USER_ASSERT( i < rows() , "Invalid row access index" );
5594 BLAZE_USER_ASSERT( j < columns(), "Invalid column access index" );
5595
5596 matrix_.erase( j, idx(i) );
5597}
5599//*************************************************************************************************
5600
5601
5602//*************************************************************************************************
5612template< typename MT // Type of the sparse matrix
5613 , typename... CRAs > // Compile time row arguments
5614inline typename Rows<MT,false,false,true,CRAs...>::Iterator
5615 Rows<MT,false,false,true,CRAs...>::erase( size_t i, Iterator pos )
5616{
5617 BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
5618
5619 return matrix_.erase( idx(i), pos );
5620}
5622//*************************************************************************************************
5623
5624
5625//*************************************************************************************************
5636template< typename MT // Type of the sparse matrix
5637 , typename... CRAs > // Compile time row arguments
5638inline typename Rows<MT,false,false,true,CRAs...>::Iterator
5639 Rows<MT,false,false,true,CRAs...>::erase( size_t i, Iterator first, Iterator last )
5640{
5641 BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
5642
5643 return matrix_.erase( idx(i), first, last );
5644}
5646//*************************************************************************************************
5647
5648
5649//*************************************************************************************************
5672template< typename MT // Type of the sparse matrix
5673 , typename... CRAs > // Compile time row arguments
5674template< typename Pred > // Type of the unary predicate
5675inline void Rows<MT,false,false,true,CRAs...>::erase( Pred predicate )
5676{
5677 for( size_t i=0UL; i<rows(); ++i ) {
5678 matrix_.erase( idx(i), begin(i), end(i), predicate );
5679 }
5680}
5682//*************************************************************************************************
5683
5684
5685//*************************************************************************************************
5712template< typename MT // Type of the sparse matrix
5713 , typename... CRAs > // Compile time row arguments
5714template< typename Pred > // Type of the unary predicate
5715inline void Rows<MT,false,false,true,CRAs...>::erase( size_t i, Iterator first, Iterator last, Pred predicate )
5716{
5717 BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
5718
5719 matrix_.erase( idx(i), first, last, predicate );
5720}
5722//*************************************************************************************************
5723
5724
5725
5726
5727//=================================================================================================
5728//
5729// LOOKUP FUNCTIONS
5730//
5731//=================================================================================================
5732
5733//*************************************************************************************************
5748template< typename MT // Type of the sparse matrix
5749 , typename... CRAs > // Compile time row arguments
5750inline typename Rows<MT,false,false,true,CRAs...>::Iterator
5751 Rows<MT,false,false,true,CRAs...>::find( size_t i, size_t j )
5752{
5753 return matrix_.find( j, idx(i) );
5754}
5756//*************************************************************************************************
5757
5758
5759//*************************************************************************************************
5774template< typename MT // Type of the sparse matrix
5775 , typename... CRAs > // Compile time row arguments
5776inline typename Rows<MT,false,false,true,CRAs...>::ConstIterator
5777 Rows<MT,false,false,true,CRAs...>::find( size_t i, size_t j ) const
5778{
5779 return matrix_.find( j, idx(i) );
5780}
5782//*************************************************************************************************
5783
5784
5785//*************************************************************************************************
5799template< typename MT // Type of the sparse matrix
5800 , typename... CRAs > // Compile time row arguments
5801inline typename Rows<MT,false,false,true,CRAs...>::Iterator
5803{
5804 return matrix_.lowerBound( j, idx(i) );
5805}
5807//*************************************************************************************************
5808
5809
5810//*************************************************************************************************
5824template< typename MT // Type of the sparse matrix
5825 , typename... CRAs > // Compile time row arguments
5826inline typename Rows<MT,false,false,true,CRAs...>::ConstIterator
5827 Rows<MT,false,false,true,CRAs...>::lowerBound( size_t i, size_t j ) const
5828{
5829 return matrix_.lowerBound( j, idx(i) );
5830}
5832//*************************************************************************************************
5833
5834
5835//*************************************************************************************************
5849template< typename MT // Type of the sparse matrix
5850 , typename... CRAs > // Compile time row arguments
5851inline typename Rows<MT,false,false,true,CRAs...>::Iterator
5853{
5854 return matrix_.upperBound( j, idx(i) );
5855}
5857//*************************************************************************************************
5858
5859
5860//*************************************************************************************************
5874template< typename MT // Type of the sparse matrix
5875 , typename... CRAs > // Compile time row arguments
5876inline typename Rows<MT,false,false,true,CRAs...>::ConstIterator
5877 Rows<MT,false,false,true,CRAs...>::upperBound( size_t i, size_t j ) const
5878{
5879 return matrix_.upperBound( j, idx(i) );
5880}
5882//*************************************************************************************************
5883
5884
5885
5886
5887//=================================================================================================
5888//
5889// EXPRESSION TEMPLATE EVALUATION FUNCTIONS
5890//
5891//=================================================================================================
5892
5893//*************************************************************************************************
5904template< typename MT // Type of the sparse matrix
5905 , typename... CRAs > // Compile time row arguments
5906template< typename Other > // Data type of the foreign expression
5907inline bool Rows<MT,false,false,true,CRAs...>::canAlias( const Other* alias ) const noexcept
5908{
5909 return matrix_.isAliased( &unview( *alias ) );
5910}
5912//*************************************************************************************************
5913
5914
5915//*************************************************************************************************
5926template< typename MT // Type of the sparse matrix
5927 , typename... CRAs > // Compile time row arguments
5928template< typename Other > // Data type of the foreign expression
5929inline bool Rows<MT,false,false,true,CRAs...>::isAliased( const Other* alias ) const noexcept
5930{
5931 return matrix_.isAliased( &unview( *alias ) );
5932}
5934//*************************************************************************************************
5935
5936
5937//*************************************************************************************************
5948template< typename MT // Type of the sparse matrix
5949 , typename... CRAs > // Compile time row arguments
5950inline bool Rows<MT,false,false,true,CRAs...>::canSMPAssign() const noexcept
5951{
5952 return false;
5953}
5955//*************************************************************************************************
5956
5957} // namespace blaze
5958
5959#endif
Header file for the addition trait.
Header file for auxiliary alias declarations.
Header file for run time assertion macros.
Header file for the blaze::checked and blaze::unchecked instances.
Constraints on the storage order of matrix types.
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:751
Constraint on the data type.
Header file for the If class template.
Header file for the IsComputation type trait class.
Header file for the IsConst type trait.
Header file for the isDefault shim.
Header file for the IsExpression type trait class.
Header file for the IsLower type trait.
Header file for the IsReference type trait.
Header file for the IsRestricted type trait.
Header file for the IsSparseMatrix type trait.
Header file for the IsStrictlyLower type trait.
Header file for the IsStrictlyUpper type trait.
Header file for the IsUniLower type trait.
Header file for the IsUniUpper type trait.
Header file for the IsUpper type trait.
Header file for the MAYBE_UNUSED function template.
Constraint on the data type.
Constraint on the data type.
Constraints on the storage order of matrix types.
Header file for the implementation of the RowsData class template.
Header file for the rows trait.
Header file for the Schur product trait.
Header file for the subtraction trait.
Constraint on the data type.
Constraint on the data type.
Initializer list type of the Blaze library.
Pointer difference type of the Blaze library.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Header file for the implementation of a matrix representation of an initializer list.
Header file for the SparseMatrix base class.
Header file for the View base class.
decltype(auto) column(Matrix< MT, SO > &matrix, RCAs... args)
Creating a view on a specific column of the given matrix.
Definition: Column.h:137
#define BLAZE_CONSTRAINT_MUST_NOT_BE_POINTER_TYPE(T)
Constraint on the data type.
Definition: Pointer.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_REFERENCE_TYPE(T)
Constraint on the data type.
Definition: Reference.h:79
auto operator/=(DenseMatrix< MT, SO > &mat, ST scalar) -> EnableIf_t< IsScalar_v< ST >, MT & >
Division assignment operator for the division of a dense matrix by a scalar value ( ).
Definition: DenseMatrix.h:574
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:1339
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:1375
decltype(auto) ctrans(const DenseMatrix< MT, SO > &dm)
Returns the conjugate transpose matrix of dm.
Definition: DMatMapExpr.h:1501
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:766
auto operator+=(DenseMatrix< MT, SO > &mat, ST scalar) -> EnableIf_t< IsScalar_v< ST >, MT & >
Addition assignment operator for the addition of a dense matrix and a scalar value ( ).
Definition: DenseMatrix.h:386
auto operator*=(DenseMatrix< MT, SO > &mat, ST scalar) -> EnableIf_t< IsScalar_v< ST >, MT & >
Multiplication assignment operator for the multiplication of a dense matrix and a scalar value ( ).
Definition: DenseMatrix.h:510
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:812
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:9640
auto operator-=(DenseMatrix< MT, SO > &mat, ST scalar) -> EnableIf_t< IsScalar_v< ST >, MT & >
Subtraction assignment operator for the subtraction of a dense matrix and a scalar value ( ).
Definition: DenseMatrix.h:448
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:207
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.
Definition: Symmetric.h:79
#define BLAZE_CONSTRAINT_MUST_BE_ROW_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.
Definition: RowMajorMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION(T)
Constraint on the data type.
Definition: RequiresEvaluation.h:81
#define BLAZE_CONSTRAINT_MUST_NOT_BE_HERMITIAN_MATRIX_TYPE(T)
Constraint on the data type.
Definition: Hermitian.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_TRANSEXPR_TYPE(T)
Constraint on the data type.
Definition: TransExpr.h:81
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SUBMATRIX_TYPE(T)
Constraint on the data type.
Definition: Submatrix.h:81
#define BLAZE_CONSTRAINT_MUST_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.
Definition: Symmetric.h:60
#define BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE(T)
Constraint on the data type.
Definition: Computation.h:81
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE(T)
Constraint on the data type.
Definition: SparseMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_NOT_BE_ROWS_TYPE(T)
Constraint on the data type.
Definition: Rows.h:81
#define BLAZE_CONSTRAINT_MUST_NOT_BE_UNITRIANGULAR_MATRIX_TYPE(T)
Constraint on the data type.
Definition: UniTriangular.h:81
#define BLAZE_CONSTRAINT_MUST_BE_COLUMN_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.
Definition: ColumnMajorMatrix.h:61
constexpr bool IsSparseMatrix_v
Auxiliary variable template for the IsSparseMatrix type trait.
Definition: IsSparseMatrix.h:124
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 operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:293
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:628
constexpr size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:644
size_t nonZeros(const Matrix< MT, SO > &matrix)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:730
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:562
size_t capacity(const Matrix< MT, SO > &matrix) noexcept
Returns the maximum capacity of the matrix.
Definition: Matrix.h:692
constexpr void reset(Matrix< MT, SO > &matrix)
Resetting the given matrix.
Definition: Matrix.h:806
constexpr size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:660
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:584
void ctranspose(Matrix< MT, SO > &matrix)
In-place conjugate transpose of the given matrix.
Definition: Matrix.h:1221
MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:518
void transpose(Matrix< MT, SO > &matrix)
In-place transpose of the given matrix.
Definition: Matrix.h:1195
decltype(auto) row(Matrix< MT, SO > &, RRAs...)
Creating a view on a specific row of the given matrix.
Definition: Row.h:137
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.
Definition: Assert.h:101
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.
Definition: Assert.h:117
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
MT::Iterator upperBound(SparseMatrix< MT, SO > &sm, size_t i, size_t j)
Returns an iterator to the first index greater than the given index.
Definition: SparseMatrix.h:244
MT::Iterator lowerBound(SparseMatrix< MT, SO > &sm, size_t i, size_t j)
Returns an iterator to the first index not less than the given index.
Definition: SparseMatrix.h:194
MT::Iterator find(SparseMatrix< MT, SO > &sm, size_t i, size_t j)
Searches for a specific matrix element.
Definition: SparseMatrix.h:144
constexpr void MAYBE_UNUSED(const Args &...)
Suppression of unused parameter warnings.
Definition: MaybeUnused.h:81
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.
Definition: Exception.h:331
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.
Definition: Exception.h:235
#define BLAZE_THROW_LOGIC_ERROR(MESSAGE)
Macro for the emission of a std::logic_error exception.
Definition: Exception.h:187
constexpr bool isChecked(const Ts &... args)
Extracting blaze::Check arguments from a given list of arguments.
Definition: Check.h:225
constexpr Unchecked unchecked
Global Unchecked instance.
Definition: Check.h:146
Header file for the exception macros of the math module.
Header file for the extended initializer_list functionality.
Header file for the SparseElement base class.
Header file for basic type definitions.
Header file for the generic max algorithm.
Header file for the generic min algorithm.
Header file for the implementation of the Rows base template.