Blaze 3.9
Sparse.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_VIEWS_COLUMN_SPARSE_H_
36#define _BLAZE_MATH_VIEWS_COLUMN_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 COLUMN-MAJOR SPARSE MATRICES
101//
102//=================================================================================================
103
104//*************************************************************************************************
112template< typename MT // Type of the sparse matrix
113 , bool SF // Symmetry flag
114 , size_t... CCAs > // Compile time column arguments
115class Column<MT,true,false,SF,CCAs...>
116 : public View< SparseVector< Column<MT,true,false,SF,CCAs...>, false > >
117 , private ColumnData<CCAs...>
118{
119 private:
120 //**Type definitions****************************************************************************
121 using DataType = ColumnData<CCAs...>;
122 using Operand = If_t< IsExpression_v<MT>, MT, MT& >;
123 //**********************************************************************************************
124
125 public:
126 //**Type definitions****************************************************************************
128 using This = Column<MT,true,false,SF,CCAs...>;
129
131 using BaseType = View< SparseVector<This,false> >;
132
133 using ViewedType = MT;
134 using ResultType = ColumnTrait_t<MT,CCAs...>;
135 using TransposeType = TransposeType_t<ResultType>;
136 using ElementType = ElementType_t<MT>;
137 using ReturnType = ReturnType_t<MT>;
138 using CompositeType = const Column&;
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... RCAs >
165 explicit inline Column( MT& matrix, RCAs... args );
166
167 Column( const Column& ) = default;
169 //**********************************************************************************************
170
171 //**Destructor**********************************************************************************
174 ~Column() = 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 Column& operator=( initializer_list<ElementType> list );
198 inline Column& operator=( const Column& rhs );
199
200 template< typename VT > inline Column& operator= ( const DenseVector<VT,false>& rhs );
201 template< typename VT > inline Column& operator= ( const SparseVector<VT,false>& rhs );
202 template< typename VT > inline Column& operator+=( const DenseVector<VT,false>& rhs );
203 template< typename VT > inline Column& operator+=( const SparseVector<VT,false>& rhs );
204 template< typename VT > inline Column& operator-=( const DenseVector<VT,false>& rhs );
205 template< typename VT > inline Column& operator-=( const SparseVector<VT,false>& rhs );
206 template< typename VT > inline Column& operator*=( const Vector<VT,false>& rhs );
207 template< typename VT > inline Column& operator/=( const DenseVector<VT,false>& rhs );
208 template< typename VT > inline Column& operator%=( const Vector<VT,false>& rhs );
210 //**********************************************************************************************
211
212 //**Utility functions***************************************************************************
215 using DataType::column;
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 Column& 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,false>& rhs );
278 template< typename VT > inline void assign ( const SparseVector<VT,false>& rhs );
279 template< typename VT > inline void addAssign( const DenseVector <VT,false>& rhs );
280 template< typename VT > inline void addAssign( const SparseVector<VT,false>& rhs );
281 template< typename VT > inline void subAssign( const DenseVector <VT,false>& rhs );
282 template< typename VT > inline void subAssign( const SparseVector<VT,false>& 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... CCAs > // Compile time column arguments
339template< typename... RCAs > // Runtime column arguments
340inline Column<MT,true,false,SF,CCAs...>::Column( MT& matrix, RCAs... args )
341 : DataType( args... ) // Base class initialization
342 , matrix_ ( matrix ) // The matrix containing the column
343{
344 if( isChecked( args... ) ) {
345 if( matrix_.columns() <= column() ) {
346 BLAZE_THROW_INVALID_ARGUMENT( "Invalid column access index" );
347 }
348 }
349 else {
350 BLAZE_USER_ASSERT( column() < matrix_.columns(), "Invalid column 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... CCAs > // Compile time column arguments
378inline typename Column<MT,true,false,SF,CCAs...>::Reference
379 Column<MT,true,false,SF,CCAs...>::operator[]( size_t index )
380{
381 BLAZE_USER_ASSERT( index < size(), "Invalid column access index" );
382 return matrix_(index,column());
383}
385//*************************************************************************************************
386
387
388//*************************************************************************************************
398template< typename MT // Type of the sparse matrix
399 , bool SF // Symmetry flag
400 , size_t... CCAs > // Compile time column arguments
401inline typename Column<MT,true,false,SF,CCAs...>::ConstReference
402 Column<MT,true,false,SF,CCAs...>::operator[]( size_t index ) const
403{
404 BLAZE_USER_ASSERT( index < size(), "Invalid column access index" );
405 return const_cast<const MT&>( matrix_ )(index,column());
406}
408//*************************************************************************************************
409
410
411//*************************************************************************************************
422template< typename MT // Type of the sparse matrix
423 , bool SF // Symmetry flag
424 , size_t... CCAs > // Compile time column arguments
425inline typename Column<MT,true,false,SF,CCAs...>::Reference
426 Column<MT,true,false,SF,CCAs...>::at( size_t index )
427{
428 if( index >= size() ) {
429 BLAZE_THROW_OUT_OF_RANGE( "Invalid column 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... CCAs > // Compile time column arguments
451inline typename Column<MT,true,false,SF,CCAs...>::ConstReference
452 Column<MT,true,false,SF,CCAs...>::at( size_t index ) const
453{
454 if( index >= size() ) {
455 BLAZE_THROW_OUT_OF_RANGE( "Invalid column 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... CCAs > // Compile time column arguments
474inline typename Column<MT,true,false,SF,CCAs...>::Iterator
476{
477 return matrix_.begin( column() );
478}
480//*************************************************************************************************
481
482
483//*************************************************************************************************
491template< typename MT // Type of the sparse matrix
492 , bool SF // Symmetry flag
493 , size_t... CCAs > // Compile time column arguments
494inline typename Column<MT,true,false,SF,CCAs...>::ConstIterator
496{
497 return matrix_.cbegin( column() );
498}
500//*************************************************************************************************
501
502
503//*************************************************************************************************
511template< typename MT // Type of the sparse matrix
512 , bool SF // Symmetry flag
513 , size_t... CCAs > // Compile time column arguments
514inline typename Column<MT,true,false,SF,CCAs...>::ConstIterator
516{
517 return matrix_.cbegin( column() );
518}
520//*************************************************************************************************
521
522
523//*************************************************************************************************
531template< typename MT // Type of the sparse matrix
532 , bool SF // Symmetry flag
533 , size_t... CCAs > // Compile time column arguments
534inline typename Column<MT,true,false,SF,CCAs...>::Iterator
536{
537 return matrix_.end( column() );
538}
540//*************************************************************************************************
541
542
543//*************************************************************************************************
551template< typename MT // Type of the sparse matrix
552 , bool SF // Symmetry flag
553 , size_t... CCAs > // Compile time column arguments
554inline typename Column<MT,true,false,SF,CCAs...>::ConstIterator
556{
557 return matrix_.cend( column() );
558}
560//*************************************************************************************************
561
562
563//*************************************************************************************************
571template< typename MT // Type of the sparse matrix
572 , bool SF // Symmetry flag
573 , size_t... CCAs > // Compile time column arguments
574inline typename Column<MT,true,false,SF,CCAs...>::ConstIterator
576{
577 return matrix_.cend( column() );
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... CCAs > // Compile time column arguments
609inline Column<MT,true,false,SF,CCAs...>&
610 Column<MT,true,false,SF,CCAs...>::operator=( initializer_list<ElementType> list )
611{
612 using blaze::assign;
613
614 if( list.size() > size() ) {
615 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to column" );
616 }
617
618 const InitializerVector<ElementType,false> tmp( list, size() );
619
620 if( !tryAssign( matrix_, tmp, 0UL, column() ) ) {
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... CCAs > // Compile time column arguments
654inline Column<MT,true,false,SF,CCAs...>&
655 Column<MT,true,false,SF,CCAs...>::operator=( const Column& rhs )
656{
657 using blaze::assign;
658
662
663 if( this == &rhs || ( &matrix_ == &rhs.matrix_ && column() == rhs.column() ) )
664 return *this;
665
666 if( size() != rhs.size() ) {
667 BLAZE_THROW_INVALID_ARGUMENT( "Column sizes do not match" );
668 }
669
670 if( !tryAssign( matrix_, rhs, 0UL, column() ) ) {
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... CCAs > // Compile time column arguments
713template< typename VT > // Type of the right-hand side dense vector
714inline Column<MT,true,false,SF,CCAs...>&
715 Column<MT,true,false,SF,CCAs...>::operator=( const DenseVector<VT,false>& rhs )
716{
717 using blaze::assign;
718
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, 0UL, column() ) ) {
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... CCAs > // Compile time column arguments
771template< typename VT > // Type of the right-hand side sparse vector
772inline Column<MT,true,false,SF,CCAs...>&
773 Column<MT,true,false,SF,CCAs...>::operator=( const SparseVector<VT,false>& rhs )
774{
775 using blaze::assign;
776
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, 0UL, column() ) ) {
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... CCAs > // Compile time column arguments
831template< typename VT > // Type of the right-hand side dense vector
832inline Column<MT,true,false,SF,CCAs...>&
833 Column<MT,true,false,SF,CCAs...>::operator+=( const DenseVector<VT,false>& rhs )
834{
835 using blaze::assign;
836
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, 0UL, column() ) ) {
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... CCAs > // Compile time column arguments
890template< typename VT > // Type of the right-hand side sparse vector
891inline Column<MT,true,false,SF,CCAs...>&
892 Column<MT,true,false,SF,CCAs...>::operator+=( const SparseVector<VT,false>& rhs )
893{
894 using blaze::assign;
895
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, 0UL, column() ) ) {
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... CCAs > // Compile time column arguments
951template< typename VT > // Type of the right-hand side dense vector
952inline Column<MT,true,false,SF,CCAs...>&
953 Column<MT,true,false,SF,CCAs...>::operator-=( const DenseVector<VT,false>& rhs )
954{
955 using blaze::assign;
956
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, 0UL, column() ) ) {
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... CCAs > // Compile time column arguments
1011template< typename VT > // Type of the right-hand side sparse vector
1012inline Column<MT,true,false,SF,CCAs...>&
1013 Column<MT,true,false,SF,CCAs...>::operator-=( const SparseVector<VT,false>& rhs )
1014{
1015 using blaze::assign;
1016
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, 0UL, column() ) ) {
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... CCAs > // Compile time column arguments
1070template< typename VT > // Type of the right-hand side vector
1071inline Column<MT,true,false,SF,CCAs...>&
1072 Column<MT,true,false,SF,CCAs...>::operator*=( const Vector<VT,false>& rhs )
1073{
1074 using blaze::assign;
1075
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, 0UL, column() ) ) {
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... CCAs > // Compile time column arguments
1125template< typename VT > // Type of the right-hand side vector
1126inline Column<MT,true,false,SF,CCAs...>&
1127 Column<MT,true,false,SF,CCAs...>::operator/=( const DenseVector<VT,false>& rhs )
1128{
1129 using blaze::assign;
1130
1134 BLAZE_CONSTRAINT_MUST_BE_DENSE_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, 0UL, column() ) ) {
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... CCAs > // Compile time column arguments
1183template< typename VT > // Type of the right-hand side vector
1184inline Column<MT,true,false,SF,CCAs...>&
1185 Column<MT,true,false,SF,CCAs...>::operator%=( const Vector<VT,false>& rhs )
1186{
1187 using blaze::assign;
1188
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, 0UL, column() ) ) {
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... CCAs > // Compile time column arguments
1238inline MT& Column<MT,true,false,SF,CCAs...>::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... CCAs > // Compile time column arguments
1255inline const MT& Column<MT,true,false,SF,CCAs...>::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... CCAs > // Compile time column arguments
1272inline size_t Column<MT,true,false,SF,CCAs...>::size() const noexcept
1273{
1274 return matrix_.rows();
1275}
1277//*************************************************************************************************
1278
1279
1280//*************************************************************************************************
1286template< typename MT // Type of the sparse matrix
1287 , bool SF // Symmetry flag
1288 , size_t... CCAs > // Compile time column arguments
1289inline size_t Column<MT,true,false,SF,CCAs...>::capacity() const noexcept
1290{
1291 return matrix_.capacity( column() );
1292}
1294//*************************************************************************************************
1295
1296
1297//*************************************************************************************************
1306template< typename MT // Type of the sparse matrix
1307 , bool SF // Symmetry flag
1308 , size_t... CCAs > // Compile time column arguments
1310{
1311 return matrix_.nonZeros( column() );
1312}
1314//*************************************************************************************************
1315
1316
1317//*************************************************************************************************
1323template< typename MT // Type of the sparse matrix
1324 , bool SF // Symmetry flag
1325 , size_t... CCAs > // Compile time column arguments
1327{
1328 matrix_.reset( column() );
1329}
1331//*************************************************************************************************
1332
1333
1334//*************************************************************************************************
1344template< typename MT // Type of the sparse matrix
1345 , bool SF // Symmetry flag
1346 , size_t... CCAs > // Compile time column arguments
1347void Column<MT,true,false,SF,CCAs...>::reserve( size_t n )
1348{
1349 matrix_.reserve( column(), n );
1350}
1352//*************************************************************************************************
1353
1354
1355//*************************************************************************************************
1364template< typename MT // Type of the sparse matrix
1365 , bool SF // Symmetry flag
1366 , size_t... CCAs > // Compile time column arguments
1367inline size_t Column<MT,true,false,SF,CCAs...>::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... CCAs > // Compile time column arguments
1407inline typename Column<MT,true,false,SF,CCAs...>::Iterator
1408 Column<MT,true,false,SF,CCAs...>::set( size_t index, const ElementType& value )
1409{
1410 return matrix_.set( index, column(), value );
1411}
1413//*************************************************************************************************
1414
1415
1416//*************************************************************************************************
1429template< typename MT // Type of the sparse matrix
1430 , bool SF // Symmetry flag
1431 , size_t... CCAs > // Compile time column arguments
1432inline typename Column<MT,true,false,SF,CCAs...>::Iterator
1433 Column<MT,true,false,SF,CCAs...>::insert( size_t index, const ElementType& value )
1434{
1435 return matrix_.insert( index, column(), value );
1436}
1438//*************************************************************************************************
1439
1440
1441//*************************************************************************************************
1466template< typename MT // Type of the sparse matrix
1467 , bool SF // Symmetry flag
1468 , size_t... CCAs > // Compile time column arguments
1469inline void Column<MT,true,false,SF,CCAs...>::append( size_t index, const ElementType& value, bool check )
1470{
1471 matrix_.append( index, column(), 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... CCAs > // Compile time column arguments
1497inline void Column<MT,true,false,SF,CCAs...>::erase( size_t index )
1498{
1499 matrix_.erase( index, column() );
1500}
1502//*************************************************************************************************
1503
1504
1505//*************************************************************************************************
1514template< typename MT // Type of the sparse matrix
1515 , bool SF // Symmetry flag
1516 , size_t... CCAs > // Compile time column arguments
1517inline typename Column<MT,true,false,SF,CCAs...>::Iterator
1518 Column<MT,true,false,SF,CCAs...>::erase( Iterator pos )
1519{
1520 return matrix_.erase( column(), pos );
1521}
1523//*************************************************************************************************
1524
1525
1526//*************************************************************************************************
1536template< typename MT // Type of the sparse matrix
1537 , bool SF // Symmetry flag
1538 , size_t... CCAs > // Compile time column arguments
1539inline typename Column<MT,true,false,SF,CCAs...>::Iterator
1540 Column<MT,true,false,SF,CCAs...>::erase( Iterator first, Iterator last )
1541{
1542 return matrix_.erase( column(), first, last );
1543}
1545//*************************************************************************************************
1546
1547
1548//*************************************************************************************************
1571template< typename MT // Type of the sparse matrix
1572 , bool SF // Symmetry flag
1573 , size_t... CCAs > // Compile time column arguments
1574template< typename Pred // Type of the unary predicate
1575 , typename > // Type restriction on the unary predicate
1576inline void Column<MT,true,false,SF,CCAs...>::erase( Pred predicate )
1577{
1578 matrix_.erase( column(), begin(), end(), predicate );
1579}
1581//*************************************************************************************************
1582
1583
1584//*************************************************************************************************
1609template< typename MT // Type of the sparse matrix
1610 , bool SF // Symmetry flag
1611 , size_t... CCAs > // Compile time column arguments
1612template< typename Pred > // Type of the unary predicate
1613inline void Column<MT,true,false,SF,CCAs...>::erase( Iterator first, Iterator last, Pred predicate )
1614{
1615 matrix_.erase( column(), 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... CCAs > // Compile time column arguments
1646inline typename Column<MT,true,false,SF,CCAs...>::Iterator
1648{
1649 return matrix_.find( index, column() );
1650}
1652//*************************************************************************************************
1653
1654
1655//*************************************************************************************************
1669template< typename MT // Type of the sparse matrix
1670 , bool SF // Symmetry flag
1671 , size_t... CCAs > // Compile time column arguments
1672inline typename Column<MT,true,false,SF,CCAs...>::ConstIterator
1673 Column<MT,true,false,SF,CCAs...>::find( size_t index ) const
1674{
1675 return matrix_.find( index, column() );
1676}
1678//*************************************************************************************************
1679
1680
1681//*************************************************************************************************
1694template< typename MT // Type of the sparse matrix
1695 , bool SF // Symmetry flag
1696 , size_t... CCAs > // Compile time column arguments
1697inline typename Column<MT,true,false,SF,CCAs...>::Iterator
1699{
1700 return matrix_.lowerBound( index, column() );
1701}
1703//*************************************************************************************************
1704
1705
1706//*************************************************************************************************
1719template< typename MT // Type of the sparse matrix
1720 , bool SF // Symmetry flag
1721 , size_t... CCAs > // Compile time column arguments
1722inline typename Column<MT,true,false,SF,CCAs...>::ConstIterator
1724{
1725 return matrix_.lowerBound( index, column() );
1726}
1728//*************************************************************************************************
1729
1730
1731//*************************************************************************************************
1744template< typename MT // Type of the sparse matrix
1745 , bool SF // Symmetry flag
1746 , size_t... CCAs > // Compile time column arguments
1747inline typename Column<MT,true,false,SF,CCAs...>::Iterator
1749{
1750 return matrix_.upperBound( index, column() );
1751}
1753//*************************************************************************************************
1754
1755
1756//*************************************************************************************************
1769template< typename MT // Type of the sparse matrix
1770 , bool SF // Symmetry flag
1771 , size_t... CCAs > // Compile time column arguments
1772inline typename Column<MT,true,false,SF,CCAs...>::ConstIterator
1774{
1775 return matrix_.upperBound( index, column() );
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... CCAs > // Compile time column arguments
1805template< typename Other > // Data type of the scalar value
1806inline Column<MT,true,false,SF,CCAs...>&
1807 Column<MT,true,false,SF,CCAs...>::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... CCAs > // Compile time column arguments
1841template< typename Other > // Data type of the foreign expression
1842inline bool Column<MT,true,false,SF,CCAs...>::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... CCAs > // Compile time column arguments
1864template< typename Other > // Data type of the foreign expression
1865inline bool Column<MT,true,false,SF,CCAs...>::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... CCAs > // Compile time column arguments
1888template< typename VT > // Type of the right-hand side dense vector
1889inline void Column<MT,true,false,SF,CCAs...>::assign( const DenseVector<VT,false>& 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 i=0UL; i<size(); ++i )
1895 {
1896 if( matrix_.nonZeros( column() ) == matrix_.capacity( column() ) )
1897 matrix_.reserve( column(), extendCapacity() );
1898
1899 matrix_.append( i, column(), (*rhs)[i], true );
1900 }
1901}
1903//*************************************************************************************************
1904
1905
1906//*************************************************************************************************
1918template< typename MT // Type of the sparse matrix
1919 , bool SF // Symmetry flag
1920 , size_t... CCAs > // Compile time column arguments
1921template< typename VT > // Type of the right-hand side sparse vector
1922inline void Column<MT,true,false,SF,CCAs...>::assign( const SparseVector<VT,false>& 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( element->index(), column(), 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... CCAs > // Compile time column arguments
1950template< typename VT > // Type of the right-hand side dense vector
1951inline void Column<MT,true,false,SF,CCAs...>::addAssign( const DenseVector<VT,false>& 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( column() );
1963 assign( tmp );
1964}
1966//*************************************************************************************************
1967
1968
1969//*************************************************************************************************
1981template< typename MT // Type of the sparse matrix
1982 , bool SF // Symmetry flag
1983 , size_t... CCAs > // Compile time column arguments
1984template< typename VT > // Type of the right-hand side sparse vector
1985inline void Column<MT,true,false,SF,CCAs...>::addAssign( const SparseVector<VT,false>& 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( column() );
1997 matrix_.reserve( column(), 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... CCAs > // Compile time column arguments
2019template< typename VT > // Type of the right-hand side dense vector
2020inline void Column<MT,true,false,SF,CCAs...>::subAssign( const DenseVector<VT,false>& 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( column() );
2032 assign( tmp );
2033}
2035//*************************************************************************************************
2036
2037
2038//*************************************************************************************************
2050template< typename MT // Type of the sparse matrix
2051 , bool SF // Symmetry flag
2052 , size_t... CCAs > // Compile time column arguments
2053template< typename VT > // Type of the right-hand side sparse vector
2054inline void Column<MT,true,false,SF,CCAs...>::subAssign( const SparseVector<VT,false>& 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( column() );
2066 matrix_.reserve( column(), tmp.nonZeros() );
2067 assign( tmp );
2068}
2070//*************************************************************************************************
2071
2072
2073
2074
2075
2076
2077
2078
2079//=================================================================================================
2080//
2081// CLASS TEMPLATE SPECIALIZATION FOR GENERAL ROW-MAJOR SPARSE MATRICES
2082//
2083//=================================================================================================
2084
2085//*************************************************************************************************
2093template< typename MT // Type of the sparse matrix
2094 , size_t... CCAs > // Compile time column arguments
2095class Column<MT,false,false,false,CCAs...>
2096 : public View< SparseVector< Column<MT,false,false,false,CCAs...>, false > >
2097 , private ColumnData<CCAs...>
2098{
2099 private:
2100 //**Type definitions****************************************************************************
2101 using DataType = ColumnData<CCAs...>;
2102 using Operand = If_t< IsExpression_v<MT>, MT, MT& >;
2103 //**********************************************************************************************
2104
2105 public:
2106 //**Type definitions****************************************************************************
2108 using This = Column<MT,false,false,false,CCAs...>;
2109
2111 using BaseType = View< SparseVector<This,false> >;
2112
2113 using ViewedType = MT;
2114 using ResultType = ColumnTrait_t<MT,CCAs...>;
2115 using TransposeType = TransposeType_t<ResultType>;
2116 using ElementType = ElementType_t<MT>;
2117 using ReturnType = ReturnType_t<MT>;
2118 using CompositeType = const Column&;
2119
2121 using ConstReference = ConstReference_t<MT>;
2122
2124 using Reference = If_t< IsConst_v<MT>, ConstReference, Reference_t<MT> >;
2125 //**********************************************************************************************
2126
2127 //**ColumnElement class definition**************************************************************
2130 template< typename MatrixType // Type of the sparse matrix
2131 , typename IteratorType > // Type of the sparse matrix iterator
2132 class ColumnElement
2133 : private SparseElement
2134 {
2135 public:
2136 //**Constructor******************************************************************************
2142 inline ColumnElement( IteratorType pos, size_t row )
2143 : pos_( pos ) // Iterator to the current position within the sparse column
2144 , row_( row ) // Index of the according row
2145 {}
2146 //*******************************************************************************************
2147
2148 //**Assignment operator**********************************************************************
2154 template< typename T > inline ColumnElement& operator=( const T& v ) {
2155 *pos_ = v;
2156 return *this;
2157 }
2158 //*******************************************************************************************
2159
2160 //**Addition assignment operator*************************************************************
2166 template< typename T > inline ColumnElement& operator+=( const T& v ) {
2167 *pos_ += v;
2168 return *this;
2169 }
2170 //*******************************************************************************************
2171
2172 //**Subtraction assignment operator**********************************************************
2178 template< typename T > inline ColumnElement& operator-=( const T& v ) {
2179 *pos_ -= v;
2180 return *this;
2181 }
2182 //*******************************************************************************************
2183
2184 //**Multiplication assignment operator*******************************************************
2190 template< typename T > inline ColumnElement& operator*=( const T& v ) {
2191 *pos_ *= v;
2192 return *this;
2193 }
2194 //*******************************************************************************************
2195
2196 //**Division assignment operator*************************************************************
2202 template< typename T > inline ColumnElement& operator/=( const T& v ) {
2203 *pos_ /= v;
2204 return *this;
2205 }
2206 //*******************************************************************************************
2207
2208 //**Element access operator******************************************************************
2213 inline const ColumnElement* 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 row_;
2235 }
2236 //*******************************************************************************************
2237
2238 private:
2239 //**Member variables*************************************************************************
2240 IteratorType pos_;
2241 size_t row_;
2242 //*******************************************************************************************
2243 };
2244 //**********************************************************************************************
2245
2246 //**ColumnIterator class definition*************************************************************
2249 template< typename MatrixType // Type of the sparse matrix
2250 , typename IteratorType > // Type of the sparse matrix iterator
2251 class ColumnIterator
2252 {
2253 public:
2254 //**Type definitions*************************************************************************
2255 using IteratorCategory = std::forward_iterator_tag;
2256 using ValueType = ColumnElement<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 ColumnIterator()
2273 : matrix_( nullptr ) // The sparse matrix containing the column
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 ColumnIterator( MatrixType& matrix, size_t row, size_t column )
2288 : matrix_( &matrix ) // The sparse matrix containing the column
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( ; row_<matrix_->rows(); ++row_ ) {
2294 pos_ = matrix_->find( row_, column_ );
2295 if( pos_ != matrix_->end( row_ ) ) break;
2296 }
2297 }
2298 //*******************************************************************************************
2299
2300 //**Constructor******************************************************************************
2308 inline ColumnIterator( MatrixType& matrix, size_t row, size_t column, IteratorType pos )
2309 : matrix_( &matrix ) // The sparse matrix containing the column
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 ColumnIterator( const ColumnIterator<MatrixType2,IteratorType2>& it )
2325 : matrix_( it.matrix_ ) // The sparse matrix containing the column
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 ColumnIterator& operator++() {
2338 ++row_;
2339 for( ; row_<matrix_->rows(); ++row_ ) {
2340 pos_ = matrix_->find( row_, column_ );
2341 if( pos_ != matrix_->end( row_ ) ) break;
2342 }
2343
2344 return *this;
2345 }
2346 //*******************************************************************************************
2347
2348 //**Postfix increment operator***************************************************************
2353 inline const ColumnIterator operator++( int ) {
2354 const ColumnIterator tmp( *this );
2355 ++(*this);
2356 return tmp;
2357 }
2358 //*******************************************************************************************
2359
2360 //**Element access operator******************************************************************
2365 inline ReferenceType operator*() const {
2366 return ReferenceType( pos_, row_ );
2367 }
2368 //*******************************************************************************************
2369
2370 //**Element access operator******************************************************************
2375 inline PointerType operator->() const {
2376 return PointerType( pos_, row_ );
2377 }
2378 //*******************************************************************************************
2379
2380 //**Equality operator************************************************************************
2386 template< typename MatrixType2, typename IteratorType2 >
2387 inline bool operator==( const ColumnIterator<MatrixType2,IteratorType2>& rhs ) const {
2388 return row_ == rhs.row_;
2389 }
2390 //*******************************************************************************************
2391
2392 //**Inequality operator**********************************************************************
2398 template< typename MatrixType2, typename IteratorType2 >
2399 inline bool operator!=( const ColumnIterator<MatrixType2,IteratorType2>& rhs ) const {
2400 return !( *this == rhs );
2401 }
2402 //*******************************************************************************************
2403
2404 //**Subtraction operator*********************************************************************
2410 inline DifferenceType operator-( const ColumnIterator& rhs ) const {
2411 size_t counter( 0UL );
2412 for( size_t i=rhs.row_; i<row_; ++i ) {
2413 if( matrix_->find( i, column_ ) != matrix_->end( i ) )
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 ColumnIterator;
2430 template< typename MT2, bool SO2, bool DF2, bool SF2, size_t... CCAs2 > friend class Column;
2431 //*******************************************************************************************
2432 };
2433 //**********************************************************************************************
2434
2435 //**Type definitions****************************************************************************
2437 using ConstIterator = ColumnIterator< const MT, ConstIterator_t<MT> >;
2438
2440 using Iterator = If_t< IsConst_v<MT>, ConstIterator, ColumnIterator< 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... RCAs >
2455 explicit inline Column( MT& matrix, RCAs... args );
2456
2457 Column( const Column& ) = default;
2459 //**********************************************************************************************
2460
2461 //**Destructor**********************************************************************************
2464 ~Column() = 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 Column& operator=( initializer_list<ElementType> list );
2488 inline Column& operator=( const Column& rhs );
2489
2490 template< typename VT > inline Column& operator= ( const Vector<VT,false>& rhs );
2491 template< typename VT > inline Column& operator+=( const Vector<VT,false>& rhs );
2492 template< typename VT > inline Column& operator-=( const Vector<VT,false>& rhs );
2493 template< typename VT > inline Column& operator*=( const Vector<VT,false>& rhs );
2494 template< typename VT > inline Column& operator/=( const DenseVector<VT,false>& rhs );
2495 template< typename VT > inline Column& operator%=( const Vector<VT,false>& rhs );
2497 //**********************************************************************************************
2498
2499 //**Utility functions***************************************************************************
2502 using DataType::column;
2503
2504 inline MT& operand() noexcept;
2505 inline const MT& operand() const noexcept;
2506
2507 inline size_t size() const;
2508 inline size_t capacity() const;
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 Column& scale( const Other& scalar );
2556 //**********************************************************************************************
2557
2558 //**Expression template evaluation functions****************************************************
2561 template< typename Other > inline bool canAlias ( const Other* alias ) const;
2562 template< typename Other > inline bool isAliased( const Other* alias ) const;
2563
2564 template< typename VT > inline void assign ( const DenseVector <VT,false>& rhs );
2565 template< typename VT > inline void assign ( const SparseVector<VT,false>& rhs );
2566 template< typename VT > inline void addAssign( const Vector<VT,false>& rhs );
2567 template< typename VT > inline void subAssign( const Vector<VT,false>& 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//*************************************************************************************************
2615template< typename MT // Type of the sparse matrix
2616 , size_t... CCAs > // Compile time column arguments
2617template< typename... RCAs > // Runtime column arguments
2618inline Column<MT,false,false,false,CCAs...>::Column( MT& matrix, RCAs... args )
2619 : DataType( args... ) // Base class initialization
2620 , matrix_ ( matrix ) // The matrix containing the column
2621{
2622 if( isChecked( args... ) ) {
2623 if( matrix_.columns() <= column() ) {
2624 BLAZE_THROW_INVALID_ARGUMENT( "Invalid column access index" );
2625 }
2626 }
2627 else {
2628 BLAZE_USER_ASSERT( column() < matrix_.columns(), "Invalid column access index" );
2629 }
2630}
2632//*************************************************************************************************
2633
2634
2635
2636
2637//=================================================================================================
2638//
2639// DATA ACCESS FUNCTIONS
2640//
2641//=================================================================================================
2642
2643//*************************************************************************************************
2653template< typename MT // Type of the sparse matrix
2654 , size_t... CCAs > // Compile time column arguments
2655inline typename Column<MT,false,false,false,CCAs...>::Reference
2656 Column<MT,false,false,false,CCAs...>::operator[]( size_t index )
2657{
2658 BLAZE_USER_ASSERT( index < size(), "Invalid column access index" );
2659 return matrix_(index,column());
2660}
2662//*************************************************************************************************
2663
2664
2665//*************************************************************************************************
2675template< typename MT // Type of the sparse matrix
2676 , size_t... CCAs > // Compile time column arguments
2677inline typename Column<MT,false,false,false,CCAs...>::ConstReference
2678 Column<MT,false,false,false,CCAs...>::operator[]( size_t index ) const
2679{
2680 BLAZE_USER_ASSERT( index < size(), "Invalid column access index" );
2681 return const_cast<const MT&>( matrix_ )(index,column());
2682}
2684//*************************************************************************************************
2685
2686
2687//*************************************************************************************************
2698template< typename MT // Type of the sparse matrix
2699 , size_t... CCAs > // Compile time column arguments
2700inline typename Column<MT,false,false,false,CCAs...>::Reference
2701 Column<MT,false,false,false,CCAs...>::at( size_t index )
2702{
2703 if( index >= size() ) {
2704 BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
2705 }
2706 return (*this)[index];
2707}
2709//*************************************************************************************************
2710
2711
2712//*************************************************************************************************
2723template< typename MT // Type of the sparse matrix
2724 , size_t... CCAs > // Compile time column arguments
2725inline typename Column<MT,false,false,false,CCAs...>::ConstReference
2726 Column<MT,false,false,false,CCAs...>::at( size_t index ) const
2727{
2728 if( index >= size() ) {
2729 BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
2730 }
2731 return (*this)[index];
2732}
2734//*************************************************************************************************
2735
2736
2737//*************************************************************************************************
2745template< typename MT // Type of the sparse matrix
2746 , size_t... CCAs > // Compile time column arguments
2747inline typename Column<MT,false,false,false,CCAs...>::Iterator
2749{
2750 return Iterator( matrix_, 0UL, column() );
2751}
2753//*************************************************************************************************
2754
2755
2756//*************************************************************************************************
2764template< typename MT // Type of the sparse matrix
2765 , size_t... CCAs > // Compile time column arguments
2766inline typename Column<MT,false,false,false,CCAs...>::ConstIterator
2768{
2769 return ConstIterator( matrix_, 0UL, column() );
2770}
2772//*************************************************************************************************
2773
2774
2775//*************************************************************************************************
2783template< typename MT // Type of the sparse matrix
2784 , size_t... CCAs > // Compile time column arguments
2785inline typename Column<MT,false,false,false,CCAs...>::ConstIterator
2787{
2788 return ConstIterator( matrix_, 0UL, column() );
2789}
2791//*************************************************************************************************
2792
2793
2794//*************************************************************************************************
2802template< typename MT // Type of the sparse matrix
2803 , size_t... CCAs > // Compile time column arguments
2804inline typename Column<MT,false,false,false,CCAs...>::Iterator
2806{
2807 return Iterator( matrix_, size(), column() );
2808}
2810//*************************************************************************************************
2811
2812
2813//*************************************************************************************************
2821template< typename MT // Type of the sparse matrix
2822 , size_t... CCAs > // Compile time column arguments
2823inline typename Column<MT,false,false,false,CCAs...>::ConstIterator
2825{
2826 return ConstIterator( matrix_, size(), column() );
2827}
2829//*************************************************************************************************
2830
2831
2832//*************************************************************************************************
2840template< typename MT // Type of the sparse matrix
2841 , size_t... CCAs > // Compile time column arguments
2842inline typename Column<MT,false,false,false,CCAs...>::ConstIterator
2844{
2845 return ConstIterator( matrix_, size(), column() );
2846}
2848//*************************************************************************************************
2849
2850
2851
2852
2853//=================================================================================================
2854//
2855// ASSIGNMENT OPERATORS
2856//
2857//=================================================================================================
2858
2859//*************************************************************************************************
2874template< typename MT // Type of the sparse matrix
2875 , size_t... CCAs > // Compile time column arguments
2876inline Column<MT,false,false,false,CCAs...>&
2877 Column<MT,false,false,false,CCAs...>::operator=( initializer_list<ElementType> list )
2878{
2879 using blaze::assign;
2880
2881 if( list.size() > size() ) {
2882 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to column" );
2883 }
2884
2885 const InitializerVector<ElementType,false> tmp( list, size() );
2886
2887 if( !tryAssign( matrix_, tmp, 0UL, column() ) ) {
2888 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
2889 }
2890
2891 decltype(auto) left( derestrict( *this ) );
2892
2893 assign( left, tmp );
2894
2895 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
2896
2897 return *this;
2898}
2900//*************************************************************************************************
2901
2902
2903//*************************************************************************************************
2917template< typename MT // Type of the sparse matrix
2918 , size_t... CCAs > // Compile time column arguments
2919inline Column<MT,false,false,false,CCAs...>&
2920 Column<MT,false,false,false,CCAs...>::operator=( const Column& rhs )
2921{
2922 using blaze::assign;
2923
2927
2928 if( this == &rhs || ( &matrix_ == &rhs.matrix_ && column() == rhs.column() ) )
2929 return *this;
2930
2931 if( size() != rhs.size() ) {
2932 BLAZE_THROW_INVALID_ARGUMENT( "Column sizes do not match" );
2933 }
2934
2935 if( !tryAssign( matrix_, rhs, 0UL, column() ) ) {
2936 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
2937 }
2938
2939 decltype(auto) left( derestrict( *this ) );
2940
2941 if( rhs.canAlias( this ) ) {
2942 const ResultType tmp( rhs );
2943 assign( left, tmp );
2944 }
2945 else {
2946 assign( left, rhs );
2947 }
2948
2949 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
2950
2951 return *this;
2952}
2954//*************************************************************************************************
2955
2956
2957//*************************************************************************************************
2971template< typename MT // Type of the sparse matrix
2972 , size_t... CCAs > // Compile time column arguments
2973template< typename VT > // Type of the right-hand side vector
2974inline Column<MT,false,false,false,CCAs...>&
2975 Column<MT,false,false,false,CCAs...>::operator=( const Vector<VT,false>& rhs )
2976{
2977 using blaze::assign;
2978
2979 if( size() != (*rhs).size() ) {
2980 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
2981 }
2982
2983 const CompositeType_t<VT> tmp( *rhs );
2984
2985 if( !tryAssign( matrix_, tmp, 0UL, column() ) ) {
2986 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
2987 }
2988
2989 decltype(auto) left( derestrict( *this ) );
2990
2991 assign( left, tmp );
2992
2993 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
2994
2995 return *this;
2996}
2998//*************************************************************************************************
2999
3000
3001//*************************************************************************************************
3015template< typename MT // Type of the sparse matrix
3016 , size_t... CCAs > // Compile time column arguments
3017template< typename VT > // Type of the right-hand side vector
3018inline Column<MT,false,false,false,CCAs...>&
3019 Column<MT,false,false,false,CCAs...>::operator+=( const Vector<VT,false>& rhs )
3020{
3021 using blaze::assign;
3022
3028
3029 using AddType = AddTrait_t< ResultType, ResultType_t<VT> >;
3030
3033
3034 if( size() != (*rhs).size() ) {
3035 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
3036 }
3037
3038 const AddType tmp( *this + (*rhs) );
3039
3040 if( !tryAssign( matrix_, tmp, 0UL, column() ) ) {
3041 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
3042 }
3043
3044 decltype(auto) left( derestrict( *this ) );
3045
3046 assign( left, tmp );
3047
3048 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
3049
3050 return *this;
3051}
3053//*************************************************************************************************
3054
3055
3056//*************************************************************************************************
3070template< typename MT // Type of the sparse matrix
3071 , size_t... CCAs > // Compile time column arguments
3072template< typename VT > // Type of the right-hand side vector
3073inline Column<MT,false,false,false,CCAs...>&
3074 Column<MT,false,false,false,CCAs...>::operator-=( const Vector<VT,false>& rhs )
3075{
3076 using blaze::assign;
3077
3083
3084 using SubType = SubTrait_t< ResultType, ResultType_t<VT> >;
3085
3088
3089 if( size() != (*rhs).size() ) {
3090 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
3091 }
3092
3093 const SubType tmp( *this - (*rhs) );
3094
3095 if( !tryAssign( matrix_, tmp, 0UL, column() ) ) {
3096 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
3097 }
3098
3099 decltype(auto) left( derestrict( *this ) );
3100
3101 assign( left, tmp );
3102
3103 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
3104
3105 return *this;
3106}
3108//*************************************************************************************************
3109
3110
3111//*************************************************************************************************
3124template< typename MT // Type of the sparse matrix
3125 , size_t... CCAs > // Compile time column arguments
3126template< typename VT > // Type of the right-hand side vector
3127inline Column<MT,false,false,false,CCAs...>&
3128 Column<MT,false,false,false,CCAs...>::operator*=( const Vector<VT,false>& rhs )
3129{
3130 using blaze::assign;
3131
3137
3138 using MultType = MultTrait_t< ResultType, ResultType_t<VT> >;
3139
3142
3143 if( size() != (*rhs).size() ) {
3144 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
3145 }
3146
3147 const MultType tmp( *this * (*rhs) );
3148
3149 if( !tryAssign( matrix_, tmp, 0UL, column() ) ) {
3150 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
3151 }
3152
3153 decltype(auto) left( derestrict( *this ) );
3154
3155 assign( left, tmp );
3156
3157 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
3158
3159 return *this;
3160}
3162//*************************************************************************************************
3163
3164
3165//*************************************************************************************************
3177template< typename MT // Type of the sparse matrix
3178 , size_t... CCAs > // Compile time column arguments
3179template< typename VT > // Type of the right-hand side vector
3180inline Column<MT,false,false,false,CCAs...>&
3181 Column<MT,false,false,false,CCAs...>::operator/=( const DenseVector<VT,false>& rhs )
3182{
3183 using blaze::assign;
3184
3188 BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE ( ResultType_t<VT> );
3191
3192 using DivType = DivTrait_t< ResultType, ResultType_t<VT> >;
3193
3197
3198 if( size() != (*rhs).size() ) {
3199 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
3200 }
3201
3202 const DivType tmp( *this / (*rhs) );
3203
3204 if( !tryAssign( matrix_, tmp, 0UL, column() ) ) {
3205 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
3206 }
3207
3208 decltype(auto) left( derestrict( *this ) );
3209
3210 assign( left, tmp );
3211
3212 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
3213
3214 return *this;
3215}
3217//*************************************************************************************************
3218
3219
3220//*************************************************************************************************
3233template< typename MT // Type of the sparse matrix
3234 , size_t... CCAs > // Compile time column arguments
3235template< typename VT > // Type of the right-hand side vector
3236inline Column<MT,false,false,false,CCAs...>&
3237 Column<MT,false,false,false,CCAs...>::operator%=( const Vector<VT,false>& rhs )
3238{
3239 using blaze::assign;
3240
3243
3244 using CrossType = CrossTrait_t< ResultType, ResultType_t<VT> >;
3245
3249
3250 if( size() != 3UL || (*rhs).size() != 3UL ) {
3251 BLAZE_THROW_INVALID_ARGUMENT( "Invalid vector size for cross product" );
3252 }
3253
3254 const CrossType tmp( *this % (*rhs) );
3255
3256 if( !tryAssign( matrix_, tmp, 0UL, column() ) ) {
3257 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
3258 }
3259
3260 decltype(auto) left( derestrict( *this ) );
3261
3262 assign( left, tmp );
3263
3264 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
3265
3266 return *this;
3267}
3269//*************************************************************************************************
3270
3271
3272
3273
3274//=================================================================================================
3275//
3276// UTILITY FUNCTIONS
3277//
3278//=================================================================================================
3279
3280//*************************************************************************************************
3286template< typename MT // Type of the sparse matrix
3287 , size_t... CCAs > // Compile time column arguments
3288inline MT& Column<MT,false,false,false,CCAs...>::operand() noexcept
3289{
3290 return matrix_;
3291}
3293//*************************************************************************************************
3294
3295
3296//*************************************************************************************************
3302template< typename MT // Type of the sparse matrix
3303 , size_t... CCAs > // Compile time column arguments
3304inline const MT& Column<MT,false,false,false,CCAs...>::operand() const noexcept
3305{
3306 return matrix_;
3307}
3309//*************************************************************************************************
3310
3311
3312//*************************************************************************************************
3318template< typename MT // Type of the sparse matrix
3319 , size_t... CCAs > // Compile time column arguments
3321{
3322 return matrix_.rows();
3323}
3325//*************************************************************************************************
3326
3327
3328//*************************************************************************************************
3334template< typename MT // Type of the sparse matrix
3335 , size_t... CCAs > // Compile time column arguments
3337{
3338 return matrix_.rows();
3339}
3341//*************************************************************************************************
3342
3343
3344//*************************************************************************************************
3353template< typename MT // Type of the sparse matrix
3354 , size_t... CCAs > // Compile time column arguments
3356{
3357 size_t counter( 0UL );
3358 for( ConstIterator element=begin(); element!=end(); ++element ) {
3359 ++counter;
3360 }
3361 return counter;
3362}
3364//*************************************************************************************************
3365
3366
3367//*************************************************************************************************
3373template< typename MT // Type of the sparse matrix
3374 , size_t... CCAs > // Compile time column arguments
3376{
3377 const size_t ibegin( ( IsLower_v<MT> )
3378 ?( ( IsUniLower_v<MT> || IsStrictlyLower_v<MT> )
3379 ?( column()+1UL )
3380 :( column() ) )
3381 :( 0UL ) );
3382 const size_t iend ( ( IsUpper_v<MT> )
3383 ?( ( IsUniUpper_v<MT> || IsStrictlyUpper_v<MT> )
3384 ?( column() )
3385 :( column()+1UL ) )
3386 :( size() ) );
3387
3388 for( size_t i=ibegin; i<iend; ++i ) {
3389 matrix_.erase( i, column() );
3390 }
3391}
3393//*************************************************************************************************
3394
3395
3396//*************************************************************************************************
3406template< typename MT // Type of the sparse matrix
3407 , size_t... CCAs > // Compile time column arguments
3408void Column<MT,false,false,false,CCAs...>::reserve( size_t n )
3409{
3410 MAYBE_UNUSED( n );
3411
3412 return;
3413}
3415//*************************************************************************************************
3416
3417
3418
3419
3420//=================================================================================================
3421//
3422// INSERTION FUNCTIONS
3423//
3424//=================================================================================================
3425
3426//*************************************************************************************************
3438template< typename MT // Type of the sparse matrix
3439 , size_t... CCAs > // Compile time column arguments
3440inline typename Column<MT,false,false,false,CCAs...>::Iterator
3441 Column<MT,false,false,false,CCAs...>::set( size_t index, const ElementType& value )
3442{
3443 return Iterator( matrix_, index, column(), matrix_.set( index, column(), value ) );
3444}
3446//*************************************************************************************************
3447
3448
3449//*************************************************************************************************
3462template< typename MT // Type of the sparse matrix
3463 , size_t... CCAs > // Compile time column arguments
3464inline typename Column<MT,false,false,false,CCAs...>::Iterator
3465 Column<MT,false,false,false,CCAs...>::insert( size_t index, const ElementType& value )
3466{
3467 return Iterator( matrix_, index, column(), matrix_.insert( index, column(), value ) );
3468}
3470//*************************************************************************************************
3471
3472
3473//*************************************************************************************************
3498template< typename MT // Type of the sparse matrix
3499 , size_t... CCAs > // Compile time column arguments
3500inline void Column<MT,false,false,false,CCAs...>::append( size_t index, const ElementType& value, bool check )
3501{
3502 if( !check || !isDefault<strict>( value ) )
3503 matrix_.insert( index, column(), value );
3504}
3506//*************************************************************************************************
3507
3508
3509
3510
3511//=================================================================================================
3512//
3513// ERASE FUNCTIONS
3514//
3515//=================================================================================================
3516
3517//*************************************************************************************************
3526template< typename MT // Type of the sparse matrix
3527 , size_t... CCAs > // Compile time column arguments
3528inline void Column<MT,false,false,false,CCAs...>::erase( size_t index )
3529{
3530 matrix_.erase( index, column() );
3531}
3533//*************************************************************************************************
3534
3535
3536//*************************************************************************************************
3545template< typename MT // Type of the sparse matrix
3546 , size_t... CCAs > // Compile time column arguments
3547inline typename Column<MT,false,false,false,CCAs...>::Iterator
3548 Column<MT,false,false,false,CCAs...>::erase( Iterator pos )
3549{
3550 const size_t row( pos.row_ );
3551
3552 if( row == size() )
3553 return pos;
3554
3555 matrix_.erase( row, pos.pos_ );
3556 return Iterator( matrix_, row+1UL, column() );
3557}
3559//*************************************************************************************************
3560
3561
3562//*************************************************************************************************
3572template< typename MT // Type of the sparse matrix
3573 , size_t... CCAs > // Compile time column arguments
3574inline typename Column<MT,false,false,false,CCAs...>::Iterator
3575 Column<MT,false,false,false,CCAs...>::erase( Iterator first, Iterator last )
3576{
3577 for( ; first!=last; ++first ) {
3578 matrix_.erase( first.row_, first.pos_ );
3579 }
3580 return last;
3581}
3583//*************************************************************************************************
3584
3585
3586//*************************************************************************************************
3609template< typename MT // Type of the sparse matrix
3610 , size_t... CCAs > // Compile time column arguments
3611template< typename Pred // Type of the unary predicate
3612 , typename > // Type restriction on the unary predicate
3613inline void Column<MT,false,false,false,CCAs...>::erase( Pred predicate )
3614{
3615 for( Iterator element=begin(); element!=end(); ++element ) {
3616 if( predicate( element->value() ) )
3617 matrix_.erase( element.row_, element.pos_ );
3618 }
3619}
3621//*************************************************************************************************
3622
3623
3624//*************************************************************************************************
3650template< typename MT // Type of the sparse matrix
3651 , size_t... CCAs > // Compile time column arguments
3652template< typename Pred > // Type of the unary predicate
3653inline void Column<MT,false,false,false,CCAs...>::erase( Iterator first, Iterator last, Pred predicate )
3654{
3655 for( ; first!=last; ++first ) {
3656 if( predicate( first->value() ) )
3657 matrix_.erase( first.row_, first.pos_ );
3658 }
3659}
3661//*************************************************************************************************
3662
3663
3664
3665
3666//=================================================================================================
3667//
3668// LOOKUP FUNCTIONS
3669//
3670//=================================================================================================
3671
3672//*************************************************************************************************
3686template< typename MT // Type of the sparse matrix
3687 , size_t... CCAs > // Compile time column arguments
3688inline typename Column<MT,false,false,false,CCAs...>::Iterator
3690{
3691 const Iterator_t<MT> pos( matrix_.find( index, column() ) );
3692
3693 if( pos != matrix_.end( index ) )
3694 return Iterator( matrix_, index, column(), pos );
3695 else
3696 return end();
3697}
3699//*************************************************************************************************
3700
3701
3702//*************************************************************************************************
3716template< typename MT // Type of the sparse matrix
3717 , size_t... CCAs > // Compile time column arguments
3718inline typename Column<MT,false,false,false,CCAs...>::ConstIterator
3719 Column<MT,false,false,false,CCAs...>::find( size_t index ) const
3720{
3721 const ConstIterator_t<MT> pos( matrix_.find( index, column() ) );
3722
3723 if( pos != matrix_.end( index ) )
3724 return ConstIterator( matrix_, index, column(), pos );
3725 else
3726 return end();
3727}
3729//*************************************************************************************************
3730
3731
3732//*************************************************************************************************
3745template< typename MT // Type of the sparse matrix
3746 , size_t... CCAs > // Compile time column arguments
3747inline typename Column<MT,false,false,false,CCAs...>::Iterator
3749{
3750 for( size_t i=index; i<size(); ++i )
3751 {
3752 const Iterator_t<MT> pos( matrix_.find( i, column() ) );
3753
3754 if( pos != matrix_.end( i ) )
3755 return Iterator( matrix_, i, column(), pos );
3756 }
3757
3758 return end();
3759}
3761//*************************************************************************************************
3762
3763
3764//*************************************************************************************************
3777template< typename MT // Type of the sparse matrix
3778 , size_t... CCAs > // Compile time column arguments
3779inline typename Column<MT,false,false,false,CCAs...>::ConstIterator
3781{
3782 for( size_t i=index; i<size(); ++i )
3783 {
3784 const ConstIterator_t<MT> pos( matrix_.find( i, column() ) );
3785
3786 if( pos != matrix_.end( i ) )
3787 return ConstIterator( matrix_, i, column(), pos );
3788 }
3789
3790 return end();
3791}
3793//*************************************************************************************************
3794
3795
3796//*************************************************************************************************
3809template< typename MT // Type of the sparse matrix
3810 , size_t... CCAs > // Compile time column arguments
3811inline typename Column<MT,false,false,false,CCAs...>::Iterator
3813{
3814 for( size_t i=index+1UL; i<size(); ++i )
3815 {
3816 const Iterator_t<MT> pos( matrix_.find( i, column() ) );
3817
3818 if( pos != matrix_.end( i ) )
3819 return Iterator( matrix_, i, column(), pos );
3820 }
3821
3822 return end();
3823}
3825//*************************************************************************************************
3826
3827
3828//*************************************************************************************************
3841template< typename MT // Type of the sparse matrix
3842 , size_t... CCAs > // Compile time column arguments
3843inline typename Column<MT,false,false,false,CCAs...>::ConstIterator
3845{
3846 for( size_t i=index+1UL; i<size(); ++i )
3847 {
3848 const ConstIterator_t<MT> pos( matrix_.find( i, column() ) );
3849
3850 if( pos != matrix_.end( i ) )
3851 return ConstIterator( matrix_, i, column(), pos );
3852 }
3853
3854 return end();
3855}
3857//*************************************************************************************************
3858
3859
3860
3861
3862//=================================================================================================
3863//
3864// NUMERIC FUNCTIONS
3865//
3866//=================================================================================================
3867
3868//*************************************************************************************************
3881template< typename MT // Type of the sparse matrix
3882 , size_t... CCAs > // Compile time column arguments
3883template< typename Other > // Data type of the scalar value
3884inline Column<MT,false,false,false,CCAs...>&
3885 Column<MT,false,false,false,CCAs...>::scale( const Other& scalar )
3886{
3888
3889 for( Iterator element=begin(); element!=end(); ++element )
3890 element->value() *= scalar;
3891 return *this;
3892}
3894//*************************************************************************************************
3895
3896
3897
3898
3899//=================================================================================================
3900//
3901// EXPRESSION TEMPLATE EVALUATION FUNCTIONS
3902//
3903//=================================================================================================
3904
3905//*************************************************************************************************
3916template< typename MT // Type of the sparse matrix
3917 , size_t... CCAs > // Compile time column arguments
3918template< typename Other > // Data type of the foreign expression
3919inline bool Column<MT,false,false,false,CCAs...>::canAlias( const Other* alias ) const
3920{
3921 return matrix_.isAliased( &unview( *alias ) );
3922}
3924//*************************************************************************************************
3925
3926
3927//*************************************************************************************************
3934template< typename MT // Type of the sparse matrix
3935 , size_t... CCAs > // Compile time column arguments
3936template< typename Other > // Data type of the foreign expression
3937inline bool Column<MT,false,false,false,CCAs...>::isAliased( const Other* alias ) const
3938{
3939 return matrix_.isAliased( &unview( *alias ) );
3940}
3942//*************************************************************************************************
3943
3944
3945//*************************************************************************************************
3957template< typename MT // Type of the sparse matrix
3958 , size_t... CCAs > // Compile time column arguments
3959template< typename VT > // Type of the right-hand side dense vector
3960inline void Column<MT,false,false,false,CCAs...>::assign( const DenseVector<VT,false>& rhs )
3961{
3962 BLAZE_INTERNAL_ASSERT( size() == (*rhs).size(), "Invalid vector sizes" );
3963
3964 for( size_t i=0UL; i<(*rhs).size(); ++i ) {
3965 matrix_(i,column()) = (*rhs)[i];
3966 }
3967}
3969//*************************************************************************************************
3970
3971
3972//*************************************************************************************************
3984template< typename MT // Type of the sparse matrix
3985 , size_t... CCAs > // Compile time column arguments
3986template< typename VT > // Type of the right-hand side sparse vector
3987inline void Column<MT,false,false,false,CCAs...>::assign( const SparseVector<VT,false>& rhs )
3988{
3989 BLAZE_INTERNAL_ASSERT( size() == (*rhs).size(), "Invalid vector sizes" );
3990
3991 size_t i( 0UL );
3992
3993 for( ConstIterator_t<VT> element=(*rhs).begin(); element!=(*rhs).end(); ++element ) {
3994 for( ; i<element->index(); ++i )
3995 matrix_.erase( i, column() );
3996 matrix_(i++,column()) = element->value();
3997 }
3998 for( ; i<size(); ++i ) {
3999 matrix_.erase( i, column() );
4000 }
4001}
4003//*************************************************************************************************
4004
4005
4006//*************************************************************************************************
4018template< typename MT // Type of the sparse matrix
4019 , size_t... CCAs > // Compile time column arguments
4020template< typename VT > // Type of the right-hand side vector
4021inline void Column<MT,false,false,false,CCAs...>::addAssign( const Vector<VT,false>& rhs )
4022{
4023 using AddType = AddTrait_t< ResultType, ResultType_t<VT> >;
4024
4027
4028 BLAZE_INTERNAL_ASSERT( size() == (*rhs).size(), "Invalid vector sizes" );
4029
4030 const AddType tmp( serial( *this + (*rhs) ) );
4031 assign( tmp );
4032}
4034//*************************************************************************************************
4035
4036
4037//*************************************************************************************************
4049template< typename MT // Type of the sparse matrix
4050 , size_t... CCAs > // Compile time column arguments
4051template< typename VT > // Type of the right-hand side vector
4052inline void Column<MT,false,false,false,CCAs...>::subAssign( const Vector<VT,false>& rhs )
4053{
4054 using SubType = SubTrait_t< ResultType, ResultType_t<VT> >;
4055
4058
4059 BLAZE_INTERNAL_ASSERT( size() == (*rhs).size(), "Invalid vector sizes" );
4060
4061 const SubType tmp( serial( *this - (*rhs) ) );
4062 assign( tmp );
4063}
4065//*************************************************************************************************
4066
4067
4068
4069
4070
4071
4072
4073
4074//=================================================================================================
4075//
4076// CLASS TEMPLATE SPECIALIZATION FOR SYMMETRIC ROW-MAJOR SPARSE MATRICES
4077//
4078//=================================================================================================
4079
4080//*************************************************************************************************
4088template< typename MT // Type of the sparse matrix
4089 , size_t... CCAs > // Compile time column arguments
4090class Column<MT,false,false,true,CCAs...>
4091 : public View< SparseVector< Column<MT,false,false,true,CCAs...>, false > >
4092 , private ColumnData<CCAs...>
4093{
4094 private:
4095 //**Type definitions****************************************************************************
4096 using DataType = ColumnData<CCAs...>;
4097 using Operand = If_t< IsExpression_v<MT>, MT, MT& >;
4098 //**********************************************************************************************
4099
4100 public:
4101 //**Type definitions****************************************************************************
4103 using This = Column<MT,false,false,true,CCAs...>;
4104
4106 using BaseType = View< SparseVector<This,false> >;
4107
4108 using ViewedType = MT;
4109 using ResultType = ColumnTrait_t<MT,CCAs...>;
4110 using TransposeType = TransposeType_t<ResultType>;
4111 using ElementType = ElementType_t<MT>;
4112 using ReturnType = ReturnType_t<MT>;
4113 using CompositeType = const Column&;
4114
4116 using ConstReference = ConstReference_t<MT>;
4117
4119 using Reference = If_t< IsConst_v<MT>, ConstReference, Reference_t<MT> >;
4120
4122 using ConstIterator = ConstIterator_t<MT>;
4123
4125 using Iterator = If_t< IsConst_v<MT>, ConstIterator, Iterator_t<MT> >;
4126 //**********************************************************************************************
4127
4128 //**Compilation flags***************************************************************************
4130 static constexpr bool smpAssignable = false;
4131
4133 static constexpr bool compileTimeArgs = DataType::compileTimeArgs;
4134 //**********************************************************************************************
4135
4136 //**Constructors********************************************************************************
4139 template< typename... RCAs >
4140 explicit inline Column( MT& matrix, RCAs... args );
4141
4142 Column( const Column& ) = default;
4144 //**********************************************************************************************
4145
4146 //**Destructor**********************************************************************************
4149 ~Column() = default;
4151 //**********************************************************************************************
4152
4153 //**Data access functions***********************************************************************
4156 inline Reference operator[]( size_t index );
4157 inline ConstReference operator[]( size_t index ) const;
4158 inline Reference at( size_t index );
4159 inline ConstReference at( size_t index ) const;
4160 inline Iterator begin ();
4161 inline ConstIterator begin () const;
4162 inline ConstIterator cbegin() const;
4163 inline Iterator end ();
4164 inline ConstIterator end () const;
4165 inline ConstIterator cend () const;
4167 //**********************************************************************************************
4168
4169 //**Assignment operators************************************************************************
4172 inline Column& operator=( initializer_list<ElementType> list );
4173 inline Column& operator=( const Column& rhs );
4174
4175 template< typename VT > inline Column& operator= ( const DenseVector<VT,false>& rhs );
4176 template< typename VT > inline Column& operator= ( const SparseVector<VT,false>& rhs );
4177 template< typename VT > inline Column& operator+=( const DenseVector<VT,false>& rhs );
4178 template< typename VT > inline Column& operator+=( const SparseVector<VT,false>& rhs );
4179 template< typename VT > inline Column& operator-=( const DenseVector<VT,false>& rhs );
4180 template< typename VT > inline Column& operator-=( const SparseVector<VT,false>& rhs );
4181 template< typename VT > inline Column& operator*=( const Vector<VT,false>& rhs );
4182 template< typename VT > inline Column& operator/=( const DenseVector<VT,false>& rhs );
4183 template< typename VT > inline Column& operator%=( const Vector<VT,false>& rhs );
4185 //**********************************************************************************************
4186
4187 //**Utility functions***************************************************************************
4190 using DataType::column;
4191
4192 inline MT& operand() noexcept;
4193 inline const MT& operand() const noexcept;
4194
4195 inline size_t size() const noexcept;
4196 inline size_t capacity() const noexcept;
4197 inline size_t nonZeros() const;
4198 inline void reset();
4199 inline void reserve( size_t n );
4201 //**********************************************************************************************
4202
4203 //**Insertion functions*************************************************************************
4206 inline Iterator set ( size_t index, const ElementType& value );
4207 inline Iterator insert( size_t index, const ElementType& value );
4208 inline void append( size_t index, const ElementType& value, bool check=false );
4210 //**********************************************************************************************
4211
4212 //**Erase functions*****************************************************************************
4215 inline void erase( size_t index );
4216 inline Iterator erase( Iterator pos );
4217 inline Iterator erase( Iterator first, Iterator last );
4218
4219 template< typename Pred, typename = DisableIf_t< IsIntegral_v<Pred> > >
4220 inline void erase( Pred predicate );
4221
4222 template< typename Pred >
4223 inline void erase( Iterator first, Iterator last, Pred predicate );
4225 //**********************************************************************************************
4226
4227 //**Lookup functions****************************************************************************
4230 inline Iterator find ( size_t index );
4231 inline ConstIterator find ( size_t index ) const;
4232 inline Iterator lowerBound( size_t index );
4233 inline ConstIterator lowerBound( size_t index ) const;
4234 inline Iterator upperBound( size_t index );
4235 inline ConstIterator upperBound( size_t index ) const;
4237 //**********************************************************************************************
4238
4239 //**Numeric functions***************************************************************************
4242 template< typename Other > inline Column& scale( const Other& scalar );
4244 //**********************************************************************************************
4245
4246 //**Expression template evaluation functions****************************************************
4249 template< typename Other > inline bool canAlias ( const Other* alias ) const noexcept;
4250 template< typename Other > inline bool isAliased( const Other* alias ) const noexcept;
4251
4252 template< typename VT > inline void assign ( const DenseVector <VT,false>& rhs );
4253 template< typename VT > inline void assign ( const SparseVector<VT,false>& rhs );
4254 template< typename VT > inline void addAssign( const DenseVector <VT,false>& rhs );
4255 template< typename VT > inline void addAssign( const SparseVector<VT,false>& rhs );
4256 template< typename VT > inline void subAssign( const DenseVector <VT,false>& rhs );
4257 template< typename VT > inline void subAssign( const SparseVector<VT,false>& rhs );
4259 //**********************************************************************************************
4260
4261 private:
4262 //**Utility functions***************************************************************************
4265 inline size_t extendCapacity() const noexcept;
4267 //**********************************************************************************************
4268
4269 //**Member variables****************************************************************************
4272 Operand matrix_;
4274 //**********************************************************************************************
4275
4276 //**Compile time checks*************************************************************************
4285 //**********************************************************************************************
4286};
4288//*************************************************************************************************
4289
4290
4291
4292
4293//=================================================================================================
4294//
4295// CONSTRUCTORS
4296//
4297//=================================================================================================
4298
4299//*************************************************************************************************
4312template< typename MT // Type of the sparse matrix
4313 , size_t... CCAs > // Compile time column arguments
4314template< typename... RCAs > // Runtime column arguments
4315inline Column<MT,false,false,true,CCAs...>::Column( MT& matrix, RCAs... args )
4316 : DataType( args... ) // Base class initialization
4317 , matrix_ ( matrix ) // The matrix containing the column
4318{
4319 if( isChecked( args... ) ) {
4320 if( matrix_.columns() <= column() ) {
4321 BLAZE_THROW_INVALID_ARGUMENT( "Invalid column access index" );
4322 }
4323 }
4324 else {
4325 BLAZE_USER_ASSERT( column() < matrix_.columns(), "Invalid column access index" );
4326 }
4327}
4329//*************************************************************************************************
4330
4331
4332
4333
4334//=================================================================================================
4335//
4336// DATA ACCESS FUNCTIONS
4337//
4338//=================================================================================================
4339
4340//*************************************************************************************************
4350template< typename MT // Type of the sparse matrix
4351 , size_t... CCAs > // Compile time column arguments
4352inline typename Column<MT,false,false,true,CCAs...>::Reference
4353 Column<MT,false,false,true,CCAs...>::operator[]( size_t index )
4354{
4355 BLAZE_USER_ASSERT( index < size(), "Invalid column access index" );
4356 return matrix_(column(),index);
4357}
4359//*************************************************************************************************
4360
4361
4362//*************************************************************************************************
4372template< typename MT // Type of the sparse matrix
4373 , size_t... CCAs > // Compile time column arguments
4374inline typename Column<MT,false,false,true,CCAs...>::ConstReference
4375 Column<MT,false,false,true,CCAs...>::operator[]( size_t index ) const
4376{
4377 BLAZE_USER_ASSERT( index < size(), "Invalid column access index" );
4378 return const_cast<const MT&>( matrix_ )(column(),index);
4379}
4381//*************************************************************************************************
4382
4383
4384//*************************************************************************************************
4395template< typename MT // Type of the sparse matrix
4396 , size_t... CCAs > // Compile time column arguments
4397inline typename Column<MT,false,false,true,CCAs...>::Reference
4398 Column<MT,false,false,true,CCAs...>::at( size_t index )
4399{
4400 if( index >= size() ) {
4401 BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
4402 }
4403 return (*this)[index];
4404}
4406//*************************************************************************************************
4407
4408
4409//*************************************************************************************************
4420template< typename MT // Type of the sparse matrix
4421 , size_t... CCAs > // Compile time column arguments
4422inline typename Column<MT,false,false,true,CCAs...>::ConstReference
4423 Column<MT,false,false,true,CCAs...>::at( size_t index ) const
4424{
4425 if( index >= size() ) {
4426 BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
4427 }
4428 return (*this)[index];
4429}
4431//*************************************************************************************************
4432
4433
4434//*************************************************************************************************
4442template< typename MT // Type of the sparse matrix
4443 , size_t... CCAs > // Compile time column arguments
4444inline typename Column<MT,false,false,true,CCAs...>::Iterator
4446{
4447 return matrix_.begin( column() );
4448}
4450//*************************************************************************************************
4451
4452
4453//*************************************************************************************************
4461template< typename MT // Type of the sparse matrix
4462 , size_t... CCAs > // Compile time column arguments
4463inline typename Column<MT,false,false,true,CCAs...>::ConstIterator
4465{
4466 return matrix_.cbegin( column() );
4467}
4469//*************************************************************************************************
4470
4471
4472//*************************************************************************************************
4480template< typename MT // Type of the sparse matrix
4481 , size_t... CCAs > // Compile time column arguments
4482inline typename Column<MT,false,false,true,CCAs...>::ConstIterator
4484{
4485 return matrix_.cbegin( column() );
4486}
4488//*************************************************************************************************
4489
4490
4491//*************************************************************************************************
4499template< typename MT // Type of the sparse matrix
4500 , size_t... CCAs > // Compile time column arguments
4501inline typename Column<MT,false,false,true,CCAs...>::Iterator
4503{
4504 return matrix_.end( column() );
4505}
4507//*************************************************************************************************
4508
4509
4510//*************************************************************************************************
4518template< typename MT // Type of the sparse matrix
4519 , size_t... CCAs > // Compile time column arguments
4520inline typename Column<MT,false,false,true,CCAs...>::ConstIterator
4522{
4523 return matrix_.cend( column() );
4524}
4526//*************************************************************************************************
4527
4528
4529//*************************************************************************************************
4537template< typename MT // Type of the sparse matrix
4538 , size_t... CCAs > // Compile time column arguments
4539inline typename Column<MT,false,false,true,CCAs...>::ConstIterator
4541{
4542 return matrix_.cend( column() );
4543}
4545//*************************************************************************************************
4546
4547
4548
4549
4550//=================================================================================================
4551//
4552// ASSIGNMENT OPERATORS
4553//
4554//=================================================================================================
4555
4556//*************************************************************************************************
4571template< typename MT // Type of the sparse matrix
4572 , size_t... CCAs > // Compile time column arguments
4573inline Column<MT,false,false,true,CCAs...>&
4574 Column<MT,false,false,true,CCAs...>::operator=( initializer_list<ElementType> list )
4575{
4576 using blaze::assign;
4577
4578 if( list.size() > size() ) {
4579 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to column" );
4580 }
4581
4582 const InitializerVector<ElementType,false> tmp( list, size() );
4583
4584 if( !tryAssign( matrix_, tmp, 0UL, column() ) ) {
4585 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
4586 }
4587
4588 decltype(auto) left( derestrict( *this ) );
4589
4590 left.reset();
4591 assign( left, tmp );
4592
4593 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
4594
4595 return *this;
4596}
4598//*************************************************************************************************
4599
4600
4601//*************************************************************************************************
4615template< typename MT // Type of the sparse matrix
4616 , size_t... CCAs > // Compile time column arguments
4617inline Column<MT,false,false,true,CCAs...>&
4618 Column<MT,false,false,true,CCAs...>::operator=( const Column& rhs )
4619{
4620 using blaze::assign;
4621
4625
4626 if( this == &rhs || ( &matrix_ == &rhs.matrix_ && column() == rhs.column() ) )
4627 return *this;
4628
4629 if( size() != rhs.size() ) {
4630 BLAZE_THROW_INVALID_ARGUMENT( "Column sizes do not match" );
4631 }
4632
4633 if( !tryAssign( matrix_, rhs, 0UL, column() ) ) {
4634 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
4635 }
4636
4637 decltype(auto) left( derestrict( *this ) );
4638
4639 if( rhs.canAlias( this ) ) {
4640 const ResultType tmp( rhs );
4641 left.reset();
4642 left.reserve( tmp.nonZeros() );
4643 assign( left, tmp );
4644 }
4645 else {
4646 left.reset();
4647 left.reserve( rhs.nonZeros() );
4648 assign( left, rhs );
4649 }
4650
4651 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
4652
4653 return *this;
4654}
4656//*************************************************************************************************
4657
4658
4659//*************************************************************************************************
4673template< typename MT // Type of the sparse matrix
4674 , size_t... CCAs > // Compile time column arguments
4675template< typename VT > // Type of the right-hand side dense vector
4676inline Column<MT,false,false,true,CCAs...>&
4677 Column<MT,false,false,true,CCAs...>::operator=( const DenseVector<VT,false>& rhs )
4678{
4679 using blaze::assign;
4680
4681 BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE ( ResultType_t<VT> );
4684
4685 if( size() != (*rhs).size() ) {
4686 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
4687 }
4688
4689 using Right = If_t< IsRestricted_v<MT>, CompositeType_t<VT>, const VT& >;
4690 Right right( *rhs );
4691
4692 if( !tryAssign( matrix_, right, 0UL, column() ) ) {
4693 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
4694 }
4695
4696 decltype(auto) left( derestrict( *this ) );
4697
4698 if( IsReference_v<Right> && right.canAlias( this ) ) {
4699 const ResultType_t<VT> tmp( right );
4700 left.reset();
4701 assign( left, tmp );
4702 }
4703 else {
4704 left.reset();
4705 assign( left, right );
4706 }
4707
4708 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
4709
4710 return *this;
4711}
4713//*************************************************************************************************
4714
4715
4716//*************************************************************************************************
4730template< typename MT // Type of the sparse matrix
4731 , size_t... CCAs > // Compile time column arguments
4732template< typename VT > // Type of the right-hand side sparse vector
4733inline Column<MT,false,false,true,CCAs...>&
4734 Column<MT,false,false,true,CCAs...>::operator=( const SparseVector<VT,false>& rhs )
4735{
4736 using blaze::assign;
4737
4741
4742 if( size() != (*rhs).size() ) {
4743 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
4744 }
4745
4746 using Right = If_t< IsRestricted_v<MT>, CompositeType_t<VT>, const VT& >;
4747 Right right( *rhs );
4748
4749 if( !tryAssign( matrix_, right, 0UL, column() ) ) {
4750 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
4751 }
4752
4753 decltype(auto) left( derestrict( *this ) );
4754
4755 if( IsReference_v<Right> && right.canAlias( this ) ) {
4756 const ResultType_t<VT> tmp( right);
4757 left.reset();
4758 left.reserve( tmp.nonZeros() );
4759 assign( left, tmp );
4760 }
4761 else {
4762 left.reset();
4763 left.reserve( right.nonZeros() );
4764 assign( left, right );
4765 }
4766
4767 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
4768
4769 return *this;
4770}
4772//*************************************************************************************************
4773
4774
4775//*************************************************************************************************
4789template< typename MT // Type of the sparse matrix
4790 , size_t... CCAs > // Compile time column arguments
4791template< typename VT > // Type of the right-hand side dense vector
4792inline Column<MT,false,false,true,CCAs...>&
4793 Column<MT,false,false,true,CCAs...>::operator+=( const DenseVector<VT,false>& rhs )
4794{
4795 using blaze::assign;
4796
4800 BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE ( ResultType_t<VT> );
4803
4804 using AddType = AddTrait_t< ResultType, ResultType_t<VT> >;
4805
4809
4810 if( size() != (*rhs).size() ) {
4811 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
4812 }
4813
4814 const AddType tmp( *this + (*rhs) );
4815
4816 if( !tryAssign( matrix_, tmp, 0UL, column() ) ) {
4817 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
4818 }
4819
4820 decltype(auto) left( derestrict( *this ) );
4821
4822 left.reset();
4823 assign( left, tmp );
4824
4825 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
4826
4827 return *this;
4828}
4830//*************************************************************************************************
4831
4832
4833//*************************************************************************************************
4847template< typename MT // Type of the sparse matrix
4848 , size_t... CCAs > // Compile time column arguments
4849template< typename VT > // Type of the right-hand side sparse vector
4850inline Column<MT,false,false,true,CCAs...>&
4851 Column<MT,false,false,true,CCAs...>::operator+=( const SparseVector<VT,false>& rhs )
4852{
4853 using blaze::assign;
4854
4861
4862 using AddType = AddTrait_t< ResultType, ResultType_t<VT> >;
4863
4867
4868 if( size() != (*rhs).size() ) {
4869 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
4870 }
4871
4872 const AddType tmp( *this + (*rhs) );
4873
4874 if( !tryAssign( matrix_, tmp, 0UL, column() ) ) {
4875 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
4876 }
4877
4878 decltype(auto) left( derestrict( *this ) );
4879
4880 left.reset();
4881 left.reserve( tmp.nonZeros() );
4882 assign( left, tmp );
4883
4884 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
4885
4886 return *this;
4887}
4889//*************************************************************************************************
4890
4891
4892//*************************************************************************************************
4907template< typename MT // Type of the sparse matrix
4908 , size_t... CCAs > // Compile time column arguments
4909template< typename VT > // Type of the right-hand side dense vector
4910inline Column<MT,false,false,true,CCAs...>&
4911 Column<MT,false,false,true,CCAs...>::operator-=( const DenseVector<VT,false>& rhs )
4912{
4913 using blaze::assign;
4914
4918 BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE ( ResultType_t<VT> );
4921
4922 using SubType = SubTrait_t< ResultType, ResultType_t<VT> >;
4923
4927
4928 if( size() != (*rhs).size() ) {
4929 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
4930 }
4931
4932 const SubType tmp( *this - (*rhs) );
4933
4934 if( !tryAssign( matrix_, tmp, 0UL, column() ) ) {
4935 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
4936 }
4937
4938 decltype(auto) left( derestrict( *this ) );
4939
4940 left.reset();
4941 assign( left, tmp );
4942
4943 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
4944
4945 return *this;
4946}
4948//*************************************************************************************************
4949
4950
4951//*************************************************************************************************
4966template< typename MT // Type of the sparse matrix
4967 , size_t... CCAs > // Compile time column arguments
4968template< typename VT > // Type of the right-hand side sparse vector
4969inline Column<MT,false,false,true,CCAs...>&
4970 Column<MT,false,false,true,CCAs...>::operator-=( const SparseVector<VT,false>& rhs )
4971{
4972 using blaze::assign;
4973
4980
4981 using SubType = SubTrait_t< ResultType, ResultType_t<VT> >;
4982
4986
4987 if( size() != (*rhs).size() ) {
4988 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
4989 }
4990
4991 const SubType tmp( *this - (*rhs) );
4992
4993 if( !tryAssign( matrix_, tmp, 0UL, column() ) ) {
4994 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
4995 }
4996
4997 decltype(auto) left( derestrict( *this ) );
4998
4999 left.reset();
5000 left.reserve( tmp.nonZeros() );
5001 assign( left, tmp );
5002
5003 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
5004
5005 return *this;
5006}
5008//*************************************************************************************************
5009
5010
5011//*************************************************************************************************
5024template< typename MT // Type of the sparse matrix
5025 , size_t... CCAs > // Compile time column arguments
5026template< typename VT > // Type of the right-hand side vector
5027inline Column<MT,false,false,true,CCAs...>&
5028 Column<MT,false,false,true,CCAs...>::operator*=( const Vector<VT,false>& rhs )
5029{
5030 using blaze::assign;
5031
5037
5038 using MultType = MultTrait_t< ResultType, ResultType_t<VT> >;
5039
5042
5043 if( size() != (*rhs).size() ) {
5044 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
5045 }
5046
5047 const MultType tmp( *this * (*rhs) );
5048
5049 if( !tryAssign( matrix_, tmp, 0UL, column() ) ) {
5050 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
5051 }
5052
5053 decltype(auto) left( derestrict( *this ) );
5054
5055 left.reset();
5056 assign( left, tmp );
5057
5058 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
5059
5060 return *this;
5061}
5063//*************************************************************************************************
5064
5065
5066//*************************************************************************************************
5078template< typename MT // Type of the sparse matrix
5079 , size_t... CCAs > // Compile time column arguments
5080template< typename VT > // Type of the right-hand side vector
5081inline Column<MT,false,false,true,CCAs...>&
5082 Column<MT,false,false,true,CCAs...>::operator/=( const DenseVector<VT,false>& rhs )
5083{
5084 using blaze::assign;
5085
5089 BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE ( ResultType_t<VT> );
5092
5093 using DivType = DivTrait_t< ResultType, ResultType_t<VT> >;
5094
5098
5099 if( size() != (*rhs).size() ) {
5100 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
5101 }
5102
5103 const DivType tmp( *this / (*rhs) );
5104
5105 if( !tryAssign( matrix_, tmp, 0UL, column() ) ) {
5106 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
5107 }
5108
5109 decltype(auto) left( derestrict( *this ) );
5110
5111 left.reset();
5112 assign( left, tmp );
5113
5114 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
5115
5116 return *this;
5117}
5119//*************************************************************************************************
5120
5121
5122//*************************************************************************************************
5135template< typename MT // Type of the sparse matrix
5136 , size_t... CCAs > // Compile time column arguments
5137template< typename VT > // Type of the right-hand side vector
5138inline Column<MT,false,false,true,CCAs...>&
5139 Column<MT,false,false,true,CCAs...>::operator%=( const Vector<VT,false>& rhs )
5140{
5141 using blaze::assign;
5142
5145
5146 using CrossType = CrossTrait_t< ResultType, ResultType_t<VT> >;
5147
5151
5152 if( size() != 3UL || (*rhs).size() != 3UL ) {
5153 BLAZE_THROW_INVALID_ARGUMENT( "Invalid vector size for cross product" );
5154 }
5155
5156 const CrossType tmp( *this % (*rhs) );
5157
5158 if( !tryAssign( matrix_, tmp, 0UL, column() ) ) {
5159 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
5160 }
5161
5162 decltype(auto) left( derestrict( *this ) );
5163
5164 left.reset();
5165 assign( left, tmp );
5166
5167 BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
5168
5169 return *this;
5170}
5172//*************************************************************************************************
5173
5174
5175
5176
5177//=================================================================================================
5178//
5179// UTILITY FUNCTIONS
5180//
5181//=================================================================================================
5182
5183//*************************************************************************************************
5189template< typename MT // Type of the sparse matrix
5190 , size_t... CCAs > // Compile time column arguments
5191inline MT& Column<MT,false,false,true,CCAs...>::operand() noexcept
5192{
5193 return matrix_;
5194}
5196//*************************************************************************************************
5197
5198
5199//*************************************************************************************************
5205template< typename MT // Type of the sparse matrix
5206 , size_t... CCAs > // Compile time column arguments
5207inline const MT& Column<MT,false,false,true,CCAs...>::operand() const noexcept
5208{
5209 return matrix_;
5210}
5212//*************************************************************************************************
5213
5214
5215//*************************************************************************************************
5221template< typename MT // Type of the sparse matrix
5222 , size_t... CCAs > // Compile time column arguments
5223inline size_t Column<MT,false,false,true,CCAs...>::size() const noexcept
5224{
5225 return matrix_.rows();
5226}
5228//*************************************************************************************************
5229
5230
5231//*************************************************************************************************
5237template< typename MT // Type of the sparse matrix
5238 , size_t... CCAs > // Compile time column arguments
5239inline size_t Column<MT,false,false,true,CCAs...>::capacity() const noexcept
5240{
5241 return matrix_.capacity( column() );
5242}
5244//*************************************************************************************************
5245
5246
5247//*************************************************************************************************
5256template< typename MT // Type of the sparse matrix
5257 , size_t... CCAs > // Compile time column arguments
5259{
5260 return matrix_.nonZeros( column() );
5261}
5263//*************************************************************************************************
5264
5265
5266//*************************************************************************************************
5272template< typename MT // Type of the sparse matrix
5273 , size_t... CCAs > // Compile time column arguments
5275{
5276 matrix_.reset( column() );
5277}
5279//*************************************************************************************************
5280
5281
5282//*************************************************************************************************
5292template< typename MT // Type of the sparse matrix
5293 , size_t... CCAs > // Compile time column arguments
5294void Column<MT,false,false,true,CCAs...>::reserve( size_t n )
5295{
5296 matrix_.reserve( column(), n );
5297}
5299//*************************************************************************************************
5300
5301
5302//*************************************************************************************************
5311template< typename MT // Type of the sparse matrix
5312 , size_t... CCAs > // Compile time column arguments
5313inline size_t Column<MT,false,false,true,CCAs...>::extendCapacity() const noexcept
5314{
5315 using blaze::max;
5316 using blaze::min;
5317
5318 size_t nonzeros( 2UL*capacity()+1UL );
5319 nonzeros = max( nonzeros, 7UL );
5320 nonzeros = min( nonzeros, size() );
5321
5322 BLAZE_INTERNAL_ASSERT( nonzeros > capacity(), "Invalid capacity value" );
5323
5324 return nonzeros;
5325}
5327//*************************************************************************************************
5328
5329
5330
5331
5332//=================================================================================================
5333//
5334// INSERTION FUNCTIONS
5335//
5336//=================================================================================================
5337
5338//*************************************************************************************************
5350template< typename MT // Type of the sparse matrix
5351 , size_t... CCAs > // Compile time column arguments
5352inline typename Column<MT,false,false,true,CCAs...>::Iterator
5353 Column<MT,false,false,true,CCAs...>::set( size_t index, const ElementType& value )
5354{
5355 return matrix_.set( column(), index, value );
5356}
5358//*************************************************************************************************
5359
5360
5361//*************************************************************************************************
5374template< typename MT // Type of the sparse matrix
5375 , size_t... CCAs > // Compile time column arguments
5376inline typename Column<MT,false,false,true,CCAs...>::Iterator
5377 Column<MT,false,false,true,CCAs...>::insert( size_t index, const ElementType& value )
5378{
5379 return matrix_.insert( column(), index, value );
5380}
5382//*************************************************************************************************
5383
5384
5385//*************************************************************************************************
5410template< typename MT // Type of the sparse matrix
5411 , size_t... CCAs > // Compile time column arguments
5412inline void Column<MT,false,false,true,CCAs...>::append( size_t index, const ElementType& value, bool check )
5413{
5414 matrix_.append( column(), index, value, check );
5415}
5417//*************************************************************************************************
5418
5419
5420
5421
5422//=================================================================================================
5423//
5424// ERASE FUNCTIONS
5425//
5426//=================================================================================================
5427
5428//*************************************************************************************************
5437template< typename MT // Type of the sparse matrix
5438 , size_t... CCAs > // Compile time column arguments
5439inline void Column<MT,false,false,true,CCAs...>::erase( size_t index )
5440{
5441 matrix_.erase( column(), index );
5442}
5444//*************************************************************************************************
5445
5446
5447//*************************************************************************************************
5456template< typename MT // Type of the sparse matrix
5457 , size_t... CCAs > // Compile time column arguments
5458inline typename Column<MT,false,false,true,CCAs...>::Iterator
5459 Column<MT,false,false,true,CCAs...>::erase( Iterator pos )
5460{
5461 return matrix_.erase( column(), pos );
5462}
5464//*************************************************************************************************
5465
5466
5467//*************************************************************************************************
5477template< typename MT // Type of the sparse matrix
5478 , size_t... CCAs > // Compile time column arguments
5479inline typename Column<MT,false,false,true,CCAs...>::Iterator
5480 Column<MT,false,false,true,CCAs...>::erase( Iterator first, Iterator last )
5481{
5482 return matrix_.erase( column(), first, last );
5483}
5485//*************************************************************************************************
5486
5487
5488//*************************************************************************************************
5511template< typename MT // Type of the sparse matrix
5512 , size_t... CCAs > // Compile time column arguments
5513template< typename Pred // Type of the unary predicate
5514 , typename > // Type restriction on the unary predicate
5515inline void Column<MT,false,false,true,CCAs...>::erase( Pred predicate )
5516{
5517 matrix_.erase( column(), begin(), end(), predicate );
5518}
5520//*************************************************************************************************
5521
5522
5523//*************************************************************************************************
5548template< typename MT // Type of the sparse matrix
5549 , size_t... CCAs > // Compile time column arguments
5550template< typename Pred > // Type of the unary predicate
5551inline void Column<MT,false,false,true,CCAs...>::erase( Iterator first, Iterator last, Pred predicate )
5552{
5553 matrix_.erase( column(), first, last, predicate );
5554}
5556//*************************************************************************************************
5557
5558
5559
5560
5561//=================================================================================================
5562//
5563// LOOKUP FUNCTIONS
5564//
5565//=================================================================================================
5566
5567//*************************************************************************************************
5581template< typename MT // Type of the sparse matrix
5582 , size_t... CCAs > // Compile time column arguments
5583inline typename Column<MT,false,false,true,CCAs...>::Iterator
5585{
5586 return matrix_.find( column(), index );
5587}
5589//*************************************************************************************************
5590
5591
5592//*************************************************************************************************
5606template< typename MT // Type of the sparse matrix
5607 , size_t... CCAs > // Compile time column arguments
5608inline typename Column<MT,false,false,true,CCAs...>::ConstIterator
5609 Column<MT,false,false,true,CCAs...>::find( size_t index ) const
5610{
5611 return matrix_.find( column(), index );
5612}
5614//*************************************************************************************************
5615
5616
5617//*************************************************************************************************
5630template< typename MT // Type of the sparse matrix
5631 , size_t... CCAs > // Compile time column arguments
5632inline typename Column<MT,false,false,true,CCAs...>::Iterator
5634{
5635 return matrix_.lowerBound( column(), index );
5636}
5638//*************************************************************************************************
5639
5640
5641//*************************************************************************************************
5654template< typename MT // Type of the sparse matrix
5655 , size_t... CCAs > // Compile time column arguments
5656inline typename Column<MT,false,false,true,CCAs...>::ConstIterator
5658{
5659 return matrix_.lowerBound( column(), index );
5660}
5662//*************************************************************************************************
5663
5664
5665//*************************************************************************************************
5678template< typename MT // Type of the sparse matrix
5679 , size_t... CCAs > // Compile time column arguments
5680inline typename Column<MT,false,false,true,CCAs...>::Iterator
5682{
5683 return matrix_.upperBound( column(), index );
5684}
5686//*************************************************************************************************
5687
5688
5689//*************************************************************************************************
5702template< typename MT // Type of the sparse matrix
5703 , size_t... CCAs > // Compile time column arguments
5704inline typename Column<MT,false,false,true,CCAs...>::ConstIterator
5706{
5707 return matrix_.upperBound( column(), index );
5708}
5710//*************************************************************************************************
5711
5712
5713
5714
5715//=================================================================================================
5716//
5717// NUMERIC FUNCTIONS
5718//
5719//=================================================================================================
5720
5721//*************************************************************************************************
5734template< typename MT // Type of the sparse matrix
5735 , size_t... CCAs > // Compile time column arguments
5736template< typename Other > // Data type of the scalar value
5737inline Column<MT,false,false,true,CCAs...>&
5738 Column<MT,false,false,true,CCAs...>::scale( const Other& scalar )
5739{
5741
5742 for( Iterator element=begin(); element!=end(); ++element )
5743 element->value() *= scalar;
5744 return *this;
5745}
5747//*************************************************************************************************
5748
5749
5750
5751
5752//=================================================================================================
5753//
5754// EXPRESSION TEMPLATE EVALUATION FUNCTIONS
5755//
5756//=================================================================================================
5757
5758//*************************************************************************************************
5769template< typename MT // Type of the sparse matrix
5770 , size_t... CCAs > // Compile time column arguments
5771template< typename Other > // Data type of the foreign expression
5772inline bool Column<MT,false,false,true,CCAs...>::canAlias( const Other* alias ) const noexcept
5773{
5774 return matrix_.isAliased( &unview( *alias ) );
5775}
5777//*************************************************************************************************
5778
5779
5780//*************************************************************************************************
5791template< typename MT // Type of the sparse matrix
5792 , size_t... CCAs > // Compile time column arguments
5793template< typename Other > // Data type of the foreign expression
5794inline bool Column<MT,false,false,true,CCAs...>::isAliased( const Other* alias ) const noexcept
5795{
5796 return matrix_.isAliased( &unview( *alias ) );
5797}
5799//*************************************************************************************************
5800
5801
5802//*************************************************************************************************
5814template< typename MT // Type of the sparse matrix
5815 , size_t... CCAs > // Compile time column arguments
5816template< typename VT > // Type of the right-hand side dense vector
5817inline void Column<MT,false,false,true,CCAs...>::assign( const DenseVector<VT,false>& rhs )
5818{
5819 BLAZE_INTERNAL_ASSERT( size() == (*rhs).size(), "Invalid vector sizes" );
5820 BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
5821
5822 for( size_t i=0UL; i<size(); ++i )
5823 {
5824 if( matrix_.nonZeros( column() ) == matrix_.capacity( column() ) )
5825 matrix_.reserve( column(), extendCapacity() );
5826
5827 matrix_.append( column(), i, (*rhs)[i], true );
5828 }
5829}
5831//*************************************************************************************************
5832
5833
5834//*************************************************************************************************
5846template< typename MT // Type of the sparse matrix
5847 , size_t... CCAs > // Compile time column arguments
5848template< typename VT > // Type of the right-hand side sparse vector
5849inline void Column<MT,false,false,true,CCAs...>::assign( const SparseVector<VT,false>& rhs )
5850{
5851 BLAZE_INTERNAL_ASSERT( size() == (*rhs).size(), "Invalid vector sizes" );
5852 BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
5853
5854 for( ConstIterator_t<VT> element=(*rhs).begin(); element!=(*rhs).end(); ++element ) {
5855 matrix_.append( column(), element->index(), element->value(), true );
5856 }
5857}
5859//*************************************************************************************************
5860
5861
5862//*************************************************************************************************
5874template< typename MT // Type of the sparse matrix
5875 , size_t... CCAs > // Compile time column arguments
5876template< typename VT > // Type of the right-hand side dense vector
5877inline void Column<MT,false,false,true,CCAs...>::addAssign( const DenseVector<VT,false>& rhs )
5878{
5879 using AddType = AddTrait_t< ResultType, ResultType_t<VT> >;
5880
5884
5885 BLAZE_INTERNAL_ASSERT( size() == (*rhs).size(), "Invalid vector sizes" );
5886
5887 const AddType tmp( serial( *this + (*rhs) ) );
5888 matrix_.reset( column() );
5889 assign( tmp );
5890}
5892//*************************************************************************************************
5893
5894
5895//*************************************************************************************************
5907template< typename MT // Type of the sparse matrix
5908 , size_t... CCAs > // Compile time column arguments
5909template< typename VT > // Type of the right-hand side sparse vector
5910inline void Column<MT,false,false,true,CCAs...>::addAssign( const SparseVector<VT,false>& rhs )
5911{
5912 using AddType = AddTrait_t< ResultType, ResultType_t<VT> >;
5913
5917
5918 BLAZE_INTERNAL_ASSERT( size() == (*rhs).size(), "Invalid vector sizes" );
5919
5920 const AddType tmp( serial( *this + (*rhs) ) );
5921 matrix_.reset( column() );
5922 matrix_.reserve( column(), tmp.nonZeros() );
5923 assign( tmp );
5924}
5926//*************************************************************************************************
5927
5928
5929//*************************************************************************************************
5941template< typename MT // Type of the sparse matrix
5942 , size_t... CCAs > // Compile time column arguments
5943template< typename VT > // Type of the right-hand side dense vector
5944inline void Column<MT,false,false,true,CCAs...>::subAssign( const DenseVector<VT,false>& rhs )
5945{
5946 using SubType = SubTrait_t< ResultType, ResultType_t<VT> >;
5947
5951
5952 BLAZE_INTERNAL_ASSERT( size() == (*rhs).size(), "Invalid vector sizes" );
5953
5954 const SubType tmp( serial( *this - (*rhs) ) );
5955 matrix_.reset( column() );
5956 assign( tmp );
5957}
5959//*************************************************************************************************
5960
5961
5962//*************************************************************************************************
5974template< typename MT // Type of the sparse matrix
5975 , size_t... CCAs > // Compile time column arguments
5976template< typename VT > // Type of the right-hand side sparse vector
5977inline void Column<MT,false,false,true,CCAs...>::subAssign( const SparseVector<VT,false>& rhs )
5978{
5979 using SubType = SubTrait_t< ResultType, ResultType_t<VT> >;
5980
5984
5985 BLAZE_INTERNAL_ASSERT( size() == (*rhs).size(), "Invalid vector sizes" );
5986
5987 const SubType tmp( serial( *this - (*rhs) ) );
5988 matrix_.reset( column() );
5989 matrix_.reserve( column(), tmp.nonZeros() );
5990 assign( tmp );
5991}
5993//*************************************************************************************************
5994
5995} // namespace blaze
5996
5997#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.
Header file for the implementation of the ColumnData class template.
Constraints on the storage order of matrix types.
Header file for the column trait.
Constraint on the transpose flag of vector 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.
Constraints on the storage order of matrix 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_COLUMN_VECTOR_TYPE(T)
Constraint on the data type.
Definition: ColumnVector.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 ColumnTrait< MT, CCAs... >::Type ColumnTrait_t
Auxiliary alias declaration for the ColumnTrait type trait.
Definition: ColumnTrait.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 Column base template.