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 
45 #include <blaze/math/shims/Clear.h>
46 #include <blaze/math/shims/Reset.h>
49 #include <blaze/system/Inline.h>
50 #include <blaze/util/DisableIf.h>
51 #include <blaze/util/EnableIf.h>
52 #include <blaze/util/Exception.h>
53 #include <blaze/util/Types.h>
54 #include <blaze/util/Unused.h>
55 
56 
57 namespace blaze {
58 
59 //=================================================================================================
60 //
61 // CLASS DEFINITION
62 //
63 //=================================================================================================
64 
65 //*************************************************************************************************
73 template< typename PT // Type of the proxy
74  , typename VT > // Type of the dense vector
75 class DenseVectorProxy : public DenseVector< PT, IsRowVector<VT>::value >
76 {
77  public:
78  //**Type definitions****************************************************************************
79  typedef typename VT::ResultType ResultType;
80  typedef typename VT::TransposeType TransposeType;
81  typedef typename VT::ElementType ElementType;
82  typedef typename VT::ReturnType ReturnType;
83  typedef typename VT::CompositeType CompositeType;
84  typedef typename VT::Reference Reference;
86  typedef typename VT::Pointer Pointer;
87  typedef typename VT::ConstPointer ConstPointer;
88  typedef typename VT::Iterator Iterator;
89  typedef typename VT::ConstIterator ConstIterator;
90  //**********************************************************************************************
91 
92  //**Compilation flags***************************************************************************
94  enum { vectorizable = VT::vectorizable };
95 
97  enum { smpAssignable = VT::smpAssignable };
98  //**********************************************************************************************
99 
100  //**Data access functions***********************************************************************
103  inline Reference operator[]( size_t index ) const;
104 
105  inline Pointer data () const;
106  inline Iterator begin () const;
107  inline ConstIterator cbegin() const;
108  inline Iterator end () const;
109  inline ConstIterator cend () const;
111  //**********************************************************************************************
112 
113  //**Utility functions***************************************************************************
116  inline size_t size() const;
117  inline size_t capacity() const;
118  inline size_t nonZeros() const;
119  inline void reset() const;
120  inline void clear() const;
121  inline void resize( size_t n, bool preserve=true ) const;
122  inline void extend( size_t n, bool preserve=true ) const;
123  inline void reserve( size_t n ) const;
124 
125  template< typename Other > inline void scale( const Other& scalar ) const;
127  //**********************************************************************************************
128 
129  private:
130  //**Compile time checks*************************************************************************
134  //**********************************************************************************************
135 };
136 //*************************************************************************************************
137 
138 
139 
140 
141 //=================================================================================================
142 //
143 // DATA ACCESS FUNCTIONS
144 //
145 //=================================================================================================
146 
147 //*************************************************************************************************
153 template< typename PT // Type of the proxy
154  , typename VT > // Type of the dense vector
157 {
158  if( (~*this).isRestricted() ) {
159  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
160  }
161 
162  return (~*this).get()[index];
163 }
164 //*************************************************************************************************
165 
166 
167 //*************************************************************************************************
174 template< typename PT // Type of the proxy
175  , typename VT > // Type of the dense vector
177 {
178  if( (~*this).isRestricted() ) {
179  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
180  }
181 
182  return (~*this).get().data();
183 }
184 //*************************************************************************************************
185 
186 
187 //*************************************************************************************************
192 template< typename PT // Type of the proxy
193  , typename VT > // Type of the dense vector
195 {
196  if( (~*this).isRestricted() ) {
197  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
198  }
199 
200  return (~*this).get().begin();
201 }
202 //*************************************************************************************************
203 
204 
205 //*************************************************************************************************
210 template< typename PT // Type of the proxy
211  , typename VT > // Type of the dense vector
213 {
214  return (~*this).get().cbegin();
215 }
216 //*************************************************************************************************
217 
218 
219 //*************************************************************************************************
224 template< typename PT // Type of the proxy
225  , typename VT > // Type of the dense vector
227 {
228  if( (~*this).isRestricted() ) {
229  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
230  }
231 
232  return (~*this).get().end();
233 }
234 //*************************************************************************************************
235 
236 
237 //*************************************************************************************************
242 template< typename PT // Type of the proxy
243  , typename VT > // Type of the dense vector
245 {
246  return (~*this).get().cend();
247 }
248 //*************************************************************************************************
249 
250 
251 
252 
253 //=================================================================================================
254 //
255 // UTILITY FUNCTIONS
256 //
257 //=================================================================================================
258 
259 //*************************************************************************************************
264 template< typename PT // Type of the proxy
265  , typename VT > // Type of the dense vector
266 inline size_t DenseVectorProxy<PT,VT>::size() const
267 {
268  return (~*this).get().size();
269 }
270 //*************************************************************************************************
271 
272 
273 //*************************************************************************************************
278 template< typename PT // Type of the proxy
279  , typename VT > // Type of the dense vector
281 {
282  return (~*this).get().capacity();
283 }
284 //*************************************************************************************************
285 
286 
287 //*************************************************************************************************
295 template< typename PT // Type of the proxy
296  , typename VT > // Type of the dense vector
298 {
299  return (~*this).get().nonZeros();
300 }
301 //*************************************************************************************************
302 
303 
304 //*************************************************************************************************
311 template< typename PT // Type of the proxy
312  , typename VT > // Type of the dense vector
314 {
315  using blaze::reset;
316 
317  reset( (~*this).get() );
318 }
319 //*************************************************************************************************
320 
321 
322 //*************************************************************************************************
329 template< typename PT // Type of the proxy
330  , typename VT > // Type of the dense vector
332 {
333  using blaze::clear;
334 
335  clear( (~*this).get() );
336 }
337 //*************************************************************************************************
338 
339 
340 //*************************************************************************************************
355 template< typename PT // Type of the proxy
356  , typename VT > // Type of the dense vector
357 inline void DenseVectorProxy<PT,VT>::resize( size_t n, bool preserve ) const
358 {
359  if( (~*this).isRestricted() ) {
360  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
361  }
362 
363  (~*this).get().resize( n, preserve );
364 }
365 //*************************************************************************************************
366 
367 
368 //*************************************************************************************************
381 template< typename PT // Type of the proxy
382  , typename VT > // Type of the dense vector
383 inline void DenseVectorProxy<PT,VT>::extend( size_t n, bool preserve ) const
384 {
385  if( (~*this).isRestricted() ) {
386  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
387  }
388 
389  (~*this).get().extend( n, preserve );
390 }
391 //*************************************************************************************************
392 
393 
394 //*************************************************************************************************
403 template< typename PT // Type of the proxy
404  , typename VT > // Type of the dense vector
405 inline void DenseVectorProxy<PT,VT>::reserve( size_t n ) const
406 {
407  if( (~*this).isRestricted() ) {
408  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
409  }
410 
411  (~*this).get().reserve( n );
412 }
413 //*************************************************************************************************
414 
415 
416 //*************************************************************************************************
422 template< typename PT // Type of the proxy
423  , typename VT > // Type of the dense vector
424 template< typename Other > // Data type of the scalar value
425 inline void DenseVectorProxy<PT,VT>::scale( const Other& scalar ) const
426 {
427  if( (~*this).isRestricted() ) {
428  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
429  }
430 
431  (~*this).get().scale( scalar );
432 }
433 //*************************************************************************************************
434 
435 
436 
437 
438 //=================================================================================================
439 //
440 // GLOBAL FUNCTIONS
441 //
442 //=================================================================================================
443 
444 //*************************************************************************************************
447 template< typename PT, typename VT >
449  begin( const DenseVectorProxy<PT,VT>& proxy );
450 
451 template< typename PT, typename VT >
453  cbegin( const DenseVectorProxy<PT,VT>& proxy );
454 
455 template< typename PT, typename VT >
457  end( const DenseVectorProxy<PT,VT>& proxy );
458 
459 template< typename PT, typename VT >
461  cend( const DenseVectorProxy<PT,VT>& proxy );
462 
463 template< typename PT, typename VT >
464 BLAZE_ALWAYS_INLINE size_t size( const DenseVectorProxy<PT,VT>& proxy );
465 
466 template< typename PT, typename VT >
468 
469 template< typename PT, typename VT >
471 
472 template< typename PT, typename VT >
473 BLAZE_ALWAYS_INLINE void resize( const DenseVectorProxy<PT,VT>& proxy, size_t n, bool preserve=true );
474 
475 template< typename PT, typename VT >
477 
478 template< typename PT, typename VT >
481 //*************************************************************************************************
482 
483 
484 //*************************************************************************************************
491 template< typename PT // Type of the proxy
492  , typename VT > // Type of the dense vector
495 {
496  return proxy.begin();
497 }
498 //*************************************************************************************************
499 
500 
501 //*************************************************************************************************
508 template< typename PT // Type of the proxy
509  , typename VT > // Type of the dense vector
512 {
513  return proxy.cbegin();
514 }
515 //*************************************************************************************************
516 
517 
518 //*************************************************************************************************
525 template< typename PT // Type of the proxy
526  , typename VT > // Type of the dense vector
528  end( const DenseVectorProxy<PT,VT>& proxy )
529 {
530  return proxy.end();
531 }
532 //*************************************************************************************************
533 
534 
535 //*************************************************************************************************
542 template< typename PT // Type of the proxy
543  , typename VT > // Type of the dense vector
546 {
547  return proxy.cend();
548 }
549 //*************************************************************************************************
550 
551 
552 //*************************************************************************************************
559 template< typename PT // Type of the proxy
560  , typename VT > // Type of the dense vector
562 {
563  return proxy.size();
564 }
565 //*************************************************************************************************
566 
567 
568 //*************************************************************************************************
575 template< typename PT // Type of the proxy
576  , typename VT > // Type of the dense vector
578 {
579  return proxy.capacity();
580 }
581 //*************************************************************************************************
582 
583 
584 //*************************************************************************************************
594 template< typename PT // Type of the proxy
595  , typename VT > // Type of the dense vector
597 {
598  return proxy.nonZeros();
599 }
600 //*************************************************************************************************
601 
602 
603 //*************************************************************************************************
618 template< typename PT // Type of the proxy
619  , typename VT > // Type of the dense vector
620 BLAZE_ALWAYS_INLINE typename DisableIf< IsResizable<VT> >::Type
621  resize_backend( const DenseVectorProxy<PT,VT>& proxy, size_t n, bool preserve )
622 {
623  UNUSED_PARAMETER( preserve );
624 
625  if( proxy.size() != n ) {
626  BLAZE_THROW_INVALID_ARGUMENT( "Vector cannot be resized" );
627  }
628 }
630 //*************************************************************************************************
631 
632 
633 //*************************************************************************************************
645 template< typename PT // Type of the proxy
646  , typename VT > // Type of the dense vector
647 BLAZE_ALWAYS_INLINE typename EnableIf< IsResizable<VT> >::Type
648  resize_backend( const DenseVectorProxy<PT,VT>& proxy, size_t n, bool preserve )
649 {
650  proxy.resize( n, preserve );
651 }
653 //*************************************************************************************************
654 
655 
656 //*************************************************************************************************
676 template< typename PT // Type of the proxy
677  , typename VT > // Type of the dense vector
678 BLAZE_ALWAYS_INLINE void resize( const DenseVectorProxy<PT,VT>& proxy, size_t n, bool preserve )
679 {
680  resize_backend( proxy, n, preserve );
681 }
682 //*************************************************************************************************
683 
684 
685 //*************************************************************************************************
694 template< typename PT // Type of the proxy
695  , typename VT > // Type of the dense vector
697 {
698  proxy.reset();
699 }
700 //*************************************************************************************************
701 
702 
703 //*************************************************************************************************
712 template< typename PT // Type of the proxy
713  , typename VT > // Type of the dense vector
715 {
716  proxy.clear();
717 }
718 //*************************************************************************************************
719 
720 } // namespace blaze
721 
722 #endif
VT::CompositeType CompositeType
Data type for composite expression templates.
Definition: DenseVectorProxy.h:83
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exceptionThis macro encapsulates the default way of...
Definition: Exception.h:187
Header file for the UNUSED_PARAMETER function template.
Header file for basic type definitions.
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:229
size_t nonZeros() const
Returns the number of non-zero elements in the represented vector.
Definition: DenseVectorProxy.h:297
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector)
Returns the current size/dimension of the vector.
Definition: Vector.h:252
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:292
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:250
ConstIterator cbegin() const
Returns an iterator to the first element of the represented vector.
Definition: DenseVectorProxy.h:212
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:507
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2588
BLAZE_ALWAYS_INLINE size_t capacity(const Matrix< MT, SO > &matrix)
Returns the maximum capacity of the matrix.
Definition: Matrix.h:340
Header file for the IsRowVector type trait.
void clear() const
Clearing the represented vector.
Definition: DenseVectorProxy.h:331
void UNUSED_PARAMETER(const T1 &)
Suppression of unused parameter warnings.
Definition: Unused.h:81
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:357
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:378
void extend(size_t n, bool preserve=true) const
Extending the size of the represented vector.
Definition: DenseVectorProxy.h:383
VT::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: DenseVectorProxy.h:80
VT::ConstReference ConstReference
Reference to a constant vector value.
Definition: DenseVectorProxy.h:85
Pointer data() const
Low-level data access to vector elements.
Definition: DenseVectorProxy.h:176
VT::ConstPointer ConstPointer
Pointer to a constant vector value.
Definition: DenseVectorProxy.h:87
VT::Iterator Iterator
Iterator over non-constant elements.
Definition: DenseVectorProxy.h:88
Proxy backend for dense vector types.The DenseVectorProxy class serves as a backend for the Proxy cla...
Definition: DenseVectorProxy.h:75
Header file for the DisableIf class template.
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:313
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2592
ConstIterator cend() const
Returns an iterator just past the last element of the represented vector.
Definition: DenseVectorProxy.h:244
size_t capacity() const
Returns the maximum capacity of the represented vector.
Definition: DenseVectorProxy.h:280
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:156
VT::Pointer Pointer
Pointer to a non-constant vector value.
Definition: DenseVectorProxy.h:86
CompressedMatrix< Type, false > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:2585
Constraint on the data type.
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:187
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:532
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2586
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2590
Header file for the EnableIf class template.
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:527
void scale(const Other &scalar) const
Scaling of the vector by the scalar value scalar ( ).
Definition: DenseVectorProxy.h:425
Iterator end() const
Returns an iterator just past the last element of the represented vector.
Definition: DenseVectorProxy.h:226
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2587
VT::ReturnType ReturnType
Return type for expression template evaluations.
Definition: DenseVectorProxy.h:82
size_t size() const
Returns the current size/dimension of the represented vector.
Definition: DenseVectorProxy.h:266
VT::Reference Reference
Reference to a non-constant vector value.
Definition: DenseVectorProxy.h:84
Header file for the reset shim.
void reserve(size_t n) const
Setting the minimum capacity of the represented vector.
Definition: DenseVectorProxy.h:405
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2591
#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:79
VT::ResultType ResultType
Result type for expression template evaluations.
Definition: DenseVectorProxy.h:79
VT::ConstIterator ConstIterator
Iterator over constant elements.
Definition: DenseVectorProxy.h:89
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2583
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2589
Header file for exception macros.
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:194
VT::ElementType ElementType
Type of the vector elements.
Definition: DenseVectorProxy.h:81