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 <utility>
44 #include <blaze/math/Aliases.h>
47 #include <blaze/math/proxy/Proxy.h>
49 #include <blaze/math/shims/Clear.h>
51 #include <blaze/math/shims/IsNaN.h>
52 #include <blaze/math/shims/IsOne.h>
55 #include <blaze/math/shims/Reset.h>
56 #include <blaze/util/Assert.h>
57 #include <blaze/util/Types.h>
58 
59 
60 namespace blaze {
61 
62 //=================================================================================================
63 //
64 // CLASS DEFINITION
65 //
66 //=================================================================================================
67 
68 //*************************************************************************************************
100 template< typename VT > // Type of the sparse vector
102  : public Proxy< VectorAccessProxy<VT>, ElementType_<VT> >
103 {
104  public:
105  //**Type definitions****************************************************************************
108  //**********************************************************************************************
109 
110  //**Constructors********************************************************************************
113  explicit inline VectorAccessProxy( VT& sv, size_t i );
114  inline VectorAccessProxy( const VectorAccessProxy& vap );
116  //**********************************************************************************************
117 
118  //**Destructor**********************************************************************************
121  inline ~VectorAccessProxy();
123  //**********************************************************************************************
124 
125  //**Operators***********************************************************************************
128  inline const VectorAccessProxy& operator=( const VectorAccessProxy& vap ) const;
129 
130  template< typename T >
131  inline const VectorAccessProxy& operator=( initializer_list<T> list ) const;
132 
133  template< typename T >
134  inline const VectorAccessProxy& operator=( initializer_list< initializer_list<T> > list ) const;
135 
136  template< typename T > inline const VectorAccessProxy& operator= ( const T& value ) const;
137  template< typename T > inline const VectorAccessProxy& operator+=( const T& value ) const;
138  template< typename T > inline const VectorAccessProxy& operator-=( const T& value ) const;
139  template< typename T > inline const VectorAccessProxy& operator*=( const T& value ) const;
140  template< typename T > inline const VectorAccessProxy& operator/=( const T& value ) const;
141  template< typename T > inline const VectorAccessProxy& operator%=( const T& value ) const;
143  //**********************************************************************************************
144 
145  //**Utility functions***************************************************************************
148  inline RawReference get() const noexcept;
149  inline bool isRestricted() const noexcept;
151  //**********************************************************************************************
152 
153  //**Conversion operator*************************************************************************
156  inline operator RawReference() const noexcept;
158  //**********************************************************************************************
159 
160  private:
161  //**Member variables****************************************************************************
164  VT& sv_;
165  size_t i_;
166 
167  //**********************************************************************************************
168 
169  //**Forbidden operations************************************************************************
172  void* operator&() const;
173 
174  //**********************************************************************************************
175 
176  //**Compile time checks*************************************************************************
180  //**********************************************************************************************
181 };
182 //*************************************************************************************************
183 
184 
185 
186 
187 //=================================================================================================
188 //
189 // CONSTRUCTORS
190 //
191 //=================================================================================================
192 
193 //*************************************************************************************************
199 template< typename VT > // Type of the sparse vector
200 inline VectorAccessProxy<VT>::VectorAccessProxy( VT& sv, size_t i )
201  : sv_( sv ) // Reference to the accessed sparse vector
202  , i_ ( i ) // Index of the accessed sparse vector element
203 {
204  const Iterator_<VT> element( sv_.find( i_ ) );
205  if( element == sv_.end() )
206  sv_.insert( i_, RepresentedType() );
207 }
208 //*************************************************************************************************
209 
210 
211 //*************************************************************************************************
216 template< typename VT > // Type of the sparse vector
218  : sv_( vap.sv_ ) // Reference to the accessed sparse vector
219  , i_ ( vap.i_ ) // Index of the accessed sparse vector element
220 {
221  BLAZE_INTERNAL_ASSERT( sv_.find( i_ ) != sv_.end(), "Missing vector element detected" );
222 }
223 //*************************************************************************************************
224 
225 
226 
227 
228 //=================================================================================================
229 //
230 // DESTRUCTOR
231 //
232 //=================================================================================================
233 
234 //*************************************************************************************************
237 template< typename VT > // Type of the sparse vector
239 {
240  const Iterator_<VT> element( sv_.find( i_ ) );
241  if( element != sv_.end() && isDefault<strict>( element->value() ) )
242  sv_.erase( element );
243 }
244 //*************************************************************************************************
245 
246 
247 
248 
249 //=================================================================================================
250 //
251 // OPERATORS
252 //
253 //=================================================================================================
254 
255 //*************************************************************************************************
261 template< typename VT > // Type of the sparse vector
263 {
264  get() = vap.get();
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 elements
278 inline const VectorAccessProxy<VT>&
280 {
281  get() = list;
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 elements
295 inline const VectorAccessProxy<VT>&
297 {
298  get() = list;
299  return *this;
300 }
301 //*************************************************************************************************
302 
303 
304 //*************************************************************************************************
310 template< typename VT > // Type of the sparse vector
311 template< typename T > // Type of the right-hand side value
312 inline const VectorAccessProxy<VT>& VectorAccessProxy<VT>::operator=( const T& value ) const
313 {
314  get() = value;
315  return *this;
316 }
317 //*************************************************************************************************
318 
319 
320 //*************************************************************************************************
326 template< typename VT > // Type of the sparse vector
327 template< typename T > // Type of the right-hand side value
328 inline const VectorAccessProxy<VT>& VectorAccessProxy<VT>::operator+=( const T& value ) const
329 {
330  get() += value;
331  return *this;
332 }
333 //*************************************************************************************************
334 
335 
336 //*************************************************************************************************
342 template< typename VT > // Type of the sparse vector
343 template< typename T > // Type of the right-hand side value
344 inline const VectorAccessProxy<VT>& VectorAccessProxy<VT>::operator-=( const T& value ) const
345 {
346  get() -= value;
347  return *this;
348 }
349 //*************************************************************************************************
350 
351 
352 //*************************************************************************************************
358 template< typename VT > // Type of the sparse vector
359 template< typename T > // Type of the right-hand side value
360 inline const VectorAccessProxy<VT>& VectorAccessProxy<VT>::operator*=( const T& value ) const
361 {
362  get() *= value;
363  return *this;
364 }
365 //*************************************************************************************************
366 
367 
368 //*************************************************************************************************
374 template< typename VT > // Type of the sparse vector
375 template< typename T > // Type of the right-hand side value
376 inline const VectorAccessProxy<VT>& VectorAccessProxy<VT>::operator/=( const T& value ) const
377 {
378  get() /= value;
379  return *this;
380 }
381 //*************************************************************************************************
382 
383 
384 //*************************************************************************************************
394 template< typename VT > // Type of the sparse vector
395 template< typename T > // Type of the right-hand side value
396 inline const VectorAccessProxy<VT>& VectorAccessProxy<VT>::operator%=( const T& value ) const
397 {
398  get() %= value;
399  return *this;
400 }
401 //*************************************************************************************************
402 
403 
404 
405 
406 //=================================================================================================
407 //
408 // UTILITY FUNCTIONS
409 //
410 //=================================================================================================
411 
412 //*************************************************************************************************
417 template< typename VT > // Type of the sparse vector
419 {
420  const Iterator_<VT> element( sv_.find( i_ ) );
421  BLAZE_INTERNAL_ASSERT( element != sv_.end(), "Missing vector element detected" );
422  return element->value();
423 }
424 //*************************************************************************************************
425 
426 
427 //*************************************************************************************************
432 template< typename VT > // Type of the sparse vector
433 inline bool VectorAccessProxy<VT>::isRestricted() const noexcept
434 {
435  return false;
436 }
437 //*************************************************************************************************
438 
439 
440 
441 
442 //=================================================================================================
443 //
444 // CONVERSION OPERATOR
445 //
446 //=================================================================================================
447 
448 //*************************************************************************************************
453 template< typename VT > // Type of the sparse vector
455 {
456  return get();
457 }
458 //*************************************************************************************************
459 
460 
461 
462 
463 //=================================================================================================
464 //
465 // GLOBAL FUNCTIONS
466 //
467 //=================================================================================================
468 
469 //*************************************************************************************************
472 template< typename VT >
473 inline void reset( const VectorAccessProxy<VT>& proxy );
474 
475 template< typename VT >
476 inline void clear( const VectorAccessProxy<VT>& proxy );
477 
478 template< bool RF, typename VT >
479 inline bool isDefault( const VectorAccessProxy<VT>& proxy );
480 
481 template< bool RF, typename VT >
482 inline bool isReal( const VectorAccessProxy<VT>& proxy );
483 
484 template< bool RF, typename VT >
485 inline bool isZero( const VectorAccessProxy<VT>& proxy );
486 
487 template< bool RF, typename VT >
488 inline bool isOne( const VectorAccessProxy<VT>& proxy );
489 
490 template< typename VT >
491 inline bool isnan( const VectorAccessProxy<VT>& proxy );
492 
493 template< typename VT >
494 inline void swap( const VectorAccessProxy<VT>& a, const VectorAccessProxy<VT>& b ) noexcept;
495 
496 template< typename VT, typename T >
497 inline void swap( const VectorAccessProxy<VT>& a, T& b ) noexcept;
498 
499 template< typename T, typename VT >
500 inline void swap( T& a, const VectorAccessProxy<VT>& v ) noexcept;
502 //*************************************************************************************************
503 
504 
505 //*************************************************************************************************
512 template< typename VT >
513 inline void reset( const VectorAccessProxy<VT>& proxy )
514 {
515  using blaze::reset;
516 
517  reset( proxy.get() );
518 }
519 //*************************************************************************************************
520 
521 
522 //*************************************************************************************************
529 template< typename VT >
530 inline void clear( const VectorAccessProxy<VT>& proxy )
531 {
532  using blaze::clear;
533 
534  clear( proxy.get() );
535 }
536 //*************************************************************************************************
537 
538 
539 //*************************************************************************************************
549 template< bool RF, typename VT >
550 inline bool isDefault( const VectorAccessProxy<VT>& proxy )
551 {
552  using blaze::isDefault;
553 
554  return isDefault<RF>( proxy.get() );
555 }
556 //*************************************************************************************************
557 
558 
559 //*************************************************************************************************
571 template< bool RF, typename VT >
572 inline bool isReal( const VectorAccessProxy<VT>& proxy )
573 {
574  using blaze::isReal;
575 
576  return isReal<RF>( proxy.get() );
577 }
578 //*************************************************************************************************
579 
580 
581 //*************************************************************************************************
591 template< bool RF, typename VT >
592 inline bool isZero( const VectorAccessProxy<VT>& proxy )
593 {
594  using blaze::isZero;
595 
596  return isZero<RF>( proxy.get() );
597 }
598 //*************************************************************************************************
599 
600 
601 //*************************************************************************************************
611 template< bool RF, typename VT >
612 inline bool isOne( const VectorAccessProxy<VT>& proxy )
613 {
614  using blaze::isOne;
615 
616  return isOne<RF>( proxy.get() );
617 }
618 //*************************************************************************************************
619 
620 
621 //*************************************************************************************************
631 template< typename VT >
632 inline bool isnan( const VectorAccessProxy<VT>& proxy )
633 {
634  using blaze::isnan;
635 
636  return isnan( proxy.get() );
637 }
638 //*************************************************************************************************
639 
640 
641 //*************************************************************************************************
649 template< typename VT >
650 inline void swap( const VectorAccessProxy<VT>& a, const VectorAccessProxy<VT>& b ) noexcept
651 {
652  using std::swap;
653 
654  swap( a.get(), b.get() );
655 }
656 //*************************************************************************************************
657 
658 
659 //*************************************************************************************************
667 template< typename VT, typename T >
668 inline void swap( const VectorAccessProxy<VT>& a, T& b ) noexcept
669 {
670  using std::swap;
671 
672  swap( a.get(), b );
673 }
674 //*************************************************************************************************
675 
676 
677 //*************************************************************************************************
685 template< typename T, typename VT >
686 inline void swap( T& a, const VectorAccessProxy<VT>& b ) noexcept
687 {
688  using std::swap;
689 
690  swap( a, b.get() );
691 }
692 //*************************************************************************************************
693 
694 } // namespace blaze
695 
696 #endif
bool isReal(const DiagonalProxy< MT > &proxy)
Returns whether the matrix element represents a real number.
Definition: DiagonalProxy.h:622
Header file for the isnan shim.
Header file for auxiliary alias declarations.
Header file for basic type definitions.
Proxy base class.The Proxy class is a base class for all proxy classes within the Blaze library that ...
Definition: Forward.h:51
Access proxy for sparse, N-dimensional vectors.The VectorAccessProxy provides safe access to the elem...
Definition: VectorAccessProxy.h:101
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:560
VT & sv_
Reference to the accessed sparse vector.
Definition: VectorAccessProxy.h:164
VectorAccessProxy(VT &sv, size_t i)
Initialization constructor for a VectorAccessProxy.
Definition: VectorAccessProxy.h:200
size_t i_
Index of the accessed sparse vector element.
Definition: VectorAccessProxy.h:165
Header file for the Proxy class.
Header file for the std::initializer_list aliases.
bool isZero(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 0.
Definition: DiagonalProxy.h:642
Header file for the clear shim.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
void swap(CompressedMatrix< Type, SO > &a, CompressedMatrix< Type, SO > &b) noexcept
Swapping the contents of two compressed matrices.
Definition: CompressedMatrix.h:5924
Header file for the isZero shim.
typename T::ElementType ElementType_
Alias declaration for nested ElementType type definitions.The ElementType_ alias declaration provides...
Definition: Aliases.h:163
#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:61
bool isnan(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is not a number.
Definition: DiagonalProxy.h:682
Constraint on the data type.
const VectorAccessProxy & operator=(const VectorAccessProxy &vap) const
Copy assignment operator for VectorAccessProxy.
Definition: VectorAccessProxy.h:262
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:580
Header file for the isOne shim.
Header file for run time assertion macros.
Header file for the relaxation flag types.
Header file for the reset shim.
bool isOne(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 1.
Definition: DiagonalProxy.h:662
Header file for the isDefault shim.
void swap(DiagonalMatrix< MT, SO, DF > &a, DiagonalMatrix< MT, SO, DF > &b) noexcept
Swapping the contents of two matrices.
Definition: DiagonalMatrix.h:270
typename T::Iterator Iterator_
Alias declaration for nested Iterator type definitions.The Iterator_ alias declaration provides a con...
Definition: Aliases.h:183
ElementType_< VT > RepresentedType
Type of the represented sparse vector element.
Definition: VectorAccessProxy.h:106
Initializer list type of the Blaze library.
RawReference get() const noexcept
Returning the value of the accessed sparse vector element.
Definition: VectorAccessProxy.h:418
~VectorAccessProxy()
The destructor for VectorAccessProxy.
Definition: VectorAccessProxy.h:238
bool isRestricted() const noexcept
Returns whether the proxy represents a restricted sparse vector element..
Definition: VectorAccessProxy.h:433
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:600
Header file for the isReal shim.
#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
RepresentedType & RawReference
Raw reference to the represented element.
Definition: VectorAccessProxy.h:107