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 <stdexcept>
46 #include <blaze/math/shims/Clear.h>
47 #include <blaze/math/shims/Reset.h>
49 #include <blaze/system/Inline.h>
50 #include <blaze/util/Types.h>
51 
52 
53 namespace blaze {
54 
55 //=================================================================================================
56 //
57 // CLASS DEFINITION
58 //
59 //=================================================================================================
60 
61 //*************************************************************************************************
69 template< typename PT // Type of the proxy
70  , typename VT > // Type of the dense vector
71 class DenseVectorProxy : public DenseVector< PT, IsRowVector<VT>::value >
72 {
73  public:
74  //**Type definitions****************************************************************************
75  typedef typename VT::Reference Reference;
77  typedef typename VT::Pointer Pointer;
78  typedef typename VT::ConstPointer ConstPointer;
79  typedef typename VT::Iterator Iterator;
80  typedef typename VT::ConstIterator ConstIterator;
81  //**********************************************************************************************
82 
83  //**Data access functions***********************************************************************
86  inline Reference operator[]( size_t index ) const;
87 
88  inline Pointer data () const;
89  inline Iterator begin () const;
90  inline ConstIterator cbegin() const;
91  inline Iterator end () const;
92  inline ConstIterator cend () const;
94  //**********************************************************************************************
95 
96  //**Utility functions***************************************************************************
99  inline size_t size() const;
100  inline size_t capacity() const;
101  inline size_t nonZeros() const;
102  inline void reset() const;
103  inline void clear() const;
104  inline void resize( size_t n, bool preserve=true ) const;
105  inline void extend( size_t n, bool preserve=true ) const;
106  inline void reserve( size_t n ) const;
107 
108  template< typename Other > inline void scale( const Other& scalar ) const;
110  //**********************************************************************************************
111 
112  private:
113  //**Compile time checks*************************************************************************
117  //**********************************************************************************************
118 };
119 //*************************************************************************************************
120 
121 
122 
123 
124 //=================================================================================================
125 //
126 // DATA ACCESS FUNCTIONS
127 //
128 //=================================================================================================
129 
130 //*************************************************************************************************
136 template< typename PT // Type of the proxy
137  , typename VT > // Type of the dense vector
140 {
141  if( (~*this).isRestricted() )
142  throw std::invalid_argument( "Invalid access to restricted element" );
143 
144  return (~*this).get()[index];
145 }
146 //*************************************************************************************************
147 
148 
149 //*************************************************************************************************
156 template< typename PT // Type of the proxy
157  , typename VT > // Type of the dense vector
159 {
160  if( (~*this).isRestricted() )
161  throw std::invalid_argument( "Invalid access to restricted element" );
162 
163  return (~*this).get().data();
164 }
165 //*************************************************************************************************
166 
167 
168 //*************************************************************************************************
173 template< typename PT // Type of the proxy
174  , typename VT > // Type of the dense vector
176 {
177  if( (~*this).isRestricted() )
178  throw std::invalid_argument( "Invalid access to restricted element" );
179 
180  return (~*this).get().begin();
181 }
182 //*************************************************************************************************
183 
184 
185 //*************************************************************************************************
190 template< typename PT // Type of the proxy
191  , typename VT > // Type of the dense vector
193 {
194  return (~*this).get().cbegin();
195 }
196 //*************************************************************************************************
197 
198 
199 //*************************************************************************************************
204 template< typename PT // Type of the proxy
205  , typename VT > // Type of the dense vector
207 {
208  if( (~*this).isRestricted() )
209  throw std::invalid_argument( "Invalid access to restricted element" );
210 
211  return (~*this).get().end();
212 }
213 //*************************************************************************************************
214 
215 
216 //*************************************************************************************************
221 template< typename PT // Type of the proxy
222  , typename VT > // Type of the dense vector
224 {
225  return (~*this).get().cend();
226 }
227 //*************************************************************************************************
228 
229 
230 
231 
232 //=================================================================================================
233 //
234 // UTILITY FUNCTIONS
235 //
236 //=================================================================================================
237 
238 //*************************************************************************************************
243 template< typename PT // Type of the proxy
244  , typename VT > // Type of the dense vector
245 inline size_t DenseVectorProxy<PT,VT>::size() const
246 {
247  return (~*this).get().size();
248 }
249 //*************************************************************************************************
250 
251 
252 //*************************************************************************************************
257 template< typename PT // Type of the proxy
258  , typename VT > // Type of the dense vector
260 {
261  return (~*this).get().capacity();
262 }
263 //*************************************************************************************************
264 
265 
266 //*************************************************************************************************
274 template< typename PT // Type of the proxy
275  , typename VT > // Type of the dense vector
277 {
278  return (~*this).get().nonZeros();
279 }
280 //*************************************************************************************************
281 
282 
283 //*************************************************************************************************
290 template< typename PT // Type of the proxy
291  , typename VT > // Type of the dense vector
293 {
294  using blaze::reset;
295 
296  reset( (~*this).get() );
297 }
298 //*************************************************************************************************
299 
300 
301 //*************************************************************************************************
308 template< typename PT // Type of the proxy
309  , typename VT > // Type of the dense vector
311 {
312  using blaze::clear;
313 
314  clear( (~*this).get() );
315 }
316 //*************************************************************************************************
317 
318 
319 //*************************************************************************************************
334 template< typename PT // Type of the proxy
335  , typename VT > // Type of the dense vector
336 inline void DenseVectorProxy<PT,VT>::resize( size_t n, bool preserve ) const
337 {
338  if( (~*this).isRestricted() )
339  throw std::invalid_argument( "Invalid access to restricted element" );
340 
341  (~*this).get().resize( n, preserve );
342 }
343 //*************************************************************************************************
344 
345 
346 //*************************************************************************************************
359 template< typename PT // Type of the proxy
360  , typename VT > // Type of the dense vector
361 inline void DenseVectorProxy<PT,VT>::extend( size_t n, bool preserve ) const
362 {
363  if( (~*this).isRestricted() )
364  throw std::invalid_argument( "Invalid access to restricted element" );
365 
366  (~*this).get().extend( n, preserve );
367 }
368 //*************************************************************************************************
369 
370 
371 //*************************************************************************************************
380 template< typename PT // Type of the proxy
381  , typename VT > // Type of the dense vector
382 inline void DenseVectorProxy<PT,VT>::reserve( size_t n ) const
383 {
384  if( (~*this).isRestricted() )
385  throw std::invalid_argument( "Invalid access to restricted element" );
386 
387  (~*this).get().reserve( n );
388 }
389 //*************************************************************************************************
390 
391 
392 //*************************************************************************************************
398 template< typename PT // Type of the proxy
399  , typename VT > // Type of the dense vector
400 template< typename Other > // Data type of the scalar value
401 inline void DenseVectorProxy<PT,VT>::scale( const Other& scalar ) const
402 {
403  if( (~*this).isRestricted() )
404  throw std::invalid_argument( "Invalid access to restricted element" );
405 
406  (~*this).get().scale( scalar );
407 }
408 //*************************************************************************************************
409 
410 
411 
412 
413 //=================================================================================================
414 //
415 // GLOBAL FUNCTIONS
416 //
417 //=================================================================================================
418 
419 //*************************************************************************************************
422 template< typename PT, typename VT >
424  begin( const DenseVectorProxy<PT,VT>& proxy );
425 
426 template< typename PT, typename VT >
428  cbegin( const DenseVectorProxy<PT,VT>& proxy );
429 
430 template< typename PT, typename VT >
432  end( const DenseVectorProxy<PT,VT>& proxy );
433 
434 template< typename PT, typename VT >
436  cend( const DenseVectorProxy<PT,VT>& proxy );
437 
438 template< typename PT, typename VT >
439 BLAZE_ALWAYS_INLINE size_t size( const DenseVectorProxy<PT,VT>& proxy );
440 
441 template< typename PT, typename VT >
443 
444 template< typename PT, typename VT >
446 
447 template< typename PT, typename VT >
449 
450 template< typename PT, typename VT >
453 //*************************************************************************************************
454 
455 
456 //*************************************************************************************************
463 template< typename PT // Type of the proxy
464  , typename VT > // Type of the dense vector
467 {
468  return proxy.begin();
469 }
470 //*************************************************************************************************
471 
472 
473 //*************************************************************************************************
480 template< typename PT // Type of the proxy
481  , typename VT > // Type of the dense vector
484 {
485  return proxy.cbegin();
486 }
487 //*************************************************************************************************
488 
489 
490 //*************************************************************************************************
497 template< typename PT // Type of the proxy
498  , typename VT > // Type of the dense vector
500  end( const DenseVectorProxy<PT,VT>& proxy )
501 {
502  return proxy.end();
503 }
504 //*************************************************************************************************
505 
506 
507 //*************************************************************************************************
514 template< typename PT // Type of the proxy
515  , typename VT > // Type of the dense vector
518 {
519  return proxy.cend();
520 }
521 //*************************************************************************************************
522 
523 
524 //*************************************************************************************************
531 template< typename PT // Type of the proxy
532  , typename VT > // Type of the dense vector
534 {
535  return proxy.size();
536 }
537 //*************************************************************************************************
538 
539 
540 //*************************************************************************************************
547 template< typename PT // Type of the proxy
548  , typename VT > // Type of the dense vector
550 {
551  return proxy.capacity();
552 }
553 //*************************************************************************************************
554 
555 
556 //*************************************************************************************************
566 template< typename PT // Type of the proxy
567  , typename VT > // Type of the dense vector
569 {
570  return proxy.nonZeros();
571 }
572 //*************************************************************************************************
573 
574 
575 //*************************************************************************************************
584 template< typename PT // Type of the proxy
585  , typename VT > // Type of the dense vector
587 {
588  proxy.reset();
589 }
590 //*************************************************************************************************
591 
592 
593 //*************************************************************************************************
602 template< typename PT // Type of the proxy
603  , typename VT > // Type of the dense vector
605 {
606  proxy.clear();
607 }
608 //*************************************************************************************************
609 
610 } // namespace blaze
611 
612 #endif
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:237
size_t nonZeros() const
Returns the number of non-zero elements in the represented vector.
Definition: DenseVectorProxy.h:276
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector)
Returns the current size/dimension of the vector.
Definition: Vector.h:264
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:300
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:258
ConstIterator cbegin() const
Returns an iterator to the first element of the represented vector.
Definition: DenseVectorProxy.h:192
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:821
BLAZE_ALWAYS_INLINE size_t capacity(const Matrix< MT, SO > &matrix)
Returns the maximum capacity of the matrix.
Definition: Matrix.h:348
Header file for the IsRowVector type trait.
void clear() const
Clearing the represented vector.
Definition: DenseVectorProxy.h:310
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:336
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:386
void extend(size_t n, bool preserve=true) const
Extending the size of the represented vector.
Definition: DenseVectorProxy.h:361
VT::ConstReference ConstReference
Reference to a constant vector value.
Definition: DenseVectorProxy.h:76
Pointer data() const
Low-level data access to vector elements.
Definition: DenseVectorProxy.h:158
VT::ConstPointer ConstPointer
Pointer to a constant vector value.
Definition: DenseVectorProxy.h:78
VT::Iterator Iterator
Iterator over non-constant elements.
Definition: DenseVectorProxy.h:79
Proxy backend for dense vector types.The DenseVectorProxy class serves as a backend for the Proxy cla...
Definition: DenseVectorProxy.h:71
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:292
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2511
ConstIterator cend() const
Returns an iterator just past the last element of the represented vector.
Definition: DenseVectorProxy.h:223
size_t capacity() const
Returns the maximum capacity of the represented vector.
Definition: DenseVectorProxy.h:259
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:139
VT::Pointer Pointer
Pointer to a non-constant vector value.
Definition: DenseVectorProxy.h:77
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:195
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2509
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:841
void scale(const Other &scalar) const
Scaling of the vector by the scalar value scalar ( ).
Definition: DenseVectorProxy.h:401
Iterator end() const
Returns an iterator just past the last element of the represented vector.
Definition: DenseVectorProxy.h:206
size_t size() const
Returns the current size/dimension of the represented vector.
Definition: DenseVectorProxy.h:245
VT::Reference Reference
Reference to a non-constant vector value.
Definition: DenseVectorProxy.h:75
Header file for the reset shim.
void reserve(size_t n) const
Setting the minimum capacity of the represented vector.
Definition: DenseVectorProxy.h:382
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2510
#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::ConstIterator ConstIterator
Iterator over constant elements.
Definition: DenseVectorProxy.h:80
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2508
System settings for the inline keywords.
Iterator begin() const
Returns an iterator to the first element of the represented vector.
Definition: DenseVectorProxy.h:175