DenseVectorProxy.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_PROXY_DENSEVECTORPROXY_H_
36 #define _BLAZE_MATH_PROXY_DENSEVECTORPROXY_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <blaze/math/Aliases.h>
45 #include <blaze/math/Exception.h>
47 #include <blaze/math/shims/Clear.h>
48 #include <blaze/math/shims/Reset.h>
51 #include <blaze/system/Inline.h>
52 #include <blaze/util/DisableIf.h>
53 #include <blaze/util/EnableIf.h>
54 #include <blaze/util/Types.h>
55 #include <blaze/util/Unused.h>
56 
57 
58 namespace blaze {
59 
60 //=================================================================================================
61 //
62 // CLASS DEFINITION
63 //
64 //=================================================================================================
65 
66 //*************************************************************************************************
74 template< typename PT // Type of the proxy
75  , typename VT > // Type of the dense vector
76 class DenseVectorProxy : public DenseVector< PT, IsRowVector<VT>::value >
77 {
78  public:
79  //**Type definitions****************************************************************************
91  //**********************************************************************************************
92 
93  //**Compilation flags***************************************************************************
95  enum : bool { simdEnabled = VT::simdEnabled };
96 
98  enum : bool { smpAssignable = VT::smpAssignable };
99  //**********************************************************************************************
100 
101  //**Data access functions***********************************************************************
104  inline Reference operator[]( size_t index ) const;
105  inline Reference at( size_t index ) const;
106 
107  inline Pointer data () const;
108  inline Iterator begin () const;
109  inline ConstIterator cbegin() const;
110  inline Iterator end () const;
111  inline ConstIterator cend () const;
113  //**********************************************************************************************
114 
115  //**Utility functions***************************************************************************
118  inline size_t size() const;
119  inline size_t capacity() const;
120  inline size_t nonZeros() const;
121  inline void reset() const;
122  inline void clear() const;
123  inline void resize( size_t n, bool preserve=true ) const;
124  inline void extend( size_t n, bool preserve=true ) const;
125  inline void reserve( size_t n ) const;
126 
127  template< typename Other > inline void scale( const Other& scalar ) const;
129  //**********************************************************************************************
130 
131  private:
132  //**Compile time checks*************************************************************************
136  //**********************************************************************************************
137 };
138 //*************************************************************************************************
139 
140 
141 
142 
143 //=================================================================================================
144 //
145 // DATA ACCESS FUNCTIONS
146 //
147 //=================================================================================================
148 
149 //*************************************************************************************************
156 template< typename PT // Type of the proxy
157  , typename VT > // Type of the dense vector
160 {
161  if( (~*this).isRestricted() ) {
162  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
163  }
164 
165  return (~*this).get()[index];
166 }
167 //*************************************************************************************************
168 
169 
170 //*************************************************************************************************
181 template< typename PT // Type of the proxy
182  , typename VT > // Type of the dense vector
184  DenseVectorProxy<PT,VT>::at( size_t index ) const
185 {
186  if( (~*this).isRestricted() ) {
187  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
188  }
189 
190  return (~*this).get().at( index );
191 }
192 //*************************************************************************************************
193 
194 
195 //*************************************************************************************************
203 template< typename PT // Type of the proxy
204  , typename VT > // Type of the dense vector
206 {
207  if( (~*this).isRestricted() ) {
208  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
209  }
210 
211  return (~*this).get().data();
212 }
213 //*************************************************************************************************
214 
215 
216 //*************************************************************************************************
222 template< typename PT // Type of the proxy
223  , typename VT > // Type of the dense vector
225 {
226  if( (~*this).isRestricted() ) {
227  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
228  }
229 
230  return (~*this).get().begin();
231 }
232 //*************************************************************************************************
233 
234 
235 //*************************************************************************************************
240 template< typename PT // Type of the proxy
241  , typename VT > // Type of the dense vector
243 {
244  return (~*this).get().cbegin();
245 }
246 //*************************************************************************************************
247 
248 
249 //*************************************************************************************************
255 template< typename PT // Type of the proxy
256  , typename VT > // Type of the dense vector
258 {
259  if( (~*this).isRestricted() ) {
260  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
261  }
262 
263  return (~*this).get().end();
264 }
265 //*************************************************************************************************
266 
267 
268 //*************************************************************************************************
273 template< typename PT // Type of the proxy
274  , typename VT > // Type of the dense vector
276 {
277  return (~*this).get().cend();
278 }
279 //*************************************************************************************************
280 
281 
282 
283 
284 //=================================================================================================
285 //
286 // UTILITY FUNCTIONS
287 //
288 //=================================================================================================
289 
290 //*************************************************************************************************
295 template< typename PT // Type of the proxy
296  , typename VT > // Type of the dense vector
297 inline size_t DenseVectorProxy<PT,VT>::size() const
298 {
299  return (~*this).get().size();
300 }
301 //*************************************************************************************************
302 
303 
304 //*************************************************************************************************
309 template< typename PT // Type of the proxy
310  , typename VT > // Type of the dense vector
312 {
313  return (~*this).get().capacity();
314 }
315 //*************************************************************************************************
316 
317 
318 //*************************************************************************************************
326 template< typename PT // Type of the proxy
327  , typename VT > // Type of the dense vector
329 {
330  return (~*this).get().nonZeros();
331 }
332 //*************************************************************************************************
333 
334 
335 //*************************************************************************************************
342 template< typename PT // Type of the proxy
343  , typename VT > // Type of the dense vector
345 {
346  using blaze::reset;
347 
348  reset( (~*this).get() );
349 }
350 //*************************************************************************************************
351 
352 
353 //*************************************************************************************************
360 template< typename PT // Type of the proxy
361  , typename VT > // Type of the dense vector
363 {
364  using blaze::clear;
365 
366  clear( (~*this).get() );
367 }
368 //*************************************************************************************************
369 
370 
371 //*************************************************************************************************
387 template< typename PT // Type of the proxy
388  , typename VT > // Type of the dense vector
389 inline void DenseVectorProxy<PT,VT>::resize( size_t n, bool preserve ) const
390 {
391  if( (~*this).isRestricted() ) {
392  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
393  }
394 
395  (~*this).get().resize( n, preserve );
396 }
397 //*************************************************************************************************
398 
399 
400 //*************************************************************************************************
414 template< typename PT // Type of the proxy
415  , typename VT > // Type of the dense vector
416 inline void DenseVectorProxy<PT,VT>::extend( size_t n, bool preserve ) const
417 {
418  if( (~*this).isRestricted() ) {
419  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
420  }
421 
422  (~*this).get().extend( n, preserve );
423 }
424 //*************************************************************************************************
425 
426 
427 //*************************************************************************************************
437 template< typename PT // Type of the proxy
438  , typename VT > // Type of the dense vector
439 inline void DenseVectorProxy<PT,VT>::reserve( size_t n ) const
440 {
441  if( (~*this).isRestricted() ) {
442  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
443  }
444 
445  (~*this).get().reserve( n );
446 }
447 //*************************************************************************************************
448 
449 
450 //*************************************************************************************************
457 template< typename PT // Type of the proxy
458  , typename VT > // Type of the dense vector
459 template< typename Other > // Data type of the scalar value
460 inline void DenseVectorProxy<PT,VT>::scale( const Other& scalar ) const
461 {
462  if( (~*this).isRestricted() ) {
463  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
464  }
465 
466  (~*this).get().scale( scalar );
467 }
468 //*************************************************************************************************
469 
470 
471 
472 
473 //=================================================================================================
474 //
475 // GLOBAL FUNCTIONS
476 //
477 //=================================================================================================
478 
479 //*************************************************************************************************
482 template< typename PT, typename VT >
484  begin( const DenseVectorProxy<PT,VT>& proxy );
485 
486 template< typename PT, typename VT >
488  cbegin( const DenseVectorProxy<PT,VT>& proxy );
489 
490 template< typename PT, typename VT >
492  end( const DenseVectorProxy<PT,VT>& proxy );
493 
494 template< typename PT, typename VT >
496  cend( const DenseVectorProxy<PT,VT>& proxy );
497 
498 template< typename PT, typename VT >
499 BLAZE_ALWAYS_INLINE size_t size( const DenseVectorProxy<PT,VT>& proxy );
500 
501 template< typename PT, typename VT >
503 
504 template< typename PT, typename VT >
506 
507 template< typename PT, typename VT >
508 BLAZE_ALWAYS_INLINE void resize( const DenseVectorProxy<PT,VT>& proxy, size_t n, bool preserve=true );
509 
510 template< typename PT, typename VT >
512 
513 template< typename PT, typename VT >
516 //*************************************************************************************************
517 
518 
519 //*************************************************************************************************
526 template< typename PT // Type of the proxy
527  , typename VT > // Type of the dense vector
530 {
531  return proxy.begin();
532 }
533 //*************************************************************************************************
534 
535 
536 //*************************************************************************************************
543 template< typename PT // Type of the proxy
544  , typename VT > // Type of the dense vector
547 {
548  return proxy.cbegin();
549 }
550 //*************************************************************************************************
551 
552 
553 //*************************************************************************************************
560 template< typename PT // Type of the proxy
561  , typename VT > // Type of the dense vector
563  end( const DenseVectorProxy<PT,VT>& proxy )
564 {
565  return proxy.end();
566 }
567 //*************************************************************************************************
568 
569 
570 //*************************************************************************************************
577 template< typename PT // Type of the proxy
578  , typename VT > // Type of the dense vector
581 {
582  return proxy.cend();
583 }
584 //*************************************************************************************************
585 
586 
587 //*************************************************************************************************
594 template< typename PT // Type of the proxy
595  , typename VT > // Type of the dense vector
597 {
598  return proxy.size();
599 }
600 //*************************************************************************************************
601 
602 
603 //*************************************************************************************************
610 template< typename PT // Type of the proxy
611  , typename VT > // Type of the dense vector
613 {
614  return proxy.capacity();
615 }
616 //*************************************************************************************************
617 
618 
619 //*************************************************************************************************
629 template< typename PT // Type of the proxy
630  , typename VT > // Type of the dense vector
632 {
633  return proxy.nonZeros();
634 }
635 //*************************************************************************************************
636 
637 
638 //*************************************************************************************************
653 template< typename PT // Type of the proxy
654  , typename VT > // Type of the dense vector
655 BLAZE_ALWAYS_INLINE DisableIf_< IsResizable<VT> >
656  resize_backend( const DenseVectorProxy<PT,VT>& proxy, size_t n, bool preserve )
657 {
658  UNUSED_PARAMETER( preserve );
659 
660  if( proxy.size() != n ) {
661  BLAZE_THROW_INVALID_ARGUMENT( "Vector cannot be resized" );
662  }
663 }
665 //*************************************************************************************************
666 
667 
668 //*************************************************************************************************
680 template< typename PT // Type of the proxy
681  , typename VT > // Type of the dense vector
682 BLAZE_ALWAYS_INLINE EnableIf_< IsResizable<VT> >
683  resize_backend( const DenseVectorProxy<PT,VT>& proxy, size_t n, bool preserve )
684 {
685  proxy.resize( n, preserve );
686 }
688 //*************************************************************************************************
689 
690 
691 //*************************************************************************************************
711 template< typename PT // Type of the proxy
712  , typename VT > // Type of the dense vector
713 BLAZE_ALWAYS_INLINE void resize( const DenseVectorProxy<PT,VT>& proxy, size_t n, bool preserve )
714 {
715  resize_backend( proxy, n, preserve );
716 }
717 //*************************************************************************************************
718 
719 
720 //*************************************************************************************************
729 template< typename PT // Type of the proxy
730  , typename VT > // Type of the dense vector
732 {
733  proxy.reset();
734 }
735 //*************************************************************************************************
736 
737 
738 //*************************************************************************************************
747 template< typename PT // Type of the proxy
748  , typename VT > // Type of the dense vector
750 {
751  proxy.clear();
752 }
753 //*************************************************************************************************
754 
755 } // namespace blaze
756 
757 #endif
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.This macro encapsulates the default way o...
Definition: Exception.h:235
Header file for auxiliary alias declarations.
Header file for the UNUSED_PARAMETER function template.
ReturnType_< VT > ReturnType
Return type for expression template evaluations.
Definition: DenseVectorProxy.h:83
BLAZE_ALWAYS_INLINE size_t capacity(const Matrix< MT, SO > &matrix) noexcept
Returns the maximum capacity of the matrix.
Definition: Matrix.h:346
Header file for basic type definitions.
size_t nonZeros() const
Returns the number of non-zero elements in the represented vector.
Definition: DenseVectorProxy.h:328
ConstIterator cbegin() const
Returns an iterator to the first element of the represented vector.
Definition: DenseVectorProxy.h:242
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector) noexcept
Returns the current size/dimension of the vector.
Definition: Vector.h:258
Pointer_< VT > Pointer
Pointer to a non-constant vector value.
Definition: DenseVectorProxy.h:87
Reference at(size_t index) const
Checked access to the vector elements.
Definition: DenseVectorProxy.h:184
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:188
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:533
Header file for the IsRowVector type trait.
void clear() const
Clearing the represented vector.
Definition: DenseVectorProxy.h:362
Header file for the DenseVector base class.
void resize(size_t n, bool preserve=true) const
Changing the size of the represented vector.
Definition: DenseVectorProxy.h:389
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:384
void extend(size_t n, bool preserve=true) const
Extending the size of the represented vector.
Definition: DenseVectorProxy.h:416
typename T::ResultType ResultType_
Alias declaration for nested ResultType type definitions.The ResultType_ alias declaration provides a...
Definition: Aliases.h:323
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:298
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:232
Pointer data() const
Low-level data access to vector elements.
Definition: DenseVectorProxy.h:205
typename T::ReturnType ReturnType_
Alias declaration for nested ReturnType type definitions.The ReturnType_ alias declaration provides a...
Definition: Aliases.h:343
Proxy backend for dense vector types.The DenseVectorProxy class serves as a backend for the Proxy cla...
Definition: DenseVectorProxy.h:76
typename T::CompositeType CompositeType_
Alias declaration for nested CompositeType type definitions.The CompositeType_ alias declaration prov...
Definition: Aliases.h:83
Header file for the DisableIf class template.
typename T::Pointer Pointer_
Alias declaration for nested Pointer type definitions.The Pointer_ alias declaration provides a conve...
Definition: Aliases.h:263
Header file for the clear shim.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
#define BLAZE_ALWAYS_INLINE
Platform dependent setup of an enforced inline keyword.
Definition: Inline.h:85
void reset() const
Reset to the default initial value.
Definition: DenseVectorProxy.h:344
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2647
ConstIterator_< VT > ConstIterator
Iterator over constant elements.
Definition: DenseVectorProxy.h:90
Iterator_< VT > Iterator
Iterator over non-constant elements.
Definition: DenseVectorProxy.h:89
ElementType_< VT > ElementType
Type of the vector elements.
Definition: DenseVectorProxy.h:82
ConstIterator cend() const
Returns an iterator just past the last element of the represented vector.
Definition: DenseVectorProxy.h:275
typename T::ElementType ElementType_
Alias declaration for nested ElementType type definitions.The ElementType_ alias declaration provides...
Definition: Aliases.h:163
size_t capacity() const
Returns the maximum capacity of the represented vector.
Definition: DenseVectorProxy.h:311
CompositeType_< VT > CompositeType
Data type for composite expression templates.
Definition: DenseVectorProxy.h:84
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
Reference operator[](size_t index) const
Subscript operator for the direct access to vector elements.
Definition: DenseVectorProxy.h:159
ResultType_< VT > ResultType
Result type for expression template evaluations.
Definition: DenseVectorProxy.h:80
Constraint on the data type.
Header file for the exception macros of the math module.
BLAZE_ALWAYS_INLINE void resize(Matrix< MT, SO > &matrix, size_t rows, size_t columns, bool preserve=true)
Changing the size of the matrix.
Definition: Matrix.h:538
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:254
typename T::Reference Reference_
Alias declaration for nested Reference type definitions.The Reference_ alias declaration provides a c...
Definition: Aliases.h:283
Header file for the EnableIf class template.
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:553
void scale(const Other &scalar) const
Scaling of the vector by the scalar value scalar ( ).
Definition: DenseVectorProxy.h:460
Iterator end() const
Returns an iterator just past the last element of the represented vector.
Definition: DenseVectorProxy.h:257
Reference_< VT > Reference
Reference to a non-constant vector value.
Definition: DenseVectorProxy.h:85
size_t size() const
Returns the current size/dimension of the represented vector.
Definition: DenseVectorProxy.h:297
Header file for the reset shim.
void reserve(size_t n) const
Setting the minimum capacity of the represented vector.
Definition: DenseVectorProxy.h:439
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2646
TransposeType_< VT > TransposeType
Transpose type for expression template evaluations.
Definition: DenseVectorProxy.h:81
ConstReference_< VT > ConstReference
Reference to a constant vector value.
Definition: DenseVectorProxy.h:86
typename T::Iterator Iterator_
Alias declaration for nested Iterator type definitions.The Iterator_ alias declaration provides a con...
Definition: Aliases.h:183
typename T::ConstPointer ConstPointer_
Alias declaration for nested ConstPointer type definitions.The ConstPointer_ alias declaration provid...
Definition: Aliases.h:123
typename T::ConstReference ConstReference_
Alias declaration for nested ConstReference type definitions.The ConstReference_ alias declaration pr...
Definition: Aliases.h:143
typename T::ConstIterator ConstIterator_
Alias declaration for nested ConstIterator type definitions.The ConstIterator_ alias declaration prov...
Definition: Aliases.h:103
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a dense, N-dimensional vector type...
Definition: DenseVector.h:61
ConstPointer_< VT > ConstPointer
Pointer to a constant vector value.
Definition: DenseVectorProxy.h:88
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2644
typename T::TransposeType TransposeType_
Alias declaration for nested TransposeType type definitions.The TransposeType_ alias declaration prov...
Definition: Aliases.h:403
void UNUSED_PARAMETER(const Args &...)
Suppression of unused parameter warnings.
Definition: Unused.h:81
Header file for the IsResizable type trait.
System settings for the inline keywords.
Iterator begin() const
Returns an iterator to the first element of the represented vector.
Definition: DenseVectorProxy.h:224