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 
44 #include <blaze/util/Assert.h>
45 #include <blaze/util/Types.h>
46 
47 
48 namespace blaze {
49 
50 //=================================================================================================
51 //
52 // CLASS DEFINITION
53 //
54 //=================================================================================================
55 
56 //*************************************************************************************************
88 template< typename VT > // Type of the sparse vector
90 {
91  public:
92  //**Type definitions****************************************************************************
93  typedef VT VectorType;
94  typedef typename VT::ElementType ElementType;
96  typedef const ElementType& ConstReference;
97  typedef typename VT::Iterator Iterator;
98  //**********************************************************************************************
99 
100  //**Constructors********************************************************************************
103  explicit inline VectorAccessProxy( VT& sv, size_t i );
104  inline VectorAccessProxy( const VectorAccessProxy& vap );
106  //**********************************************************************************************
107 
108  //**Destructor**********************************************************************************
111  inline ~VectorAccessProxy();
113  //**********************************************************************************************
114 
115  //**Operators***********************************************************************************
118  inline VectorAccessProxy& operator= ( const VectorAccessProxy& vap );
119  template< typename T > inline VectorAccessProxy& operator= ( const T& value );
120  template< typename T > inline VectorAccessProxy& operator+=( const T& value );
121  template< typename T > inline VectorAccessProxy& operator-=( const T& value );
122  template< typename T > inline VectorAccessProxy& operator*=( const T& value );
123  template< typename T > inline VectorAccessProxy& operator/=( const T& value );
125  //**********************************************************************************************
126 
127  //**Conversion operator*************************************************************************
130  inline operator Reference() const;
132  //**********************************************************************************************
133 
134  private:
135  //**Utility functions***************************************************************************
138  Reference get() const;
139  void set( ConstReference value ) const;
141  //**********************************************************************************************
142 
143  //**Member variables****************************************************************************
146  VT& sv_;
147  size_t i_;
148 
149  //**********************************************************************************************
150 };
151 //*************************************************************************************************
152 
153 
154 
155 
156 //=================================================================================================
157 //
158 // CONSTRUCTORS
159 //
160 //=================================================================================================
161 
162 //*************************************************************************************************
168 template< typename VT > // Type of the sparse vector
170  : sv_( sv ) // Reference to the accessed sparse vector
171  , i_ ( i ) // Index of the accessed sparse vector element
172 {
173  const Iterator element( sv_.find( i_ ) );
174  if( element == sv_.end() )
175  sv_.insert( i_, ElementType() );
176 }
177 //*************************************************************************************************
178 
179 
180 //*************************************************************************************************
185 template< typename VT > // Type of the sparse vector
187  : sv_( vap.sv_ ) // Reference to the accessed sparse vector
188  , i_ ( vap.i_ ) // Index of the accessed sparse vector element
189 {
190  BLAZE_INTERNAL_ASSERT( sv_.find( i_ ) != sv_.end(), "Missing vector element detected" );
191 }
192 //*************************************************************************************************
193 
194 
195 
196 
197 //=================================================================================================
198 //
199 // DESTRUCTOR
200 //
201 //=================================================================================================
202 
203 //*************************************************************************************************
206 template< typename VT > // Type of the sparse vector
208 {
209  const Iterator element( sv_.find( i_ ) );
210  if( element != sv_.end() && isDefault( element->value() ) )
211  sv_.erase( element );
212 }
213 //*************************************************************************************************
214 
215 
216 
217 
218 //=================================================================================================
219 //
220 // OPERATORS
221 //
222 //=================================================================================================
223 
224 //*************************************************************************************************
230 template< typename VT > // Type of the sparse vector
232 {
233  set( vap.get() );
234  return *this;
235 }
236 //*************************************************************************************************
237 
238 
239 //*************************************************************************************************
245 template< typename VT > // Type of the sparse vector
246 template< typename T > // Type of the right-hand side value
248 {
249  set( value );
250  return *this;
251 }
252 //*************************************************************************************************
253 
254 
255 //*************************************************************************************************
261 template< typename VT > // Type of the sparse vector
262 template< typename T > // Type of the right-hand side value
264 {
265  get() += value;
266  return *this;
267 }
268 //*************************************************************************************************
269 
270 
271 //*************************************************************************************************
277 template< typename VT > // Type of the sparse vector
278 template< typename T > // Type of the right-hand side value
280 {
281  get() -= value;
282  return *this;
283 }
284 //*************************************************************************************************
285 
286 
287 //*************************************************************************************************
293 template< typename VT > // Type of the sparse vector
294 template< typename T > // Type of the right-hand side value
296 {
297  get() *= value;
298  return *this;
299 }
300 //*************************************************************************************************
301 
302 
303 //*************************************************************************************************
309 template< typename VT > // Type of the sparse vector
310 template< typename T > // Type of the right-hand side value
312 {
313  get() /= value;
314  return *this;
315 }
316 //*************************************************************************************************
317 
318 
319 
320 
321 //=================================================================================================
322 //
323 // CONVERSION OPERATOR
324 //
325 //=================================================================================================
326 
327 //*************************************************************************************************
332 template< typename VT > // Type of the sparse vector
334 {
335  return get();
336 }
337 //*************************************************************************************************
338 
339 
340 
341 
342 //=================================================================================================
343 //
344 // UTILITY FUNCTIONS
345 //
346 //=================================================================================================
347 
348 //*************************************************************************************************
353 template< typename VT > // Type of the sparse vector
355 {
356  const Iterator element( sv_.find( i_ ) );
357  BLAZE_INTERNAL_ASSERT( element != sv_.end(), "Missing vector element detected" );
358  return element->value();
359 }
360 //*************************************************************************************************
361 
362 
363 //*************************************************************************************************
369 template< typename VT > // Type of the sparse vector
370 inline void VectorAccessProxy<VT>::set( ConstReference value ) const
371 {
372  const Iterator element( sv_.find( i_ ) );
373  BLAZE_INTERNAL_ASSERT( element != sv_.end(), "Missing vector element detected" );
374  element->value() = value;
375 }
376 //*************************************************************************************************
377 
378 
379 
380 
381 //=================================================================================================
382 //
383 // GLOBAL OPERATORS
384 //
385 //=================================================================================================
386 
387 //*************************************************************************************************
390 template< typename VT1, typename VT2 >
391 inline bool operator==( const VectorAccessProxy<VT1>& lhs, const VectorAccessProxy<VT2>& rhs );
392 
393 template< typename VT, typename T >
394 inline bool operator==( const VectorAccessProxy<VT>& lhs, const T& rhs );
395 
396 template< typename T, typename VT >
397 inline bool operator==( const T& lhs, const VectorAccessProxy<VT>& rhs );
398 
399 template< typename VT1, typename VT2 >
400 inline bool operator!=( const VectorAccessProxy<VT1>& lhs, const VectorAccessProxy<VT2>& rhs );
401 
402 template< typename VT, typename T >
403 inline bool operator!=( const VectorAccessProxy<VT>& lhs, const T& rhs );
404 
405 template< typename T, typename VT >
406 inline bool operator!=( const T& lhs, const VectorAccessProxy<VT>& rhs );
407 
408 template< typename VT1, typename VT2 >
409 inline bool operator<( const VectorAccessProxy<VT1>& lhs, const VectorAccessProxy<VT2>& rhs );
410 
411 template< typename VT, typename T >
412 inline bool operator<( const VectorAccessProxy<VT>& lhs, const T& rhs );
413 
414 template< typename T, typename VT >
415 inline bool operator<( const T& lhs, const VectorAccessProxy<VT>& rhs );
416 
417 template< typename VT1, typename VT2 >
418 inline bool operator>( const VectorAccessProxy<VT1>& lhs, const VectorAccessProxy<VT2>& rhs );
419 
420 template< typename VT, typename T >
421 inline bool operator>( const VectorAccessProxy<VT>& lhs, const T& rhs );
422 
423 template< typename T, typename VT >
424 inline bool operator>( const T& lhs, const VectorAccessProxy<VT>& rhs );
425 
426 template< typename VT1, typename VT2 >
427 inline bool operator<=( const VectorAccessProxy<VT1>& lhs, const VectorAccessProxy<VT2>& rhs );
428 
429 template< typename VT, typename T >
430 inline bool operator<=( const VectorAccessProxy<VT>& lhs, const T& rhs );
431 
432 template< typename T, typename VT >
433 inline bool operator<=( const T& lhs, const VectorAccessProxy<VT>& rhs );
434 
435 template< typename VT1, typename VT2 >
436 inline bool operator>=( const VectorAccessProxy<VT1>& lhs, const VectorAccessProxy<VT2>& rhs );
437 
438 template< typename VT, typename T >
439 inline bool operator>=( const VectorAccessProxy<VT>& lhs, const T& rhs );
440 
441 template< typename T, typename VT >
442 inline bool operator>=( const T& lhs, const VectorAccessProxy<VT>& rhs );
444 //*************************************************************************************************
445 
446 
447 //*************************************************************************************************
455 template< typename VT1, typename VT2 >
456 inline bool operator==( const VectorAccessProxy<VT1>& lhs, const VectorAccessProxy<VT2>& rhs )
457 {
458  typedef typename VectorAccessProxy<VT1>::Reference LhsReference;
459  typedef typename VectorAccessProxy<VT2>::Reference RhsReference;
460  return ( static_cast<LhsReference>( lhs ) == static_cast<RhsReference>( rhs ) );
461 }
462 //*************************************************************************************************
463 
464 
465 //*************************************************************************************************
473 template< typename VT, typename T >
474 inline bool operator==( const VectorAccessProxy<VT>& lhs, const T& rhs )
475 {
477  return ( static_cast<Reference>( lhs ) == rhs );
478 }
479 //*************************************************************************************************
480 
481 
482 //*************************************************************************************************
490 template< typename T, typename VT >
491 inline bool operator==( const T& lhs, const VectorAccessProxy<VT>& rhs )
492 {
494  return ( lhs == static_cast<Reference>( rhs ) );
495 }
496 //*************************************************************************************************
497 
498 
499 //*************************************************************************************************
507 template< typename VT1, typename VT2 >
508 inline bool operator!=( const VectorAccessProxy<VT1>& lhs, const VectorAccessProxy<VT2>& rhs )
509 {
510  typedef typename VectorAccessProxy<VT1>::Reference LhsReference;
511  typedef typename VectorAccessProxy<VT2>::Reference RhsReference;
512  return ( static_cast<LhsReference>( lhs ) != static_cast<RhsReference>( rhs ) );
513 }
514 //*************************************************************************************************
515 
516 
517 //*************************************************************************************************
525 template< typename VT, typename T >
526 inline bool operator!=( const VectorAccessProxy<VT>& lhs, const T& rhs )
527 {
529  return ( static_cast<Reference>( lhs ) != rhs );
530 }
531 //*************************************************************************************************
532 
533 
534 //*************************************************************************************************
542 template< typename T, typename VT >
543 inline bool operator!=( const T& lhs, const VectorAccessProxy<VT>& rhs )
544 {
546  return ( lhs != static_cast<Reference>( rhs ) );
547 }
548 //*************************************************************************************************
549 
550 
551 //*************************************************************************************************
559 template< typename VT1, typename VT2 >
560 inline bool operator<( const VectorAccessProxy<VT1>& lhs, const VectorAccessProxy<VT2>& rhs )
561 {
562  typedef typename VectorAccessProxy<VT1>::Reference LhsReference;
563  typedef typename VectorAccessProxy<VT2>::Reference RhsReference;
564  return ( static_cast<LhsReference>( lhs ) < static_cast<RhsReference>( rhs ) );
565 }
566 //*************************************************************************************************
567 
568 
569 //*************************************************************************************************
577 template< typename VT, typename T >
578 inline bool operator<( const VectorAccessProxy<VT>& lhs, const T& rhs )
579 {
581  return ( static_cast<Reference>( lhs ) < rhs );
582 }
583 //*************************************************************************************************
584 
585 
586 //*************************************************************************************************
594 template< typename T, typename VT >
595 inline bool operator<( const T& lhs, const VectorAccessProxy<VT>& rhs )
596 {
598  return ( lhs < static_cast<Reference>( rhs ) );
599 }
600 //*************************************************************************************************
601 
602 
603 //*************************************************************************************************
611 template< typename VT1, typename VT2 >
612 inline bool operator>( const VectorAccessProxy<VT1>& lhs, const VectorAccessProxy<VT2>& rhs )
613 {
614  typedef typename VectorAccessProxy<VT1>::Reference LhsReference;
615  typedef typename VectorAccessProxy<VT2>::Reference RhsReference;
616  return ( static_cast<LhsReference>( lhs ) > static_cast<RhsReference>( rhs ) );
617 }
618 //*************************************************************************************************
619 
620 
621 //*************************************************************************************************
629 template< typename VT, typename T >
630 inline bool operator>( const VectorAccessProxy<VT>& lhs, const T& rhs )
631 {
633  return ( static_cast<Reference>( lhs ) > rhs );
634 }
635 //*************************************************************************************************
636 
637 
638 //*************************************************************************************************
646 template< typename T, typename VT >
647 inline bool operator>( const T& lhs, const VectorAccessProxy<VT>& rhs )
648 {
650  return ( lhs > static_cast<Reference>( rhs ) );
651 }
652 //*************************************************************************************************
653 
654 
655 //*************************************************************************************************
663 template< typename VT1, typename VT2 >
664 inline bool operator<=( const VectorAccessProxy<VT1>& lhs, const VectorAccessProxy<VT2>& rhs )
665 {
666  typedef typename VectorAccessProxy<VT1>::Reference LhsReference;
667  typedef typename VectorAccessProxy<VT2>::Reference RhsReference;
668  return ( static_cast<LhsReference>( lhs ) <= static_cast<RhsReference>( rhs ) );
669 }
670 //*************************************************************************************************
671 
672 
673 //*************************************************************************************************
681 template< typename VT, typename T >
682 inline bool operator<=( const VectorAccessProxy<VT>& lhs, const T& rhs )
683 {
685  return ( static_cast<Reference>( lhs ) <= rhs );
686 }
687 //*************************************************************************************************
688 
689 
690 //*************************************************************************************************
698 template< typename T, typename VT >
699 inline bool operator<=( const T& lhs, const VectorAccessProxy<VT>& rhs )
700 {
702  return ( lhs <= static_cast<Reference>( rhs ) );
703 }
704 //*************************************************************************************************
705 
706 
707 //*************************************************************************************************
715 template< typename VT1, typename VT2 >
716 inline bool operator>=( const VectorAccessProxy<VT1>& lhs, const VectorAccessProxy<VT2>& rhs )
717 {
718  typedef typename VectorAccessProxy<VT1>::Reference LhsReference;
719  typedef typename VectorAccessProxy<VT2>::Reference RhsReference;
720  return ( static_cast<LhsReference>( lhs ) >= static_cast<RhsReference>( rhs ) );
721 }
722 //*************************************************************************************************
723 
724 
725 //*************************************************************************************************
733 template< typename VT, typename T >
734 inline bool operator>=( const VectorAccessProxy<VT>& lhs, const T& rhs )
735 {
737  return ( static_cast<Reference>( lhs ) >= rhs );
738 }
739 //*************************************************************************************************
740 
741 
742 //*************************************************************************************************
750 template< typename T, typename VT >
751 inline bool operator>=( const T& lhs, const VectorAccessProxy<VT>& rhs )
752 {
754  return ( lhs >= static_cast<Reference>( rhs ) );
755 }
756 //*************************************************************************************************
757 
758 } // namespace blaze
759 
760 #endif
Reference get() const
Returning the value of the accessed sparse vector element.
Definition: VectorAccessProxy.h:354
bool isDefault(const DynamicMatrix< Type, SO > &m)
Returns whether the given dense matrix is in default state.
Definition: DynamicMatrix.h:4642
VT::Iterator Iterator
Iterator type of the accessed sparse vector.
Definition: VectorAccessProxy.h:97
Access proxy for sparse, N-dimensional vectors.The VectorAccessProxy provides safe access to the elem...
Definition: VectorAccessProxy.h:89
VT & sv_
Reference to the accessed sparse vector.
Definition: VectorAccessProxy.h:146
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:169
size_t i_
Index of the accessed sparse vector element.
Definition: VectorAccessProxy.h:147
const ElementType & ConstReference
Reference type of the accessed constant element.
Definition: VectorAccessProxy.h:96
ElementType & Reference
Reference type of the accessed element.
Definition: VectorAccessProxy.h:95
VectorAccessProxy & operator=(const VectorAccessProxy &vap)
Copy assignment operator for VectorAccessProxy.
Definition: VectorAccessProxy.h:231
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2406
VT VectorType
Type of the accessed sparse vector.
Definition: VectorAccessProxy.h:93
Header file for run time assertion macros.
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2411
void set(ConstReference value) const
Setting the value of the accessed sparse vector element.
Definition: VectorAccessProxy.h:370
Header file for the isDefault shim.
VT::ElementType ElementType
Type of the accessed sparse vector element.
Definition: VectorAccessProxy.h:94
~VectorAccessProxy()
The destructor for VectorAccessProxy.
Definition: VectorAccessProxy.h:207
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.
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2409
#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
EnableIf< IsIntegral< T >, Set< T, sizeof(T)> >::Type::Type set(T value)
Sets all values in the vector to the given integral value.
Definition: Set.h:209