Blaze 3.9
Loading...
Searching...
No Matches
CompressedVector.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_SPARSE_COMPRESSEDVECTOR_H_
36#define _BLAZE_MATH_SPARSE_COMPRESSEDVECTOR_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <algorithm>
44#include <utility>
45#include <blaze/math/Aliases.h>
53#include <blaze/math/Forward.h>
92#include <blaze/util/Assert.h>
98#include <blaze/util/EnableIf.h>
100#include <blaze/util/Memory.h>
101#include <blaze/util/Types.h>
105
106
107namespace blaze {
108
109//=================================================================================================
110//
111// CLASS DEFINITION
112//
113//=================================================================================================
114
115//*************************************************************************************************
215template< typename Type // Data type of the vector
216 , bool TF // Transpose flag
217 , typename Tag > // Type tag
219 : public SparseVector< CompressedVector<Type,TF,Tag>, TF >
220{
221 private:
222 //**Type definitions****************************************************************************
225 //**********************************************************************************************
226
227 //**Private class Element***********************************************************************
234 struct Element
235 : public ElementBase
236 {
237 //**Constructors*****************************************************************************
238 Element() = default;
239 Element( const Element& rhs ) = default;
240 Element( Element&& rhs ) = default;
241 //*******************************************************************************************
242
243 //**Assignment operators*********************************************************************
244 inline Element& operator=( const Element& rhs )
245 {
246 this->value_ = rhs.value_;
247 return *this;
248 }
249
250 inline Element& operator=( Element&& rhs )
251 {
252 this->value_ = std::move( rhs.value_ );
253 return *this;
254 }
255
256 template< typename Other >
257 inline auto operator=( const Other& rhs )
259 {
260 this->value_ = rhs.value();
261 return *this;
262 }
263
264 template< typename Other >
265 inline auto operator=( Other&& rhs )
268 {
269 this->value_ = std::move( rhs.value() );
270 return *this;
271 }
272
273 template< typename Other >
274 inline auto operator=( const Other& v )
276 {
277 this->value_ = v;
278 return *this;
279 }
280
281 template< typename Other >
282 inline auto operator=( Other&& v )
285 {
286 this->value_ = std::move( v );
287 return *this;
288 }
289 //*******************************************************************************************
290
291 //**Friend declarations**********************************************************************
292 friend class CompressedVector;
293 //*******************************************************************************************
294 };
296 //**********************************************************************************************
297
298 public:
299 //**Type definitions****************************************************************************
301 using BaseType = SparseVector<This,TF>;
302 using ResultType = This;
303
306
308 using TagType = Tag;
309 using ReturnType = const Type&;
311
313 using ConstReference = const Type&;
314 using Iterator = Element*;
315 using ConstIterator = const Element*;
316 //**********************************************************************************************
317
318 //**Rebind struct definition********************************************************************
321 template< typename NewType > // Data type of the other vector
325 //**********************************************************************************************
326
327 //**Resize struct definition********************************************************************
330 template< size_t NewN > // Number of elements of the other vector
334 //**********************************************************************************************
335
336 //**Compilation flags***************************************************************************
338
341 static constexpr bool smpAssignable = !IsSMPAssignable_v<Type>;
342 //**********************************************************************************************
343
344 //**Constructors********************************************************************************
347 inline CompressedVector() noexcept;
348 explicit inline CompressedVector( size_t size ) noexcept;
349 inline CompressedVector( size_t size, size_t nonzeros );
351
353 inline CompressedVector( CompressedVector&& sv ) noexcept;
354
355 template< typename VT > inline CompressedVector( const DenseVector<VT,TF>& dv );
356 template< typename VT > inline CompressedVector( const SparseVector<VT,TF>& sv );
358 //**********************************************************************************************
359
360 //**Destructor**********************************************************************************
365 //**********************************************************************************************
366
367 //**Data access functions***********************************************************************
370 inline Reference operator[]( size_t index ) noexcept;
371 inline ConstReference operator[]( size_t index ) const noexcept;
372 inline Reference at( size_t index );
373 inline ConstReference at( size_t index ) const;
374 inline Iterator begin () noexcept;
375 inline ConstIterator begin () const noexcept;
376 inline ConstIterator cbegin() const noexcept;
377 inline Iterator end () noexcept;
378 inline ConstIterator end () const noexcept;
379 inline ConstIterator cend () const noexcept;
381 //**********************************************************************************************
382
383 //**Assignment operators************************************************************************
386 inline CompressedVector& operator=( initializer_list<Type> list ) &;
387 inline CompressedVector& operator=( const CompressedVector& rhs ) &;
388 inline CompressedVector& operator=( CompressedVector&& rhs ) & noexcept;
389
390 template< typename VT > inline CompressedVector& operator= ( const DenseVector<VT,TF>& rhs ) &;
391 template< typename VT > inline CompressedVector& operator= ( const SparseVector<VT,TF>& rhs ) &;
392 template< typename VT > inline CompressedVector& operator+=( const Vector<VT,TF>& rhs ) &;
393 template< typename VT > inline CompressedVector& operator-=( const Vector<VT,TF>& rhs ) &;
394 template< typename VT > inline CompressedVector& operator*=( const DenseVector<VT,TF>& rhs ) &;
395 template< typename VT > inline CompressedVector& operator*=( const SparseVector<VT,TF>& rhs ) &;
396 template< typename VT > inline CompressedVector& operator/=( const DenseVector<VT,TF>& rhs ) &;
397 template< typename VT > inline CompressedVector& operator%=( const Vector<VT,TF>& rhs ) &;
399 //**********************************************************************************************
400
401 //**Utility functions***************************************************************************
404 inline size_t size() const noexcept;
405 inline size_t capacity() const noexcept;
406 inline size_t nonZeros() const;
407 inline void reset();
408 inline void clear();
409 inline void resize( size_t n, bool preserve=true );
410 void reserve( size_t n );
411 inline void shrinkToFit();
412 inline void swap( CompressedVector& sv ) noexcept;
414 //**********************************************************************************************
415
416 //**Insertion functions*************************************************************************
419 inline Iterator set ( size_t index, const Type& value );
420 inline Iterator insert( size_t index, const Type& value );
421 inline void append( size_t index, const Type& value, bool check=false );
423 //**********************************************************************************************
424
425 //**Erase functions*****************************************************************************
428 inline void erase( size_t index );
429 inline Iterator erase( Iterator pos );
430 inline Iterator erase( Iterator first, Iterator last );
431
432 template< typename Pred, typename = DisableIf_t< IsIntegral_v<Pred> > >
433 inline void erase( Pred predicate );
434
435 template< typename Pred >
436 inline void erase( Iterator first, Iterator last, Pred predicate );
438 //**********************************************************************************************
439
440 //**Lookup functions****************************************************************************
443 inline Iterator find ( size_t index );
444 inline ConstIterator find ( size_t index ) const;
445 inline Iterator lowerBound( size_t index );
446 inline ConstIterator lowerBound( size_t index ) const;
447 inline Iterator upperBound( size_t index );
448 inline ConstIterator upperBound( size_t index ) const;
450 //**********************************************************************************************
451
452 //**Numeric functions***************************************************************************
455 template< typename Other > inline CompressedVector& scale( const Other& scalar );
457 //**********************************************************************************************
458
459 //**Expression template evaluation functions****************************************************
462 template< typename Other > inline bool canAlias ( const Other* alias ) const noexcept;
463 template< typename Other > inline bool isAliased( const Other* alias ) const noexcept;
464
465 inline bool canSMPAssign() const noexcept;
466
467 template< typename VT > inline void assign ( const DenseVector <VT,TF>& rhs );
468 template< typename VT > inline void assign ( const SparseVector<VT,TF>& rhs );
469 template< typename VT > inline void addAssign ( const DenseVector <VT,TF>& rhs );
470 template< typename VT > inline void addAssign ( const SparseVector<VT,TF>& rhs );
471 template< typename VT > inline void subAssign ( const DenseVector <VT,TF>& rhs );
472 template< typename VT > inline void subAssign ( const SparseVector<VT,TF>& rhs );
473 template< typename VT > inline void multAssign( const DenseVector <VT,TF>& rhs );
474 template< typename VT > inline void divAssign ( const DenseVector <VT,TF>& rhs );
476 //**********************************************************************************************
477
478 private:
479 //**Utility functions***************************************************************************
482 inline size_t extendCapacity() const noexcept;
483 inline Iterator castDown( IteratorBase it ) const noexcept;
484 inline IteratorBase castUp ( Iterator it ) const noexcept;
486 //**********************************************************************************************
487
488 //**Insertion functions***************************************************************************
491 Iterator insert( Iterator pos, size_t index, const Type& value );
493 //**********************************************************************************************
494
495 //**Member variables****************************************************************************
498 size_t size_;
499 size_t capacity_;
502
503 static const Type zero_;
505 //**********************************************************************************************
506
507 //**Compile time checks*************************************************************************
515 //**********************************************************************************************
516};
517//*************************************************************************************************
518
519
520
521
522//=================================================================================================
523//
524// DEFINITION AND INITIALIZATION OF THE STATIC MEMBER VARIABLES
525//
526//=================================================================================================
527
528template< typename Type // Data type of the vector
529 , bool TF // Transpose flag
530 , typename Tag > // Type tag
531const Type CompressedVector<Type,TF,Tag>::zero_{};
532
533
534
535
536//=================================================================================================
537//
538// CONSTRUCTORS
539//
540//=================================================================================================
541
542//*************************************************************************************************
545template< typename Type // Data type of the vector
546 , bool TF // Transpose flag
547 , typename Tag > // Type tag
549 : size_ ( 0UL ) // The current size/dimension of the compressed vector
550 , capacity_( 0UL ) // The maximum capacity of the compressed vector
551 , begin_ ( nullptr ) // Pointer to the first non-zero element of the compressed vector
552 , end_ ( nullptr ) // Pointer to the last non-zero element of the compressed vector
553{}
554//*************************************************************************************************
555
556
557//*************************************************************************************************
562template< typename Type // Data type of the vector
563 , bool TF // Transpose flag
564 , typename Tag > // Type tag
566 : size_ ( n ) // The current size/dimension of the compressed vector
567 , capacity_( 0UL ) // The maximum capacity of the compressed vector
568 , begin_ ( nullptr ) // Pointer to the first non-zero element of the compressed vector
569 , end_ ( nullptr ) // Pointer to the last non-zero element of the compressed vector
570{}
571//*************************************************************************************************
572
573
574//*************************************************************************************************
580template< typename Type // Data type of the vector
581 , bool TF // Transpose flag
582 , typename Tag > // Type tag
583inline CompressedVector<Type,TF,Tag>::CompressedVector( size_t n, size_t nonzeros )
584 : size_ ( n ) // The current size/dimension of the compressed vector
585 , capacity_( nonzeros ) // The maximum capacity of the compressed vector
586 , begin_ ( allocate<Element>( capacity_ ) ) // Pointer to the first non-zero element of the compressed vector
587 , end_ ( begin_ ) // Pointer to the last non-zero element of the compressed vector
588{}
589//*************************************************************************************************
590
591
592//*************************************************************************************************
607template< typename Type // Data type of the vector
608 , bool TF // Transpose flag
609 , typename Tag > // Type tag
611 : CompressedVector( list.size(), blaze::nonZeros( list ) )
612{
613 size_t i( 0UL );
614
615 for( const Type& element : list ) {
616 if( !isDefault<strict>( element ) )
617 append( i, element );
618 ++i;
619 }
620}
621//*************************************************************************************************
622
623
624//*************************************************************************************************
632template< typename Type // Data type of the vector
633 , bool TF // Transpose flag
634 , typename Tag > // Type tag
636 : CompressedVector( sv.size_, sv.nonZeros() )
637{
639 std::copy( sv.begin_, sv.end_, castUp( begin_ ) );
640}
641//*************************************************************************************************
642
643
644//*************************************************************************************************
649template< typename Type // Data type of the vector
650 , bool TF // Transpose flag
651 , typename Tag > // Type tag
653 : size_ ( sv.size_ ) // The current size/dimension of the compressed vector
654 , capacity_( sv.capacity_ ) // The maximum capacity of the compressed vector
655 , begin_ ( sv.begin_ ) // Pointer to the first non-zero element of the compressed vector
656 , end_ ( sv.end_ ) // Pointer to the last non-zero element of the compressed vector
657{
658 sv.size_ = 0UL;
659 sv.capacity_ = 0UL;
660 sv.begin_ = nullptr;
661 sv.end_ = nullptr;
662}
663//*************************************************************************************************
664
665
666//*************************************************************************************************
671template< typename Type // Data type of the vector
672 , bool TF // Transpose flag
673 , typename Tag > // Type tag
674template< typename VT > // Type of the foreign dense vector
676 : CompressedVector( (*dv).size() )
677{
678 using blaze::assign;
679
681
682 assign( *this, *dv );
683}
684//*************************************************************************************************
685
686
687//*************************************************************************************************
692template< typename Type // Data type of the vector
693 , bool TF // Transpose flag
694 , typename Tag > // Type tag
695template< typename VT > // Type of the foreign sparse vector
696inline CompressedVector<Type,TF,Tag>::CompressedVector( const SparseVector<VT,TF>& sv )
697 : CompressedVector( (*sv).size(), (*sv).nonZeros() )
698{
699 using blaze::assign;
700
702
703 assign( *this, *sv );
704}
705//*************************************************************************************************
706
707
708
709
710//=================================================================================================
711//
712// DESTRUCTOR
713//
714//=================================================================================================
715
716//*************************************************************************************************
719template< typename Type // Data type of the vector
720 , bool TF // Transpose flag
721 , typename Tag > // Type tag
726//*************************************************************************************************
727
728
729
730
731//=================================================================================================
732//
733// DATA ACCESS FUNCTIONS
734//
735//=================================================================================================
736
737//*************************************************************************************************
748template< typename Type // Data type of the vector
749 , bool TF // Transpose flag
750 , typename Tag > // Type tag
753{
754 BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
755
756 return Reference( *this, index );
757}
758//*************************************************************************************************
759
760
761//*************************************************************************************************
767template< typename Type // Data type of the vector
768 , bool TF // Transpose flag
769 , typename Tag > // Type tag
771 CompressedVector<Type,TF,Tag>::operator[]( size_t index ) const noexcept
772{
773 BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
774
775 const ConstIterator pos( lowerBound( index ) );
776
777 if( pos == end_ || pos->index_ != index )
778 return zero_;
779 else
780 return pos->value_;
781}
782//*************************************************************************************************
783
784
785//*************************************************************************************************
797template< typename Type // Data type of the vector
798 , bool TF // Transpose flag
799 , typename Tag > // Type tag
802{
803 if( index >= size_ ) {
804 BLAZE_THROW_OUT_OF_RANGE( "Invalid compressed vector access index" );
805 }
806 return (*this)[index];
807}
808//*************************************************************************************************
809
810
811//*************************************************************************************************
821template< typename Type // Data type of the vector
822 , bool TF // Transpose flag
823 , typename Tag > // Type tag
826{
827 if( index >= size_ ) {
828 BLAZE_THROW_OUT_OF_RANGE( "Invalid compressed vector access index" );
829 }
830 return (*this)[index];
831}
832//*************************************************************************************************
833
834
835//*************************************************************************************************
840template< typename Type // Data type of the vector
841 , bool TF // Transpose flag
842 , typename Tag > // Type tag
845{
846 return Iterator( begin_ );
847}
848//*************************************************************************************************
849
850
851//*************************************************************************************************
856template< typename Type // Data type of the vector
857 , bool TF // Transpose flag
858 , typename Tag > // Type tag
861{
862 return ConstIterator( begin_ );
863}
864//*************************************************************************************************
865
866
867//*************************************************************************************************
872template< typename Type // Data type of the vector
873 , bool TF // Transpose flag
874 , typename Tag > // Type tag
877{
878 return ConstIterator( begin_ );
879}
880//*************************************************************************************************
881
882
883//*************************************************************************************************
888template< typename Type // Data type of the vector
889 , bool TF // Transpose flag
890 , typename Tag > // Type tag
893{
894 return Iterator( end_ );
895}
896//*************************************************************************************************
897
898
899//*************************************************************************************************
904template< typename Type // Data type of the vector
905 , bool TF // Transpose flag
906 , typename Tag > // Type tag
909{
910 return ConstIterator( end_ );
911}
912//*************************************************************************************************
913
914
915//*************************************************************************************************
920template< typename Type // Data type of the vector
921 , bool TF // Transpose flag
922 , typename Tag > // Type tag
925{
926 return ConstIterator( end_ );
927}
928//*************************************************************************************************
929
930
931
932
933//=================================================================================================
934//
935// ASSIGNMENT OPERATORS
936//
937//=================================================================================================
938
939//*************************************************************************************************
955template< typename Type // Data type of the vector
956 , bool TF // Transpose flag
957 , typename Tag > // Type tag
960{
961 using blaze::nonZeros;
962
963 resize( list.size(), false );
964 reserve( nonZeros( list ) );
965
966 size_t i( 0UL );
967
968 for( const Type& element : list ) {
969 if( !isDefault<strict>( element ) )
970 append( i, element );
971 ++i;
972 }
973
974 return *this;
975}
976//*************************************************************************************************
977
978
979//*************************************************************************************************
988template< typename Type // Data type of the vector
989 , bool TF // Transpose flag
990 , typename Tag > // Type tag
993{
994 using std::swap;
995
996 if( &rhs == this ) return *this;
997
998 const size_t nonzeros( rhs.nonZeros() );
999
1000 if( nonzeros > capacity_ ) {
1001 Iterator newBegin( allocate<Element>( nonzeros ) );
1002 end_ = castDown( std::copy( rhs.begin_, rhs.end_, castUp( newBegin ) ) );
1003 swap( begin_, newBegin );
1004 deallocate( newBegin );
1005
1006 size_ = rhs.size_;
1007 capacity_ = nonzeros;
1008 }
1009 else {
1010 end_ = castDown( std::copy( rhs.begin_, rhs.end_, castUp( begin_ ) ) );
1011 size_ = rhs.size_;
1012 }
1013
1014 return *this;
1015}
1016//*************************************************************************************************
1017
1018
1019//*************************************************************************************************
1025template< typename Type // Data type of the vector
1026 , bool TF // Transpose flag
1027 , typename Tag > // Type tag
1030{
1031 deallocate( begin_ );
1032
1033 size_ = rhs.size_;
1034 capacity_ = rhs.capacity_;
1035 begin_ = rhs.begin_;
1036 end_ = rhs.end_;
1037
1038 rhs.size_ = 0UL;
1039 rhs.capacity_ = 0UL;
1040 rhs.begin_ = nullptr;
1041 rhs.end_ = nullptr;
1042
1043 return *this;
1044}
1045//*************************************************************************************************
1046
1047
1048//*************************************************************************************************
1057template< typename Type // Data type of the vector
1058 , bool TF // Transpose flag
1059 , typename Tag > // Type tag
1060template< typename VT > // Type of the right-hand side dense vector
1063{
1064 using blaze::assign;
1065
1067
1068 if( (*rhs).canAlias( this ) ) {
1069 CompressedVector tmp( *rhs );
1070 swap( tmp );
1071 }
1072 else {
1073 size_ = (*rhs).size();
1074 end_ = begin_;
1075 assign( *this, *rhs );
1076 }
1077
1078 return *this;
1079}
1080//*************************************************************************************************
1081
1082
1083//*************************************************************************************************
1092template< typename Type // Data type of the vector
1093 , bool TF // Transpose flag
1094 , typename Tag > // Type tag
1095template< typename VT > // Type of the right-hand side sparse vector
1097 CompressedVector<Type,TF,Tag>::operator=( const SparseVector<VT,TF>& rhs ) &
1098{
1099 using blaze::assign;
1100
1102
1103 if( (*rhs).canAlias( this ) || (*rhs).nonZeros() > capacity_ ) {
1104 CompressedVector tmp( *rhs );
1105 swap( tmp );
1106 }
1107 else {
1108 size_ = (*rhs).size();
1109 end_ = begin_;
1110
1111 if( !IsZero_v<VT> ) {
1112 assign( *this, *rhs );
1113 }
1114 }
1115
1116 return *this;
1117}
1118//*************************************************************************************************
1119
1120
1121//*************************************************************************************************
1131template< typename Type // Data type of the vector
1132 , bool TF // Transpose flag
1133 , typename Tag > // Type tag
1134template< typename VT > // Type of the right-hand side vector
1136 CompressedVector<Type,TF,Tag>::operator+=( const Vector<VT,TF>& rhs ) &
1137{
1138 using blaze::addAssign;
1139
1141
1142 if( (*rhs).size() != size_ ) {
1143 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1144 }
1145
1146 if( !IsZero_v<VT> ) {
1147 addAssign( *this, *rhs );
1148 }
1149
1150 return *this;
1151}
1152//*************************************************************************************************
1153
1154
1155//*************************************************************************************************
1165template< typename Type // Data type of the vector
1166 , bool TF // Transpose flag
1167 , typename Tag > // Type tag
1168template< typename VT > // Type of the right-hand side vector
1170 CompressedVector<Type,TF,Tag>::operator-=( const Vector<VT,TF>& rhs ) &
1171{
1172 using blaze::subAssign;
1173
1175
1176 if( (*rhs).size() != size_ ) {
1177 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1178 }
1179
1180 if( !IsZero_v<VT> ) {
1181 subAssign( *this, *rhs );
1182 }
1183
1184 return *this;
1185}
1186//*************************************************************************************************
1187
1188
1189//*************************************************************************************************
1200template< typename Type // Data type of the vector
1201 , bool TF // Transpose flag
1202 , typename Tag > // Type tag
1203template< typename VT > // Type of the right-hand side vector
1205 CompressedVector<Type,TF,Tag>::operator*=( const DenseVector<VT,TF>& rhs ) &
1206{
1207 using blaze::multAssign;
1208
1210
1211 if( (*rhs).size() != size_ ) {
1212 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1213 }
1214
1215 if( (*rhs).canAlias( this ) ) {
1216 CompressedVector tmp( *this * (*rhs) );
1217 swap( tmp );
1218 }
1219 else {
1220 CompositeType_t<VT> tmp( *rhs );
1221 multAssign( *this, tmp );
1222 }
1223
1224 return *this;
1225}
1226//*************************************************************************************************
1227
1228
1229//*************************************************************************************************
1240template< typename Type // Data type of the vector
1241 , bool TF // Transpose flag
1242 , typename Tag > // Type tag
1243template< typename VT > // Type of the right-hand side vector
1245 CompressedVector<Type,TF,Tag>::operator*=( const SparseVector<VT,TF>& rhs ) &
1246{
1248
1249 if( (*rhs).size() != size_ ) {
1250 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1251 }
1252
1253 if( !IsZero_v<VT> ) {
1254 CompressedVector tmp( *this * (*rhs) );
1255 swap( tmp );
1256 }
1257 else {
1258 reset();
1259 }
1260
1261 return *this;
1262}
1263//*************************************************************************************************
1264
1265
1266//*************************************************************************************************
1276template< typename Type // Data type of the vector
1277 , bool TF // Transpose flag
1278 , typename Tag > // Type tag
1279template< typename VT > // Type of the right-hand side vector
1281 CompressedVector<Type,TF,Tag>::operator/=( const DenseVector<VT,TF>& rhs ) &
1282{
1283 using blaze::divAssign;
1284
1286
1287 if( (*rhs).size() != size_ ) {
1288 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1289 }
1290
1291 if( (*rhs).canAlias( this ) ) {
1292 CompressedVector tmp( *this / (*rhs) );
1293 swap( tmp );
1294 }
1295 else {
1296 CompositeType_t<VT> tmp( *rhs );
1297 divAssign( *this, tmp );
1298 }
1299
1300 return *this;
1301}
1302//*************************************************************************************************
1303
1304
1305//*************************************************************************************************
1316template< typename Type // Data type of the vector
1317 , bool TF // Transpose flag
1318 , typename Tag > // Type tag
1319template< typename VT > // Type of the right-hand side vector
1321 CompressedVector<Type,TF,Tag>::operator%=( const Vector<VT,TF>& rhs ) &
1322{
1323 using blaze::assign;
1324
1326
1329
1330 using CrossType = CrossTrait_t< This, ResultType_t<VT> >;
1331
1335
1336 if( size_ != 3UL || (*rhs).size() != 3UL ) {
1337 BLAZE_THROW_INVALID_ARGUMENT( "Invalid vector size for cross product" );
1338 }
1339
1340 if( !IsZero_v<VT> ) {
1341 const CrossType tmp( *this % (*rhs) );
1342 reset();
1343 assign( *this, tmp );
1344 }
1345 else {
1346 reset();
1347 }
1348
1349 return *this;
1350}
1351//*************************************************************************************************
1352
1353
1354
1355
1356//=================================================================================================
1357//
1358// UTILITY FUNCTIONS
1359//
1360//=================================================================================================
1361
1362//*************************************************************************************************
1367template< typename Type // Data type of the vector
1368 , bool TF // Transpose flag
1369 , typename Tag > // Type tag
1370inline size_t CompressedVector<Type,TF,Tag>::size() const noexcept
1371{
1372 return size_;
1373}
1374//*************************************************************************************************
1375
1376
1377//*************************************************************************************************
1382template< typename Type // Data type of the vector
1383 , bool TF // Transpose flag
1384 , typename Tag > // Type tag
1385inline size_t CompressedVector<Type,TF,Tag>::capacity() const noexcept
1386{
1387 return capacity_;
1388}
1389//*************************************************************************************************
1390
1391
1392//*************************************************************************************************
1400template< typename Type // Data type of the vector
1401 , bool TF // Transpose flag
1402 , typename Tag > // Type tag
1404{
1405 return end_ - begin_;
1406}
1407//*************************************************************************************************
1408
1409
1410//*************************************************************************************************
1415template< typename Type // Data type of the vector
1416 , bool TF // Transpose flag
1417 , typename Tag > // Type tag
1419{
1420 end_ = begin_;
1421}
1422//*************************************************************************************************
1423
1424
1425//*************************************************************************************************
1432template< typename Type // Data type of the vector
1433 , bool TF // Transpose flag
1434 , typename Tag > // Type tag
1436{
1437 size_ = 0UL;
1438 end_ = begin_;
1439}
1440//*************************************************************************************************
1441
1442
1443//*************************************************************************************************
1457template< typename Type // Data type of the vector
1458 , bool TF // Transpose flag
1459 , typename Tag > // Type tag
1460inline void CompressedVector<Type,TF,Tag>::resize( size_t n, bool preserve )
1461{
1462 if( preserve ) {
1463 end_ = lowerBound( n );
1464 }
1465 else {
1466 end_ = begin_;
1467 }
1468
1469 size_ = n;
1470}
1471//*************************************************************************************************
1472
1473
1474//*************************************************************************************************
1483template< typename Type // Data type of the vector
1484 , bool TF // Transpose flag
1485 , typename Tag > // Type tag
1487{
1488 using std::swap;
1489
1490 if( n > capacity_ ) {
1491 const size_t newCapacity( n );
1492
1493 // Allocating a new data and index array
1494 Iterator newBegin = allocate<Element>( newCapacity );
1495
1496 // Replacing the old data and index array
1497 end_ = castDown( transfer( begin_, end_, castUp( newBegin ) ) );
1498 swap( newBegin, begin_ );
1499 capacity_ = newCapacity;
1500 deallocate( newBegin );
1501 }
1502}
1503//*************************************************************************************************
1504
1505
1506//*************************************************************************************************
1515template< typename Type // Data type of the vector
1516 , bool TF // Transpose flag
1517 , typename Tag > // Type tag
1519{
1520 if( nonZeros() < capacity_ ) {
1521 CompressedVector( *this ).swap( *this );
1522 }
1523}
1524//*************************************************************************************************
1525
1526
1527//*************************************************************************************************
1533template< typename Type // Data type of the vector
1534 , bool TF // Transpose flag
1535 , typename Tag > // Type tag
1537{
1538 using std::swap;
1539
1540 swap( size_, sv.size_ );
1541 swap( capacity_, sv.capacity_ );
1542 swap( begin_, sv.begin_ );
1543 swap( end_, sv.end_ );
1544}
1545//*************************************************************************************************
1546
1547
1548//*************************************************************************************************
1556template< typename Type // Data type of the vector
1557 , bool TF // Transpose flag
1558 , typename Tag > // Type tag
1560{
1561 using blaze::max;
1562 using blaze::min;
1563
1564 size_t nonzeros( 2UL*capacity_+1UL );
1565 nonzeros = max( nonzeros, 7UL );
1566 nonzeros = min( nonzeros, size_ );
1567
1568 BLAZE_INTERNAL_ASSERT( nonzeros > capacity_, "Invalid capacity value" );
1569
1570 return nonzeros;
1571}
1572//*************************************************************************************************
1573
1574
1575//*************************************************************************************************
1583template< typename Type // Data type of the vector
1584 , bool TF // Transpose flag
1585 , typename Tag > // Type tag
1588{
1589 return static_cast<Iterator>( it );
1590}
1591//*************************************************************************************************
1592
1593
1594//*************************************************************************************************
1602template< typename Type // Data type of the vector
1603 , bool TF // Transpose flag
1604 , typename Tag > // Type tag
1607{
1608 return static_cast<IteratorBase>( it );
1609}
1610//*************************************************************************************************
1611
1612
1613
1614
1615//=================================================================================================
1616//
1617// INSERTION FUNCTIONS
1618//
1619//=================================================================================================
1620
1621//*************************************************************************************************
1632template< typename Type // Data type of the vector
1633 , bool TF // Transpose flag
1634 , typename Tag > // Type tag
1636 CompressedVector<Type,TF,Tag>::set( size_t index, const Type& value )
1637{
1638 BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
1639
1640 const Iterator pos( lowerBound( index ) );
1641
1642 if( pos != end_ && pos->index_ == index ) {
1643 pos->value() = value;
1644 return pos;
1645 }
1646 else return insert( pos, index, value );
1647}
1648//*************************************************************************************************
1649
1650
1651//*************************************************************************************************
1663template< typename Type // Data type of the vector
1664 , bool TF // Transpose flag
1665 , typename Tag > // Type tag
1667 CompressedVector<Type,TF,Tag>::insert( size_t index, const Type& value )
1668{
1669 BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
1670
1671 const Iterator pos( lowerBound( index ) );
1672
1673 if( pos != end_ && pos->index_ == index ) {
1674 BLAZE_THROW_INVALID_ARGUMENT( "Bad access index" );
1675 }
1676
1677 return insert( pos, index, value );
1678}
1679//*************************************************************************************************
1680
1681
1682//*************************************************************************************************
1691template< typename Type // Data type of the vector
1692 , bool TF // Transpose flag
1693 , typename Tag > // Type tag
1695 CompressedVector<Type,TF,Tag>::insert( Iterator pos, size_t index, const Type& value )
1696{
1697 using std::swap;
1698
1699 if( nonZeros() != capacity_ ) {
1700 std::move_backward( pos, end_, castUp( end_+1 ) );
1701 pos->value_ = value;
1702 pos->index_ = index;
1703 ++end_;
1704
1705 return pos;
1706 }
1707 else {
1708 size_t newCapacity( extendCapacity() );
1709
1710 Iterator newBegin = allocate<Element>( newCapacity );
1711 Iterator tmp = castDown( std::move( begin_, pos, castUp( newBegin ) ) );
1712 tmp->value_ = value;
1713 tmp->index_ = index;
1714 end_ = castDown( std::move( pos, end_, castUp( tmp+1 ) ) );
1715
1716 swap( newBegin, begin_ );
1717 deallocate( newBegin );
1718 capacity_ = newCapacity;
1719
1720 return tmp;
1721 }
1722}
1723//*************************************************************************************************
1724
1725
1726//*************************************************************************************************
1750template< typename Type // Data type of the vector
1751 , bool TF // Transpose flag
1752 , typename Tag > // Type tag
1753inline void CompressedVector<Type,TF,Tag>::append( size_t index, const Type& value, bool check )
1754{
1755 BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
1756 BLAZE_USER_ASSERT( nonZeros() < capacity(), "Not enough reserved capacity" );
1757 BLAZE_USER_ASSERT( begin_ == end_ || (end_-1UL)->index_ < index, "Index is not strictly increasing" );
1758
1759 end_->value_ = value;
1760
1761 if( !check || !isDefault<strict>( end_->value_ ) ) {
1762 end_->index_ = index;
1763 ++end_;
1764 }
1765}
1766//*************************************************************************************************
1767
1768
1769
1770
1771//=================================================================================================
1772//
1773// ERASE FUNCTIONS
1774//
1775//=================================================================================================
1776
1777//*************************************************************************************************
1785template< typename Type // Data type of the vector
1786 , bool TF // Transpose flag
1787 , typename Tag > // Type tag
1788inline void CompressedVector<Type,TF,Tag>::erase( size_t index )
1789{
1790 BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
1791
1792 const Iterator pos( find( index ) );
1793 if( pos != end_ )
1794 end_ = castDown( std::move( pos+1, end_, castUp( pos ) ) );
1795}
1796//*************************************************************************************************
1797
1798
1799//*************************************************************************************************
1807template< typename Type // Data type of the vector
1808 , bool TF // Transpose flag
1809 , typename Tag > // Type tag
1812{
1813 BLAZE_USER_ASSERT( pos >= begin_ && pos <= end_, "Invalid compressed vector iterator" );
1814
1815 if( pos != end_ )
1816 end_ = castDown( std::move( pos+1, end_, castUp( pos ) ) );
1817 return pos;
1818}
1819//*************************************************************************************************
1820
1821
1822//*************************************************************************************************
1831template< typename Type // Data type of the vector
1832 , bool TF // Transpose flag
1833 , typename Tag > // Type tag
1836{
1837 BLAZE_USER_ASSERT( first <= last, "Invalid iterator range" );
1838 BLAZE_USER_ASSERT( first >= begin_ && first <= end_, "Invalid compressed vector iterator" );
1839 BLAZE_USER_ASSERT( last >= begin_ && last <= end_, "Invalid compressed vector iterator" );
1840
1841 if( first != last )
1842 end_ = castDown( std::move( last, end_, castUp( first ) ) );
1843 return first;
1844}
1845//*************************************************************************************************
1846
1847
1848//*************************************************************************************************
1869template< typename Type // Data type of the vector
1870 , bool TF // Transpose flag
1871 , typename Tag > // Type tag
1872template< typename Pred // Type of the unary predicate
1873 , typename > // Type restriction on the unary predicate
1874inline void CompressedVector<Type,TF,Tag>::erase( Pred predicate )
1875{
1876 end_ = castDown( std::remove_if( castUp( begin_ ), castUp( end_ ),
1877 [predicate=predicate]( const ElementBase& element ) {
1878 return predicate( element.value() );
1879 } ) );
1880}
1881//*************************************************************************************************
1882
1883
1884//*************************************************************************************************
1907template< typename Type // Data type of the vector
1908 , bool TF // Transpose flag
1909 , typename Tag > // Type tag
1910template< typename Pred > // Type of the unary predicate
1911inline void CompressedVector<Type,TF,Tag>::erase( Iterator first, Iterator last, Pred predicate )
1912{
1913 BLAZE_USER_ASSERT( first <= last, "Invalid iterator range" );
1914 BLAZE_USER_ASSERT( first >= begin_ && first <= end_, "Invalid compressed vector iterator" );
1915 BLAZE_USER_ASSERT( last >= begin_ && last <= end_, "Invalid compressed vector iterator" );
1916
1917 const auto pos = std::remove_if( castUp( first ), castUp( last ),
1918 [predicate=predicate]( const ElementBase& element ) {
1919 return predicate( element.value() );
1920 } );
1921
1922 end_ = castDown( std::move( last, end_, pos ) );
1923}
1924//*************************************************************************************************
1925
1926
1927
1928
1929//=================================================================================================
1930//
1931// LOOKUP FUNCTIONS
1932//
1933//=================================================================================================
1934
1935//*************************************************************************************************
1948template< typename Type // Data type of the vector
1949 , bool TF // Transpose flag
1950 , typename Tag > // Type tag
1953{
1954 return const_cast<Iterator>( const_cast<const This&>( *this ).find( index ) );
1955}
1956//*************************************************************************************************
1957
1958
1959//*************************************************************************************************
1972template< typename Type // Data type of the vector
1973 , bool TF // Transpose flag
1974 , typename Tag > // Type tag
1977{
1978 const ConstIterator pos( lowerBound( index ) );
1979 if( pos != end_ && pos->index_ == index )
1980 return pos;
1981 else return end_;
1982}
1983//*************************************************************************************************
1984
1985
1986//*************************************************************************************************
1998template< typename Type // Data type of the vector
1999 , bool TF // Transpose flag
2000 , typename Tag > // Type tag
2003{
2004 return const_cast<Iterator>( const_cast<const This&>( *this ).lowerBound( index ) );
2005}
2006//*************************************************************************************************
2007
2008
2009//*************************************************************************************************
2021template< typename Type // Data type of the vector
2022 , bool TF // Transpose flag
2023 , typename Tag > // Type tag
2026{
2027 return std::lower_bound( begin_, end_, index,
2028 []( const Element& element, size_t i )
2029 {
2030 return element.index() < i;
2031 } );
2032}
2033//*************************************************************************************************
2034
2035
2036//*************************************************************************************************
2048template< typename Type // Data type of the vector
2049 , bool TF // Transpose flag
2050 , typename Tag > // Type tag
2053{
2054 return const_cast<Iterator>( const_cast<const This&>( *this ).upperBound( index ) );
2055}
2056//*************************************************************************************************
2057
2058
2059//*************************************************************************************************
2071template< typename Type // Data type of the vector
2072 , bool TF // Transpose flag
2073 , typename Tag > // Type tag
2076{
2077 return std::upper_bound( begin_, end_, index,
2078 []( size_t i, const Element& element )
2079 {
2080 return i < element.index();
2081 } );
2082}
2083//*************************************************************************************************
2084
2085
2086
2087
2088//=================================================================================================
2089//
2090// NUMERIC FUNCTIONS
2091//
2092//=================================================================================================
2093
2094//*************************************************************************************************
2111template< typename Type // Data type of the vector
2112 , bool TF // Transpose flag
2113 , typename Tag > // Type tag
2114template< typename Other > // Data type of the scalar value
2115inline CompressedVector<Type,TF,Tag>& CompressedVector<Type,TF,Tag>::scale( const Other& scalar )
2116{
2117 for( auto element=begin_; element!=end_; ++element )
2118 element->value_ *= scalar;
2119 return *this;
2120}
2121//*************************************************************************************************
2122
2123
2124
2125
2126//=================================================================================================
2127//
2128// EXPRESSION TEMPLATE EVALUATION FUNCTIONS
2129//
2130//=================================================================================================
2131
2132//*************************************************************************************************
2142template< typename Type // Data type of the vector
2143 , bool TF // Transpose flag
2144 , typename Tag > // Type tag
2145template< typename Other > // Data type of the foreign expression
2146inline bool CompressedVector<Type,TF,Tag>::canAlias( const Other* alias ) const noexcept
2147{
2148 return static_cast<const void*>( this ) == static_cast<const void*>( alias );
2149}
2150//*************************************************************************************************
2151
2152
2153//*************************************************************************************************
2163template< typename Type // Data type of the vector
2164 , bool TF // Transpose flag
2165 , typename Tag > // Type tag
2166template< typename Other > // Data type of the foreign expression
2167inline bool CompressedVector<Type,TF,Tag>::isAliased( const Other* alias ) const noexcept
2168{
2169 return static_cast<const void*>( this ) == static_cast<const void*>( alias );
2170}
2171//*************************************************************************************************
2172
2173
2174//*************************************************************************************************
2184template< typename Type // Data type of the vector
2185 , bool TF // Transpose flag
2186 , typename Tag > // Type tag
2188{
2189 return false;
2190}
2191//*************************************************************************************************
2192
2193
2194//*************************************************************************************************
2205template< typename Type // Data type of the vector
2206 , bool TF // Transpose flag
2207 , typename Tag > // Type tag
2208template< typename VT > // Type of the right-hand side dense vector
2210{
2211 BLAZE_INTERNAL_ASSERT( size_ == (*rhs).size(), "Invalid vector sizes" );
2212 BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
2213
2214 size_t nonzeros( 0UL );
2215
2216 for( size_t i=0UL; i<size_; ++i )
2217 {
2218 if( nonzeros == capacity_ )
2220
2221 end_->value_ = (*rhs)[i];
2222
2223 if( !isDefault<strict>( end_->value_ ) ) {
2224 end_->index_ = i;
2225 ++end_;
2226 ++nonzeros;
2227 }
2228 }
2229}
2230//*************************************************************************************************
2231
2232
2233//*************************************************************************************************
2244template< typename Type // Data type of the vector
2245 , bool TF // Transpose flag
2246 , typename Tag > // Type tag
2247template< typename VT > // Type of the right-hand side sparse vector
2248inline void CompressedVector<Type,TF,Tag>::assign( const SparseVector<VT,TF>& rhs )
2249{
2250 BLAZE_INTERNAL_ASSERT( size_ == (*rhs).size(), "Invalid vector sizes" );
2251 BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
2252
2253 // Using the following formulation instead of a std::copy function call of the form
2254 //
2255 // end_ = std::copy( (*rhs).begin(), (*rhs).end(), begin_ );
2256 //
2257 // results in much less requirements on the ConstIterator type provided from the right-hand
2258 // sparse vector type
2259 for( auto element=(*rhs).begin(); element!=(*rhs).end(); ++element )
2260 append( element->index(), element->value() );
2261}
2262//*************************************************************************************************
2263
2264
2265//*************************************************************************************************
2276template< typename Type // Data type of the vector
2277 , bool TF // Transpose flag
2278 , typename Tag > // Type tag
2279template< typename VT > // Type of the right-hand side dense vector
2281{
2282 using AddType = AddTrait_t< This, ResultType_t<VT> >;
2283
2287
2288 BLAZE_INTERNAL_ASSERT( size_ == (*rhs).size(), "Invalid vector sizes" );
2289
2290 const AddType tmp( serial( *this + (*rhs) ) );
2291 reset();
2292 assign( tmp );
2293}
2294//*************************************************************************************************
2295
2296
2297//*************************************************************************************************
2308template< typename Type // Data type of the vector
2309 , bool TF // Transpose flag
2310 , typename Tag > // Type tag
2311template< typename VT > // Type of the right-hand side sparse vector
2312inline void CompressedVector<Type,TF,Tag>::addAssign( const SparseVector<VT,TF>& rhs )
2313{
2314 BLAZE_INTERNAL_ASSERT( size_ == (*rhs).size(), "Invalid vector sizes" );
2315
2316 CompressedVector tmp( serial( *this + (*rhs) ) );
2317 swap( tmp );
2318}
2319//*************************************************************************************************
2320
2321
2322//*************************************************************************************************
2333template< typename Type // Data type of the vector
2334 , bool TF // Transpose flag
2335 , typename Tag > // Type tag
2336template< typename VT > // Type of the right-hand side dense vector
2338{
2339 using SubType = SubTrait_t< This, ResultType_t<VT> >;
2340
2344
2345 BLAZE_INTERNAL_ASSERT( size_ == (*rhs).size(), "Invalid vector sizes" );
2346
2347 const SubType tmp( serial( *this - (*rhs) ) );
2348 reset();
2349 assign( tmp );
2350}
2351//*************************************************************************************************
2352
2353
2354//*************************************************************************************************
2365template< typename Type // Data type of the vector
2366 , bool TF // Transpose flag
2367 , typename Tag > // Type tag
2368template< typename VT > // Type of the right-hand side sparse vector
2369inline void CompressedVector<Type,TF,Tag>::subAssign( const SparseVector<VT,TF>& rhs )
2370{
2371 BLAZE_INTERNAL_ASSERT( size_ == (*rhs).size(), "Invalid vector sizes" );
2372
2373 CompressedVector tmp( serial( *this - (*rhs) ) );
2374 swap( tmp );
2375}
2376//*************************************************************************************************
2377
2378
2379//*************************************************************************************************
2390template< typename Type // Data type of the vector
2391 , bool TF // Transpose flag
2392 , typename Tag > // Type tag
2393template< typename VT > // Type of the right-hand side dense vector
2395{
2396 BLAZE_INTERNAL_ASSERT( size_ == (*rhs).size(), "Invalid vector sizes" );
2397
2399
2400 for( auto element=begin_; element!=end_; ++element ) {
2401 element->value_ *= (*rhs)[element->index_];
2402 }
2403}
2404//*************************************************************************************************
2405
2406
2407//*************************************************************************************************
2418template< typename Type // Data type of the vector
2419 , bool TF // Transpose flag
2420 , typename Tag > // Type tag
2421template< typename VT > // Type of the right-hand side dense vector
2423{
2424 BLAZE_INTERNAL_ASSERT( size_ == (*rhs).size(), "Invalid vector sizes" );
2425
2427
2428 for( auto element=begin_; element!=end_; ++element ) {
2429 element->value_ /= (*rhs)[element->index_];
2430 }
2431}
2432//*************************************************************************************************
2433
2434
2435
2436
2437//=================================================================================================
2438//
2439// COMPRESSEDVECTOR OPERATORS
2440//
2441//=================================================================================================
2442
2443//*************************************************************************************************
2446template< RelaxationFlag RF, typename Type, bool TF, typename Tag >
2448
2449template< typename Type, bool TF, typename Tag >
2450bool isIntact( const CompressedVector<Type,TF,Tag>& v ) noexcept;
2451
2452template< typename Type, bool TF, typename Tag >
2455//*************************************************************************************************
2456
2457
2458//*************************************************************************************************
2482template< RelaxationFlag RF // Relaxation flag
2483 , typename Type // Data type of the vector
2484 , bool TF // Transpose flag
2485 , typename Tag > // Type tag
2487{
2488 return ( v.size() == 0UL );
2489}
2490//*************************************************************************************************
2491
2492
2493//*************************************************************************************************
2511template< typename Type // Data type of the vector
2512 , bool TF // Transpose flag
2513 , typename Tag > // Type tag
2514inline bool isIntact( const CompressedVector<Type,TF,Tag>& v ) noexcept
2515{
2516 return ( v.nonZeros() <= v.capacity() );
2517}
2518//*************************************************************************************************
2519
2520
2521//*************************************************************************************************
2529template< typename Type // Data type of the vector
2530 , bool TF // Transpose flag
2531 , typename Tag > // Type tag
2533{
2534 a.swap( b );
2535}
2536//*************************************************************************************************
2537
2538
2539
2540
2541//=================================================================================================
2542//
2543// ADDTRAIT SPECIALIZATIONS
2544//
2545//=================================================================================================
2546
2547//*************************************************************************************************
2549template< typename T1, typename T2 >
2550struct AddTraitEval2< T1, T2
2552{
2553 using Type = CompressedVector< AddTrait_t< ElementType_t<T1>, ElementType_t<T2> >
2555 , AddTrait_t< TagType_t<T1>, TagType_t<T2> > >;
2556};
2558//*************************************************************************************************
2559
2560
2561
2562
2563//=================================================================================================
2564//
2565// SUBTRAIT SPECIALIZATIONS
2566//
2567//=================================================================================================
2568
2569//*************************************************************************************************
2571template< typename T1, typename T2 >
2572struct SubTraitEval2< T1, T2
2574{
2578};
2580//*************************************************************************************************
2581
2582
2583
2584
2585//=================================================================================================
2586//
2587// MULTTRAIT SPECIALIZATIONS
2588//
2589//=================================================================================================
2590
2591//*************************************************************************************************
2593template< typename T1, typename T2 >
2594struct MultTraitEval2< T1, T2
2596{
2600};
2601
2602template< typename T1, typename T2 >
2603struct MultTraitEval2< T1, T2
2605{
2609};
2610
2611template< typename T1, typename T2 >
2612struct MultTraitEval2< T1, T2
2613 , EnableIf_t< ( ( IsRowVector_v<T1> && IsRowVector_v<T2> ) ||
2616{
2620};
2621
2622template< typename T1, typename T2 >
2623struct MultTraitEval2< T1, T2
2627{
2629 using MultTag = MultTrait_t< TagType_t<T1>, TagType_t<T2> >;
2630
2632 , false
2634};
2635
2636template< typename T1, typename T2 >
2637struct MultTraitEval2< T1, T2
2641{
2643 using MultTag = MultTrait_t< TagType_t<T1>, TagType_t<T2> >;
2644
2646 , true
2648};
2650//*************************************************************************************************
2651
2652
2653
2654
2655//=================================================================================================
2656//
2657// KRONTRAIT SPECIALIZATIONS
2658//
2659//=================================================================================================
2660
2661//*************************************************************************************************
2663template< typename T1 // Type of the left-hand side operand
2664 , typename T2 > // Type of the right-hand side operand
2665struct KronTraitEval2< T1, T2
2666 , EnableIf_t< IsVector_v<T1> &&
2669{
2673};
2675//*************************************************************************************************
2676
2677
2678
2679
2680//=================================================================================================
2681//
2682// DIVTRAIT SPECIALIZATIONS
2683//
2684//=================================================================================================
2685
2686//*************************************************************************************************
2688template< typename T1, typename T2 >
2689struct DivTraitEval2< T1, T2
2691{
2694 , DivTrait_t< TagType_t<T1>, T2 > >;
2695};
2696
2697template< typename T1, typename T2 >
2698struct DivTraitEval2< T1, T2
2700{
2704};
2706//*************************************************************************************************
2707
2708
2709
2710
2711//=================================================================================================
2712//
2713// MAPTRAIT SPECIALIZATIONS
2714//
2715//=================================================================================================
2716
2717//*************************************************************************************************
2719template< typename T, typename OP >
2720struct UnaryMapTraitEval2< T, OP
2722{
2723 using ElementType = decltype( std::declval<OP>()( std::declval< ElementType_t<T> >() ) );
2724
2725 using Type = CompressedVector< EvaluateTrait_t<ElementType>
2726 , TransposeFlag_v<T>
2727 , MapTrait_t< TagType_t<T>, OP > >;
2728};
2730//*************************************************************************************************
2731
2732
2733
2734
2735//=================================================================================================
2736//
2737// REPEATTRAIT SPECIALIZATIONS
2738//
2739//=================================================================================================
2740
2741//*************************************************************************************************
2743template< typename T, size_t R0 >
2744struct RepeatTraitEval2< T, R0, inf, inf
2746{
2747 using Type = CompressedVector< ElementType_t<T>
2748 , TransposeFlag_v<T>
2749 , TagType_t<T> >;
2750};
2752//*************************************************************************************************
2753
2754
2755
2756
2757//=================================================================================================
2758//
2759// HIGHTYPE SPECIALIZATIONS
2760//
2761//=================================================================================================
2762
2763//*************************************************************************************************
2765template< typename T1, bool TF, typename Tag, typename T2 >
2766struct HighType< CompressedVector<T1,TF,Tag>, CompressedVector<T2,TF,Tag> >
2767{
2768 using Type = CompressedVector< typename HighType<T1,T2>::Type, TF, Tag >;
2769};
2771//*************************************************************************************************
2772
2773
2774
2775
2776//=================================================================================================
2777//
2778// MATHTRAIT SPECIALIZATIONS
2779//
2780//=================================================================================================
2781
2782//*************************************************************************************************
2784template< typename T1, bool TF, typename Tag, typename T2 >
2785struct LowType< CompressedVector<T1,TF,Tag>, CompressedVector<T2,TF,Tag> >
2786{
2787 using Type = CompressedVector< typename LowType<T1,T2>::Type, TF, Tag >;
2788};
2790//*************************************************************************************************
2791
2792
2793
2794
2795//=================================================================================================
2796//
2797// SUBVECTORTRAIT SPECIALIZATIONS
2798//
2799//=================================================================================================
2800
2801//*************************************************************************************************
2803template< typename VT, size_t I, size_t N >
2804struct SubvectorTraitEval2< VT, I, N
2805 , EnableIf_t< IsSparseVector_v<VT> > >
2806{
2807 using Type = CompressedVector< RemoveConst_t< ElementType_t<VT> >
2808 , TransposeFlag_v<VT>
2809 , TagType_t<VT> >;
2810};
2812//*************************************************************************************************
2813
2814
2815
2816
2817//=================================================================================================
2818//
2819// ELEMENTSTRAIT SPECIALIZATIONS
2820//
2821//=================================================================================================
2822
2823//*************************************************************************************************
2825template< typename VT, size_t N >
2826struct ElementsTraitEval2< VT, N
2827 , EnableIf_t< IsSparseVector_v<VT> > >
2828{
2829 using Type = CompressedVector< RemoveConst_t< ElementType_t<VT> >
2830 , TransposeFlag_v<VT>
2831 , TagType_t<VT> >;
2832};
2834//*************************************************************************************************
2835
2836
2837
2838
2839//=================================================================================================
2840//
2841// ROWTRAIT SPECIALIZATIONS
2842//
2843//=================================================================================================
2844
2845//*************************************************************************************************
2847template< typename MT, size_t I >
2848struct RowTraitEval2< MT, I
2849 , EnableIf_t< IsSparseMatrix_v<MT> > >
2850{
2851 using Type = CompressedVector< RemoveConst_t< ElementType_t<MT> >
2852 , true
2853 , TagType_t<MT> >;
2854};
2856//*************************************************************************************************
2857
2858
2859
2860
2861//=================================================================================================
2862//
2863// COLUMNTRAIT SPECIALIZATIONS
2864//
2865//=================================================================================================
2866
2867//*************************************************************************************************
2869template< typename MT, size_t I >
2870struct ColumnTraitEval2< MT, I
2871 , EnableIf_t< IsSparseMatrix_v<MT> > >
2872{
2873 using Type = CompressedVector< RemoveConst_t< ElementType_t<MT> >
2874 , false
2875 , TagType_t<MT> >;
2876};
2878//*************************************************************************************************
2879
2880
2881
2882
2883//=================================================================================================
2884//
2885// BANDTRAIT SPECIALIZATIONS
2886//
2887//=================================================================================================
2888
2889//*************************************************************************************************
2891template< typename MT, ptrdiff_t I >
2892struct BandTraitEval2< MT, I
2893 , EnableIf_t< IsSparseMatrix_v<MT> > >
2894{
2895 using Type = CompressedVector< RemoveConst_t< ElementType_t<MT> >
2897 , TagType_t<MT> >;
2898};
2900//*************************************************************************************************
2901
2902} // namespace blaze
2903
2904#endif
Header file for the addition trait.
Header file for auxiliary alias declarations.
typename ResultType_t< T >::TagType TagType_t
Alias declaration for nested TagType type definitions.
Definition Aliases.h:530
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.
Definition Aliases.h:110
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.
Definition Aliases.h:190
typename T::ResultType ResultType_t
Alias declaration for nested ResultType type definitions.
Definition Aliases.h:450
Header file for run time assertion macros.
Header file for the band trait.
Header file for the column trait.
Constraint on the data type.
Header file for the cross product trait.
Header file for the division trait.
Header file for the elements trait.
Header file for the EnableIf class template.
Header file for the EvaluateTrait class template.
Header file for the HighType type trait.
Header file for the IntegralConstant class template.
Header file for the IsColumnVector type trait.
Header file for the isDefault shim.
Header file for the IsDenseVector type trait.
Header file for the IsFloatingPoint type trait.
Header file for the IsIntegral type trait.
Header file for the IsRowVector type trait.
Header file for the IsSMPAssignable type trait.
Header file for the IsScalar type trait.
Header file for the IsSparseMatrix type trait.
Header file for the IsSparseVector type trait.
Header file for the IsVector type trait.
Header file for the Kron product trait.
Header file for the LowType type trait.
Header file for the map trait.
Header file for memory allocation and deallocation functionality.
Header file for the multiplication trait.
Constraint on the data type.
Constraint on the data type.
Header file for the relaxation flag enumeration.
Header file for the RemoveConst type trait.
Header file for the repeat trait.
Header file for the row trait.
Constraint on the size of two data types.
Data type constraint.
Header file for the subtraction trait.
Header file for the subvector trait.
Header file for the generic transfer algorithm.
Header file for the ValueIndexPair class.
Header file for the VectorAccessProxy class.
Constraint on the data type.
Efficient implementation of an arbitrary sized sparse vector.
Definition CompressedVector.h:220
bool canAlias(const Other *alias) const noexcept
SparseVector< This, TF > BaseType
Base type of this CompressedVector instance.
Definition CompressedVector.h:301
Iterator insert(size_t index, const Type &value)
ConstIterator cbegin() const noexcept
const CompressedVector & CompositeType
Definition CompressedVector.h:310
Iterator begin_
Definition CompressedVector.h:500
void swap(CompressedVector &sv) noexcept
Iterator end_
Definition CompressedVector.h:501
Tag TagType
Definition CompressedVector.h:308
void subAssign(const DenseVector< VT, TF > &rhs)
void assign(const DenseVector< VT, TF > &rhs)
ConstIterator cend() const noexcept
This ResultType
Result type for expression template evaluations.
Definition CompressedVector.h:302
Type ElementType
Definition CompressedVector.h:307
Reference operator[](size_t index) noexcept
Subscript operator for the direct access to the compressed vector elements.
Definition CompressedVector.h:752
ElementBase * IteratorBase
Iterator over non-constant base elements.
Definition CompressedVector.h:224
bool isAliased(const Other *alias) const noexcept
size_t extendCapacity() const noexcept
static const Type zero_
Definition CompressedVector.h:503
void divAssign(const DenseVector< VT, TF > &rhs)
void multAssign(const DenseVector< VT, TF > &rhs)
void resize(size_t n, bool preserve=true)
Iterator castDown(IteratorBase it) const noexcept
void addAssign(const DenseVector< VT, TF > &rhs)
void append(size_t index, const Type &value, bool check=false)
IteratorBase castUp(Iterator it) const noexcept
CompressedVector() noexcept
The default constructor for CompressedVector.
Definition CompressedVector.h:548
const Type & ReturnType
Definition CompressedVector.h:309
Element * Iterator
Definition CompressedVector.h:314
static constexpr bool smpAssignable
Definition CompressedVector.h:341
~CompressedVector()
The destructor for CompressedVector.
Definition CompressedVector.h:722
VectorAccessProxy< This > Reference
Definition CompressedVector.h:312
ValueIndexPair< Type > ElementBase
Base class for the compressed vector element.
Definition CompressedVector.h:223
size_t size_
Definition CompressedVector.h:498
CompressedVector & operator=(initializer_list< Type > list) &
List assignment to all vector elements.
Definition CompressedVector.h:959
CompressedVector< Type,!TF, Tag > TransposeType
Transpose type for expression template evaluations.
Definition CompressedVector.h:305
size_t capacity_
Definition CompressedVector.h:499
CompressedVector< Type, TF, Tag > This
Type of this CompressedVector instance.
Definition CompressedVector.h:300
const Element * ConstIterator
Definition CompressedVector.h:315
const Type & ConstReference
Definition CompressedVector.h:313
Iterator set(size_t index, const Type &value)
Base class for N-dimensional dense vectors.
Definition DenseVector.h:77
Index-value-pair for sparse vectors and matrices.
Definition ValueIndexPair.h:75
constexpr Reference value() noexcept
Access to the current value of the value-index-pair.
Definition ValueIndexPair.h:370
Access proxy for sparse, N-dimensional vectors.
Definition VectorAccessProxy.h:101
Base class for N-dimensional vectors.
Definition Vector.h:82
Initializer list type of the Blaze library.
Constraint on the data type.
Constraint on the data type.
Header file for the DenseVector base class.
Header file for the SparseVector base class.
OutputIterator transfer(InputIterator first, InputIterator last, OutputIterator dest)
Transfers the elements from the given source range to the destination range.
Definition Transfer.h:71
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE(T)
Constraint on the data type.
Definition Volatile.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_POINTER_TYPE(T)
Constraint on the data type.
Definition Pointer.h:79
#define BLAZE_CONSTRAINT_MUST_HAVE_SAME_SIZE(T1, T2)
Constraint on the size of two data types.
Definition SameSize.h:60
#define BLAZE_CONSTRAINT_MUST_BE_REFERENCE_TYPE(T)
Constraint on the data type.
Definition Reference.h:60
#define BLAZE_CONSTRAINT_MUST_NOT_BE_CONST(T)
Constraint on the data type.
Definition Const.h:79
#define BLAZE_CONSTRAINT_MUST_BE_SAME_TAG(A, B)
Data type constraint.
Definition SameTag.h:68
#define BLAZE_CONSTRAINT_MUST_NOT_BE_REFERENCE_TYPE(T)
Constraint on the data type.
Definition Reference.h:79
decltype(auto) min(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the componentwise minimum of the dense matrices lhs and rhs.
Definition DMatDMatMapExpr.h:1339
decltype(auto) max(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the componentwise maximum of the dense matrices lhs and rhs.
Definition DMatDMatMapExpr.h:1375
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition DMatSerialExpr.h:812
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition DiagonalMatrix.h:207
void swap(DiagonalMatrix< MT, SO, DF > &a, DiagonalMatrix< MT, SO, DF > &b) noexcept
Swapping the contents of two matrices.
Definition DiagonalMatrix.h:225
bool isDefault(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the given diagonal matrix is in default state.
Definition DiagonalMatrix.h:169
#define BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION(T)
Constraint on the data type.
Definition RequiresEvaluation.h:81
#define BLAZE_CONSTRAINT_MUST_BE_VECTOR_WITH_TRANSPOSE_FLAG(T, TF)
Constraint on the data type.
Definition TransposeFlag.h:63
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE(T)
Constraint on the data type.
Definition DenseVector.h:61
typename CrossTrait< T1, T2 >::Type CrossTrait_t
Auxiliary alias declaration for the CrossTrait class template.
Definition CrossTrait.h:138
typename SubTrait< T1, T2 >::Type SubTrait_t
Auxiliary alias declaration for the SubTrait class template.
Definition SubTrait.h:163
typename AddTrait< T1, T2 >::Type AddTrait_t
Auxiliary alias declaration for the AddTrait class template.
Definition AddTrait.h:163
typename DivTrait< T1, T2 >::Type DivTrait_t
Auxiliary alias declaration for the DivTrait class template.
Definition DivTrait.h:164
typename MultTrait< T1, T2 >::Type MultTrait_t
Auxiliary alias declaration for the MultTrait class template.
Definition MultTrait.h:165
constexpr bool IsScalar_v
Auxiliary variable template for the IsScalar type trait.
Definition IsScalar.h:104
constexpr bool IsVector_v
Auxiliary variable template for the IsVector type trait.
Definition IsVector.h:125
constexpr bool IsZero_v
Auxiliary variable template for the IsZero type trait.
Definition IsZero.h:166
constexpr bool IsColumnVector_v
Auxiliary variable template for the IsColumnVector type trait.
Definition IsColumnVector.h:126
constexpr bool IsSparseMatrix_v
Auxiliary variable template for the IsSparseMatrix type trait.
Definition IsSparseMatrix.h:124
constexpr bool IsSMPAssignable_v
Auxiliary variable template for the IsSMPAssignable type trait.
Definition IsSMPAssignable.h:132
constexpr bool IsRowVector_v
Auxiliary variable template for the IsRowVector type trait.
Definition IsRowVector.h:126
constexpr bool IsSparseVector_v
Auxiliary variable template for the IsSparseVector type trait.
Definition IsSparseVector.h:124
constexpr bool TransposeFlag_v
Auxiliary variable template for the TransposeFlag type trait.
Definition TransposeFlag.h:93
constexpr bool IsDenseVector_v
Auxiliary variable template for the IsDenseVector type trait.
Definition IsDenseVector.h:124
RelaxationFlag
Relaxation flag for strict or relaxed semantics.
Definition RelaxationFlag.h:66
constexpr Infinity inf
Global Infinity instance.
Definition Infinity.h:1080
size_t nonZeros(const Matrix< MT, SO > &matrix)
Returns the total number of non-zero elements in the matrix.
Definition Matrix.h:730
#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
constexpr bool defaultTransposeFlag
The default transpose flag for all vectors of the Blaze library.
Definition TransposeFlag.h:75
constexpr bool IsRValueReference_v
Auxiliary variable template for the IsRValueReference type trait.
Definition IsRValueReference.h:97
constexpr bool IsIntegral_v
Auxiliary variable template for the IsIntegral type trait.
Definition IsIntegral.h:95
void deallocate(T *address) noexcept
Deallocation of memory for built-in data types.
Definition Memory.h:230
typename EnableIf< Condition, T >::Type EnableIf_t
Auxiliary type for the EnableIf class template.
Definition EnableIf.h:138
#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
T * allocate(size_t size)
Aligned array allocation for built-in data types.
Definition Memory.h:158
typename EnableIf<!Condition, T >::Type DisableIf_t
Auxiliary type for the EnableIf class template.
Definition EnableIf.h:175
Header file for the exception macros of the math module.
Header file for all forward declarations of the math module.
Header file for the extended initializer_list functionality.
Constraint on the data type.
Header file for all forward declarations for sparse vectors and matrices.
Header file for the TransposeFlag type trait.
Header file for the serial shim.
Rebind mechanism to obtain a CompressedVector with different data/element type.
Definition CompressedVector.h:322
CompressedVector< NewType, TF, Tag > Other
The type of the other CompressedVector.
Definition CompressedVector.h:323
Resize mechanism to obtain a CompressedVector with a different fixed number of elements.
Definition CompressedVector.h:331
CompressedVector< Type, TF, Tag > Other
The type of the other CompressedVector.
Definition CompressedVector.h:332
Base template for the HighType type trait.
Definition HighType.h:322
Base template for the LowType type trait.
Definition LowType.h:322
Header file for the thresholds for matrix/vector and matrix/matrix multiplications.
Header file for the default transpose flag for all vectors of the Blaze library.
Header file for the IsZero type trait.
Header file for basic type definitions.
Header file for the generic max algorithm.
Header file for the generic min algorithm.