All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
45 #include <blaze/math/shims/Clear.h>
46 #include <blaze/math/shims/Reset.h>
48 #include <blaze/system/Inline.h>
49 #include <blaze/util/Types.h>
50 
51 
52 namespace blaze {
53 
54 //=================================================================================================
55 //
56 // CLASS DEFINITION
57 //
58 //=================================================================================================
59 
60 //*************************************************************************************************
68 template< typename PT // Type of the proxy
69  , typename VT > // Type of the sparse vector
70 class SparseVectorProxy : public SparseVector< PT, IsRowVector<VT>::value >
71 {
72  public:
73  //**Type definitions****************************************************************************
74  typedef typename VT::ElementType ElementType;
75  typedef typename VT::Reference Reference;
77  typedef typename VT::Iterator Iterator;
78  typedef typename VT::ConstIterator ConstIterator;
79  //**********************************************************************************************
80 
81  //**Data access functions***********************************************************************
84  inline Reference operator[]( size_t index ) const;
85 
86  inline Iterator begin () const;
87  inline ConstIterator cbegin() const;
88  inline Iterator end () const;
89  inline ConstIterator cend () const;
91  //**********************************************************************************************
92 
93  //**Utility functions***************************************************************************
96  inline size_t size() const;
97  inline size_t capacity() const;
98  inline size_t nonZeros() const;
99  inline void reset() const;
100  inline void clear() const;
101  inline Iterator set( size_t index, const ElementType& value ) const;
102  inline Iterator insert( size_t index, const ElementType& value ) const;
103  inline void append( size_t index, const ElementType& value, bool check=false ) const;
104  inline void erase( size_t index ) const;
105  inline Iterator erase( Iterator pos ) const;
106  inline Iterator erase( Iterator first, Iterator last ) const;
107  inline void resize( size_t n, bool preserve=true ) const;
108  inline void reserve( size_t n ) const;
109 
110  template< typename Other > inline void scale( const Other& scalar ) const;
112  //**********************************************************************************************
113 
114  //**Lookup functions****************************************************************************
117  inline Iterator find ( size_t index ) const;
118  inline Iterator find ( size_t i, size_t j ) const;
119  inline Iterator lowerBound( size_t index ) const;
120  inline Iterator lowerBound( size_t i, size_t j ) const;
121  inline Iterator upperBound( size_t index ) const;
122  inline Iterator upperBound( size_t i, size_t j ) const;
124  //**********************************************************************************************
125 
126  private:
127  //**Compile time checks*************************************************************************
131  //**********************************************************************************************
132 };
133 //*************************************************************************************************
134 
135 
136 
137 
138 //=================================================================================================
139 //
140 // DATA ACCESS FUNCTIONS
141 //
142 //=================================================================================================
143 
144 //*************************************************************************************************
155 template< typename PT // Type of the proxy
156  , typename VT > // Type of the sparse vector
159 {
160  return (~*this).get()[index];
161 }
162 //*************************************************************************************************
163 
164 
165 //*************************************************************************************************
170 template< typename PT // Type of the proxy
171  , typename VT > // Type of the sparse vector
173 {
174  return (~*this).get().begin();
175 }
176 //*************************************************************************************************
177 
178 
179 //*************************************************************************************************
184 template< typename PT // Type of the proxy
185  , typename VT > // Type of the sparse vector
187 {
188  return (~*this).get().cbegin();
189 }
190 //*************************************************************************************************
191 
192 
193 //*************************************************************************************************
198 template< typename PT // Type of the proxy
199  , typename VT > // Type of the sparse vector
201 {
202  return (~*this).get().end();
203 }
204 //*************************************************************************************************
205 
206 
207 //*************************************************************************************************
212 template< typename PT // Type of the proxy
213  , typename VT > // Type of the sparse vector
215 {
216  return (~*this).get().cend();
217 }
218 //*************************************************************************************************
219 
220 
221 
222 
223 //=================================================================================================
224 //
225 // UTILITY FUNCTIONS
226 //
227 //=================================================================================================
228 
229 //*************************************************************************************************
234 template< typename PT // Type of the proxy
235  , typename VT > // Type of the sparse vector
236 inline size_t SparseVectorProxy<PT,VT>::size() const
237 {
238  return (~*this).get().size();
239 }
240 //*************************************************************************************************
241 
242 
243 //*************************************************************************************************
248 template< typename PT // Type of the proxy
249  , typename VT > // Type of the sparse vector
251 {
252  return (~*this).get().capacity();
253 }
254 //*************************************************************************************************
255 
256 
257 //*************************************************************************************************
265 template< typename PT // Type of the proxy
266  , typename VT > // Type of the sparse vector
268 {
269  return (~*this).get().nonZeros();
270 }
271 //*************************************************************************************************
272 
273 
274 //*************************************************************************************************
281 template< typename PT // Type of the proxy
282  , typename VT > // Type of the sparse vector
284 {
285  using blaze::reset;
286 
287  reset( (~*this).get() );
288 }
289 //*************************************************************************************************
290 
291 
292 //*************************************************************************************************
299 template< typename PT // Type of the proxy
300  , typename VT > // Type of the sparse vector
302 {
303  using blaze::clear;
304 
305  clear( (~*this).get() );
306 }
307 //*************************************************************************************************
308 
309 
310 //*************************************************************************************************
322 template< typename PT // Type of the proxy
323  , typename VT > // Type of the sparse vector
325  SparseVectorProxy<PT,VT>::set( size_t index, const ElementType& value ) const
326 {
327  return (~*this).get().set( index, value );
328 }
329 //*************************************************************************************************
330 
331 
332 //*************************************************************************************************
344 template< typename PT // Type of the proxy
345  , typename VT > // Type of the sparse vector
347  SparseVectorProxy<PT,VT>::insert( size_t index, const ElementType& value ) const
348 {
349  return (~*this).get().insert( index, value );
350 }
351 //*************************************************************************************************
352 
353 
354 //*************************************************************************************************
378 template< typename PT // Type of the proxy
379  , typename VT > // Type of the sparse vector
380 inline void SparseVectorProxy<PT,VT>::append( size_t index, const ElementType& value, bool check ) const
381 {
382  (~*this).get().append( index, value, check );
383 }
384 //*************************************************************************************************
385 
386 
387 //*************************************************************************************************
395 template< typename PT // Type of the proxy
396  , typename VT > // Type of the sparse vector
397 inline void SparseVectorProxy<PT,VT>::erase( size_t index ) const
398 {
399  (~*this).get().erase( index );
400 }
401 //*************************************************************************************************
402 
403 
404 //*************************************************************************************************
412 template< typename PT // Type of the proxy
413  , typename VT > // Type of the sparse vector
415 {
416  return (~*this).get().erase( pos );
417 }
418 //*************************************************************************************************
419 
420 
421 //*************************************************************************************************
430 template< typename PT // Type of the proxy
431  , typename VT > // Type of the sparse vector
434 {
435  return (~*this).get().erase( first, last );
436 }
437 //*************************************************************************************************
438 
439 
440 //*************************************************************************************************
454 template< typename PT // Type of the proxy
455  , typename VT > // Type of the sparse vector
456 inline void SparseVectorProxy<PT,VT>::resize( size_t n, bool preserve ) const
457 {
458  (~*this).get().resize( n, preserve );
459 }
460 //*************************************************************************************************
461 
462 
463 //*************************************************************************************************
472 template< typename PT // Type of the proxy
473  , typename VT > // Type of the sparse vector
474 inline void SparseVectorProxy<PT,VT>::reserve( size_t n ) const
475 {
476  (~*this).get().reserve( n );
477 }
478 //*************************************************************************************************
479 
480 
481 //*************************************************************************************************
487 template< typename PT // Type of the proxy
488  , typename VT > // Type of the sparse vector
489 template< typename Other > // Data type of the scalar value
490 inline void SparseVectorProxy<PT,VT>::scale( const Other& scalar ) const
491 {
492  (~*this).get().scale( scalar );
493 }
494 //*************************************************************************************************
495 
496 
497 
498 
499 //=================================================================================================
500 //
501 // LOOKUP FUNCTIONS
502 //
503 //=================================================================================================
504 
505 //*************************************************************************************************
518 template< typename PT // Type of the proxy
519  , typename VT > // Type of the sparse vector
521  SparseVectorProxy<PT,VT>::find( size_t index ) const
522 {
523  return (~*this).get().find( index );
524 }
525 //*************************************************************************************************
526 
527 
528 //*************************************************************************************************
540 template< typename PT // Type of the proxy
541  , typename VT > // Type of the sparse vector
544 {
545  return (~*this).get().lowerBound( index );
546 }
547 //*************************************************************************************************
548 
549 
550 //*************************************************************************************************
562 template< typename PT // Type of the proxy
563  , typename VT > // Type of the sparse vector
566 {
567  return (~*this).get().upperBound( index );
568 }
569 //*************************************************************************************************
570 
571 
572 
573 
574 //=================================================================================================
575 //
576 // GLOBAL FUNCTIONS
577 //
578 //=================================================================================================
579 
580 //*************************************************************************************************
583 template< typename PT, typename VT >
585  begin( const SparseVectorProxy<PT,VT>& proxy );
586 
587 template< typename PT, typename VT >
589  cbegin( const SparseVectorProxy<PT,VT>& proxy );
590 
591 template< typename PT, typename VT >
593  end( const SparseVectorProxy<PT,VT>& proxy );
594 
595 template< typename PT, typename VT >
597  cend( const SparseVectorProxy<PT,VT>& proxy );
598 
599 template< typename PT, typename VT >
600 BLAZE_ALWAYS_INLINE size_t size( const SparseVectorProxy<PT,VT>& proxy );
601 
602 template< typename PT, typename VT >
604 
605 template< typename PT, typename VT >
607 
608 template< typename PT, typename VT >
610 
611 template< typename PT, typename VT >
614 //*************************************************************************************************
615 
616 
617 //*************************************************************************************************
624 template< typename PT // Type of the proxy
625  , typename VT > // Type of the sparse vector
628 {
629  return proxy.begin();
630 }
631 //*************************************************************************************************
632 
633 
634 //*************************************************************************************************
641 template< typename PT // Type of the proxy
642  , typename VT > // Type of the sparse vector
645 {
646  return proxy.cbegin();
647 }
648 //*************************************************************************************************
649 
650 
651 //*************************************************************************************************
658 template< typename PT // Type of the proxy
659  , typename VT > // Type of the sparse vector
662 {
663  return proxy.end();
664 }
665 //*************************************************************************************************
666 
667 
668 //*************************************************************************************************
675 template< typename PT // Type of the proxy
676  , typename VT > // Type of the sparse vector
679 {
680  return proxy.cend();
681 }
682 //*************************************************************************************************
683 
684 
685 //*************************************************************************************************
692 template< typename PT // Type of the proxy
693  , typename VT > // Type of the sparse vector
695 {
696  return proxy.size();
697 }
698 //*************************************************************************************************
699 
700 
701 //*************************************************************************************************
708 template< typename PT // Type of the proxy
709  , typename VT > // Type of the sparse vector
711 {
712  return proxy.capacity();
713 }
714 //*************************************************************************************************
715 
716 
717 //*************************************************************************************************
727 template< typename PT // Type of the proxy
728  , typename VT > // Type of the sparse vector
730 {
731  return proxy.nonZeros();
732 }
733 //*************************************************************************************************
734 
735 
736 //*************************************************************************************************
745 template< typename PT // Type of the proxy
746  , typename VT > // Type of the sparse vector
748 {
749  proxy.reset();
750 }
751 //*************************************************************************************************
752 
753 
754 //*************************************************************************************************
763 template< typename PT // Type of the proxy
764  , typename VT > // Type of the sparse vector
766 {
767  proxy.clear();
768 }
769 //*************************************************************************************************
770 
771 } // namespace blaze
772 
773 #endif
Header file for the SparseVector base class.
BLAZE_ALWAYS_INLINE MT::ConstIterator cbegin(const Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:237
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector)
Returns the current size/dimension of the vector.
Definition: Vector.h:258
BLAZE_ALWAYS_INLINE MT::ConstIterator cend(const Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:300
BLAZE_ALWAYS_INLINE MT::Iterator end(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:258
void append(size_t index, const ElementType &value, bool check=false) const
Appending an element to the represented sparse vector.
Definition: SparseVectorProxy.h:380
VT::Iterator Iterator
Iterator over non-constant elements.
Definition: SparseVectorProxy.h:77
BLAZE_ALWAYS_INLINE size_t capacity(const Matrix< MT, SO > &matrix)
Returns the maximum capacity of the matrix.
Definition: Matrix.h:348
Header file for the IsRowVector type trait.
BLAZE_ALWAYS_INLINE size_t nonZeros(const Matrix< MT, SO > &matrix)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:386
void reset() const
Reset to the default initial value.
Definition: SparseVectorProxy.h:283
Iterator end() const
Returns an iterator just past the last element of the represented vector.
Definition: SparseVectorProxy.h:200
Iterator lowerBound(size_t index) const
Returns an iterator to the first index not less then the given index.
Definition: SparseVectorProxy.h:543
size_t capacity() const
Returns the maximum capacity of the represented vector.
Definition: SparseVectorProxy.h:250
Iterator upperBound(size_t index) const
Returns an iterator to the first index greater then the given index.
Definition: SparseVectorProxy.h:565
Header file for the clear shim.
#define BLAZE_ALWAYS_INLINE
Platform dependent setup of an enforced inline keyword.
Definition: Inline.h:85
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2482
Iterator set(size_t index, const ElementType &value) const
Setting an element of the represented sparse vector.
Definition: SparseVectorProxy.h:325
BLAZE_ALWAYS_INLINE void clear(const NonNumericProxy< MT > &proxy)
Clearing the represented element.
Definition: NonNumericProxy.h:854
void erase(size_t index) const
Erasing an element from the sparse vector.
Definition: SparseVectorProxy.h:397
VT::Reference Reference
Reference to a non-constant vector value.
Definition: SparseVectorProxy.h:75
ConstIterator cend() const
Returns an iterator just past the last element of the represented vector.
Definition: SparseVectorProxy.h:214
void resize(size_t n, bool preserve=true) const
Changing the size of the represented vector.
Definition: SparseVectorProxy.h:456
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a sparse, N-dimensional vector type...
Definition: SparseVector.h:79
Reference operator[](size_t index) const
Subscript operator for the direct access to vector elements.
Definition: SparseVectorProxy.h:158
RawReference get() const
Returning the value of the accessed sparse matrix element.
Definition: MatrixAccessProxy.h:360
BLAZE_ALWAYS_INLINE MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:195
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2476
Constraint on the data type.
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2480
size_t nonZeros() const
Returns the number of non-zero elements in the represented vector.
Definition: SparseVectorProxy.h:267
Iterator begin() const
Returns an iterator to the first element of the represented vector.
Definition: SparseVectorProxy.h:172
void scale(const Other &scalar) const
Scaling of the sparse vector by the scalar value scalar ( ).
Definition: SparseVectorProxy.h:490
VT::ElementType ElementType
Type of the sparse vector elements.
Definition: SparseVectorProxy.h:74
Iterator find(size_t index) const
Searches for a specific vector element.
Definition: SparseVectorProxy.h:521
Iterator insert(size_t index, const ElementType &value) const
Inserting an element into the represented sparse vector.
Definition: SparseVectorProxy.h:347
void clear() const
Clearing the represented vector.
Definition: SparseVectorProxy.h:301
Header file for the reset shim.
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2481
BLAZE_ALWAYS_INLINE void reset(const NonNumericProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: NonNumericProxy.h:833
Proxy backend for sparse vector types.The SparseVectorProxy class serves as a backend for the Proxy c...
Definition: SparseVectorProxy.h:70
VT::ConstIterator ConstIterator
Iterator over constant elements.
Definition: SparseVectorProxy.h:78
VT::ConstReference ConstReference
Reference to a constant vector value.
Definition: SparseVectorProxy.h:76
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:108
Header file for basic type definitions.
size_t size() const
Returns the current size/dimension of the represented vector.
Definition: SparseVectorProxy.h:236
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2479
System settings for the inline keywords.
ConstIterator cbegin() const
Returns an iterator to the first element of the represented vector.
Definition: SparseVectorProxy.h:186
void reserve(size_t n) const
Setting the minimum capacity of the represented vector.
Definition: SparseVectorProxy.h:474