Blaze 3.9
SparseVectorProxy.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_PROXY_SPARSEVECTORPROXY_H_
36#define _BLAZE_MATH_PROXY_SPARSEVECTORPROXY_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <blaze/math/Aliases.h>
50#include <blaze/system/Inline.h>
51#include <blaze/util/EnableIf.h>
52#include <blaze/util/Types.h>
54
55
56namespace blaze {
57
58//=================================================================================================
59//
60// CLASS DEFINITION
61//
62//=================================================================================================
63
64//*************************************************************************************************
72template< typename PT // Type of the proxy
73 , typename VT > // Type of the sparse vector
75 : public SparseVector< PT, IsRowVector_v<VT> >
76{
77 public:
78 //**Type definitions****************************************************************************
88 //**********************************************************************************************
89
90 //**Compilation flags***************************************************************************
92 static constexpr bool smpAssignable = VT::smpAssignable;
93 //**********************************************************************************************
94
95 //**Data access functions***********************************************************************
98 inline Reference operator[]( size_t index ) const;
99 inline Reference at( size_t index ) const;
100
101 inline Iterator begin () const;
102 inline ConstIterator cbegin() const;
103 inline Iterator end () const;
104 inline ConstIterator cend () const;
106 //**********************************************************************************************
107
108 //**Utility functions***************************************************************************
111 inline size_t size() const;
112 inline size_t capacity() const;
113 inline size_t nonZeros() const;
114 inline void reset() const;
115 inline void clear() const;
116 inline void resize( size_t n, bool preserve=true ) const;
117 inline void reserve( size_t n ) const;
119 //**********************************************************************************************
120
121 //**Insertion functions*************************************************************************
124 inline Iterator set ( size_t index, const ElementType& value ) const;
125 inline Iterator insert( size_t index, const ElementType& value ) const;
126 inline void append( size_t index, const ElementType& value, bool check=false ) const;
128 //**********************************************************************************************
129
130 //**Erase functions*****************************************************************************
133 inline void erase( size_t index ) const;
134 inline Iterator erase( Iterator pos ) const;
135 inline Iterator erase( Iterator first, Iterator last ) const;
136
137 template< typename Pred, typename = DisableIf_t< IsIntegral_v<Pred> > >
138 inline void erase( Pred predicate );
139
140 template< typename Pred >
141 inline void erase( Iterator first, Iterator last, Pred predicate );
143 //**********************************************************************************************
144
145 //**Lookup functions****************************************************************************
148 inline Iterator find ( size_t index ) const;
149 inline Iterator lowerBound( size_t index ) const;
150 inline Iterator upperBound( size_t index ) const;
152 //**********************************************************************************************
153
154 //**Numeric functions***************************************************************************
157 template< typename Other > inline void scale( const Other& scalar ) const;
159 //**********************************************************************************************
160
161 protected:
162 //**Special member functions********************************************************************
165 SparseVectorProxy() = default;
166 SparseVectorProxy( const SparseVectorProxy& ) = default;
168 ~SparseVectorProxy() = default;
169 SparseVectorProxy& operator=( const SparseVectorProxy& ) = default;
170 SparseVectorProxy& operator=( SparseVectorProxy&& ) = default;
172 //**********************************************************************************************
173
174 private:
175 //**Compile time checks*************************************************************************
179 //**********************************************************************************************
180};
181//*************************************************************************************************
182
183
184
185
186//=================================================================================================
187//
188// DATA ACCESS FUNCTIONS
189//
190//=================================================================================================
191
192//*************************************************************************************************
204template< typename PT // Type of the proxy
205 , typename VT > // Type of the sparse vector
208{
209 if( (**this).isRestricted() ) {
210 BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
211 }
212
213 return (**this).get()[index];
214}
215//*************************************************************************************************
216
217
218//*************************************************************************************************
231template< typename PT // Type of the proxy
232 , typename VT > // Type of the sparse vector
234 SparseVectorProxy<PT,VT>::at( size_t index ) const
235{
236 if( (**this).isRestricted() ) {
237 BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
238 }
239
240 return (**this).get().at( index );
241}
242//*************************************************************************************************
243
244
245//*************************************************************************************************
250template< typename PT // Type of the proxy
251 , typename VT > // Type of the sparse vector
253{
254 return (**this).get().begin();
255}
256//*************************************************************************************************
257
258
259//*************************************************************************************************
264template< typename PT // Type of the proxy
265 , typename VT > // Type of the sparse vector
267{
268 return (**this).get().cbegin();
269}
270//*************************************************************************************************
271
272
273//*************************************************************************************************
278template< typename PT // Type of the proxy
279 , typename VT > // Type of the sparse vector
281{
282 return (**this).get().end();
283}
284//*************************************************************************************************
285
286
287//*************************************************************************************************
292template< typename PT // Type of the proxy
293 , typename VT > // Type of the sparse vector
295{
296 return (**this).get().cend();
297}
298//*************************************************************************************************
299
300
301
302
303//=================================================================================================
304//
305// UTILITY FUNCTIONS
306//
307//=================================================================================================
308
309//*************************************************************************************************
314template< typename PT // Type of the proxy
315 , typename VT > // Type of the sparse vector
317{
318 return (**this).get().size();
319}
320//*************************************************************************************************
321
322
323//*************************************************************************************************
328template< typename PT // Type of the proxy
329 , typename VT > // Type of the sparse vector
331{
332 return (**this).get().capacity();
333}
334//*************************************************************************************************
335
336
337//*************************************************************************************************
345template< typename PT // Type of the proxy
346 , typename VT > // Type of the sparse vector
348{
349 return (**this).get().nonZeros();
350}
351//*************************************************************************************************
352
353
354//*************************************************************************************************
361template< typename PT // Type of the proxy
362 , typename VT > // Type of the sparse vector
364{
365 using blaze::reset;
366
367 reset( (**this).get() );
368}
369//*************************************************************************************************
370
371
372//*************************************************************************************************
379template< typename PT // Type of the proxy
380 , typename VT > // Type of the sparse vector
382{
383 using blaze::clear;
384
385 clear( (**this).get() );
386}
387//*************************************************************************************************
388
389
390//*************************************************************************************************
403template< typename PT // Type of the proxy
404 , typename VT > // Type of the sparse vector
406 SparseVectorProxy<PT,VT>::set( size_t index, const ElementType& value ) const
407{
408 if( (**this).isRestricted() ) {
409 BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
410 }
411
412 return (**this).get().set( index, value );
413}
414//*************************************************************************************************
415
416
417//*************************************************************************************************
430template< typename PT // Type of the proxy
431 , typename VT > // Type of the sparse vector
433 SparseVectorProxy<PT,VT>::insert( size_t index, const ElementType& value ) const
434{
435 if( (**this).isRestricted() ) {
436 BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
437 }
438
439 return (**this).get().insert( index, value );
440}
441//*************************************************************************************************
442
443
444//*************************************************************************************************
469template< typename PT // Type of the proxy
470 , typename VT > // Type of the sparse vector
471inline void SparseVectorProxy<PT,VT>::append( size_t index, const ElementType& value, bool check ) const
472{
473 if( (**this).isRestricted() ) {
474 BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
475 }
476
477 (**this).get().append( index, value, check );
478}
479//*************************************************************************************************
480
481
482//*************************************************************************************************
497template< typename PT // Type of the proxy
498 , typename VT > // Type of the sparse vector
499inline void SparseVectorProxy<PT,VT>::resize( size_t n, bool preserve ) const
500{
501 if( (**this).isRestricted() ) {
502 BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
503 }
504
505 (**this).get().resize( n, preserve );
506}
507//*************************************************************************************************
508
509
510//*************************************************************************************************
520template< typename PT // Type of the proxy
521 , typename VT > // Type of the sparse vector
522inline void SparseVectorProxy<PT,VT>::reserve( size_t n ) const
523{
524 if( (**this).isRestricted() ) {
525 BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
526 }
527
528 (**this).get().reserve( n );
529}
530//*************************************************************************************************
531
532
533//*************************************************************************************************
544template< typename PT // Type of the proxy
545 , typename VT > // Type of the sparse vector
546template< typename Other > // Data type of the scalar value
547inline void SparseVectorProxy<PT,VT>::scale( const Other& scalar ) const
548{
549 if( (**this).isRestricted() ) {
550 BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
551 }
552
553 (**this).get().scale( scalar );
554}
555//*************************************************************************************************
556
557
558
559
560//=================================================================================================
561//
562// ERASE FUNCTIONS
563//
564//=================================================================================================
565
566//*************************************************************************************************
575template< typename PT // Type of the proxy
576 , typename VT > // Type of the sparse vector
577inline void SparseVectorProxy<PT,VT>::erase( size_t index ) const
578{
579 if( (**this).isRestricted() ) {
580 BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
581 }
582
583 (**this).get().erase( index );
584}
585//*************************************************************************************************
586
587
588//*************************************************************************************************
597template< typename PT // Type of the proxy
598 , typename VT > // Type of the sparse vector
600{
601 if( (**this).isRestricted() ) {
602 BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
603 }
604
605 return (**this).get().erase( pos );
606}
607//*************************************************************************************************
608
609
610//*************************************************************************************************
620template< typename PT // Type of the proxy
621 , typename VT > // Type of the sparse vector
624{
625 if( (**this).isRestricted() ) {
626 BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
627 }
628
629 return (**this).get().erase( first, last );
630}
631//*************************************************************************************************
632
633
634//*************************************************************************************************
647template< typename PT // Type of the proxy
648 , typename VT > // Type of the sparse vector
649template< typename Pred // Type of the unary predicate
650 , typename > // Type restriction on the unary predicate
651inline void SparseVectorProxy<PT,VT>::erase( Pred predicate )
652{
653 if( (**this).isRestricted() ) {
654 BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
655 }
656
657 (**this).get().erase( predicate );
658}
659//*************************************************************************************************
660
661
662//*************************************************************************************************
677template< typename PT // Type of the proxy
678 , typename VT > // Type of the sparse vector
679template< typename Pred > // Type of the unary predicate
680inline void SparseVectorProxy<PT,VT>::erase( Iterator first, Iterator last, Pred predicate )
681{
682 if( (**this).isRestricted() ) {
683 BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
684 }
685
686 (**this).get().erase( first, last, predicate );
687}
688//*************************************************************************************************
689
690
691
692
693//=================================================================================================
694//
695// LOOKUP FUNCTIONS
696//
697//=================================================================================================
698
699//*************************************************************************************************
712template< typename PT // Type of the proxy
713 , typename VT > // Type of the sparse vector
715 SparseVectorProxy<PT,VT>::find( size_t index ) const
716{
717 return (**this).get().find( index );
718}
719//*************************************************************************************************
720
721
722//*************************************************************************************************
734template< typename PT // Type of the proxy
735 , typename VT > // Type of the sparse vector
738{
739 return (**this).get().lowerBound( index );
740}
741//*************************************************************************************************
742
743
744//*************************************************************************************************
756template< typename PT // Type of the proxy
757 , typename VT > // Type of the sparse vector
760{
761 return (**this).get().upperBound( index );
762}
763//*************************************************************************************************
764
765
766
767
768//=================================================================================================
769//
770// GLOBAL FUNCTIONS
771//
772//=================================================================================================
773
774//*************************************************************************************************
777template< typename PT, typename VT >
779 begin( const SparseVectorProxy<PT,VT>& proxy );
780
781template< typename PT, typename VT >
783 cbegin( const SparseVectorProxy<PT,VT>& proxy );
784
785template< typename PT, typename VT >
787 end( const SparseVectorProxy<PT,VT>& proxy );
788
789template< typename PT, typename VT >
791 cend( const SparseVectorProxy<PT,VT>& proxy );
792
793template< typename PT, typename VT >
794size_t size( const SparseVectorProxy<PT,VT>& proxy );
795
796template< typename PT, typename VT >
797size_t capacity( const SparseVectorProxy<PT,VT>& proxy );
798
799template< typename PT, typename VT >
800size_t nonZeros( const SparseVectorProxy<PT,VT>& proxy );
801
802template< typename PT, typename VT >
803void resize( const SparseVectorProxy<PT,VT>& proxy, size_t n, bool preserve=true );
804
805template< typename PT, typename VT >
807 find( const SparseVectorProxy<PT,VT>& proxy, size_t index );
808
809template< typename PT, typename VT >
811 lowerBound( const SparseVectorProxy<PT,VT>& proxy, size_t index );
812
813template< typename PT, typename VT >
815 upperBound( const SparseVectorProxy<PT,VT>& proxy, size_t index );
817//*************************************************************************************************
818
819
820//*************************************************************************************************
827template< typename PT // Type of the proxy
828 , typename VT > // Type of the sparse vector
831{
832 return proxy.begin();
833}
834//*************************************************************************************************
835
836
837//*************************************************************************************************
844template< typename PT // Type of the proxy
845 , typename VT > // Type of the sparse vector
848{
849 return proxy.cbegin();
850}
851//*************************************************************************************************
852
853
854//*************************************************************************************************
861template< typename PT // Type of the proxy
862 , typename VT > // Type of the sparse vector
865{
866 return proxy.end();
867}
868//*************************************************************************************************
869
870
871//*************************************************************************************************
878template< typename PT // Type of the proxy
879 , typename VT > // Type of the sparse vector
882{
883 return proxy.cend();
884}
885//*************************************************************************************************
886
887
888//*************************************************************************************************
895template< typename PT // Type of the proxy
896 , typename VT > // Type of the sparse vector
898{
899 return proxy.size();
900}
901//*************************************************************************************************
902
903
904//*************************************************************************************************
911template< typename PT // Type of the proxy
912 , typename VT > // Type of the sparse vector
914{
915 return proxy.capacity();
916}
917//*************************************************************************************************
918
919
920//*************************************************************************************************
930template< typename PT // Type of the proxy
931 , typename VT > // Type of the sparse vector
933{
934 return proxy.nonZeros();
935}
936//*************************************************************************************************
937
938
939//*************************************************************************************************
950template< typename PT // Type of the proxy
951 , typename VT > // Type of the sparse vector
952BLAZE_ALWAYS_INLINE void resize( const SparseVectorProxy<PT,VT>& proxy, size_t n, bool preserve )
953{
954 proxy.resize( n, preserve );
955}
956//*************************************************************************************************
957
958
959//*************************************************************************************************
967template< typename PT // Type of the proxy
968 , typename VT > // Type of the sparse vector
970 find( const SparseVectorProxy<PT,VT>& proxy, size_t index )
971{
972 return proxy.find( index );
973}
974//*************************************************************************************************
975
976
977//*************************************************************************************************
985template< typename PT // Type of the proxy
986 , typename VT > // Type of the sparse vector
988 lowerBound( const SparseVectorProxy<PT,VT>& proxy, size_t index )
989{
990 return proxy.lowerBound( index );
991}
992//*************************************************************************************************
993
994
995//*************************************************************************************************
1003template< typename PT // Type of the proxy
1004 , typename VT > // Type of the sparse vector
1006 upperBound( const SparseVectorProxy<PT,VT>& proxy, size_t index )
1007{
1008 return proxy.upperBound( index );
1009}
1010//*************************************************************************************************
1011
1012} // namespace blaze
1013
1014#endif
Header file for auxiliary alias declarations.
typename T::ConstReference ConstReference_t
Alias declaration for nested ConstReference type definitions.
Definition: Aliases.h:170
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.
Definition: Aliases.h:110
typename T::ReturnType ReturnType_t
Alias declaration for nested ReturnType type definitions.
Definition: Aliases.h:470
typename T::ResultType ResultType_t
Alias declaration for nested ResultType type definitions.
Definition: Aliases.h:450
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.
Definition: Aliases.h:190
typename T::Iterator Iterator_t
Alias declaration for nested Iterator type definitions.
Definition: Aliases.h:210
typename T::ConstIterator ConstIterator_t
Alias declaration for nested ConstIterator type definitions.
Definition: Aliases.h:130
typename T::Reference Reference_t
Alias declaration for nested Reference type definitions.
Definition: Aliases.h:390
typename T::TransposeType TransposeType_t
Alias declaration for nested TransposeType type definitions.
Definition: Aliases.h:550
Header file for the EnableIf class template.
Header file for the IsIntegral type trait.
Header file for the IsRowVector type trait.
Proxy backend for sparse vector types.
Definition: SparseVectorProxy.h:76
size_t size() const
Returns the current size/dimension of the represented vector.
Definition: SparseVectorProxy.h:316
Iterator_t< VT > Iterator
Iterator over non-constant elements.
Definition: SparseVectorProxy.h:86
void reserve(size_t n) const
Setting the minimum capacity of the represented vector.
Definition: SparseVectorProxy.h:522
Iterator end() const
Returns an iterator just past the last element of the represented vector.
Definition: SparseVectorProxy.h:280
Iterator insert(size_t index, const ElementType &value) const
Inserting an element into the represented sparse vector.
Definition: SparseVectorProxy.h:433
void scale(const Other &scalar) const
Scaling of the sparse vector by the scalar value scalar ( ).
Definition: SparseVectorProxy.h:547
Iterator find(size_t index) const
Searches for a specific vector element.
Definition: SparseVectorProxy.h:715
void clear() const
Clearing the represented vector.
Definition: SparseVectorProxy.h:381
size_t nonZeros() const
Returns the number of non-zero elements in the represented vector.
Definition: SparseVectorProxy.h:347
void resize(size_t n, bool preserve=true) const
Changing the size of the represented vector.
Definition: SparseVectorProxy.h:499
ConstIterator cend() const
Returns an iterator just past the last element of the represented vector.
Definition: SparseVectorProxy.h:294
static constexpr bool smpAssignable
Compilation flag for SMP assignments.
Definition: SparseVectorProxy.h:92
ConstReference_t< VT > ConstReference
Reference to a constant vector value.
Definition: SparseVectorProxy.h:85
Iterator upperBound(size_t index) const
Returns an iterator to the first index greater then the given index.
Definition: SparseVectorProxy.h:759
void erase(size_t index) const
Erasing an element from the sparse vector.
Definition: SparseVectorProxy.h:577
void reset() const
Reset to the default initial value.
Definition: SparseVectorProxy.h:363
ReturnType_t< VT > ReturnType
Return type for expression template evaluations.
Definition: SparseVectorProxy.h:82
Iterator lowerBound(size_t index) const
Returns an iterator to the first index not less then the given index.
Definition: SparseVectorProxy.h:737
ResultType_t< VT > ResultType
Result type for expression template evaluations.
Definition: SparseVectorProxy.h:79
Iterator begin() const
Returns an iterator to the first element of the represented vector.
Definition: SparseVectorProxy.h:252
void append(size_t index, const ElementType &value, bool check=false) const
Appending an element to the represented sparse vector.
Definition: SparseVectorProxy.h:471
ElementType_t< VT > ElementType
Type of the sparse vector elements.
Definition: SparseVectorProxy.h:81
size_t capacity() const
Returns the maximum capacity of the represented vector.
Definition: SparseVectorProxy.h:330
Reference at(size_t index) const
Checked access to the vector elements.
Definition: SparseVectorProxy.h:234
TransposeType_t< VT > TransposeType
Transpose type for expression template evaluations.
Definition: SparseVectorProxy.h:80
ConstIterator_t< VT > ConstIterator
Iterator over constant elements.
Definition: SparseVectorProxy.h:87
Reference operator[](size_t index) const
Subscript operator for the direct access to vector elements.
Definition: SparseVectorProxy.h:207
CompositeType_t< VT > CompositeType
Data type for composite expression templates.
Definition: SparseVectorProxy.h:83
ConstIterator cbegin() const
Returns an iterator to the first element of the represented vector.
Definition: SparseVectorProxy.h:266
Reference_t< VT > Reference
Reference to a non-constant vector value.
Definition: SparseVectorProxy.h:84
Iterator set(size_t index, const ElementType &value) const
Setting an element of the represented sparse vector.
Definition: SparseVectorProxy.h:406
Base class for sparse vectors.
Definition: SparseVector.h:72
Constraint on the data type.
Header file for the SparseVector base class.
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_VECTOR_TYPE(T)
Constraint on the data type.
Definition: SparseVector.h:61
BLAZE_ALWAYS_INLINE size_t capacity(const SparseVectorProxy< PT, VT > &proxy)
Returns the maximum capacity of the represented vector.
Definition: SparseVectorProxy.h:913
BLAZE_ALWAYS_INLINE SparseVectorProxy< PT, VT >::ConstIterator cend(const SparseVectorProxy< PT, VT > &proxy)
Returns an iterator just past the last element of the represented vector.
Definition: SparseVectorProxy.h:881
BLAZE_ALWAYS_INLINE SparseVectorProxy< PT, VT >::Iterator lowerBound(const SparseVectorProxy< PT, VT > &proxy, size_t index)
Returns an iterator to the first index not less then the given index.
Definition: SparseVectorProxy.h:988
BLAZE_ALWAYS_INLINE SparseVectorProxy< PT, VT >::Iterator end(const SparseVectorProxy< PT, VT > &proxy)
Returns an iterator just past the last element of the represented vector.
Definition: SparseVectorProxy.h:864
BLAZE_ALWAYS_INLINE SparseVectorProxy< PT, VT >::Iterator begin(const SparseVectorProxy< PT, VT > &proxy)
Returns an iterator to the first element of the represented vector.
Definition: SparseVectorProxy.h:830
BLAZE_ALWAYS_INLINE SparseVectorProxy< PT, VT >::Iterator find(const SparseVectorProxy< PT, VT > &proxy, size_t index)
Searches for a specific sparse vector element.
Definition: SparseVectorProxy.h:970
BLAZE_ALWAYS_INLINE void resize(const SparseVectorProxy< PT, VT > &proxy, size_t n, bool preserve)
Changing the size of the represented vector.
Definition: SparseVectorProxy.h:952
BLAZE_ALWAYS_INLINE SparseVectorProxy< PT, VT >::ConstIterator cbegin(const SparseVectorProxy< PT, VT > &proxy)
Returns an iterator to the first element of the represented vector.
Definition: SparseVectorProxy.h:847
BLAZE_ALWAYS_INLINE SparseVectorProxy< PT, VT >::Iterator upperBound(const SparseVectorProxy< PT, VT > &proxy, size_t index)
Returns an iterator to the first index greater then the given index.
Definition: SparseVectorProxy.h:1006
BLAZE_ALWAYS_INLINE size_t size(const SparseVectorProxy< PT, VT > &proxy)
Returns the current size/dimension of the represented vector.
Definition: SparseVectorProxy.h:897
BLAZE_ALWAYS_INLINE size_t nonZeros(const SparseVectorProxy< PT, VT > &proxy)
Returns the number of non-zero elements in the represented vector.
Definition: SparseVectorProxy.h:932
constexpr void clear(Matrix< MT, SO > &matrix)
Clearing the given matrix.
Definition: Matrix.h:960
constexpr void reset(Matrix< MT, SO > &matrix)
Resetting the given matrix.
Definition: Matrix.h:806
#define BLAZE_ALWAYS_INLINE
Platform dependent setup of an enforced inline keyword.
Definition: Inline.h:85
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.
Definition: Exception.h:235
Header file for the exception macros of the math module.
Header file for the clear shim.
Header file for the reset shim.
System settings for the inline keywords.
Header file for basic type definitions.