All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VectorAccessProxy.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_SPARSE_VECTORACCESSPROXY_H_
36 #define _BLAZE_MATH_SPARSE_VECTORACCESSPROXY_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <algorithm>
44 #include <ostream>
46 #include <blaze/math/proxy/Proxy.h>
47 #include <blaze/math/shims/Clear.h>
49 #include <blaze/math/shims/Reset.h>
50 #include <blaze/util/Assert.h>
51 #include <blaze/util/Types.h>
52 
53 
54 namespace blaze {
55 
56 //=================================================================================================
57 //
58 // CLASS DEFINITION
59 //
60 //=================================================================================================
61 
62 //*************************************************************************************************
94 template< typename VT > // Type of the sparse vector
95 class VectorAccessProxy : public Proxy< VectorAccessProxy<VT>, typename VT::ElementType >
96 {
97  public:
98  //**Type definitions****************************************************************************
99  typedef typename VT::ElementType RepresentedType;
101  //**********************************************************************************************
102 
103  //**Constructors********************************************************************************
106  explicit inline VectorAccessProxy( VT& sv, size_t i );
107  inline VectorAccessProxy( const VectorAccessProxy& vap );
109  //**********************************************************************************************
110 
111  //**Destructor**********************************************************************************
114  inline ~VectorAccessProxy();
116  //**********************************************************************************************
117 
118  //**Operators***********************************************************************************
121  inline VectorAccessProxy& operator= ( const VectorAccessProxy& vap );
122  template< typename T > inline VectorAccessProxy& operator= ( const T& value );
123  template< typename T > inline VectorAccessProxy& operator+=( const T& value );
124  template< typename T > inline VectorAccessProxy& operator-=( const T& value );
125  template< typename T > inline VectorAccessProxy& operator*=( const T& value );
126  template< typename T > inline VectorAccessProxy& operator/=( const T& value );
128  //**********************************************************************************************
129 
130  //**Utility functions***************************************************************************
133  inline RawReference get() const;
135  //**********************************************************************************************
136 
137  //**Conversion operator*************************************************************************
140  inline operator RawReference() const;
142  //**********************************************************************************************
143 
144  private:
145  //**Member variables****************************************************************************
148  VT& sv_;
149  size_t i_;
150 
151  //**********************************************************************************************
152 
153  //**Forbidden operations************************************************************************
156  void* operator&() const;
157 
158  //**********************************************************************************************
159 
160  //**Compile time checks*************************************************************************
164  //**********************************************************************************************
165 };
166 //*************************************************************************************************
167 
168 
169 
170 
171 //=================================================================================================
172 //
173 // CONSTRUCTORS
174 //
175 //=================================================================================================
176 
177 //*************************************************************************************************
183 template< typename VT > // Type of the sparse vector
185  : sv_( sv ) // Reference to the accessed sparse vector
186  , i_ ( i ) // Index of the accessed sparse vector element
187 {
188  const typename VT::Iterator element( sv_.find( i_ ) );
189  if( element == sv_.end() )
190  sv_.insert( i_, RepresentedType() );
191 }
192 //*************************************************************************************************
193 
194 
195 //*************************************************************************************************
200 template< typename VT > // Type of the sparse vector
202  : sv_( vap.sv_ ) // Reference to the accessed sparse vector
203  , i_ ( vap.i_ ) // Index of the accessed sparse vector element
204 {
205  BLAZE_INTERNAL_ASSERT( sv_.find( i_ ) != sv_.end(), "Missing vector element detected" );
206 }
207 //*************************************************************************************************
208 
209 
210 
211 
212 //=================================================================================================
213 //
214 // DESTRUCTOR
215 //
216 //=================================================================================================
217 
218 //*************************************************************************************************
221 template< typename VT > // Type of the sparse vector
223 {
224  const typename VT::Iterator element( sv_.find( i_ ) );
225  if( element != sv_.end() && isDefault( element->value() ) )
226  sv_.erase( element );
227 }
228 //*************************************************************************************************
229 
230 
231 
232 
233 //=================================================================================================
234 //
235 // OPERATORS
236 //
237 //=================================================================================================
238 
239 //*************************************************************************************************
245 template< typename VT > // Type of the sparse vector
247 {
248  get() = vap.get();
249  return *this;
250 }
251 //*************************************************************************************************
252 
253 
254 //*************************************************************************************************
260 template< typename VT > // Type of the sparse vector
261 template< typename T > // Type of the right-hand side value
263 {
264  get() = value;
265  return *this;
266 }
267 //*************************************************************************************************
268 
269 
270 //*************************************************************************************************
276 template< typename VT > // Type of the sparse vector
277 template< typename T > // Type of the right-hand side value
279 {
280  get() += value;
281  return *this;
282 }
283 //*************************************************************************************************
284 
285 
286 //*************************************************************************************************
292 template< typename VT > // Type of the sparse vector
293 template< typename T > // Type of the right-hand side value
295 {
296  get() -= value;
297  return *this;
298 }
299 //*************************************************************************************************
300 
301 
302 //*************************************************************************************************
308 template< typename VT > // Type of the sparse vector
309 template< typename T > // Type of the right-hand side value
311 {
312  get() *= value;
313  return *this;
314 }
315 //*************************************************************************************************
316 
317 
318 //*************************************************************************************************
324 template< typename VT > // Type of the sparse vector
325 template< typename T > // Type of the right-hand side value
327 {
328  get() /= value;
329  return *this;
330 }
331 //*************************************************************************************************
332 
333 
334 
335 
336 //=================================================================================================
337 //
338 // UTILITY FUNCTIONS
339 //
340 //=================================================================================================
341 
342 //*************************************************************************************************
347 template< typename VT > // Type of the sparse vector
349 {
350  const typename VT::Iterator element( sv_.find( i_ ) );
351  BLAZE_INTERNAL_ASSERT( element != sv_.end(), "Missing vector element detected" );
352  return element->value();
353 }
354 //*************************************************************************************************
355 
356 
357 
358 
359 //=================================================================================================
360 //
361 // CONVERSION OPERATOR
362 //
363 //=================================================================================================
364 
365 //*************************************************************************************************
370 template< typename VT > // Type of the sparse vector
372 {
373  return get();
374 }
375 //*************************************************************************************************
376 
377 
378 
379 
380 //=================================================================================================
381 //
382 // GLOBAL OPERATORS
383 //
384 //=================================================================================================
385 
386 //*************************************************************************************************
389 template< typename VT1, typename VT2 >
390 inline bool operator==( const VectorAccessProxy<VT1>& lhs, const VectorAccessProxy<VT2>& rhs );
391 
392 template< typename VT, typename T >
393 inline bool operator==( const VectorAccessProxy<VT>& lhs, const T& rhs );
394 
395 template< typename T, typename VT >
396 inline bool operator==( const T& lhs, const VectorAccessProxy<VT>& rhs );
397 
398 template< typename VT1, typename VT2 >
399 inline bool operator!=( const VectorAccessProxy<VT1>& lhs, const VectorAccessProxy<VT2>& rhs );
400 
401 template< typename VT, typename T >
402 inline bool operator!=( const VectorAccessProxy<VT>& lhs, const T& rhs );
403 
404 template< typename T, typename VT >
405 inline bool operator!=( const T& lhs, const VectorAccessProxy<VT>& rhs );
406 
407 template< typename VT1, typename VT2 >
408 inline bool operator<( const VectorAccessProxy<VT1>& lhs, const VectorAccessProxy<VT2>& rhs );
409 
410 template< typename VT, typename T >
411 inline bool operator<( const VectorAccessProxy<VT>& lhs, const T& rhs );
412 
413 template< typename T, typename VT >
414 inline bool operator<( const T& lhs, const VectorAccessProxy<VT>& rhs );
415 
416 template< typename VT1, typename VT2 >
417 inline bool operator>( const VectorAccessProxy<VT1>& lhs, const VectorAccessProxy<VT2>& rhs );
418 
419 template< typename VT, typename T >
420 inline bool operator>( const VectorAccessProxy<VT>& lhs, const T& rhs );
421 
422 template< typename T, typename VT >
423 inline bool operator>( const T& lhs, const VectorAccessProxy<VT>& rhs );
424 
425 template< typename VT1, typename VT2 >
426 inline bool operator<=( const VectorAccessProxy<VT1>& lhs, const VectorAccessProxy<VT2>& rhs );
427 
428 template< typename VT, typename T >
429 inline bool operator<=( const VectorAccessProxy<VT>& lhs, const T& rhs );
430 
431 template< typename T, typename VT >
432 inline bool operator<=( const T& lhs, const VectorAccessProxy<VT>& rhs );
433 
434 template< typename VT1, typename VT2 >
435 inline bool operator>=( const VectorAccessProxy<VT1>& lhs, const VectorAccessProxy<VT2>& rhs );
436 
437 template< typename VT, typename T >
438 inline bool operator>=( const VectorAccessProxy<VT>& lhs, const T& rhs );
439 
440 template< typename T, typename VT >
441 inline bool operator>=( const T& lhs, const VectorAccessProxy<VT>& rhs );
442 
443 template< typename VT >
444 inline std::ostream& operator<<( std::ostream& os, const VectorAccessProxy<VT>& proxy );
446 //*************************************************************************************************
447 
448 
449 //*************************************************************************************************
457 template< typename VT1, typename VT2 >
458 inline bool operator==( const VectorAccessProxy<VT1>& lhs, const VectorAccessProxy<VT2>& rhs )
459 {
460  return ( lhs.get() == rhs.get() );
461 }
462 //*************************************************************************************************
463 
464 
465 //*************************************************************************************************
473 template< typename VT, typename T >
474 inline bool operator==( const VectorAccessProxy<VT>& lhs, const T& rhs )
475 {
476  return ( lhs.get() == rhs );
477 }
478 //*************************************************************************************************
479 
480 
481 //*************************************************************************************************
489 template< typename T, typename VT >
490 inline bool operator==( const T& lhs, const VectorAccessProxy<VT>& rhs )
491 {
492  return ( lhs == rhs.get() );
493 }
494 //*************************************************************************************************
495 
496 
497 //*************************************************************************************************
505 template< typename VT1, typename VT2 >
506 inline bool operator!=( const VectorAccessProxy<VT1>& lhs, const VectorAccessProxy<VT2>& rhs )
507 {
508  return ( lhs.get() != rhs.get() );
509 }
510 //*************************************************************************************************
511 
512 
513 //*************************************************************************************************
521 template< typename VT, typename T >
522 inline bool operator!=( const VectorAccessProxy<VT>& lhs, const T& rhs )
523 {
524  return ( lhs.get() != rhs );
525 }
526 //*************************************************************************************************
527 
528 
529 //*************************************************************************************************
537 template< typename T, typename VT >
538 inline bool operator!=( const T& lhs, const VectorAccessProxy<VT>& rhs )
539 {
540  return ( lhs != rhs.get() );
541 }
542 //*************************************************************************************************
543 
544 
545 //*************************************************************************************************
553 template< typename VT1, typename VT2 >
554 inline bool operator<( const VectorAccessProxy<VT1>& lhs, const VectorAccessProxy<VT2>& rhs )
555 {
556  return ( lhs.get() < rhs.get() );
557 }
558 //*************************************************************************************************
559 
560 
561 //*************************************************************************************************
569 template< typename VT, typename T >
570 inline bool operator<( const VectorAccessProxy<VT>& lhs, const T& rhs )
571 {
572  return ( lhs.get() < rhs );
573 }
574 //*************************************************************************************************
575 
576 
577 //*************************************************************************************************
585 template< typename T, typename VT >
586 inline bool operator<( const T& lhs, const VectorAccessProxy<VT>& rhs )
587 {
588  return ( lhs < rhs.get() );
589 }
590 //*************************************************************************************************
591 
592 
593 //*************************************************************************************************
601 template< typename VT1, typename VT2 >
602 inline bool operator>( const VectorAccessProxy<VT1>& lhs, const VectorAccessProxy<VT2>& rhs )
603 {
604  return ( lhs.get() > rhs.get() );
605 }
606 //*************************************************************************************************
607 
608 
609 //*************************************************************************************************
617 template< typename VT, typename T >
618 inline bool operator>( const VectorAccessProxy<VT>& lhs, const T& rhs )
619 {
620  return ( lhs.get() > rhs );
621 }
622 //*************************************************************************************************
623 
624 
625 //*************************************************************************************************
633 template< typename T, typename VT >
634 inline bool operator>( const T& lhs, const VectorAccessProxy<VT>& rhs )
635 {
636  return ( lhs > rhs.get() );
637 }
638 //*************************************************************************************************
639 
640 
641 //*************************************************************************************************
649 template< typename VT1, typename VT2 >
650 inline bool operator<=( const VectorAccessProxy<VT1>& lhs, const VectorAccessProxy<VT2>& rhs )
651 {
652  return ( lhs.get() <= rhs.get() );
653 }
654 //*************************************************************************************************
655 
656 
657 //*************************************************************************************************
665 template< typename VT, typename T >
666 inline bool operator<=( const VectorAccessProxy<VT>& lhs, const T& rhs )
667 {
668  return ( lhs.get() <= rhs );
669 }
670 //*************************************************************************************************
671 
672 
673 //*************************************************************************************************
681 template< typename T, typename VT >
682 inline bool operator<=( const T& lhs, const VectorAccessProxy<VT>& rhs )
683 {
684  return ( lhs <= rhs.get() );
685 }
686 //*************************************************************************************************
687 
688 
689 //*************************************************************************************************
697 template< typename VT1, typename VT2 >
698 inline bool operator>=( const VectorAccessProxy<VT1>& lhs, const VectorAccessProxy<VT2>& rhs )
699 {
700  return ( lhs.get() >= rhs.get() );
701 }
702 //*************************************************************************************************
703 
704 
705 //*************************************************************************************************
713 template< typename VT, typename T >
714 inline bool operator>=( const VectorAccessProxy<VT>& lhs, const T& rhs )
715 {
716  return ( lhs.get() >= rhs );
717 }
718 //*************************************************************************************************
719 
720 
721 //*************************************************************************************************
729 template< typename T, typename VT >
730 inline bool operator>=( const T& lhs, const VectorAccessProxy<VT>& rhs )
731 {
732  return ( lhs >= rhs.get() );
733 }
734 //*************************************************************************************************
735 
736 
737 //*************************************************************************************************
745 template< typename VT >
746 inline std::ostream& operator<<( std::ostream& os, const VectorAccessProxy<VT>& proxy )
747 {
748  return os << proxy.get();
749 }
750 //*************************************************************************************************
751 
752 
753 
754 
755 //=================================================================================================
756 //
757 // GLOBAL FUNCTIONS
758 //
759 //=================================================================================================
760 
761 //*************************************************************************************************
764 template< typename VT >
765 inline void reset( const VectorAccessProxy<VT>& proxy );
766 
767 template< typename VT >
768 inline void clear( const VectorAccessProxy<VT>& proxy );
769 
770 template< typename VT >
771 inline bool isDefault( const VectorAccessProxy<VT>& proxy );
772 
773 template< typename VT >
774 inline void swap( const VectorAccessProxy<VT>& a, const VectorAccessProxy<VT>& b ) /* throw() */;
775 
776 template< typename VT, typename T >
777 inline void swap( const VectorAccessProxy<VT>& a, T& b ) /* throw() */;
778 
779 template< typename T, typename VT >
780 inline void swap( T& a, const VectorAccessProxy<VT>& v ) /* throw() */;
782 //*************************************************************************************************
783 
784 
785 //*************************************************************************************************
792 template< typename VT >
793 inline void reset( const VectorAccessProxy<VT>& proxy )
794 {
795  using blaze::reset;
796 
797  reset( proxy.get() );
798 }
799 //*************************************************************************************************
800 
801 
802 //*************************************************************************************************
809 template< typename VT >
810 inline void clear( const VectorAccessProxy<VT>& proxy )
811 {
812  using blaze::clear;
813 
814  clear( proxy.get() );
815 }
816 //*************************************************************************************************
817 
818 
819 //*************************************************************************************************
829 template< typename VT >
830 inline bool isDefault( const VectorAccessProxy<VT>& proxy )
831 {
832  using blaze::isDefault;
833 
834  return isDefault( proxy.get() );
835 }
836 //*************************************************************************************************
837 
838 
839 //*************************************************************************************************
848 template< typename VT >
849 inline void swap( const VectorAccessProxy<VT>& a, const VectorAccessProxy<VT>& b ) /* throw() */
850 {
851  using std::swap;
852 
853  swap( a.get(), b.get() );
854 }
855 //*************************************************************************************************
856 
857 
858 //*************************************************************************************************
867 template< typename VT, typename T >
868 inline void swap( const VectorAccessProxy<VT>& a, T& b ) /* throw() */
869 {
870  using std::swap;
871 
872  swap( a.get(), b );
873 }
874 //*************************************************************************************************
875 
876 
877 //*************************************************************************************************
886 template< typename T, typename VT >
887 inline void swap( T& a, const VectorAccessProxy<VT>& b ) /* throw() */
888 {
889  using std::swap;
890 
891  swap( a, b.get() );
892 }
893 //*************************************************************************************************
894 
895 } // namespace blaze
896 
897 #endif
void swap(SymmetricMatrix< MT, SO, DF, NF > &a, SymmetricMatrix< MT, SO, DF, NF > &b)
Swapping the contents of two matrices.
Definition: SymmetricMatrix.h:195
Proxy base class.The Proxy class is a base class for all proxy classes within the Blaze library that ...
Definition: Proxy.h:99
Access proxy for sparse, N-dimensional vectors.The VectorAccessProxy provides safe access to the elem...
Definition: VectorAccessProxy.h:95
VT & sv_
Reference to the accessed sparse vector.
Definition: VectorAccessProxy.h:148
bool operator>(const NegativeAccuracy< A > &lhs, const T &rhs)
Greater-than comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:366
bool operator>=(const NegativeAccuracy< A > &, const T &rhs)
Greater-or-equal-than comparison between a NegativeAccuracy object and a floating point value...
Definition: Accuracy.h:442
VectorAccessProxy(VT &sv, size_t i)
Initialization constructor for a VectorAccessProxy.
Definition: VectorAccessProxy.h:184
size_t i_
Index of the accessed sparse vector element.
Definition: VectorAccessProxy.h:149
Header file for the clear shim.
void swap(CompressedMatrix< Type, SO > &a, CompressedMatrix< Type, SO > &b)
Swapping the contents of two compressed matrices.
Definition: CompressedMatrix.h:4754
BLAZE_ALWAYS_INLINE void clear(const NonNumericProxy< MT > &proxy)
Clearing the represented element.
Definition: NonNumericProxy.h:854
RepresentedType & RawReference
Raw reference to the represented element.
Definition: VectorAccessProxy.h:100
#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
VectorAccessProxy & operator=(const VectorAccessProxy &vap)
Copy assignment operator for VectorAccessProxy.
Definition: VectorAccessProxy.h:246
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2476
Constraint on the data type.
Header file for run time assertion macros.
Header file for the Proxy class.
Header file for the reset shim.
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2481
Header file for the isDefault shim.
BLAZE_ALWAYS_INLINE bool isDefault(const NonNumericProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: NonNumericProxy.h:874
BLAZE_ALWAYS_INLINE void reset(const NonNumericProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: NonNumericProxy.h:833
RawReference get() const
Returning the value of the accessed sparse vector element.
Definition: VectorAccessProxy.h:348
VT::ElementType RepresentedType
Type of the represented sparse vector element.
Definition: VectorAccessProxy.h:99
~VectorAccessProxy()
The destructor for VectorAccessProxy.
Definition: VectorAccessProxy.h:222
bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value. ...
Definition: Accuracy.h:249
bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:289
Header file for basic type definitions.
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_INTERNAL_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERTION flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:101
void * operator&() const
Address operator (private & undefined)