Blaze 3.9
Sparse.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_VIEWS_ROW_SPARSE_H_
36#define _BLAZE_MATH_VIEWS_ROW_SPARSE_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <iterator>
44#include <blaze/math/Aliases.h>
84#include <blaze/util/Assert.h>
87#include <blaze/util/EnableIf.h>
89#include <blaze/util/mpl/If.h>
90#include <blaze/util/Types.h>
94
95
96namespace blaze {
97
98//=================================================================================================
99//
100// CLASS TEMPLATE SPECIALIZATION FOR ROW-MAJOR SPARSE MATRICES
101//
102//=================================================================================================
103
104//*************************************************************************************************
112template< typename MT // Type of the sparse matrix
113 , bool SF // Symmetry flag
114 , size_t... CRAs > // Compile time row arguments
115class Row<MT,true,false,SF,CRAs...>
116 : public View< SparseVector< Row<MT,true,false,SF,CRAs...>, true > >
117 , private RowData<CRAs...>
118{
119 private:
120 //**Type definitions****************************************************************************
121 using DataType = RowData<CRAs...>;
122 using Operand = If_t< IsExpression_v<MT>, MT, MT& >;
123 //**********************************************************************************************
124
125 public:
126 //**Type definitions****************************************************************************
128 using This = Row<MT,true,false,SF,CRAs...>;
129
131 using BaseType = View< SparseVector<This,true> >;
132
133 using ViewedType = MT;
134 using ResultType = RowTrait_t<MT,CRAs...>;
135 using TransposeType = TransposeType_t<ResultType>;
136 using ElementType = ElementType_t<MT>;
137 using ReturnType = ReturnType_t<MT>;
138 using CompositeType = const Row&;
139
141 using ConstReference = ConstReference_t<MT>;
142
144 using Reference = If_t< IsConst_v<MT>, ConstReference, Reference_t<MT> >;
145
147 using ConstIterator = ConstIterator_t<MT>;
148
150 using Iterator = If_t< IsConst_v<MT>, ConstIterator, Iterator_t<MT> >;
151 //**********************************************************************************************
152
153 //**Compilation flags***************************************************************************
155 static constexpr bool smpAssignable = false;
156
158 static constexpr bool compileTimeArgs = DataType::compileTimeArgs;
159 //**********************************************************************************************
160
161 //**Constructors********************************************************************************
164 template< typename... RRAs >
165 explicit inline Row( MT& matrix, RRAs... args );
166
167 Row( const Row& ) = default;
169 //**********************************************************************************************
170
171 //**Destructor**********************************************************************************
174 ~Row() = default;
176 //**********************************************************************************************
177
178 //**Data access functions***********************************************************************
181 inline Reference operator[]( size_t index );
182 inline ConstReference operator[]( size_t index ) const;
183 inline Reference at( size_t index );
184 inline ConstReference at( size_t index ) const;
185 inline Iterator begin ();
186 inline ConstIterator begin () const;
187 inline ConstIterator cbegin() const;
188 inline Iterator end ();
189 inline ConstIterator end () const;
190 inline ConstIterator cend () const;
192 //**********************************************************************************************
193
194 //**Assignment operators************************************************************************
197 inline Row& operator=( initializer_list<ElementType> list );
198 inline Row& operator=( const Row& rhs );
199
200 template< typename VT > inline Row& operator= ( const DenseVector<VT,true>& rhs );
201 template< typename VT > inline Row& operator= ( const SparseVector<VT,true>& rhs );
202 template< typename VT > inline Row& operator+=( const DenseVector<VT,true>& rhs );
203 template< typename VT > inline Row& operator+=( const SparseVector<VT,true>& rhs );
204 template< typename VT > inline Row& operator-=( const DenseVector<VT,true>& rhs );
205 template< typename VT > inline Row& operator-=( const SparseVector<VT,true>& rhs );
206 template< typename VT > inline Row& operator*=( const Vector<VT,true>& rhs );
207 template< typename VT > inline Row& operator/=( const DenseVector<VT,true>& rhs );
208 template< typename VT > inline Row& operator%=( const Vector<VT,true>& rhs );
210 //**********************************************************************************************
211
212 //**Utility functions***************************************************************************
215 using DataType::row;
216
217 inline MT& operand() noexcept;
218 inline const MT& operand() const noexcept;
219
220 inline size_t size() const noexcept;
221 inline size_t capacity() const noexcept;
222 inline size_t nonZeros() const;
223 inline void reset();
224 inline void reserve( size_t n );
226 //**********************************************************************************************
227
228 //**Insertion functions*************************************************************************
231 inline Iterator set ( size_t index, const ElementType& value );
232 inline Iterator insert( size_t index, const ElementType& value );
233 inline void append( size_t index, const ElementType& value, bool check=false );
235 //**********************************************************************************************
236
237 //**Erase functions*****************************************************************************
240 inline void erase( size_t index );
241 inline Iterator erase( Iterator pos );
242 inline Iterator erase( Iterator first, Iterator last );
243
244 template< typename Pred, typename = DisableIf_t< IsIntegral_v<Pred> > >
245 inline void erase( Pred predicate );
246
247 template< typename Pred >
248 inline void erase( Iterator first, Iterator last, Pred predicate );
250 //**********************************************************************************************
251
252 //**Lookup functions****************************************************************************
255 inline Iterator find ( size_t index );
256 inline ConstIterator find ( size_t index ) const;
257 inline Iterator lowerBound( size_t index );
258 inline ConstIterator lowerBound( size_t index ) const;
259 inline Iterator upperBound( size_t index );
260 inline ConstIterator upperBound( size_t index ) const;
262 //**********************************************************************************************
263
264 //**Numeric functions***************************************************************************
267 template< typename Other > inline Row& scale( const Other& scalar );
269 //**********************************************************************************************
270
271 //**Expression template evaluation functions****************************************************
274 template< typename Other > inline bool canAlias ( const Other* alias ) const noexcept;
275 template< typename Other > inline bool isAliased( const Other* alias ) const noexcept;
276
277 template< typename VT > inline void assign ( const DenseVector <VT,true>& rhs );
278 template< typename VT > inline void assign ( const SparseVector<VT,true>& rhs );
279 template< typename VT > inline void addAssign( const DenseVector <VT,true>& rhs );
280 template< typename VT > inline void addAssign( const SparseVector<VT,true>& rhs );
281 template< typename VT > inline void subAssign( const DenseVector <VT,true>& rhs );
282 template< typename VT > inline void subAssign( const SparseVector<VT,true>& rhs );
284 //**********************************************************************************************
285
286 private:
287 //**Utility functions***************************************************************************
290 inline size_t extendCapacity() const noexcept;
292 //**********************************************************************************************
293
294 //**Member variables****************************************************************************
297 Operand matrix_;
299 //**********************************************************************************************
300
301 //**Compile time checks*************************************************************************
309 //**********************************************************************************************
310};
312//*************************************************************************************************
313
314
315
316
317//=================================================================================================
318//
319// CONSTRUCTORS
320//
321//=================================================================================================
322
323//*************************************************************************************************
336template< typename MT // Type of the sparse matrix
337 , bool SF // Symmetry flag
338 , size_t... CRAs > // Compile time row arguments
339template< typename... RRAs > // Runtime row arguments
340inline Row<MT,true,false,SF,CRAs...>::Row( MT& matrix, RRAs... args )
341 : DataType( args... ) // Base class initialization
342 , matrix_ ( matrix ) // The matrix containing the row
343{
344 if( isChecked( args... ) ) {
345 if( matrix_.rows() <= row() ) {
346 BLAZE_THROW_INVALID_ARGUMENT( "Invalid row access index" );
347 }
348 }
349 else {
350 BLAZE_USER_ASSERT( row() < matrix_.rows(), "Invalid row access index" );
351 }
352}
354//*************************************************************************************************
355
356
357
358
359//=================================================================================================
360//
361// DATA ACCESS FUNCTIONS
362//
363//=================================================================================================
364
365//*************************************************************************************************
375template< typename MT // Type of the sparse matrix
376 , bool SF // Symmetry flag
377 , size_t... CRAs > // Compile time row arguments
378inline typename Row<MT,true,false,SF,CRAs...>::Reference
379 Row<MT,true,false,SF,CRAs...>::operator[]( size_t index )
380{
381 BLAZE_USER_ASSERT( index < size(), "Invalid row access index" );
382 return matrix_(row(),index);
383}
385//*************************************************************************************************
386
387
388//*************************************************************************************************
398template< typename MT // Type of the sparse matrix
399 , bool SF // Symmetry flag
400 , size_t... CRAs > // Compile time row arguments
401inline typename Row<MT,true,false,SF,CRAs...>::ConstReference
402 Row<MT,true,false,SF,CRAs...>::operator[]( size_t index ) const
403{
404 BLAZE_USER_ASSERT( index < size(), "Invalid row access index" );
405 return const_cast<const MT&>( matrix_ )(row(),index);
406}
408//*************************************************************************************************
409
410
411//*************************************************************************************************
422template< typename MT // Type of the sparse matrix
423 , bool SF // Symmetry flag
424 , size_t... CRAs > // Compile time row arguments
425inline typename Row<MT,true,false,SF,CRAs...>::Reference
426 Row<MT,true,false,SF,CRAs...>::at( size_t index )
427{
428 if( index >= size() ) {
429 BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
430 }
431 return (*this)[index];
432}
434//*************************************************************************************************
435
436
437//*************************************************************************************************
448template< typename MT // Type of the sparse matrix
449 , bool SF // Symmetry flag
450 , size_t... CRAs > // Compile time row arguments
451inline typename Row<MT,true,false,SF,CRAs...>::ConstReference
452 Row<MT,true,false,SF,CRAs...>::at( size_t index ) const
453{
454 if( index >= size() ) {
455 BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
456 }
457 return (*this)[index];
458}
460//*************************************************************************************************
461
462
463//*************************************************************************************************
471template< typename MT // Type of the sparse matrix
472 , bool SF // Symmetry flag
473 , size_t... CRAs > // Compile time row arguments
474inline typename Row<MT,true,false,SF,CRAs...>::Iterator
476{
477 return matrix_.begin( row() );
478}
480//*************************************************************************************************
481
482
483//*************************************************************************************************
491template< typename MT // Type of the sparse matrix
492 , bool SF // Symmetry flag
493 , size_t... CRAs > // Compile time row arguments
494inline typename Row<MT,true,false,SF,CRAs...>::ConstIterator
496{
497 return matrix_.cbegin( row() );
498}
500//*************************************************************************************************
501
502
503//*************************************************************************************************
511template< typename MT // Type of the sparse matrix
512 , bool SF // Symmetry flag
513 , size_t... CRAs > // Compile time row arguments
514inline typename Row<MT,true,false,SF,CRAs...>::ConstIterator
516{
517 return matrix_.cbegin( row() );
518}
520//*************************************************************************************************
521
522
523//*************************************************************************************************
531template< typename MT // Type of the sparse matrix
532 , bool SF // Symmetry flag
533 , size_t... CRAs > // Compile time row arguments
534inline typename Row<MT,true,false,SF,CRAs...>::Iterator
536{
537 return matrix_.end( row() );
538}
540//*************************************************************************************************
541
542
543//*************************************************************************************************
551template< typename MT // Type of the sparse matrix
552 , bool SF // Symmetry flag
553 , size_t... CRAs > // Compile time row arguments
554inline typename Row<MT,true,false,SF,CRAs...>::ConstIterator
556{
557 return matrix_.cend( row() );
558}
560//*************************************************************************************************
561
562
563//*************************************************************************************************
571template< typename MT // Type of the sparse matrix
572 , bool SF // Symmetry flag
573 , size_t... CRAs > // Compile time row arguments
574inline typename Row<MT,true,false,SF,CRAs...>::ConstIterator
576{
577 return matrix_.cend( row() );
578}
580//*************************************************************************************************
581
582
583
584
585//=================================================================================================
586//
587// ASSIGNMENT OPERATORS
588//
589//=================================================================================================
590
591//*************************************************************************************************
606template< typename MT // Type of the sparse matrix
607 , bool SF // Symmetry flag
608 , size_t... CRAs > // Compile time row arguments
609inline Row<MT,true,false,SF,CRAs...>&
610 Row<MT,true,false,SF,CRAs...>::operator=( initializer_list<ElementType> list )
611{
612 using blaze::assign;
613
614 if( list.size() > size() ) {
615 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to row" );
616 }
617
618 const InitializerVector<ElementType,true> tmp( list, size() );
619
620 if( !tryAssign( matrix_, tmp, row(), 0UL ) ) {
621 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
622 }
623
624 decltype(auto) left( derestrict( *this ) );
625
626 left.reset();
627 assign( left, tmp );
628
629 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
630
631 return *this;
632}
634//*************************************************************************************************
635
636
637//*************************************************************************************************
651template< typename MT // Type of the sparse matrix
652 , bool SF // Symmetry flag
653 , size_t... CRAs > // Compile time row arguments
654inline Row<MT,true,false,SF,CRAs...>&
655 Row<MT,true,false,SF,CRAs...>::operator=( const Row& rhs )
656{
657 using blaze::assign;
658
662
663 if( this == &rhs || ( &matrix_ == &rhs.matrix_ && row() == rhs.row() ) )
664 return *this;
665
666 if( size() != rhs.size() ) {
667 BLAZE_THROW_INVALID_ARGUMENT( "Row sizes do not match" );
668 }
669
670 if( !tryAssign( matrix_, rhs, row(), 0UL ) ) {
671 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
672 }
673
674 decltype(auto) left( derestrict( *this ) );
675
676 if( rhs.canAlias( this ) ) {
677 const ResultType tmp( rhs );
678 left.reset();
679 left.reserve( tmp.nonZeros() );
680 assign( left, tmp );
681 }
682 else {
683 left.reset();
684 left.reserve( rhs.nonZeros() );
685 assign( left, rhs );
686 }
687
688 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
689
690 return *this;
691}
693//*************************************************************************************************
694
695
696//*************************************************************************************************
710template< typename MT // Type of the sparse matrix
711 , bool SF // Symmetry flag
712 , size_t... CRAs > // Compile time row arguments
713template< typename VT > // Type of the right-hand side dense vector
714inline Row<MT,true,false,SF,CRAs...>&
715 Row<MT,true,false,SF,CRAs...>::operator=( const DenseVector<VT,true>& rhs )
716{
717 using blaze::assign;
718
720 BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE ( ResultType_t<VT> );
722
723 if( size() != (*rhs).size() ) {
724 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
725 }
726
727 using Right = If_t< IsRestricted_v<MT>, CompositeType_t<VT>, const VT& >;
728 Right right( *rhs );
729
730 if( !tryAssign( matrix_, right, row(), 0UL ) ) {
731 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
732 }
733
734 decltype(auto) left( derestrict( *this ) );
735
736 if( IsReference_v<Right> && right.canAlias( this ) ) {
737 const ResultType_t<VT> tmp( right );
738 left.reset();
739 assign( left, tmp );
740 }
741 else {
742 left.reset();
743 assign( left, right );
744 }
745
746 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
747
748 return *this;
749}
751//*************************************************************************************************
752
753
754//*************************************************************************************************
768template< typename MT // Type of the sparse matrix
769 , bool SF // Symmetry flag
770 , size_t... CRAs > // Compile time row arguments
771template< typename VT > // Type of the right-hand side sparse vector
772inline Row<MT,true,false,SF,CRAs...>&
773 Row<MT,true,false,SF,CRAs...>::operator=( const SparseVector<VT,true>& rhs )
774{
775 using blaze::assign;
776
778 BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE ( ResultType_t<VT> );
780
781 if( size() != (*rhs).size() ) {
782 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
783 }
784
785 using Right = If_t< IsRestricted_v<MT>, CompositeType_t<VT>, const VT& >;
786 Right right( *rhs );
787
788 if( !tryAssign( matrix_, right, row(), 0UL ) ) {
789 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
790 }
791
792 decltype(auto) left( derestrict( *this ) );
793
794 if( IsReference_v<Right> && right.canAlias( this ) ) {
795 const ResultType_t<VT> tmp( right );
796 left.reset();
797 left.reserve( tmp.nonZeros() );
798 assign( left, tmp );
799 }
800 else {
801 left.reset();
802 left.reserve( right.nonZeros() );
803 assign( left, right );
804 }
805
806 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
807
808 return *this;
809}
811//*************************************************************************************************
812
813
814//*************************************************************************************************
828template< typename MT // Type of the sparse matrix
829 , bool SF // Symmetry flag
830 , size_t... CRAs > // Compile time row arguments
831template< typename VT > // Type of the right-hand side dense vector
832inline Row<MT,true,false,SF,CRAs...>&
833 Row<MT,true,false,SF,CRAs...>::operator+=( const DenseVector<VT,true>& rhs )
834{
835 using blaze::assign;
836
841 BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE ( ResultType_t<VT> );
843
844 using AddType = AddTrait_t< ResultType, ResultType_t<VT> >;
845
849
850 if( size() != (*rhs).size() ) {
851 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
852 }
853
854 const AddType tmp( *this + (*rhs) );
855
856 if( !tryAssign( matrix_, tmp, row(), 0UL ) ) {
857 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
858 }
859
860 decltype(auto) left( derestrict( *this ) );
861
862 left.reset();
863 assign( left, tmp );
864
865 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
866
867 return *this;
868}
870//*************************************************************************************************
871
872
873//*************************************************************************************************
887template< typename MT // Type of the sparse matrix
888 , bool SF // Symmetry flag
889 , size_t... CRAs > // Compile time row arguments
890template< typename VT > // Type of the right-hand side sparse vector
891inline Row<MT,true,false,SF,CRAs...>&
892 Row<MT,true,false,SF,CRAs...>::operator+=( const SparseVector<VT,true>& rhs )
893{
894 using blaze::assign;
895
900 BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE ( ResultType_t<VT> );
902
903 using AddType = AddTrait_t< ResultType, ResultType_t<VT> >;
904
908
909 if( size() != (*rhs).size() ) {
910 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
911 }
912
913 const AddType tmp( *this + (*rhs) );
914
915 if( !tryAssign( matrix_, tmp, row(), 0UL ) ) {
916 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
917 }
918
919 decltype(auto) left( derestrict( *this ) );
920
921 left.reset();
922 left.reserve( tmp.nonZeros() );
923 assign( left, tmp );
924
925 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
926
927 return *this;
928}
930//*************************************************************************************************
931
932
933//*************************************************************************************************
948template< typename MT // Type of the sparse matrix
949 , bool SF // Symmetry flag
950 , size_t... CRAs > // Compile time row arguments
951template< typename VT > // Type of the right-hand side dense vector
952inline Row<MT,true,false,SF,CRAs...>&
953 Row<MT,true,false,SF,CRAs...>::operator-=( const DenseVector<VT,true>& rhs )
954{
955 using blaze::assign;
956
961 BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE ( ResultType_t<VT> );
963
964 using SubType = SubTrait_t< ResultType, ResultType_t<VT> >;
965
969
970 if( size() != (*rhs).size() ) {
971 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
972 }
973
974 const SubType tmp( *this - (*rhs) );
975
976 if( !tryAssign( matrix_, tmp, row(), 0UL ) ) {
977 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
978 }
979
980 decltype(auto) left( derestrict( *this ) );
981
982 left.reset();
983 assign( left, tmp );
984
985 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
986
987 return *this;
988}
990//*************************************************************************************************
991
992
993//*************************************************************************************************
1008template< typename MT // Type of the sparse matrix
1009 , bool SF // Symmetry flag
1010 , size_t... CRAs > // Compile time row arguments
1011template< typename VT > // Type of the right-hand side sparse vector
1012inline Row<MT,true,false,SF,CRAs...>&
1013 Row<MT,true,false,SF,CRAs...>::operator-=( const SparseVector<VT,true>& rhs )
1014{
1015 using blaze::assign;
1016
1021 BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE ( ResultType_t<VT> );
1023
1024 using SubType = SubTrait_t< ResultType, ResultType_t<VT> >;
1025
1029
1030 if( size() != (*rhs).size() ) {
1031 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1032 }
1033
1034 const SubType tmp( *this - (*rhs) );
1035
1036 if( !tryAssign( matrix_, tmp, row(), 0UL ) ) {
1037 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
1038 }
1039
1040 decltype(auto) left( derestrict( *this ) );
1041
1042 left.reset();
1043 left.reserve( tmp.nonZeros() );
1044 assign( left, tmp );
1045
1046 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
1047
1048 return *this;
1049}
1051//*************************************************************************************************
1052
1053
1054//*************************************************************************************************
1067template< typename MT // Type of the sparse matrix
1068 , bool SF // Symmetry flag
1069 , size_t... CRAs > // Compile time row arguments
1070template< typename VT > // Type of the right-hand side vector
1071inline Row<MT,true,false,SF,CRAs...>&
1072 Row<MT,true,false,SF,CRAs...>::operator*=( const Vector<VT,true>& rhs )
1073{
1074 using blaze::assign;
1075
1079 BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE ( ResultType_t<VT> );
1081
1082 using MultType = MultTrait_t< ResultType, ResultType_t<VT> >;
1083
1086
1087 if( size() != (*rhs).size() ) {
1088 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1089 }
1090
1091 const MultType tmp( *this * (*rhs) );
1092
1093 if( !tryAssign( matrix_, tmp, row(), 0UL ) ) {
1094 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
1095 }
1096
1097 decltype(auto) left( derestrict( *this ) );
1098
1099 left.reset();
1100 assign( left, tmp );
1101
1102 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
1103
1104 return *this;
1105}
1107//*************************************************************************************************
1108
1109
1110//*************************************************************************************************
1122template< typename MT // Type of the sparse matrix
1123 , bool SF // Symmetry flag
1124 , size_t... CRAs > // Compile time row arguments
1125template< typename VT > // Type of the right-hand side vector
1126inline Row<MT,true,false,SF,CRAs...>&
1127 Row<MT,true,false,SF,CRAs...>::operator/=( const DenseVector<VT,true>& rhs )
1128{
1129 using blaze::assign;
1130
1134 BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE ( ResultType_t<VT> );
1135 BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE ( ResultType_t<VT> );
1137
1138 using DivType = DivTrait_t< ResultType, ResultType_t<VT> >;
1139
1143
1144 if( size() != (*rhs).size() ) {
1145 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1146 }
1147
1148 const DivType tmp( *this / (*rhs) );
1149
1150 if( !tryAssign( matrix_, tmp, row(), 0UL ) ) {
1151 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
1152 }
1153
1154 decltype(auto) left( derestrict( *this ) );
1155
1156 left.reset();
1157 assign( left, tmp );
1158
1159 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
1160
1161 return *this;
1162}
1164//*************************************************************************************************
1165
1166
1167//*************************************************************************************************
1180template< typename MT // Type of the sparse matrix
1181 , bool SF // Symmetry flag
1182 , size_t... CRAs > // Compile time row arguments
1183template< typename VT > // Type of the right-hand side vector
1184inline Row<MT,true,false,SF,CRAs...>&
1185 Row<MT,true,false,SF,CRAs...>::operator%=( const Vector<VT,true>& rhs )
1186{
1187 using blaze::assign;
1188
1189 BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE ( ResultType_t<VT> );
1191
1192 using CrossType = CrossTrait_t< ResultType, ResultType_t<VT> >;
1193
1197
1198 if( size() != 3UL || (*rhs).size() != 3UL ) {
1199 BLAZE_THROW_INVALID_ARGUMENT( "Invalid vector size for cross product" );
1200 }
1201
1202 const CrossType tmp( *this % (*rhs) );
1203
1204 if( !tryAssign( matrix_, tmp, row(), 0UL ) ) {
1205 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
1206 }
1207
1208 decltype(auto) left( derestrict( *this ) );
1209
1210 left.reset();
1211 assign( left, tmp );
1212
1213 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
1214
1215 return *this;
1216}
1218//*************************************************************************************************
1219
1220
1221
1222
1223//=================================================================================================
1224//
1225// UTILITY FUNCTIONS
1226//
1227//=================================================================================================
1228
1229//*************************************************************************************************
1235template< typename MT // Type of the sparse matrix
1236 , bool SF // Symmetry flag
1237 , size_t... CRAs > // Compile time row arguments
1238inline MT& Row<MT,true,false,SF,CRAs...>::operand() noexcept
1239{
1240 return matrix_;
1241}
1243//*************************************************************************************************
1244
1245
1246//*************************************************************************************************
1252template< typename MT // Type of the sparse matrix
1253 , bool SF // Symmetry flag
1254 , size_t... CRAs > // Compile time row arguments
1255inline const MT& Row<MT,true,false,SF,CRAs...>::operand() const noexcept
1256{
1257 return matrix_;
1258}
1260//*************************************************************************************************
1261
1262
1263//*************************************************************************************************
1269template< typename MT // Type of the sparse matrix
1270 , bool SF // Symmetry flag
1271 , size_t... CRAs > // Compile time row arguments
1272inline size_t Row<MT,true,false,SF,CRAs...>::size() const noexcept
1273{
1274 return matrix_.columns();
1275}
1277//*************************************************************************************************
1278
1279
1280//*************************************************************************************************
1286template< typename MT // Type of the sparse matrix
1287 , bool SF // Symmetry flag
1288 , size_t... CRAs > // Compile time row arguments
1289inline size_t Row<MT,true,false,SF,CRAs...>::capacity() const noexcept
1290{
1291 return matrix_.capacity( row() );
1292}
1294//*************************************************************************************************
1295
1296
1297//*************************************************************************************************
1306template< typename MT // Type of the sparse matrix
1307 , bool SF // Symmetry flag
1308 , size_t... CRAs > // Compile time row arguments
1309inline size_t Row<MT,true,false,SF,CRAs...>::nonZeros() const
1310{
1311 return matrix_.nonZeros( row() );
1312}
1314//*************************************************************************************************
1315
1316
1317//*************************************************************************************************
1323template< typename MT // Type of the sparse matrix
1324 , bool SF // Symmetry flag
1325 , size_t... CRAs > // Compile time row arguments
1327{
1328 matrix_.reset( row() );
1329}
1331//*************************************************************************************************
1332
1333
1334//*************************************************************************************************
1344template< typename MT // Type of the sparse matrix
1345 , bool SF // Symmetry flag
1346 , size_t... CRAs > // Compile time row arguments
1347void Row<MT,true,false,SF,CRAs...>::reserve( size_t n )
1348{
1349 matrix_.reserve( row(), n );
1350}
1352//*************************************************************************************************
1353
1354
1355//*************************************************************************************************
1364template< typename MT // Type of the sparse matrix
1365 , bool SF // Symmetry flag
1366 , size_t... CRAs > // Compile time row arguments
1367inline size_t Row<MT,true,false,SF,CRAs...>::extendCapacity() const noexcept
1368{
1369 using blaze::max;
1370 using blaze::min;
1371
1372 size_t nonzeros( 2UL*capacity()+1UL );
1373 nonzeros = max( nonzeros, 7UL );
1374 nonzeros = min( nonzeros, size() );
1375
1376 BLAZE_INTERNAL_ASSERT( nonzeros > capacity(), "Invalid capacity value" );
1377
1378 return nonzeros;
1379}
1381//*************************************************************************************************
1382
1383
1384
1385
1386//=================================================================================================
1387//
1388// INSERTION FUNCTIONS
1389//
1390//=================================================================================================
1391
1392//*************************************************************************************************
1404template< typename MT // Type of the sparse matrix
1405 , bool SF // Symmetry flag
1406 , size_t... CRAs > // Compile time row arguments
1407inline typename Row<MT,true,false,SF,CRAs...>::Iterator
1408 Row<MT,true,false,SF,CRAs...>::set( size_t index, const ElementType& value )
1409{
1410 return matrix_.set( row(), index, value );
1411}
1413//*************************************************************************************************
1414
1415
1416//*************************************************************************************************
1429template< typename MT // Type of the sparse matrix
1430 , bool SF // Symmetry flag
1431 , size_t... CRAs > // Compile time row arguments
1432inline typename Row<MT,true,false,SF,CRAs...>::Iterator
1433 Row<MT,true,false,SF,CRAs...>::insert( size_t index, const ElementType& value )
1434{
1435 return matrix_.insert( row(), index, value );
1436}
1438//*************************************************************************************************
1439
1440
1441//*************************************************************************************************
1466template< typename MT // Type of the sparse matrix
1467 , bool SF // Symmetry flag
1468 , size_t... CRAs > // Compile time row arguments
1469inline void Row<MT,true,false,SF,CRAs...>::append( size_t index, const ElementType& value, bool check )
1470{
1471 matrix_.append( row(), index, value, check );
1472}
1474//*************************************************************************************************
1475
1476
1477
1478
1479//=================================================================================================
1480//
1481// ERASE FUNCTIONS
1482//
1483//=================================================================================================
1484
1485//*************************************************************************************************
1494template< typename MT // Type of the sparse matrix
1495 , bool SF // Symmetry flag
1496 , size_t... CRAs > // Compile time row arguments
1497inline void Row<MT,true,false,SF,CRAs...>::erase( size_t index )
1498{
1499 matrix_.erase( row(), index );
1500}
1502//*************************************************************************************************
1503
1504
1505//*************************************************************************************************
1514template< typename MT // Type of the sparse matrix
1515 , bool SF // Symmetry flag
1516 , size_t... CRAs > // Compile time row arguments
1517inline typename Row<MT,true,false,SF,CRAs...>::Iterator
1518 Row<MT,true,false,SF,CRAs...>::erase( Iterator pos )
1519{
1520 return matrix_.erase( row(), pos );
1521}
1523//*************************************************************************************************
1524
1525
1526//*************************************************************************************************
1536template< typename MT // Type of the sparse matrix
1537 , bool SF // Symmetry flag
1538 , size_t... CRAs > // Compile time row arguments
1539inline typename Row<MT,true,false,SF,CRAs...>::Iterator
1540 Row<MT,true,false,SF,CRAs...>::erase( Iterator first, Iterator last )
1541{
1542 return matrix_.erase( row(), first, last );
1543}
1545//*************************************************************************************************
1546
1547
1548//*************************************************************************************************
1571template< typename MT // Type of the sparse matrix
1572 , bool SF // Symmetry flag
1573 , size_t... CRAs > // Compile time row arguments
1574template< typename Pred // Type of the unary predicate
1575 , typename > // Type restriction on the unary predicate
1576inline void Row<MT,true,false,SF,CRAs...>::erase( Pred predicate )
1577{
1578 matrix_.erase( row(), begin(), end(), predicate );
1579}
1581//*************************************************************************************************
1582
1583
1584//*************************************************************************************************
1609template< typename MT // Type of the sparse matrix
1610 , bool SF // Symmetry flag
1611 , size_t... CRAs > // Compile time row arguments
1612template< typename Pred > // Type of the unary predicate
1613inline void Row<MT,true,false,SF,CRAs...>::erase( Iterator first, Iterator last, Pred predicate )
1614{
1615 matrix_.erase( row(), first, last, predicate );
1616}
1618//*************************************************************************************************
1619
1620
1621
1622
1623//=================================================================================================
1624//
1625// LOOKUP FUNCTIONS
1626//
1627//=================================================================================================
1628
1629//*************************************************************************************************
1643template< typename MT // Type of the sparse matrix
1644 , bool SF // Symmetry flag
1645 , size_t... CRAs > // Compile time row arguments
1646inline typename Row<MT,true,false,SF,CRAs...>::Iterator
1648{
1649 return matrix_.find( row(), index );
1650}
1652//*************************************************************************************************
1653
1654
1655//*************************************************************************************************
1669template< typename MT // Type of the sparse matrix
1670 , bool SF // Symmetry flag
1671 , size_t... CRAs > // Compile time row arguments
1672inline typename Row<MT,true,false,SF,CRAs...>::ConstIterator
1673 Row<MT,true,false,SF,CRAs...>::find( size_t index ) const
1674{
1675 return matrix_.find( row(), index );
1676}
1678//*************************************************************************************************
1679
1680
1681//*************************************************************************************************
1694template< typename MT // Type of the sparse matrix
1695 , bool SF // Symmetry flag
1696 , size_t... CRAs > // Compile time row arguments
1697inline typename Row<MT,true,false,SF,CRAs...>::Iterator
1699{
1700 return matrix_.lowerBound( row(), index );
1701}
1703//*************************************************************************************************
1704
1705
1706//*************************************************************************************************
1719template< typename MT // Type of the sparse matrix
1720 , bool SF // Symmetry flag
1721 , size_t... CRAs > // Compile time row arguments
1722inline typename Row<MT,true,false,SF,CRAs...>::ConstIterator
1723 Row<MT,true,false,SF,CRAs...>::lowerBound( size_t index ) const
1724{
1725 return matrix_.lowerBound( row(), index );
1726}
1728//*************************************************************************************************
1729
1730
1731//*************************************************************************************************
1744template< typename MT // Type of the sparse matrix
1745 , bool SF // Symmetry flag
1746 , size_t... CRAs > // Compile time row arguments
1747inline typename Row<MT,true,false,SF,CRAs...>::Iterator
1749{
1750 return matrix_.upperBound( row(), index );
1751}
1753//*************************************************************************************************
1754
1755
1756//*************************************************************************************************
1769template< typename MT // Type of the sparse matrix
1770 , bool SF // Symmetry flag
1771 , size_t... CRAs > // Compile time row arguments
1772inline typename Row<MT,true,false,SF,CRAs...>::ConstIterator
1773 Row<MT,true,false,SF,CRAs...>::upperBound( size_t index ) const
1774{
1775 return matrix_.upperBound( row(), index );
1776}
1778//*************************************************************************************************
1779
1780
1781
1782
1783//=================================================================================================
1784//
1785// NUMERIC FUNCTIONS
1786//
1787//=================================================================================================
1788
1789//*************************************************************************************************
1802template< typename MT // Type of the sparse matrix
1803 , bool SF // Symmetry flag
1804 , size_t... CRAs > // Compile time row arguments
1805template< typename Other > // Data type of the scalar value
1806inline Row<MT,true,false,SF,CRAs...>&
1807 Row<MT,true,false,SF,CRAs...>::scale( const Other& scalar )
1808{
1810
1811 for( Iterator element=begin(); element!=end(); ++element )
1812 element->value() *= scalar;
1813 return *this;
1814}
1816//*************************************************************************************************
1817
1818
1819
1820
1821//=================================================================================================
1822//
1823// EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1824//
1825//=================================================================================================
1826
1827//*************************************************************************************************
1838template< typename MT // Type of the sparse matrix
1839 , bool SF // Symmetry flag
1840 , size_t... CRAs > // Compile time row arguments
1841template< typename Other > // Data type of the foreign expression
1842inline bool Row<MT,true,false,SF,CRAs...>::canAlias( const Other* alias ) const noexcept
1843{
1844 return matrix_.isAliased( &unview( *alias ) );
1845}
1847//*************************************************************************************************
1848
1849
1850//*************************************************************************************************
1861template< typename MT // Type of the sparse matrix
1862 , bool SF // Symmetry flag
1863 , size_t... CRAs > // Compile time row arguments
1864template< typename Other > // Data type of the foreign expression
1865inline bool Row<MT,true,false,SF,CRAs...>::isAliased( const Other* alias ) const noexcept
1866{
1867 return matrix_.isAliased( &unview( *alias ) );
1868}
1870//*************************************************************************************************
1871
1872
1873//*************************************************************************************************
1885template< typename MT // Type of the sparse matrix
1886 , bool SF // Symmetry flag
1887 , size_t... CRAs > // Compile time row arguments
1888template< typename VT > // Type of the right-hand side dense vector
1889inline void Row<MT,true,false,SF,CRAs...>::assign( const DenseVector<VT,true>& rhs )
1890{
1891 BLAZE_INTERNAL_ASSERT( size() == (*rhs).size(), "Invalid vector sizes" );
1892 BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
1893
1894 for( size_t j=0UL; j<size(); ++j )
1895 {
1896 if( matrix_.nonZeros( row() ) == matrix_.capacity( row() ) )
1897 matrix_.reserve( row(), extendCapacity() );
1898
1899 matrix_.append( row(), j, (*rhs)[j], true );
1900 }
1901}
1903//*************************************************************************************************
1904
1905
1906//*************************************************************************************************
1918template< typename MT // Type of the sparse matrix
1919 , bool SF // Symmetry flag
1920 , size_t... CRAs > // Compile time row arguments
1921template< typename VT > // Type of the right-hand side sparse vector
1922inline void Row<MT,true,false,SF,CRAs...>::assign( const SparseVector<VT,true>& rhs )
1923{
1924 BLAZE_INTERNAL_ASSERT( size() == (*rhs).size(), "Invalid vector sizes" );
1925 BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
1926
1927 for( ConstIterator_t<VT> element=(*rhs).begin(); element!=(*rhs).end(); ++element ) {
1928 matrix_.append( row(), element->index(), element->value(), true );
1929 }
1930}
1932//*************************************************************************************************
1933
1934
1935//*************************************************************************************************
1947template< typename MT // Type of the sparse matrix
1948 , bool SF // Symmetry flag
1949 , size_t... CRAs > // Compile time row arguments
1950template< typename VT > // Type of the right-hand side dense vector
1951inline void Row<MT,true,false,SF,CRAs...>::addAssign( const DenseVector<VT,true>& rhs )
1952{
1953 using AddType = AddTrait_t< ResultType, ResultType_t<VT> >;
1954
1958
1959 BLAZE_INTERNAL_ASSERT( size() == (*rhs).size(), "Invalid vector sizes" );
1960
1961 const AddType tmp( serial( *this + (*rhs) ) );
1962 matrix_.reset( row() );
1963 assign( tmp );
1964}
1966//*************************************************************************************************
1967
1968
1969//*************************************************************************************************
1981template< typename MT // Type of the sparse matrix
1982 , bool SF // Symmetry flag
1983 , size_t... CRAs > // Compile time row arguments
1984template< typename VT > // Type of the right-hand side sparse vector
1985inline void Row<MT,true,false,SF,CRAs...>::addAssign( const SparseVector<VT,true>& rhs )
1986{
1987 using AddType = AddTrait_t< ResultType, ResultType_t<VT> >;
1988
1992
1993 BLAZE_INTERNAL_ASSERT( size() == (*rhs).size(), "Invalid vector sizes" );
1994
1995 const AddType tmp( serial( *this + (*rhs) ) );
1996 matrix_.reset( row() );
1997 matrix_.reserve( row(), tmp.nonZeros() );
1998 assign( tmp );
1999}
2001//*************************************************************************************************
2002
2003
2004//*************************************************************************************************
2016template< typename MT // Type of the sparse matrix
2017 , bool SF // Symmetry flag
2018 , size_t... CRAs > // Compile time row arguments
2019template< typename VT > // Type of the right-hand side dense vector
2020inline void Row<MT,true,false,SF,CRAs...>::subAssign( const DenseVector<VT,true>& rhs )
2021{
2022 using SubType = SubTrait_t< ResultType, ResultType_t<VT> >;
2023
2027
2028 BLAZE_INTERNAL_ASSERT( size() == (*rhs).size(), "Invalid vector sizes" );
2029
2030 const SubType tmp( serial( *this - (*rhs) ) );
2031 matrix_.reset( row() );
2032 assign( tmp );
2033}
2035//*************************************************************************************************
2036
2037
2038//*************************************************************************************************
2050template< typename MT // Type of the sparse matrix
2051 , bool SF // Symmetry flag
2052 , size_t... CRAs > // Compile time row arguments
2053template< typename VT > // Type of the right-hand side sparse vector
2054inline void Row<MT,true,false,SF,CRAs...>::subAssign( const SparseVector<VT,true>& rhs )
2055{
2056 using SubType = SubTrait_t< ResultType, ResultType_t<VT> >;
2057
2061
2062 BLAZE_INTERNAL_ASSERT( size() == (*rhs).size(), "Invalid vector sizes" );
2063
2064 const SubType tmp( serial( *this - (*rhs) ) );
2065 matrix_.reset( row() );
2066 matrix_.reserve( row(), tmp.nonZeros() );
2067 assign( tmp );
2068}
2070//*************************************************************************************************
2071
2072
2073
2074
2075
2076
2077
2078
2079//=================================================================================================
2080//
2081// CLASS TEMPLATE SPECIALIZATION FOR GENERAL COLUMN-MAJOR SPARSE MATRICES
2082//
2083//=================================================================================================
2084
2085//*************************************************************************************************
2093template< typename MT // Type of the sparse matrix
2094 , size_t... CRAs > // Compile time row arguments
2095class Row<MT,false,false,false,CRAs...>
2096 : public View< SparseVector< Row<MT,false,false,false,CRAs...>, true > >
2097 , private RowData<CRAs...>
2098{
2099 private:
2100 //**Type definitions****************************************************************************
2101 using DataType = RowData<CRAs...>;
2102 using Operand = If_t< IsExpression_v<MT>, MT, MT& >;
2103 //**********************************************************************************************
2104
2105 public:
2106 //**Type definitions****************************************************************************
2108 using This = Row<MT,false,false,false,CRAs...>;
2109
2111 using BaseType = View< SparseVector<This,true> >;
2112
2113 using ViewedType = MT;
2114 using ResultType = RowTrait_t<MT,CRAs...>;
2115 using TransposeType = TransposeType_t<ResultType>;
2116 using ElementType = ElementType_t<MT>;
2117 using ReturnType = ReturnType_t<MT>;
2118 using CompositeType = const Row&;
2119
2121 using ConstReference = ConstReference_t<MT>;
2122
2124 using Reference = If_t< IsConst_v<MT>, ConstReference, Reference_t<MT> >;
2125 //**********************************************************************************************
2126
2127 //**RowElement class definition*****************************************************************
2130 template< typename MatrixType // Type of the sparse matrix
2131 , typename IteratorType > // Type of the sparse matrix iterator
2132 class RowElement
2133 : private SparseElement
2134 {
2135 public:
2136 //**Constructor******************************************************************************
2142 inline RowElement( IteratorType pos, size_t column )
2143 : pos_ ( pos ) // Iterator to the current position within the sparse row
2144 , column_( column ) // Index of the according column
2145 {}
2146 //*******************************************************************************************
2147
2148 //**Assignment operator**********************************************************************
2154 template< typename T > inline RowElement& operator=( const T& v ) {
2155 *pos_ = v;
2156 return *this;
2157 }
2158 //*******************************************************************************************
2159
2160 //**Addition assignment operator*************************************************************
2166 template< typename T > inline RowElement& operator+=( const T& v ) {
2167 *pos_ += v;
2168 return *this;
2169 }
2170 //*******************************************************************************************
2171
2172 //**Subtraction assignment operator**********************************************************
2178 template< typename T > inline RowElement& operator-=( const T& v ) {
2179 *pos_ -= v;
2180 return *this;
2181 }
2182 //*******************************************************************************************
2183
2184 //**Multiplication assignment operator*******************************************************
2190 template< typename T > inline RowElement& operator*=( const T& v ) {
2191 *pos_ *= v;
2192 return *this;
2193 }
2194 //*******************************************************************************************
2195
2196 //**Division assignment operator*************************************************************
2202 template< typename T > inline RowElement& operator/=( const T& v ) {
2203 *pos_ /= v;
2204 return *this;
2205 }
2206 //*******************************************************************************************
2207
2208 //**Element access operator******************************************************************
2213 inline const RowElement* operator->() const {
2214 return this;
2215 }
2216 //*******************************************************************************************
2217
2218 //**Value function***************************************************************************
2223 inline decltype(auto) value() const {
2224 return pos_->value();
2225 }
2226 //*******************************************************************************************
2227
2228 //**Index function***************************************************************************
2233 inline size_t index() const {
2234 return column_;
2235 }
2236 //*******************************************************************************************
2237
2238 private:
2239 //**Member variables*************************************************************************
2240 IteratorType pos_;
2241 size_t column_;
2242 //*******************************************************************************************
2243 };
2244 //**********************************************************************************************
2245
2246 //**RowIterator class definition****************************************************************
2249 template< typename MatrixType // Type of the sparse matrix
2250 , typename IteratorType > // Type of the sparse matrix iterator
2251 class RowIterator
2252 {
2253 public:
2254 //**Type definitions*************************************************************************
2255 using IteratorCategory = std::forward_iterator_tag;
2256 using ValueType = RowElement<MatrixType,IteratorType>;
2257 using PointerType = ValueType;
2258 using ReferenceType = ValueType;
2259 using DifferenceType = ptrdiff_t;
2260
2261 // STL iterator requirements
2262 using iterator_category = IteratorCategory;
2263 using value_type = ValueType;
2264 using pointer = PointerType;
2265 using reference = ReferenceType;
2266 using difference_type = DifferenceType;
2267 //*******************************************************************************************
2268
2269 //**Constructor******************************************************************************
2272 inline RowIterator()
2273 : matrix_( nullptr ) // The sparse matrix containing the row
2274 , row_ ( 0UL ) // The current row index
2275 , column_( 0UL ) // The current column index
2276 , pos_ () // Iterator to the current sparse element
2277 {}
2278 //*******************************************************************************************
2279
2280 //**Constructor******************************************************************************
2287 inline RowIterator( MatrixType& matrix, size_t row, size_t column )
2288 : matrix_( &matrix ) // The sparse matrix containing the row
2289 , row_ ( row ) // The current row index
2290 , column_( column ) // The current column index
2291 , pos_ () // Iterator to the current sparse element
2292 {
2293 for( ; column_<matrix_->columns(); ++column_ ) {
2294 pos_ = matrix_->find( row_, column_ );
2295 if( pos_ != matrix_->end( column_ ) ) break;
2296 }
2297 }
2298 //*******************************************************************************************
2299
2300 //**Constructor******************************************************************************
2308 inline RowIterator( MatrixType& matrix, size_t row, size_t column, IteratorType pos )
2309 : matrix_( &matrix ) // The sparse matrix containing the row
2310 , row_ ( row ) // The current row index
2311 , column_( column ) // The current column index
2312 , pos_ ( pos ) // Iterator to the current sparse element
2313 {
2314 BLAZE_INTERNAL_ASSERT( matrix.find( row, column ) == pos, "Invalid initial iterator position" );
2315 }
2316 //*******************************************************************************************
2317
2318 //**Constructor******************************************************************************
2323 template< typename MatrixType2, typename IteratorType2 >
2324 inline RowIterator( const RowIterator<MatrixType2,IteratorType2>& it )
2325 : matrix_( it.matrix_ ) // The sparse matrix containing the row
2326 , row_ ( it.row_ ) // The current row index
2327 , column_( it.column_ ) // The current column index
2328 , pos_ ( it.pos_ ) // Iterator to the current sparse element
2329 {}
2330 //*******************************************************************************************
2331
2332 //**Prefix increment operator****************************************************************
2337 inline RowIterator& operator++() {
2338 ++column_;
2339 for( ; column_<matrix_->columns(); ++column_ ) {
2340 pos_ = matrix_->find( row_, column_ );
2341 if( pos_ != matrix_->end( column_ ) ) break;
2342 }
2343
2344 return *this;
2345 }
2346 //*******************************************************************************************
2347
2348 //**Postfix increment operator***************************************************************
2353 inline const RowIterator operator++( int ) {
2354 const RowIterator tmp( *this );
2355 ++(*this);
2356 return tmp;
2357 }
2358 //*******************************************************************************************
2359
2360 //**Element access operator******************************************************************
2365 inline ReferenceType operator*() const {
2366 return ReferenceType( pos_, column_ );
2367 }
2368 //*******************************************************************************************
2369
2370 //**Element access operator******************************************************************
2375 inline PointerType operator->() const {
2376 return PointerType( pos_, column_ );
2377 }
2378 //*******************************************************************************************
2379
2380 //**Equality operator************************************************************************
2386 template< typename MatrixType2, typename IteratorType2 >
2387 inline bool operator==( const RowIterator<MatrixType2,IteratorType2>& rhs ) const noexcept {
2388 return column_ == rhs.column_;
2389 }
2390 //*******************************************************************************************
2391
2392 //**Inequality operator**********************************************************************
2398 template< typename MatrixType2, typename IteratorType2 >
2399 inline bool operator!=( const RowIterator<MatrixType2,IteratorType2>& rhs ) const noexcept {
2400 return !( *this == rhs );
2401 }
2402 //*******************************************************************************************
2403
2404 //**Subtraction operator*********************************************************************
2410 inline DifferenceType operator-( const RowIterator& rhs ) const {
2411 size_t counter( 0UL );
2412 for( size_t j=rhs.column_; j<column_; ++j ) {
2413 if( matrix_->find( row_, j ) != matrix_->end( j ) )
2414 ++counter;
2415 }
2416 return counter;
2417 }
2418 //*******************************************************************************************
2419
2420 private:
2421 //**Member variables*************************************************************************
2422 MatrixType* matrix_;
2423 size_t row_;
2424 size_t column_;
2425 IteratorType pos_;
2426 //*******************************************************************************************
2427
2428 //**Friend declarations**********************************************************************
2429 template< typename MatrixType2, typename IteratorType2 > friend class RowIterator;
2430 template< typename MT2, bool SO2, bool DF2, bool SF2, size_t... CRAs2 > friend class Row;
2431 //*******************************************************************************************
2432 };
2433 //**********************************************************************************************
2434
2435 //**Type definitions****************************************************************************
2437 using ConstIterator = RowIterator< const MT, ConstIterator_t<MT> >;
2438
2440 using Iterator = If_t< IsConst_v<MT>, ConstIterator, RowIterator< MT, Iterator_t<MT> > >;
2441 //**********************************************************************************************
2442
2443 //**Compilation flags***************************************************************************
2445 static constexpr bool smpAssignable = false;
2446
2448 static constexpr bool compileTimeArgs = DataType::compileTimeArgs;
2449 //**********************************************************************************************
2450
2451 //**Constructors********************************************************************************
2454 template< typename... RRAs >
2455 explicit inline Row( MT& matrix, RRAs... args );
2456
2457 Row( const Row& ) = default;
2459 //**********************************************************************************************
2460
2461 //**Destructor**********************************************************************************
2464 ~Row() = default;
2466 //**********************************************************************************************
2467
2468 //**Data access functions***********************************************************************
2471 inline Reference operator[]( size_t index );
2472 inline ConstReference operator[]( size_t index ) const;
2473 inline Reference at( size_t index );
2474 inline ConstReference at( size_t index ) const;
2475 inline Iterator begin ();
2476 inline ConstIterator begin () const;
2477 inline ConstIterator cbegin() const;
2478 inline Iterator end ();
2479 inline ConstIterator end () const;
2480 inline ConstIterator cend () const;
2482 //**********************************************************************************************
2483
2484 //**Assignment operators************************************************************************
2487 inline Row& operator=( initializer_list<ElementType> list );
2488 inline Row& operator=( const Row& rhs );
2489
2490 template< typename VT > inline Row& operator= ( const Vector<VT,true>& rhs );
2491 template< typename VT > inline Row& operator+=( const Vector<VT,true>& rhs );
2492 template< typename VT > inline Row& operator-=( const Vector<VT,true>& rhs );
2493 template< typename VT > inline Row& operator*=( const Vector<VT,true>& rhs );
2494 template< typename VT > inline Row& operator/=( const DenseVector<VT,true>& rhs );
2495 template< typename VT > inline Row& operator%=( const Vector<VT,true>& rhs );
2497 //**********************************************************************************************
2498
2499 //**Utility functions***************************************************************************
2502 using DataType::row;
2503
2504 inline MT& operand() noexcept;
2505 inline const MT& operand() const noexcept;
2506
2507 inline size_t size() const noexcept;
2508 inline size_t capacity() const noexcept;
2509 inline size_t nonZeros() const;
2510 inline void reset();
2511 inline void reserve( size_t n );
2513 //**********************************************************************************************
2514
2515 //**Insertion functions*************************************************************************
2518 inline Iterator set ( size_t index, const ElementType& value );
2519 inline Iterator insert( size_t index, const ElementType& value );
2520 inline void append( size_t index, const ElementType& value, bool check=false );
2522 //**********************************************************************************************
2523
2524 //**Erase functions*****************************************************************************
2527 inline void erase( size_t index );
2528 inline Iterator erase( Iterator pos );
2529 inline Iterator erase( Iterator first, Iterator last );
2530
2531 template< typename Pred, typename = DisableIf_t< IsIntegral_v<Pred> > >
2532 inline void erase( Pred predicate );
2533
2534 template< typename Pred >
2535 inline void erase( Iterator first, Iterator last, Pred predicate );
2537 //**********************************************************************************************
2538
2539 //**Lookup functions****************************************************************************
2542 inline Iterator find ( size_t index );
2543 inline ConstIterator find ( size_t index ) const;
2544 inline Iterator lowerBound( size_t index );
2545 inline ConstIterator lowerBound( size_t index ) const;
2546 inline Iterator upperBound( size_t index );
2547 inline ConstIterator upperBound( size_t index ) const;
2549 //**********************************************************************************************
2550
2551 //**Numeric functions***************************************************************************
2554 template< typename Other > inline Row& scale( const Other& scalar );
2556 //**********************************************************************************************
2557
2558 //**Expression template evaluation functions****************************************************
2561 template< typename Other > inline bool canAlias ( const Other* alias ) const noexcept;
2562 template< typename Other > inline bool isAliased( const Other* alias ) const noexcept;
2563
2564 template< typename VT > inline void assign ( const DenseVector <VT,true>& rhs );
2565 template< typename VT > inline void assign ( const SparseVector<VT,true>& rhs );
2566 template< typename VT > inline void addAssign( const Vector<VT,true>& rhs );
2567 template< typename VT > inline void subAssign( const Vector<VT,true>& rhs );
2569 //**********************************************************************************************
2570
2571 private:
2572 //**Member variables****************************************************************************
2575 Operand matrix_;
2577 //**********************************************************************************************
2578
2579 //**Compile time checks*************************************************************************
2588 //**********************************************************************************************
2589};
2591//*************************************************************************************************
2592
2593
2594
2595
2596//=================================================================================================
2597//
2598// CONSTRUCTORS
2599//
2600//=================================================================================================
2601
2602//*************************************************************************************************
2610template< typename MT // Type of the sparse matrix
2611 , size_t... CRAs > // Compile time row arguments
2612template< typename... RRAs > // Runtime row arguments
2613inline Row<MT,false,false,false,CRAs...>::Row( MT& matrix, RRAs... args )
2614 : DataType( args... ) // Base class initialization
2615 , matrix_ ( matrix ) // The matrix containing the row
2616{
2617 if( isChecked( args... ) ) {
2618 if( matrix_.rows() <= row() ) {
2619 BLAZE_THROW_INVALID_ARGUMENT( "Invalid row access index" );
2620 }
2621 }
2622 else {
2623 BLAZE_USER_ASSERT( row() < matrix_.rows(), "Invalid row access index" );
2624 }
2625}
2627//*************************************************************************************************
2628
2629
2630
2631
2632//=================================================================================================
2633//
2634// DATA ACCESS FUNCTIONS
2635//
2636//=================================================================================================
2637
2638//*************************************************************************************************
2648template< typename MT // Type of the sparse matrix
2649 , size_t... CRAs > // Compile time row arguments
2650inline typename Row<MT,false,false,false,CRAs...>::Reference
2651 Row<MT,false,false,false,CRAs...>::operator[]( size_t index )
2652{
2653 BLAZE_USER_ASSERT( index < size(), "Invalid row access index" );
2654 return matrix_(row(),index);
2655}
2657//*************************************************************************************************
2658
2659
2660//*************************************************************************************************
2670template< typename MT // Type of the sparse matrix
2671 , size_t... CRAs > // Compile time row arguments
2672inline typename Row<MT,false,false,false,CRAs...>::ConstReference
2673 Row<MT,false,false,false,CRAs...>::operator[]( size_t index ) const
2674{
2675 BLAZE_USER_ASSERT( index < size(), "Invalid row access index" );
2676 return const_cast<const MT&>( matrix_ )(row(),index);
2677}
2679//*************************************************************************************************
2680
2681
2682//*************************************************************************************************
2693template< typename MT // Type of the sparse matrix
2694 , size_t... CRAs > // Compile time row arguments
2695inline typename Row<MT,false,false,false,CRAs...>::Reference
2696 Row<MT,false,false,false,CRAs...>::at( size_t index )
2697{
2698 if( index >= size() ) {
2699 BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
2700 }
2701 return (*this)[index];
2702}
2704//*************************************************************************************************
2705
2706
2707//*************************************************************************************************
2718template< typename MT // Type of the sparse matrix
2719 , size_t... CRAs > // Compile time row arguments
2720inline typename Row<MT,false,false,false,CRAs...>::ConstReference
2721 Row<MT,false,false,false,CRAs...>::at( size_t index ) const
2722{
2723 if( index >= size() ) {
2724 BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
2725 }
2726 return (*this)[index];
2727}
2729//*************************************************************************************************
2730
2731
2732//*************************************************************************************************
2740template< typename MT // Type of the sparse matrix
2741 , size_t... CRAs > // Compile time row arguments
2742inline typename Row<MT,false,false,false,CRAs...>::Iterator
2744{
2745 return Iterator( matrix_, row(), 0UL );
2746}
2748//*************************************************************************************************
2749
2750
2751//*************************************************************************************************
2759template< typename MT // Type of the sparse matrix
2760 , size_t... CRAs > // Compile time row arguments
2761inline typename Row<MT,false,false,false,CRAs...>::ConstIterator
2763{
2764 return ConstIterator( matrix_, row(), 0UL );
2765}
2767//*************************************************************************************************
2768
2769
2770//*************************************************************************************************
2778template< typename MT // Type of the sparse matrix
2779 , size_t... CRAs > // Compile time row arguments
2780inline typename Row<MT,false,false,false,CRAs...>::ConstIterator
2782{
2783 return ConstIterator( matrix_, row(), 0UL );
2784}
2786//*************************************************************************************************
2787
2788
2789//*************************************************************************************************
2797template< typename MT // Type of the sparse matrix
2798 , size_t... CRAs > // Compile time row arguments
2799inline typename Row<MT,false,false,false,CRAs...>::Iterator
2801{
2802 return Iterator( matrix_, row(), size() );
2803}
2805//*************************************************************************************************
2806
2807
2808//*************************************************************************************************
2816template< typename MT // Type of the sparse matrix
2817 , size_t... CRAs > // Compile time row arguments
2818inline typename Row<MT,false,false,false,CRAs...>::ConstIterator
2820{
2821 return ConstIterator( matrix_, row(), size() );
2822}
2824//*************************************************************************************************
2825
2826
2827//*************************************************************************************************
2835template< typename MT // Type of the sparse matrix
2836 , size_t... CRAs > // Compile time row arguments
2837inline typename Row<MT,false,false,false,CRAs...>::ConstIterator
2839{
2840 return ConstIterator( matrix_, row(), size() );
2841}
2843//*************************************************************************************************
2844
2845
2846
2847
2848//=================================================================================================
2849//
2850// ASSIGNMENT OPERATORS
2851//
2852//=================================================================================================
2853
2854//*************************************************************************************************
2869template< typename MT // Type of the sparse matrix
2870 , size_t... CRAs > // Compile time row arguments
2871inline Row<MT,false,false,false,CRAs...>&
2872 Row<MT,false,false,false,CRAs...>::operator=( initializer_list<ElementType> list )
2873{
2874 using blaze::assign;
2875
2876 if( list.size() > size() ) {
2877 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to row" );
2878 }
2879
2880 const InitializerVector<ElementType,true> tmp( list, size() );
2881
2882 if( !tryAssign( matrix_, tmp, row(), 0UL ) ) {
2883 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
2884 }
2885
2886 decltype(auto) left( derestrict( *this ) );
2887
2888 assign( left, tmp );
2889
2890 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
2891
2892 return *this;
2893}
2895//*************************************************************************************************
2896
2897
2898//*************************************************************************************************
2912template< typename MT // Type of the sparse matrix
2913 , size_t... CRAs > // Compile time row arguments
2914inline Row<MT,false,false,false,CRAs...>&
2915 Row<MT,false,false,false,CRAs...>::operator=( const Row& rhs )
2916{
2917 using blaze::assign;
2918
2922
2923 if( this == &rhs || ( &matrix_ == &rhs.matrix_ && row() == rhs.row() ) )
2924 return *this;
2925
2926 if( size() != rhs.size() ) {
2927 BLAZE_THROW_INVALID_ARGUMENT( "Row sizes do not match" );
2928 }
2929
2930 if( !tryAssign( matrix_, rhs, row(), 0UL ) ) {
2931 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
2932 }
2933
2934 decltype(auto) left( derestrict( *this ) );
2935
2936 if( rhs.canAlias( this ) ) {
2937 const ResultType tmp( rhs );
2938 assign( left, tmp );
2939 }
2940 else {
2941 assign( left, rhs );
2942 }
2943
2944 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
2945
2946 return *this;
2947}
2949//*************************************************************************************************
2950
2951
2952//*************************************************************************************************
2966template< typename MT // Type of the sparse matrix
2967 , size_t... CRAs > // Compile time row arguments
2968template< typename VT > // Type of the right-hand side vector
2969inline Row<MT,false,false,false,CRAs...>&
2970 Row<MT,false,false,false,CRAs...>::operator=( const Vector<VT,true>& rhs )
2971{
2972 using blaze::assign;
2973
2974 if( size() != (*rhs).size() ) {
2975 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
2976 }
2977
2978 const CompositeType_t<VT> tmp( *rhs );
2979
2980 if( !tryAssign( matrix_, tmp, row(), 0UL ) ) {
2981 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
2982 }
2983
2984 decltype(auto) left( derestrict( *this ) );
2985
2986 assign( left, tmp );
2987
2988 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
2989
2990 return *this;
2991}
2993//*************************************************************************************************
2994
2995
2996//*************************************************************************************************
3010template< typename MT // Type of the sparse matrix
3011 , size_t... CRAs > // Compile time row arguments
3012template< typename VT > // Type of the right-hand side vector
3013inline Row<MT,false,false,false,CRAs...>&
3014 Row<MT,false,false,false,CRAs...>::operator+=( const Vector<VT,true>& rhs )
3015{
3016 using blaze::assign;
3017
3021 BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE ( ResultType_t<VT> );
3023
3024 using AddType = AddTrait_t< ResultType, ResultType_t<VT> >;
3025
3028
3029 if( size() != (*rhs).size() ) {
3030 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
3031 }
3032
3033 const AddType tmp( *this + (*rhs) );
3034
3035 if( !tryAssign( matrix_, tmp, row(), 0UL ) ) {
3036 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
3037 }
3038
3039 decltype(auto) left( derestrict( *this ) );
3040
3041 assign( left, tmp );
3042
3043 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
3044
3045 return *this;
3046}
3048//*************************************************************************************************
3049
3050
3051//*************************************************************************************************
3065template< typename MT // Type of the sparse matrix
3066 , size_t... CRAs > // Compile time row arguments
3067template< typename VT > // Type of the right-hand side vector
3068inline Row<MT,false,false,false,CRAs...>&
3069 Row<MT,false,false,false,CRAs...>::operator-=( const Vector<VT,true>& rhs )
3070{
3071 using blaze::assign;
3072
3076 BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE ( ResultType_t<VT> );
3078
3079 using SubType = SubTrait_t< ResultType, ResultType_t<VT> >;
3080
3083
3084 if( size() != (*rhs).size() ) {
3085 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
3086 }
3087
3088 const SubType tmp( *this - (*rhs) );
3089
3090 if( !tryAssign( matrix_, tmp, row(), 0UL ) ) {
3091 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
3092 }
3093
3094 decltype(auto) left( derestrict( *this ) );
3095
3096 assign( left, tmp );
3097
3098 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
3099
3100 return *this;
3101}
3103//*************************************************************************************************
3104
3105
3106//*************************************************************************************************
3119template< typename MT // Type of the sparse matrix
3120 , size_t... CRAs > // Compile time row arguments
3121template< typename VT > // Type of the right-hand side vector
3122inline Row<MT,false,false,false,CRAs...>&
3123 Row<MT,false,false,false,CRAs...>::operator*=( const Vector<VT,true>& rhs )
3124{
3125 using blaze::assign;
3126
3130 BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE ( ResultType_t<VT> );
3132
3133 using MultType = MultTrait_t< ResultType, ResultType_t<VT> >;
3134
3137
3138 if( size() != (*rhs).size() ) {
3139 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
3140 }
3141
3142 const MultType tmp( *this * (*rhs) );
3143
3144 if( !tryAssign( matrix_, tmp, row(), 0UL ) ) {
3145 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
3146 }
3147
3148 decltype(auto) left( derestrict( *this ) );
3149
3150 assign( left, tmp );
3151
3152 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
3153
3154 return *this;
3155}
3157//*************************************************************************************************
3158
3159
3160//*************************************************************************************************
3172template< typename MT // Type of the sparse matrix
3173 , size_t... CRAs > // Compile time row arguments
3174template< typename VT > // Type of the right-hand side vector
3175inline Row<MT,false,false,false,CRAs...>&
3176 Row<MT,false,false,false,CRAs...>::operator/=( const DenseVector<VT,true>& rhs )
3177{
3178 using blaze::assign;
3179
3183 BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE ( ResultType_t<VT> );
3184 BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE ( ResultType_t<VT> );
3186
3187 using DivType = DivTrait_t< ResultType, ResultType_t<VT> >;
3188
3192
3193 if( size() != (*rhs).size() ) {
3194 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
3195 }
3196
3197 const DivType tmp( *this / (*rhs) );
3198
3199 if( !tryAssign( matrix_, tmp, row(), 0UL ) ) {
3200 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
3201 }
3202
3203 decltype(auto) left( derestrict( *this ) );
3204
3205 assign( left, tmp );
3206
3207 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
3208
3209 return *this;
3210}
3212//*************************************************************************************************
3213
3214
3215//*************************************************************************************************
3228template< typename MT // Type of the sparse matrix
3229 , size_t... CRAs > // Compile time row arguments
3230template< typename VT > // Type of the right-hand side vector
3231inline Row<MT,false,false,false,CRAs...>&
3232 Row<MT,false,false,false,CRAs...>::operator%=( const Vector<VT,true>& rhs )
3233{
3234 using blaze::assign;
3235
3236 BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE ( ResultType_t<VT> );
3238
3239 using CrossType = CrossTrait_t< ResultType, ResultType_t<VT> >;
3240
3244
3245 if( size() != 3UL || (*rhs).size() != 3UL ) {
3246 BLAZE_THROW_INVALID_ARGUMENT( "Invalid vector size for cross product" );
3247 }
3248
3249 const CrossType tmp( *this % (*rhs) );
3250
3251 if( !tryAssign( matrix_, tmp, row(), 0UL ) ) {
3252 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
3253 }
3254
3255 decltype(auto) left( derestrict( *this ) );
3256
3257 assign( left, tmp );
3258
3259 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
3260
3261 return *this;
3262}
3264//*************************************************************************************************
3265
3266
3267
3268
3269//=================================================================================================
3270//
3271// UTILITY FUNCTIONS
3272//
3273//=================================================================================================
3274
3275//*************************************************************************************************
3281template< typename MT // Type of the sparse matrix
3282 , size_t... CRAs > // Compile time row arguments
3283inline MT& Row<MT,false,false,false,CRAs...>::operand() noexcept
3284{
3285 return matrix_;
3286}
3288//*************************************************************************************************
3289
3290
3291//*************************************************************************************************
3297template< typename MT // Type of the sparse matrix
3298 , size_t... CRAs > // Compile time row arguments
3299inline const MT& Row<MT,false,false,false,CRAs...>::operand() const noexcept
3300{
3301 return matrix_;
3302}
3304//************************************************************************************************
3305
3306
3307//*************************************************************************************************
3313template< typename MT // Type of the sparse matrix
3314 , size_t... CRAs > // Compile time row arguments
3315inline size_t Row<MT,false,false,false,CRAs...>::size() const noexcept
3316{
3317 return matrix_.columns();
3318}
3320//*************************************************************************************************
3321
3322
3323//*************************************************************************************************
3329template< typename MT // Type of the sparse matrix
3330 , size_t... CRAs > // Compile time row arguments
3331inline size_t Row<MT,false,false,false,CRAs...>::capacity() const noexcept
3332{
3333 return matrix_.columns();
3334}
3336//*************************************************************************************************
3337
3338
3339//*************************************************************************************************
3348template< typename MT // Type of the sparse matrix
3349 , size_t... CRAs > // Compile time row arguments
3351{
3352 size_t counter( 0UL );
3353 for( ConstIterator element=begin(); element!=end(); ++element ) {
3354 ++counter;
3355 }
3356 return counter;
3357}
3359//*************************************************************************************************
3360
3361
3362//*************************************************************************************************
3368template< typename MT // Type of the sparse matrix
3369 , size_t... CRAs > // Compile time row arguments
3371{
3372 const size_t jbegin( ( IsUpper_v<MT> )
3373 ?( ( IsUniUpper_v<MT> || IsStrictlyUpper_v<MT> )
3374 ?( row()+1UL )
3375 :( row() ) )
3376 :( 0UL ) );
3377 const size_t jend ( ( IsLower_v<MT> )
3378 ?( ( IsUniLower_v<MT> || IsStrictlyLower_v<MT> )
3379 ?( row() )
3380 :( row()+1UL ) )
3381 :( size() ) );
3382
3383 for( size_t j=jbegin; j<jend; ++j ) {
3384 matrix_.erase( row(), j );
3385 }
3386}
3388//*************************************************************************************************
3389
3390
3391//*************************************************************************************************
3401template< typename MT // Type of the sparse matrix
3402 , size_t... CRAs > // Compile time row arguments
3403void Row<MT,false,false,false,CRAs...>::reserve( size_t n )
3404{
3405 MAYBE_UNUSED( n );
3406
3407 return;
3408}
3410//*************************************************************************************************
3411
3412
3413
3414
3415//=================================================================================================
3416//
3417// INSERTION FUNCTIONS
3418//
3419//=================================================================================================
3420
3421//*************************************************************************************************
3433template< typename MT // Type of the sparse matrix
3434 , size_t... CRAs > // Compile time row arguments
3435inline typename Row<MT,false,false,false,CRAs...>::Iterator
3436 Row<MT,false,false,false,CRAs...>::set( size_t index, const ElementType& value )
3437{
3438 return Iterator( matrix_, row(), index, matrix_.set( row(), index, value ) );
3439}
3441//*************************************************************************************************
3442
3443
3444//*************************************************************************************************
3457template< typename MT // Type of the sparse matrix
3458 , size_t... CRAs > // Compile time row arguments
3459inline typename Row<MT,false,false,false,CRAs...>::Iterator
3460 Row<MT,false,false,false,CRAs...>::insert( size_t index, const ElementType& value )
3461{
3462 return Iterator( matrix_, row(), index, matrix_.insert( row(), index, value ) );
3463}
3465//*************************************************************************************************
3466
3467
3468//*************************************************************************************************
3493template< typename MT // Type of the sparse matrix
3494 , size_t... CRAs > // Compile time row arguments
3495inline void Row<MT,false,false,false,CRAs...>::append( size_t index, const ElementType& value, bool check )
3496{
3497 if( !check || !isDefault<strict>( value ) )
3498 matrix_.insert( row(), index, value );
3499}
3501//*************************************************************************************************
3502
3503
3504
3505
3506//=================================================================================================
3507//
3508// ERASE FUNCTIONS
3509//
3510//=================================================================================================
3511
3512//*************************************************************************************************
3521template< typename MT // Type of the sparse matrix
3522 , size_t... CRAs > // Compile time row arguments
3523inline void Row<MT,false,false,false,CRAs...>::erase( size_t index )
3524{
3525 matrix_.erase( row(), index );
3526}
3528//*************************************************************************************************
3529
3530
3531//*************************************************************************************************
3540template< typename MT // Type of the sparse matrix
3541 , size_t... CRAs > // Compile time row arguments
3542inline typename Row<MT,false,false,false,CRAs...>::Iterator
3543 Row<MT,false,false,false,CRAs...>::erase( Iterator pos )
3544{
3545 const size_t column( pos.column_ );
3546
3547 if( column == size() )
3548 return pos;
3549
3550 matrix_.erase( column, pos.pos_ );
3551 return Iterator( matrix_, row(), column+1UL );
3552}
3554//*************************************************************************************************
3555
3556
3557//*************************************************************************************************
3567template< typename MT // Type of the sparse matrix
3568 , size_t... CRAs > // Compile time row arguments
3569inline typename Row<MT,false,false,false,CRAs...>::Iterator
3570 Row<MT,false,false,false,CRAs...>::erase( Iterator first, Iterator last )
3571{
3572 for( ; first!=last; ++first ) {
3573 matrix_.erase( first.column_, first.pos_ );
3574 }
3575 return last;
3576}
3578//*************************************************************************************************
3579
3580
3581//*************************************************************************************************
3604template< typename MT // Type of the sparse matrix
3605 , size_t... CRAs > // Compile time row arguments
3606template< typename Pred // Type of the unary predicate
3607 , typename > // Type restriction on the unary predicate
3608inline void Row<MT,false,false,false,CRAs...>::erase( Pred predicate )
3609{
3610 for( Iterator element=begin(); element!=end(); ++element ) {
3611 if( predicate( element->value() ) )
3612 matrix_.erase( element.column_, element.pos_ );
3613 }
3614}
3616//*************************************************************************************************
3617
3618
3619//*************************************************************************************************
3644template< typename MT // Type of the sparse matrix
3645 , size_t... CRAs > // Compile time row arguments
3646template< typename Pred > // Type of the unary predicate
3647inline void Row<MT,false,false,false,CRAs...>::erase( Iterator first, Iterator last, Pred predicate )
3648{
3649 for( ; first!=last; ++first ) {
3650 if( predicate( first->value() ) )
3651 matrix_.erase( first.column_, first.pos_ );
3652 }
3653}
3655//*************************************************************************************************
3656
3657
3658
3659
3660//=================================================================================================
3661//
3662// LOOKUP FUNCTIONS
3663//
3664//=================================================================================================
3665
3666//*************************************************************************************************
3680template< typename MT // Type of the sparse matrix
3681 , size_t... CRAs > // Compile time row arguments
3682inline typename Row<MT,false,false,false,CRAs...>::Iterator
3684{
3685 const Iterator_t<MT> pos( matrix_.find( row(), index ) );
3686
3687 if( pos != matrix_.end( index ) )
3688 return Iterator( matrix_, row(), index, pos );
3689 else
3690 return end();
3691}
3693//*************************************************************************************************
3694
3695
3696//*************************************************************************************************
3710template< typename MT // Type of the sparse matrix
3711 , size_t... CRAs > // Compile time row arguments
3712inline typename Row<MT,false,false,false,CRAs...>::ConstIterator
3713 Row<MT,false,false,false,CRAs...>::find( size_t index ) const
3714{
3715 const ConstIterator_t<MT> pos( matrix_.find( row(), index ) );
3716
3717 if( pos != matrix_.end( index ) )
3718 return ConstIterator( matrix_, row(), index, pos );
3719 else
3720 return end();
3721}
3723//*************************************************************************************************
3724
3725
3726//*************************************************************************************************
3739template< typename MT // Type of the sparse matrix
3740 , size_t... CRAs > // Compile time row arguments
3741inline typename Row<MT,false,false,false,CRAs...>::Iterator
3743{
3744 for( size_t i=index; i<size(); ++i )
3745 {
3746 const Iterator_t<MT> pos( matrix_.find( row(), i ) );
3747
3748 if( pos != matrix_.end( i ) )
3749 return Iterator( matrix_, row(), i, pos );
3750 }
3751
3752 return end();
3753}
3755//*************************************************************************************************
3756
3757
3758//*************************************************************************************************
3771template< typename MT // Type of the sparse matrix
3772 , size_t... CRAs > // Compile time row arguments
3773inline typename Row<MT,false,false,false,CRAs...>::ConstIterator
3775{
3776 for( size_t i=index; i<size(); ++i )
3777 {
3778 const ConstIterator_t<MT> pos( matrix_.find( row(), i ) );
3779
3780 if( pos != matrix_.end( i ) )
3781 return ConstIterator( matrix_, row(), i, pos );
3782 }
3783
3784 return end();
3785}
3787//*************************************************************************************************
3788
3789
3790//*************************************************************************************************
3803template< typename MT // Type of the sparse matrix
3804 , size_t... CRAs > // Compile time row arguments
3805inline typename Row<MT,false,false,false,CRAs...>::Iterator
3807{
3808 for( size_t i=index+1UL; i<size(); ++i )
3809 {
3810 const Iterator_t<MT> pos( matrix_.find( row(), i ) );
3811
3812 if( pos != matrix_.end( i ) )
3813 return Iterator( matrix_, row(), i, pos );
3814 }
3815
3816 return end();
3817}
3819//*************************************************************************************************
3820
3821
3822//*************************************************************************************************
3835template< typename MT // Type of the sparse matrix
3836 , size_t... CRAs > // Compile time row arguments
3837inline typename Row<MT,false,false,false,CRAs...>::ConstIterator
3839{
3840 for( size_t i=index+1UL; i<size(); ++i )
3841 {
3842 const ConstIterator_t<MT> pos( matrix_.find( row(), i ) );
3843
3844 if( pos != matrix_.end( i ) )
3845 return ConstIterator( matrix_, row(), i, pos );
3846 }
3847
3848 return end();
3849}
3851//*************************************************************************************************
3852
3853
3854
3855
3856//=================================================================================================
3857//
3858// NUMERIC FUNCTIONS
3859//
3860//=================================================================================================
3861
3862//*************************************************************************************************
3875template< typename MT // Type of the sparse matrix
3876 , size_t... CRAs > // Compile time row arguments
3877template< typename Other > // Data type of the scalar value
3878inline Row<MT,false,false,false,CRAs...>&
3879 Row<MT,false,false,false,CRAs...>::scale( const Other& scalar )
3880{
3882
3883 for( Iterator element=begin(); element!=end(); ++element )
3884 element->value() *= scalar;
3885 return *this;
3886}
3888//*************************************************************************************************
3889
3890
3891
3892
3893//=================================================================================================
3894//
3895// EXPRESSION TEMPLATE EVALUATION FUNCTIONS
3896//
3897//=================================================================================================
3898
3899//*************************************************************************************************
3910template< typename MT // Type of the sparse matrix
3911 , size_t... CRAs > // Compile time row arguments
3912template< typename Other > // Data type of the foreign expression
3913inline bool Row<MT,false,false,false,CRAs...>::canAlias( const Other* alias ) const noexcept
3914{
3915 return matrix_.isAliased( &unview( *alias ) );
3916}
3918//*************************************************************************************************
3919
3920
3921//*************************************************************************************************
3928template< typename MT // Type of the sparse matrix
3929 , size_t... CRAs > // Compile time row arguments
3930template< typename Other > // Data type of the foreign expression
3931inline bool Row<MT,false,false,false,CRAs...>::isAliased( const Other* alias ) const noexcept
3932{
3933 return matrix_.isAliased( &unview( *alias ) );
3934}
3936//*************************************************************************************************
3937
3938
3939//*************************************************************************************************
3951template< typename MT // Type of the sparse matrix
3952 , size_t... CRAs > // Compile time row arguments
3953template< typename VT > // Type of the right-hand side dense vector
3954inline void Row<MT,false,false,false,CRAs...>::assign( const DenseVector<VT,true>& rhs )
3955{
3956 BLAZE_INTERNAL_ASSERT( size() == (*rhs).size(), "Invalid vector sizes" );
3957
3958 for( size_t j=0UL; j<(*rhs).size(); ++j ) {
3959 matrix_(row(),j) = (*rhs)[j];
3960 }
3961}
3963//*************************************************************************************************
3964
3965
3966//*************************************************************************************************
3978template< typename MT // Type of the sparse matrix
3979 , size_t... CRAs > // Compile time row arguments
3980template< typename VT > // Type of the right-hand side sparse vector
3981inline void Row<MT,false,false,false,CRAs...>::assign( const SparseVector<VT,true>& rhs )
3982{
3983 BLAZE_INTERNAL_ASSERT( size() == (*rhs).size(), "Invalid vector sizes" );
3984
3985 size_t j( 0UL );
3986
3987 for( ConstIterator_t<VT> element=(*rhs).begin(); element!=(*rhs).end(); ++element ) {
3988 for( ; j<element->index(); ++j )
3989 matrix_.erase( row(), j );
3990 matrix_(row(),j++) = element->value();
3991 }
3992 for( ; j<size(); ++j ) {
3993 matrix_.erase( row(), j );
3994 }
3995}
3997//*************************************************************************************************
3998
3999
4000//*************************************************************************************************
4012template< typename MT // Type of the sparse matrix
4013 , size_t... CRAs > // Compile time row arguments
4014template< typename VT > // Type of the right-hand side vector
4015inline void Row<MT,false,false,false,CRAs...>::addAssign( const Vector<VT,true>& rhs )
4016{
4017 using AddType = AddTrait_t< ResultType, ResultType_t<VT> >;
4018
4021
4022 BLAZE_INTERNAL_ASSERT( size() == (*rhs).size(), "Invalid vector sizes" );
4023
4024 const AddType tmp( serial( *this + (*rhs) ) );
4025 assign( tmp );
4026}
4028//*************************************************************************************************
4029
4030
4031//*************************************************************************************************
4043template< typename MT // Type of the sparse matrix
4044 , size_t... CRAs > // Compile time row arguments
4045template< typename VT > // Type of the right-hand side vector
4046inline void Row<MT,false,false,false,CRAs...>::subAssign( const Vector<VT,true>& rhs )
4047{
4048 using SubType = SubTrait_t< ResultType, ResultType_t<VT> >;
4049
4052
4053 BLAZE_INTERNAL_ASSERT( size() == (*rhs).size(), "Invalid vector sizes" );
4054
4055 const SubType tmp( serial( *this - (*rhs) ) );
4056 assign( tmp );
4057}
4059//*************************************************************************************************
4060
4061
4062
4063
4064
4065
4066
4067
4068//=================================================================================================
4069//
4070// CLASS TEMPLATE SPECIALIZATION FOR SYMMETRIC COLUMN-MAJOR SPARSE MATRICES
4071//
4072//=================================================================================================
4073
4074//*************************************************************************************************
4082template< typename MT // Type of the sparse matrix
4083 , size_t... CRAs > // Compile time row arguments
4084class Row<MT,false,false,true,CRAs...>
4085 : public View< SparseVector< Row<MT,false,false,true,CRAs...>, true > >
4086 , private RowData<CRAs...>
4087{
4088 private:
4089 //**Type definitions****************************************************************************
4090 using DataType = RowData<CRAs...>;
4091 using Operand = If_t< IsExpression_v<MT>, MT, MT& >;
4092 //**********************************************************************************************
4093
4094 public:
4095 //**Type definitions****************************************************************************
4097 using This = Row<MT,false,false,true,CRAs...>;
4098
4100 using BaseType = View< SparseVector<This,true> >;
4101
4102 using ViewedType = MT;
4103 using ResultType = RowTrait_t<MT,CRAs...>;
4104 using TransposeType = TransposeType_t<ResultType>;
4105 using ElementType = ElementType_t<MT>;
4106 using ReturnType = ReturnType_t<MT>;
4107 using CompositeType = const Row&;
4108
4110 using ConstReference = ConstReference_t<MT>;
4111
4113 using Reference = If_t< IsConst_v<MT>, ConstReference, Reference_t<MT> >;
4114
4116 using ConstIterator = ConstIterator_t<MT>;
4117
4119 using Iterator = If_t< IsConst_v<MT>, ConstIterator, Iterator_t<MT> >;
4120 //**********************************************************************************************
4121
4122 //**Compilation flags***************************************************************************
4124 static constexpr bool smpAssignable = false;
4125
4127 static constexpr bool compileTimeArgs = DataType::compileTimeArgs;
4128 //**********************************************************************************************
4129
4130 //**Constructors********************************************************************************
4133 template< typename... RRAs >
4134 explicit inline Row( MT& matrix, RRAs... args );
4135
4136 Row( const Row& ) = default;
4138 //**********************************************************************************************
4139
4140 //**Destructor**********************************************************************************
4143 ~Row() = default;
4145 //**********************************************************************************************
4146
4147 //**Data access functions***********************************************************************
4150 inline Reference operator[]( size_t index );
4151 inline ConstReference operator[]( size_t index ) const;
4152 inline Reference at( size_t index );
4153 inline ConstReference at( size_t index ) const;
4154 inline Iterator begin ();
4155 inline ConstIterator begin () const;
4156 inline ConstIterator cbegin() const;
4157 inline Iterator end ();
4158 inline ConstIterator end () const;
4159 inline ConstIterator cend () const;
4161 //**********************************************************************************************
4162
4163 //**Assignment operators************************************************************************
4166 inline Row& operator=( initializer_list<ElementType> list );
4167 inline Row& operator=( const Row& rhs );
4168
4169 template< typename VT > inline Row& operator= ( const DenseVector<VT,true>& rhs );
4170 template< typename VT > inline Row& operator= ( const SparseVector<VT,true>& rhs );
4171 template< typename VT > inline Row& operator+=( const DenseVector<VT,true>& rhs );
4172 template< typename VT > inline Row& operator+=( const SparseVector<VT,true>& rhs );
4173 template< typename VT > inline Row& operator-=( const DenseVector<VT,true>& rhs );
4174 template< typename VT > inline Row& operator-=( const SparseVector<VT,true>& rhs );
4175 template< typename VT > inline Row& operator*=( const Vector<VT,true>& rhs );
4176 template< typename VT > inline Row& operator/=( const DenseVector<VT,true>& rhs );
4177 template< typename VT > inline Row& operator%=( const Vector<VT,true>& rhs );
4179 //**********************************************************************************************
4180
4181 //**Utility functions***************************************************************************
4184 using DataType::row;
4185
4186 inline MT& operand() noexcept;
4187 inline const MT& operand() const noexcept;
4188
4189 inline size_t size() const noexcept;
4190 inline size_t capacity() const noexcept;
4191 inline size_t nonZeros() const;
4192 inline void reset();
4193 inline void reserve( size_t n );
4195 //**********************************************************************************************
4196
4197 //**Insertion functions*************************************************************************
4200 inline Iterator set ( size_t index, const ElementType& value );
4201 inline Iterator insert( size_t index, const ElementType& value );
4202 inline void append( size_t index, const ElementType& value, bool check=false );
4204 //**********************************************************************************************
4205
4206 //**Erase functions*****************************************************************************
4209 inline void erase( size_t index );
4210 inline Iterator erase( Iterator pos );
4211 inline Iterator erase( Iterator first, Iterator last );
4212
4213 template< typename Pred, typename = DisableIf_t< IsIntegral_v<Pred> > >
4214 inline void erase( Pred predicate );
4215
4216 template< typename Pred >
4217 inline void erase( Iterator first, Iterator last, Pred predicate );
4219 //**********************************************************************************************
4220
4221 //**Lookup functions****************************************************************************
4224 inline Iterator find ( size_t index );
4225 inline ConstIterator find ( size_t index ) const;
4226 inline Iterator lowerBound( size_t index );
4227 inline ConstIterator lowerBound( size_t index ) const;
4228 inline Iterator upperBound( size_t index );
4229 inline ConstIterator upperBound( size_t index ) const;
4231 //**********************************************************************************************
4232
4233 //**Numeric functions***************************************************************************
4236 template< typename Other > inline Row& scale( const Other& scalar );
4238 //**********************************************************************************************
4239
4240 //**Expression template evaluation functions****************************************************
4243 template< typename Other > inline bool canAlias ( const Other* alias ) const noexcept;
4244 template< typename Other > inline bool isAliased( const Other* alias ) const noexcept;
4245
4246 template< typename VT > inline void assign ( const DenseVector <VT,true>& rhs );
4247 template< typename VT > inline void assign ( const SparseVector<VT,true>& rhs );
4248 template< typename VT > inline void addAssign( const DenseVector <VT,true>& rhs );
4249 template< typename VT > inline void addAssign( const SparseVector<VT,true>& rhs );
4250 template< typename VT > inline void subAssign( const DenseVector <VT,true>& rhs );
4251 template< typename VT > inline void subAssign( const SparseVector<VT,true>& rhs );
4253 //**********************************************************************************************
4254
4255 private:
4256 //**Utility functions***************************************************************************
4259 inline size_t extendCapacity() const;
4261 //**********************************************************************************************
4262
4263 //**Member variables****************************************************************************
4266 Operand matrix_;
4268 //**********************************************************************************************
4269
4270 //**Compile time checks*************************************************************************
4279 //**********************************************************************************************
4280};
4282//*************************************************************************************************
4283
4284
4285
4286
4287//=================================================================================================
4288//
4289// CONSTRUCTORS
4290//
4291//=================================================================================================
4292
4293//*************************************************************************************************
4306template< typename MT // Type of the sparse matrix
4307 , size_t... CRAs > // Compile time row arguments
4308template< typename... RRAs > // Runtime row arguments
4309inline Row<MT,false,false,true,CRAs...>::Row( MT& matrix, RRAs... args )
4310 : DataType( args... ) // Base class initialization
4311 , matrix_ ( matrix ) // The matrix containing the row
4312{
4313 if( isChecked( args... ) ) {
4314 if( matrix_.rows() <= row() ) {
4315 BLAZE_THROW_INVALID_ARGUMENT( "Invalid row access index" );
4316 }
4317 }
4318 else {
4319 BLAZE_USER_ASSERT( row() < matrix_.rows(), "Invalid row access index" );
4320 }
4321}
4323//*************************************************************************************************
4324
4325
4326
4327
4328//=================================================================================================
4329//
4330// DATA ACCESS FUNCTIONS
4331//
4332//=================================================================================================
4333
4334//*************************************************************************************************
4344template< typename MT // Type of the sparse matrix
4345 , size_t... CRAs > // Compile time row arguments
4346inline typename Row<MT,false,false,true,CRAs...>::Reference
4347 Row<MT,false,false,true,CRAs...>::operator[]( size_t index )
4348{
4349 BLAZE_USER_ASSERT( index < size(), "Invalid row access index" );
4350 return matrix_(index,row());
4351}
4353//*************************************************************************************************
4354
4355
4356//*************************************************************************************************
4366template< typename MT // Type of the sparse matrix
4367 , size_t... CRAs > // Compile time row arguments
4368inline typename Row<MT,false,false,true,CRAs...>::ConstReference
4369 Row<MT,false,false,true,CRAs...>::operator[]( size_t index ) const
4370{
4371 BLAZE_USER_ASSERT( index < size(), "Invalid row access index" );
4372 return const_cast<const MT&>( matrix_ )(index,row());
4373}
4375//*************************************************************************************************
4376
4377
4378//*************************************************************************************************
4389template< typename MT // Type of the sparse matrix
4390 , size_t... CRAs > // Compile time row arguments
4391inline typename Row<MT,false,false,true,CRAs...>::Reference
4392 Row<MT,false,false,true,CRAs...>::at( size_t index )
4393{
4394 if( index >= size() ) {
4395 BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
4396 }
4397 return (*this)[index];
4398}
4400//*************************************************************************************************
4401
4402
4403//*************************************************************************************************
4414template< typename MT // Type of the sparse matrix
4415 , size_t... CRAs > // Compile time row arguments
4416inline typename Row<MT,false,false,true,CRAs...>::ConstReference
4417 Row<MT,false,false,true,CRAs...>::at( size_t index ) const
4418{
4419 if( index >= size() ) {
4420 BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
4421 }
4422 return (*this)[index];
4423}
4425//*************************************************************************************************
4426
4427
4428//*************************************************************************************************
4436template< typename MT // Type of the sparse matrix
4437 , size_t... CRAs > // Compile time row arguments
4438inline typename Row<MT,false,false,true,CRAs...>::Iterator
4440{
4441 return matrix_.begin( row() );
4442}
4444//*************************************************************************************************
4445
4446
4447//*************************************************************************************************
4455template< typename MT // Type of the sparse matrix
4456 , size_t... CRAs > // Compile time row arguments
4457inline typename Row<MT,false,false,true,CRAs...>::ConstIterator
4459{
4460 return matrix_.cbegin( row() );
4461}
4463//*************************************************************************************************
4464
4465
4466//*************************************************************************************************
4474template< typename MT // Type of the sparse matrix
4475 , size_t... CRAs > // Compile time row arguments
4476inline typename Row<MT,false,false,true,CRAs...>::ConstIterator
4478{
4479 return matrix_.cbegin( row() );
4480}
4482//*************************************************************************************************
4483
4484
4485//*************************************************************************************************
4493template< typename MT // Type of the sparse matrix
4494 , size_t... CRAs > // Compile time row arguments
4495inline typename Row<MT,false,false,true,CRAs...>::Iterator
4497{
4498 return matrix_.end( row() );
4499}
4501//*************************************************************************************************
4502
4503
4504//*************************************************************************************************
4512template< typename MT // Type of the sparse matrix
4513 , size_t... CRAs > // Compile time row arguments
4514inline typename Row<MT,false,false,true,CRAs...>::ConstIterator
4516{
4517 return matrix_.cend( row() );
4518}
4520//*************************************************************************************************
4521
4522
4523//*************************************************************************************************
4531template< typename MT // Type of the sparse matrix
4532 , size_t... CRAs > // Compile time row arguments
4533inline typename Row<MT,false,false,true,CRAs...>::ConstIterator
4535{
4536 return matrix_.cend( row() );
4537}
4539//*************************************************************************************************
4540
4541
4542
4543
4544//=================================================================================================
4545//
4546// ASSIGNMENT OPERATORS
4547//
4548//=================================================================================================
4549
4550//*************************************************************************************************
4565template< typename MT // Type of the sparse matrix
4566 , size_t... CRAs > // Compile time row arguments
4567inline Row<MT,false,false,true,CRAs...>&
4568 Row<MT,false,false,true,CRAs...>::operator=( initializer_list<ElementType> list )
4569{
4570 using blaze::assign;
4571
4572 if( list.size() > size() ) {
4573 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to row" );
4574 }
4575
4576 const InitializerVector<ElementType,true> tmp( list, size() );
4577
4578 if( !tryAssign( matrix_, tmp, row(), 0UL ) ) {
4579 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
4580 }
4581
4582 decltype(auto) left( derestrict( *this ) );
4583
4584 left.reset();
4585 assign( left, tmp );
4586
4587 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
4588
4589 return *this;
4590}
4592//*************************************************************************************************
4593
4594
4595//*************************************************************************************************
4609template< typename MT // Type of the sparse matrix
4610 , size_t... CRAs > // Compile time row arguments
4611inline Row<MT,false,false,true,CRAs...>&
4612 Row<MT,false,false,true,CRAs...>::operator=( const Row& rhs )
4613{
4614 using blaze::assign;
4615
4619
4620 if( this == &rhs || ( &matrix_ == &rhs.matrix_ && row() == rhs.row() ) )
4621 return *this;
4622
4623 if( size() != rhs.size() ) {
4624 BLAZE_THROW_INVALID_ARGUMENT( "Row sizes do not match" );
4625 }
4626
4627 if( !tryAssign( matrix_, rhs, row(), 0UL ) ) {
4628 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
4629 }
4630
4631 decltype(auto) left( derestrict( *this ) );
4632
4633 if( rhs.canAlias( this ) ) {
4634 const ResultType tmp( rhs );
4635 left.reset();
4636 left.reserve( tmp.nonZeros() );
4637 assign( left, tmp );
4638 }
4639 else {
4640 left.reset();
4641 left.reserve( rhs.nonZeros() );
4642 assign( left, rhs );
4643 }
4644
4645 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
4646
4647 return *this;
4648}
4650//*************************************************************************************************
4651
4652
4653//*************************************************************************************************
4667template< typename MT // Type of the sparse matrix
4668 , size_t... CRAs > // Compile time row arguments
4669template< typename VT > // Type of the right-hand side dense vector
4670inline Row<MT,false,false,true,CRAs...>&
4671 Row<MT,false,false,true,CRAs...>::operator=( const DenseVector<VT,true>& rhs )
4672{
4673 using blaze::assign;
4674
4675 BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE ( ResultType_t<VT> );
4676 BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE ( ResultType_t<VT> );
4678
4679 if( size() != (*rhs).size() ) {
4680 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
4681 }
4682
4683 using Right = If_t< IsRestricted_v<MT>, CompositeType_t<VT>, const VT& >;
4684 Right right( *rhs );
4685
4686 if( !tryAssign( matrix_, right, row(), 0UL ) ) {
4687 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
4688 }
4689
4690 decltype(auto) left( derestrict( *this ) );
4691
4692 if( IsReference_v<Right> && right.canAlias( this ) ) {
4693 const ResultType_t<VT> tmp( right );
4694 left.reset();
4695 assign( left, tmp );
4696 }
4697 else {
4698 left.reset();
4699 assign( left, right );
4700 }
4701
4702 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
4703
4704 return *this;
4705}
4707//*************************************************************************************************
4708
4709
4710//*************************************************************************************************
4724template< typename MT // Type of the sparse matrix
4725 , size_t... CRAs > // Compile time row arguments
4726template< typename VT > // Type of the right-hand side sparse vector
4727inline Row<MT,false,false,true,CRAs...>&
4728 Row<MT,false,false,true,CRAs...>::operator=( const SparseVector<VT,true>& rhs )
4729{
4730 using blaze::assign;
4731
4733 BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE ( ResultType_t<VT> );
4735
4736 if( size() != (*rhs).size() ) {
4737 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
4738 }
4739
4740 using Right = If_t< IsRestricted_v<MT>, CompositeType_t<VT>, const VT& >;
4741 Right right( *rhs );
4742
4743 if( !tryAssign( matrix_, right, row(), 0UL ) ) {
4744 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
4745 }
4746
4747 decltype(auto) left( derestrict( *this ) );
4748
4749 if( IsReference_v<Right> && right.canAlias( this ) ) {
4750 const ResultType_t<VT> tmp( right );
4751 left.reset();
4752 left.reserve( tmp.nonZeros() );
4753 assign( left, tmp );
4754 }
4755 else {
4756 left.reset();
4757 left.reserve( right.nonZeros() );
4758 assign( left, right );
4759 }
4760
4761 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
4762
4763 return *this;
4764}
4766//*************************************************************************************************
4767
4768
4769//*************************************************************************************************
4783template< typename MT // Type of the sparse matrix
4784 , size_t... CRAs > // Compile time row arguments
4785template< typename VT > // Type of the right-hand side dense vector
4786inline Row<MT,false,false,true,CRAs...>&
4787 Row<MT,false,false,true,CRAs...>::operator+=( const DenseVector<VT,true>& rhs )
4788{
4789 using blaze::assign;
4790
4794 BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE ( ResultType_t<VT> );
4795 BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE ( ResultType_t<VT> );
4797
4798 using AddType = AddTrait_t< ResultType, ResultType_t<VT> >;
4799
4803
4804 if( size() != (*rhs).size() ) {
4805 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
4806 }
4807
4808 const AddType tmp( *this + (*rhs) );
4809
4810 if( !tryAssign( matrix_, tmp, row(), 0UL ) ) {
4811 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
4812 }
4813
4814 decltype(auto) left( derestrict( *this ) );
4815
4816 left.reset();
4817 assign( left, tmp );
4818
4819 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
4820
4821 return *this;
4822}
4824//*************************************************************************************************
4825
4826
4827//*************************************************************************************************
4841template< typename MT // Type of the sparse matrix
4842 , size_t... CRAs > // Compile time row arguments
4843template< typename VT > // Type of the right-hand side sparse vector
4844inline Row<MT,false,false,true,CRAs...>&
4845 Row<MT,false,false,true,CRAs...>::operator+=( const SparseVector<VT,true>& rhs )
4846{
4847 using blaze::assign;
4848
4853 BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE ( ResultType_t<VT> );
4855
4856 using AddType = AddTrait_t< ResultType, ResultType_t<VT> >;
4857
4861
4862 if( size() != (*rhs).size() ) {
4863 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
4864 }
4865
4866 const AddType tmp( *this + (*rhs) );
4867
4868 if( !tryAssign( matrix_, tmp, row(), 0UL ) ) {
4869 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
4870 }
4871
4872 decltype(auto) left( derestrict( *this ) );
4873
4874 left.reset();
4875 left.reserve( tmp.nonZeros() );
4876 assign( left, tmp );
4877
4878 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
4879
4880 return *this;
4881}
4883//*************************************************************************************************
4884
4885
4886//*************************************************************************************************
4901template< typename MT // Type of the sparse matrix
4902 , size_t... CRAs > // Compile time row arguments
4903template< typename VT > // Type of the right-hand side dense vector
4904inline Row<MT,false,false,true,CRAs...>&
4905 Row<MT,false,false,true,CRAs...>::operator-=( const DenseVector<VT,true>& rhs )
4906{
4907 using blaze::assign;
4908
4912 BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE ( ResultType_t<VT> );
4913 BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE ( ResultType_t<VT> );
4915
4916 using SubType = SubTrait_t< ResultType, ResultType_t<VT> >;
4917
4921
4922 if( size() != (*rhs).size() ) {
4923 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
4924 }
4925
4926 const SubType tmp( *this - (*rhs) );
4927
4928 if( !tryAssign( matrix_, tmp, row(), 0UL ) ) {
4929 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
4930 }
4931
4932 decltype(auto) left( derestrict( *this ) );
4933
4934 left.reset();
4935 assign( left, tmp );
4936
4937 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
4938
4939 return *this;
4940}
4942//*************************************************************************************************
4943
4944
4945//*************************************************************************************************
4960template< typename MT // Type of the sparse matrix
4961 , size_t... CRAs > // Compile time row arguments
4962template< typename VT > // Type of the right-hand side sparse vector
4963inline Row<MT,false,false,true,CRAs...>&
4964 Row<MT,false,false,true,CRAs...>::operator-=( const SparseVector<VT,true>& rhs )
4965{
4966 using blaze::assign;
4967
4972 BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE ( ResultType_t<VT> );
4974
4975 using SubType = SubTrait_t< ResultType, ResultType_t<VT> >;
4976
4980
4981 if( size() != (*rhs).size() ) {
4982 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
4983 }
4984
4985 const SubType tmp( *this - (*rhs) );
4986
4987 if( !tryAssign( matrix_, tmp, row(), 0UL ) ) {
4988 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
4989 }
4990
4991 decltype(auto) left( derestrict( *this ) );
4992
4993 left.reset();
4994 left.reserve( tmp.nonZeros() );
4995 assign( left, tmp );
4996
4997 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
4998
4999 return *this;
5000}
5002//*************************************************************************************************
5003
5004
5005//*************************************************************************************************
5018template< typename MT // Type of the sparse matrix
5019 , size_t... CRAs > // Compile time row arguments
5020template< typename VT > // Type of the right-hand side vector
5021inline Row<MT,false,false,true,CRAs...>&
5022 Row<MT,false,false,true,CRAs...>::operator*=( const Vector<VT,true>& rhs )
5023{
5024 using blaze::assign;
5025
5029 BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE ( ResultType_t<VT> );
5031
5032 using MultType = MultTrait_t< ResultType, ResultType_t<VT> >;
5033
5036
5037 if( size() != (*rhs).size() ) {
5038 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
5039 }
5040
5041 const MultType tmp( *this * (*rhs) );
5042
5043 if( !tryAssign( matrix_, tmp, row(), 0UL ) ) {
5044 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
5045 }
5046
5047 decltype(auto) left( derestrict( *this ) );
5048
5049 left.reset();
5050 assign( left, tmp );
5051
5052 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
5053
5054 return *this;
5055}
5057//*************************************************************************************************
5058
5059
5060//*************************************************************************************************
5072template< typename MT // Type of the sparse matrix
5073 , size_t... CRAs > // Compile time row arguments
5074template< typename VT > // Type of the right-hand side vector
5075inline Row<MT,false,false,true,CRAs...>&
5076 Row<MT,false,false,true,CRAs...>::operator/=( const DenseVector<VT,true>& rhs )
5077{
5078 using blaze::assign;
5079
5083 BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE ( ResultType_t<VT> );
5084 BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE ( ResultType_t<VT> );
5086
5087 using DivType = DivTrait_t< ResultType, ResultType_t<VT> >;
5088
5092
5093 if( size() != (*rhs).size() ) {
5094 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
5095 }
5096
5097 const DivType tmp( *this / (*rhs) );
5098
5099 if( !tryAssign( matrix_, tmp, row(), 0UL ) ) {
5100 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
5101 }
5102
5103 decltype(auto) left( derestrict( *this ) );
5104
5105 left.reset();
5106 assign( left, tmp );
5107
5108 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
5109
5110 return *this;
5111}
5113//*************************************************************************************************
5114
5115
5116//*************************************************************************************************
5129template< typename MT // Type of the sparse matrix
5130 , size_t... CRAs > // Compile time row arguments
5131template< typename VT > // Type of the right-hand side vector
5132inline Row<MT,false,false,true,CRAs...>&
5133 Row<MT,false,false,true,CRAs...>::operator%=( const Vector<VT,true>& rhs )
5134{
5135 using blaze::assign;
5136
5137 BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE ( ResultType_t<VT> );
5139
5140 using CrossType = CrossTrait_t< ResultType, ResultType_t<VT> >;
5141
5145
5146 if( size() != 3UL || (*rhs).size() != 3UL ) {
5147 BLAZE_THROW_INVALID_ARGUMENT( "Invalid vector size for cross product" );
5148 }
5149
5150 const CrossType tmp( *this % (*rhs) );
5151
5152 if( !tryAssign( matrix_, tmp, row(), 0UL ) ) {
5153 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
5154 }
5155
5156 decltype(auto) left( derestrict( *this ) );
5157
5158 left.reset();
5159 assign( left, tmp );
5160
5161 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
5162
5163 return *this;
5164}
5166//*************************************************************************************************
5167
5168
5169
5170
5171//=================================================================================================
5172//
5173// UTILITY FUNCTIONS
5174//
5175//=================================================================================================
5176
5177//*************************************************************************************************
5183template< typename MT // Type of the sparse matrix
5184 , size_t... CRAs > // Compile time row arguments
5185inline MT& Row<MT,false,false,true,CRAs...>::operand() noexcept
5186{
5187 return matrix_;
5188}
5190//*************************************************************************************************
5191
5192
5193//*************************************************************************************************
5199template< typename MT // Type of the sparse matrix
5200 , size_t... CRAs > // Compile time row arguments
5201inline const MT& Row<MT,false,false,true,CRAs...>::operand() const noexcept
5202{
5203 return matrix_;
5204}
5206//*************************************************************************************************
5207
5208
5209//*************************************************************************************************
5215template< typename MT // Type of the sparse matrix
5216 , size_t... CRAs > // Compile time row arguments
5217inline size_t Row<MT,false,false,true,CRAs...>::size() const noexcept
5218{
5219 return matrix_.columns();
5220}
5222//*************************************************************************************************
5223
5224
5225//*************************************************************************************************
5231template< typename MT // Type of the sparse matrix
5232 , size_t... CRAs > // Compile time row arguments
5233inline size_t Row<MT,false,false,true,CRAs...>::capacity() const noexcept
5234{
5235 return matrix_.capacity( row() );
5236}
5238//*************************************************************************************************
5239
5240
5241//*************************************************************************************************
5250template< typename MT // Type of the sparse matrix
5251 , size_t... CRAs > // Compile time row arguments
5253{
5254 return matrix_.nonZeros( row() );
5255}
5257//*************************************************************************************************
5258
5259
5260//*************************************************************************************************
5266template< typename MT // Type of the sparse matrix
5267 , size_t... CRAs > // Compile time row arguments
5269{
5270 matrix_.reset( row() );
5271}
5273//*************************************************************************************************
5274
5275
5276//*************************************************************************************************
5286template< typename MT // Type of the sparse matrix
5287 , size_t... CRAs > // Compile time row arguments
5288void Row<MT,false,false,true,CRAs...>::reserve( size_t n )
5289{
5290 matrix_.reserve( row(), n );
5291}
5293//*************************************************************************************************
5294
5295
5296//*************************************************************************************************
5305template< typename MT // Type of the sparse matrix
5306 , size_t... CRAs > // Compile time row arguments
5307inline size_t Row<MT,false,false,true,CRAs...>::extendCapacity() const
5308{
5309 using blaze::max;
5310 using blaze::min;
5311
5312 size_t nonzeros( 2UL*capacity()+1UL );
5313 nonzeros = max( nonzeros, 7UL );
5314 nonzeros = min( nonzeros, size() );
5315
5316 BLAZE_INTERNAL_ASSERT( nonzeros > capacity(), "Invalid capacity value" );
5317
5318 return nonzeros;
5319}
5321//*************************************************************************************************
5322
5323
5324
5325
5326//=================================================================================================
5327//
5328// INSERTION FUNCTIONS
5329//
5330//=================================================================================================
5331
5332//*************************************************************************************************
5344template< typename MT // Type of the sparse matrix
5345 , size_t... CRAs > // Compile time row arguments
5346inline typename Row<MT,false,false,true,CRAs...>::Iterator
5347 Row<MT,false,false,true,CRAs...>::set( size_t index, const ElementType& value )
5348{
5349 return matrix_.set( index, row(), value );
5350}
5352//*************************************************************************************************
5353
5354
5355//*************************************************************************************************
5368template< typename MT // Type of the sparse matrix
5369 , size_t... CRAs > // Compile time row arguments
5370inline typename Row<MT,false,false,true,CRAs...>::Iterator
5371 Row<MT,false,false,true,CRAs...>::insert( size_t index, const ElementType& value )
5372{
5373 return matrix_.insert( index, row(), value );
5374}
5376//*************************************************************************************************
5377
5378
5379//*************************************************************************************************
5404template< typename MT // Type of the sparse matrix
5405 , size_t... CRAs > // Compile time row arguments
5406inline void Row<MT,false,false,true,CRAs...>::append( size_t index, const ElementType& value, bool check )
5407{
5408 matrix_.append( index, row(), value, check );
5409}
5411//*************************************************************************************************
5412
5413
5414
5415
5416//=================================================================================================
5417//
5418// ERASE FUNCTIONS
5419//
5420//=================================================================================================
5421
5422//*************************************************************************************************
5431template< typename MT // Type of the sparse matrix
5432 , size_t... CRAs > // Compile time row arguments
5433inline void Row<MT,false,false,true,CRAs...>::erase( size_t index )
5434{
5435 matrix_.erase( index, row() );
5436}
5438//*************************************************************************************************
5439
5440
5441//*************************************************************************************************
5450template< typename MT // Type of the sparse matrix
5451 , size_t... CRAs > // Compile time row arguments
5452inline typename Row<MT,false,false,true,CRAs...>::Iterator
5453 Row<MT,false,false,true,CRAs...>::erase( Iterator pos )
5454{
5455 return matrix_.erase( row(), pos );
5456}
5458//*************************************************************************************************
5459
5460
5461//*************************************************************************************************
5471template< typename MT // Type of the sparse matrix
5472 , size_t... CRAs > // Compile time row arguments
5473inline typename Row<MT,false,false,true,CRAs...>::Iterator
5474 Row<MT,false,false,true,CRAs...>::erase( Iterator first, Iterator last )
5475{
5476 return matrix_.erase( row(), first, last );
5477}
5479//*************************************************************************************************
5480
5481
5482//*************************************************************************************************
5505template< typename MT // Type of the sparse matrix
5506 , size_t... CRAs > // Compile time row arguments
5507template< typename Pred // Type of the unary predicate
5508 , typename > // Type restriction on the unary predicate
5509inline void Row<MT,false,false,true,CRAs...>::erase( Pred predicate )
5510{
5511 matrix_.erase( row(), begin(), end(), predicate );
5512}
5514//*************************************************************************************************
5515
5516
5517//*************************************************************************************************
5542template< typename MT // Type of the sparse matrix
5543 , size_t... CRAs > // Compile time row arguments
5544template< typename Pred > // Type of the unary predicate
5545inline void Row<MT,false,false,true,CRAs...>::erase( Iterator first, Iterator last, Pred predicate )
5546{
5547 matrix_.erase( row(), first, last, predicate );
5548}
5550//*************************************************************************************************
5551
5552
5553
5554
5555//=================================================================================================
5556//
5557// LOOKUP FUNCTIONS
5558//
5559//=================================================================================================
5560
5561//*************************************************************************************************
5575template< typename MT // Type of the sparse matrix
5576 , size_t... CRAs > // Compile time row arguments
5577inline typename Row<MT,false,false,true,CRAs...>::Iterator
5579{
5580 return matrix_.find( index, row() );
5581}
5583//*************************************************************************************************
5584
5585
5586//*************************************************************************************************
5600template< typename MT // Type of the sparse matrix
5601 , size_t... CRAs > // Compile time row arguments
5602inline typename Row<MT,false,false,true,CRAs...>::ConstIterator
5603 Row<MT,false,false,true,CRAs...>::find( size_t index ) const
5604{
5605 return matrix_.find( index, row() );
5606}
5608//*************************************************************************************************
5609
5610
5611//*************************************************************************************************
5624template< typename MT // Type of the sparse matrix
5625 , size_t... CRAs > // Compile time row arguments
5626inline typename Row<MT,false,false,true,CRAs...>::Iterator
5628{
5629 return matrix_.lowerBound( index, row() );
5630}
5632//*************************************************************************************************
5633
5634
5635//*************************************************************************************************
5648template< typename MT // Type of the sparse matrix
5649 , size_t... CRAs > // Compile time row arguments
5650inline typename Row<MT,false,false,true,CRAs...>::ConstIterator
5652{
5653 return matrix_.lowerBound( index, row() );
5654}
5656//*************************************************************************************************
5657
5658
5659//*************************************************************************************************
5672template< typename MT // Type of the sparse matrix
5673 , size_t... CRAs > // Compile time row arguments
5674inline typename Row<MT,false,false,true,CRAs...>::Iterator
5676{
5677 return matrix_.upperBound( index, row() );
5678}
5680//*************************************************************************************************
5681
5682
5683//*************************************************************************************************
5696template< typename MT // Type of the sparse matrix
5697 , size_t... CRAs > // Compile time row arguments
5698inline typename Row<MT,false,false,true,CRAs...>::ConstIterator
5700{
5701 return matrix_.upperBound( index, row() );
5702}
5704//*************************************************************************************************
5705
5706
5707
5708
5709//=================================================================================================
5710//
5711// NUMERIC FUNCTIONS
5712//
5713//=================================================================================================
5714
5715//*************************************************************************************************
5728template< typename MT // Type of the sparse matrix
5729 , size_t... CRAs > // Compile time row arguments
5730template< typename Other > // Data type of the scalar value
5731inline Row<MT,false,false,true,CRAs...>&
5732 Row<MT,false,false,true,CRAs...>::scale( const Other& scalar )
5733{
5735
5736 for( Iterator element=begin(); element!=end(); ++element )
5737 element->value() *= scalar;
5738 return *this;
5739}
5741//*************************************************************************************************
5742
5743
5744
5745
5746//=================================================================================================
5747//
5748// EXPRESSION TEMPLATE EVALUATION FUNCTIONS
5749//
5750//=================================================================================================
5751
5752//*************************************************************************************************
5763template< typename MT // Type of the sparse matrix
5764 , size_t... CRAs > // Compile time row arguments
5765template< typename Other > // Data type of the foreign expression
5766inline bool Row<MT,false,false,true,CRAs...>::canAlias( const Other* alias ) const noexcept
5767{
5768 return matrix_.isAliased( &unview( *alias ) );
5769}
5771//*************************************************************************************************
5772
5773
5774//*************************************************************************************************
5785template< typename MT // Type of the sparse matrix
5786 , size_t... CRAs > // Compile time row arguments
5787template< typename Other > // Data type of the foreign expression
5788inline bool Row<MT,false,false,true,CRAs...>::isAliased( const Other* alias ) const noexcept
5789{
5790 return matrix_.isAliased( &unview( *alias ) );
5791}
5793//*************************************************************************************************
5794
5795
5796//*************************************************************************************************
5808template< typename MT // Type of the sparse matrix
5809 , size_t... CRAs > // Compile time row arguments
5810template< typename VT > // Type of the right-hand side dense vector
5811inline void Row<MT,false,false,true,CRAs...>::assign( const DenseVector<VT,true>& rhs )
5812{
5813 BLAZE_INTERNAL_ASSERT( size() == (*rhs).size(), "Invalid vector sizes" );
5814 BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
5815
5816 for( size_t i=0UL; i<size(); ++i )
5817 {
5818 if( matrix_.nonZeros( row() ) == matrix_.capacity( row() ) )
5819 matrix_.reserve( row(), extendCapacity() );
5820
5821 matrix_.append( i, row(), (*rhs)[i], true );
5822 }
5823}
5825//*************************************************************************************************
5826
5827
5828//*************************************************************************************************
5840template< typename MT // Type of the sparse matrix
5841 , size_t... CRAs > // Compile time row arguments
5842template< typename VT > // Type of the right-hand side sparse vector
5843inline void Row<MT,false,false,true,CRAs...>::assign( const SparseVector<VT,true>& rhs )
5844{
5845 BLAZE_INTERNAL_ASSERT( size() == (*rhs).size(), "Invalid vector sizes" );
5846 BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
5847
5848 for( ConstIterator_t<VT> element=(*rhs).begin(); element!=(*rhs).end(); ++element ) {
5849 matrix_.append( element->index(), row(), element->value(), true );
5850 }
5851}
5853//*************************************************************************************************
5854
5855
5856//*************************************************************************************************
5868template< typename MT // Type of the sparse matrix
5869 , size_t... CRAs > // Compile time row arguments
5870template< typename VT > // Type of the right-hand side dense vector
5871inline void Row<MT,false,false,true,CRAs...>::addAssign( const DenseVector<VT,true>& rhs )
5872{
5873 using AddType = AddTrait_t< ResultType, ResultType_t<VT> >;
5874
5878
5879 BLAZE_INTERNAL_ASSERT( size() == (*rhs).size(), "Invalid vector sizes" );
5880
5881 const AddType tmp( serial( *this + (*rhs) ) );
5882 matrix_.reset( row() );
5883 assign( tmp );
5884}
5886//*************************************************************************************************
5887
5888
5889//*************************************************************************************************
5901template< typename MT // Type of the sparse matrix
5902 , size_t... CRAs > // Compile time row arguments
5903template< typename VT > // Type of the right-hand side sparse vector
5904inline void Row<MT,false,false,true,CRAs...>::addAssign( const SparseVector<VT,true>& rhs )
5905{
5906 using AddType = AddTrait_t< ResultType, ResultType_t<VT> >;
5907
5911
5912 BLAZE_INTERNAL_ASSERT( size() == (*rhs).size(), "Invalid vector sizes" );
5913
5914 const AddType tmp( serial( *this + (*rhs) ) );
5915 matrix_.reset( row() );
5916 matrix_.reserve( row(), tmp.nonZeros() );
5917 assign( tmp );
5918}
5920//*************************************************************************************************
5921
5922
5923//*************************************************************************************************
5935template< typename MT // Type of the sparse matrix
5936 , size_t... CRAs > // Compile time row arguments
5937template< typename VT > // Type of the right-hand side dense vector
5938inline void Row<MT,false,false,true,CRAs...>::subAssign( const DenseVector<VT,true>& rhs )
5939{
5940 using SubType = SubTrait_t< ResultType, ResultType_t<VT> >;
5941
5945
5946 BLAZE_INTERNAL_ASSERT( size() == (*rhs).size(), "Invalid vector sizes" );
5947
5948 const SubType tmp( serial( *this - (*rhs) ) );
5949 matrix_.reset( row() );
5950 assign( tmp );
5951}
5953//*************************************************************************************************
5954
5955
5956//*************************************************************************************************
5968template< typename MT // Type of the sparse matrix
5969 , size_t... CRAs > // Compile time row arguments
5970template< typename VT > // Type of the right-hand side sparse vector
5971inline void Row<MT,false,false,true,CRAs...>::subAssign( const SparseVector<VT,true>& rhs )
5972{
5973 using SubType = SubTrait_t< ResultType, ResultType_t<VT> >;
5974
5978
5979 BLAZE_INTERNAL_ASSERT( size() == (*rhs).size(), "Invalid vector sizes" );
5980
5981 const SubType tmp( serial( *this - (*rhs) ) );
5982 matrix_.reset( row() );
5983 matrix_.reserve( row(), tmp.nonZeros() );
5984 assign( tmp );
5985}
5987//*************************************************************************************************
5988
5989} // namespace blaze
5990
5991#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.
Header file for the cross product trait.
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
Header file for the division trait.
Header file for the EnableIf class template.
Header file for the If class template.
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 IsIntegral type trait.
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 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.
Header file for the multiplication trait.
Constraint on the data type.
Constraint on the data type.
Header file for the implementation of the RowData class template.
Constraints on the storage order of matrix types.
Header file for the row trait.
Constraint on the transpose flag of vector types.
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.
Constraint on the data type.
Header file for the implementation of a vector representation of an initializer list.
Header file for the SparseVector 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
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_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_VECTOR_TYPE(T)
Constraint on the data type.
Definition: SparseVector.h:61
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE(T)
Constraint on the data type.
Definition: SparseMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE(T)
Constraint on the data type.
Definition: DenseVector.h:61
#define BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE(T)
Constraint on the data type.
Definition: RowVector.h:61
#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
typename RowTrait< MT, CRAs... >::Type RowTrait_t
Auxiliary alias declaration for the RowTrait type trait.
Definition: RowTrait.h:144
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
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
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
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
constexpr size_t size(const Matrix< MT, SO > &matrix) noexcept
Returns the total number of elements of the matrix.
Definition: Matrix.h:676
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
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 bool IsIntegral_v
Auxiliary variable template for the IsIntegral type trait.
Definition: IsIntegral.h:95
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
typename EnableIf<!Condition, T >::Type DisableIf_t
Auxiliary type for the EnableIf class template.
Definition: EnableIf.h:175
constexpr bool isChecked(const Ts &... args)
Extracting blaze::Check arguments from a given list of arguments.
Definition: Check.h:225
Header file for the exception macros of the math module.
Header file for the reset shim.
Header file for the serial shim.
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 Row base template.