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;
127  //**********************************************************************************************
128 
129  //**Numeric functions***************************************************************************
132  template< typename Other > inline void scale( const Other& scalar ) const;
134  //**********************************************************************************************
135 
136  private:
137  //**Compile time checks*************************************************************************
141  //**********************************************************************************************
142 };
143 //*************************************************************************************************
144 
145 
146 
147 
148 //=================================================================================================
149 //
150 // DATA ACCESS FUNCTIONS
151 //
152 //=================================================================================================
153 
154 //*************************************************************************************************
161 template< typename PT // Type of the proxy
162  , typename VT > // Type of the dense vector
165 {
166  if( (~*this).isRestricted() ) {
167  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
168  }
169 
170  return (~*this).get()[index];
171 }
172 //*************************************************************************************************
173 
174 
175 //*************************************************************************************************
186 template< typename PT // Type of the proxy
187  , typename VT > // Type of the dense vector
189  DenseVectorProxy<PT,VT>::at( size_t index ) const
190 {
191  if( (~*this).isRestricted() ) {
192  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
193  }
194 
195  return (~*this).get().at( index );
196 }
197 //*************************************************************************************************
198 
199 
200 //*************************************************************************************************
208 template< typename PT // Type of the proxy
209  , typename VT > // Type of the dense vector
211 {
212  if( (~*this).isRestricted() ) {
213  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
214  }
215 
216  return (~*this).get().data();
217 }
218 //*************************************************************************************************
219 
220 
221 //*************************************************************************************************
227 template< typename PT // Type of the proxy
228  , typename VT > // Type of the dense vector
230 {
231  if( (~*this).isRestricted() ) {
232  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
233  }
234 
235  return (~*this).get().begin();
236 }
237 //*************************************************************************************************
238 
239 
240 //*************************************************************************************************
245 template< typename PT // Type of the proxy
246  , typename VT > // Type of the dense vector
248 {
249  return (~*this).get().cbegin();
250 }
251 //*************************************************************************************************
252 
253 
254 //*************************************************************************************************
260 template< typename PT // Type of the proxy
261  , typename VT > // Type of the dense vector
263 {
264  if( (~*this).isRestricted() ) {
265  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
266  }
267 
268  return (~*this).get().end();
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().cend();
283 }
284 //*************************************************************************************************
285 
286 
287 
288 
289 //=================================================================================================
290 //
291 // UTILITY FUNCTIONS
292 //
293 //=================================================================================================
294 
295 //*************************************************************************************************
300 template< typename PT // Type of the proxy
301  , typename VT > // Type of the dense vector
302 inline size_t DenseVectorProxy<PT,VT>::size() const
303 {
304  return (~*this).get().size();
305 }
306 //*************************************************************************************************
307 
308 
309 //*************************************************************************************************
314 template< typename PT // Type of the proxy
315  , typename VT > // Type of the dense vector
317 {
318  return (~*this).get().capacity();
319 }
320 //*************************************************************************************************
321 
322 
323 //*************************************************************************************************
331 template< typename PT // Type of the proxy
332  , typename VT > // Type of the dense vector
334 {
335  return (~*this).get().nonZeros();
336 }
337 //*************************************************************************************************
338 
339 
340 //*************************************************************************************************
347 template< typename PT // Type of the proxy
348  , typename VT > // Type of the dense vector
350 {
351  using blaze::reset;
352 
353  reset( (~*this).get() );
354 }
355 //*************************************************************************************************
356 
357 
358 //*************************************************************************************************
365 template< typename PT // Type of the proxy
366  , typename VT > // Type of the dense vector
368 {
369  using blaze::clear;
370 
371  clear( (~*this).get() );
372 }
373 //*************************************************************************************************
374 
375 
376 //*************************************************************************************************
392 template< typename PT // Type of the proxy
393  , typename VT > // Type of the dense vector
394 inline void DenseVectorProxy<PT,VT>::resize( size_t n, bool preserve ) const
395 {
396  if( (~*this).isRestricted() ) {
397  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
398  }
399 
400  (~*this).get().resize( n, preserve );
401 }
402 //*************************************************************************************************
403 
404 
405 //*************************************************************************************************
419 template< typename PT // Type of the proxy
420  , typename VT > // Type of the dense vector
421 inline void DenseVectorProxy<PT,VT>::extend( size_t n, bool preserve ) const
422 {
423  if( (~*this).isRestricted() ) {
424  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
425  }
426 
427  (~*this).get().extend( n, preserve );
428 }
429 //*************************************************************************************************
430 
431 
432 //*************************************************************************************************
442 template< typename PT // Type of the proxy
443  , typename VT > // Type of the dense vector
444 inline void DenseVectorProxy<PT,VT>::reserve( size_t n ) const
445 {
446  if( (~*this).isRestricted() ) {
447  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
448  }
449 
450  (~*this).get().reserve( n );
451 }
452 //*************************************************************************************************
453 
454 
455 //*************************************************************************************************
462 template< typename PT // Type of the proxy
463  , typename VT > // Type of the dense vector
464 template< typename Other > // Data type of the scalar value
465 inline void DenseVectorProxy<PT,VT>::scale( const Other& scalar ) const
466 {
467  if( (~*this).isRestricted() ) {
468  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
469  }
470 
471  (~*this).get().scale( scalar );
472 }
473 //*************************************************************************************************
474 
475 
476 
477 
478 //=================================================================================================
479 //
480 // GLOBAL FUNCTIONS
481 //
482 //=================================================================================================
483 
484 //*************************************************************************************************
487 template< typename PT, typename VT >
489  begin( const DenseVectorProxy<PT,VT>& proxy );
490 
491 template< typename PT, typename VT >
493  cbegin( const DenseVectorProxy<PT,VT>& proxy );
494 
495 template< typename PT, typename VT >
497  end( const DenseVectorProxy<PT,VT>& proxy );
498 
499 template< typename PT, typename VT >
501  cend( const DenseVectorProxy<PT,VT>& proxy );
502 
503 template< typename PT, typename VT >
504 BLAZE_ALWAYS_INLINE size_t size( const DenseVectorProxy<PT,VT>& proxy );
505 
506 template< typename PT, typename VT >
508 
509 template< typename PT, typename VT >
511 
512 template< typename PT, typename VT >
513 BLAZE_ALWAYS_INLINE void resize( const DenseVectorProxy<PT,VT>& proxy, size_t n, bool preserve=true );
514 
515 template< typename PT, typename VT >
517 
518 template< typename PT, typename VT >
521 //*************************************************************************************************
522 
523 
524 //*************************************************************************************************
531 template< typename PT // Type of the proxy
532  , typename VT > // Type of the dense vector
535 {
536  return proxy.begin();
537 }
538 //*************************************************************************************************
539 
540 
541 //*************************************************************************************************
548 template< typename PT // Type of the proxy
549  , typename VT > // Type of the dense vector
552 {
553  return proxy.cbegin();
554 }
555 //*************************************************************************************************
556 
557 
558 //*************************************************************************************************
565 template< typename PT // Type of the proxy
566  , typename VT > // Type of the dense vector
568  end( const DenseVectorProxy<PT,VT>& proxy )
569 {
570  return proxy.end();
571 }
572 //*************************************************************************************************
573 
574 
575 //*************************************************************************************************
582 template< typename PT // Type of the proxy
583  , typename VT > // Type of the dense vector
586 {
587  return proxy.cend();
588 }
589 //*************************************************************************************************
590 
591 
592 //*************************************************************************************************
599 template< typename PT // Type of the proxy
600  , typename VT > // Type of the dense vector
602 {
603  return proxy.size();
604 }
605 //*************************************************************************************************
606 
607 
608 //*************************************************************************************************
615 template< typename PT // Type of the proxy
616  , typename VT > // Type of the dense vector
618 {
619  return proxy.capacity();
620 }
621 //*************************************************************************************************
622 
623 
624 //*************************************************************************************************
634 template< typename PT // Type of the proxy
635  , typename VT > // Type of the dense vector
637 {
638  return proxy.nonZeros();
639 }
640 //*************************************************************************************************
641 
642 
643 //*************************************************************************************************
658 template< typename PT // Type of the proxy
659  , typename VT > // Type of the dense vector
661  resize_backend( const DenseVectorProxy<PT,VT>& proxy, size_t n, bool preserve )
662 {
663  UNUSED_PARAMETER( preserve );
664 
665  if( proxy.size() != n ) {
666  BLAZE_THROW_INVALID_ARGUMENT( "Vector cannot be resized" );
667  }
668 }
670 //*************************************************************************************************
671 
672 
673 //*************************************************************************************************
685 template< typename PT // Type of the proxy
686  , typename VT > // Type of the dense vector
688  resize_backend( const DenseVectorProxy<PT,VT>& proxy, size_t n, bool preserve )
689 {
690  proxy.resize( n, preserve );
691 }
693 //*************************************************************************************************
694 
695 
696 //*************************************************************************************************
716 template< typename PT // Type of the proxy
717  , typename VT > // Type of the dense vector
718 BLAZE_ALWAYS_INLINE void resize( const DenseVectorProxy<PT,VT>& proxy, size_t n, bool preserve )
719 {
720  resize_backend( proxy, n, preserve );
721 }
722 //*************************************************************************************************
723 
724 
725 //*************************************************************************************************
734 template< typename PT // Type of the proxy
735  , typename VT > // Type of the dense vector
737 {
738  proxy.reset();
739 }
740 //*************************************************************************************************
741 
742 
743 //*************************************************************************************************
752 template< typename PT // Type of the proxy
753  , typename VT > // Type of the dense vector
755 {
756  proxy.clear();
757 }
758 //*************************************************************************************************
759 
760 } // namespace blaze
761 
762 #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
Header file for basic type definitions.
Pointer_< VT > Pointer
Pointer to a non-constant vector value.
Definition: DenseVectorProxy.h:87
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:533
void resize(size_t n, bool preserve=true) const
Changing the size of the represented vector.
Definition: DenseVectorProxy.h:394
Header file for the IsRowVector type trait.
typename DisableIf< Condition, T >::Type DisableIf_
Auxiliary type for the DisableIf class template.The DisableIf_ alias declaration provides a convenien...
Definition: DisableIf.h:223
Header file for the DenseVector base class.
typename T::ResultType ResultType_
Alias declaration for nested ResultType type definitions.The ResultType_ alias declaration provides a...
Definition: Aliases.h:323
size_t capacity() const
Returns the maximum capacity of the represented vector.
Definition: DenseVectorProxy.h:316
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
Pointer data() const
Low-level data access to vector elements.
Definition: DenseVectorProxy.h:210
typename T::CompositeType CompositeType_
Alias declaration for nested CompositeType type definitions.The CompositeType_ alias declaration prov...
Definition: Aliases.h:83
void clear() const
Clearing the represented vector.
Definition: DenseVectorProxy.h:367
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
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
void reset() const
Reset to the default initial value.
Definition: DenseVectorProxy.h:349
typename T::ElementType ElementType_
Alias declaration for nested ElementType type definitions.The ElementType_ alias declaration provides...
Definition: Aliases.h:163
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
void scale(const Other &scalar) const
Scaling of the vector by the scalar value scalar ( ).
Definition: DenseVectorProxy.h:465
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.
ConstIterator cbegin() const
Returns an iterator to the first element of the represented vector.
Definition: DenseVectorProxy.h:247
Iterator begin() const
Returns an iterator to the first element of the represented vector.
Definition: DenseVectorProxy.h:229
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
Reference at(size_t index) const
Checked access to the vector elements.
Definition: DenseVectorProxy.h:189
Reference_< VT > Reference
Reference to a non-constant vector value.
Definition: DenseVectorProxy.h:85
Iterator end() const
Returns an iterator just past the last element of the represented vector.
Definition: DenseVectorProxy.h:262
void reserve(size_t n) const
Setting the minimum capacity of the represented vector.
Definition: DenseVectorProxy.h:444
Header file for the reset shim.
size_t nonZeros() const
Returns the number of non-zero elements in the represented vector.
Definition: DenseVectorProxy.h:333
TransposeType_< VT > TransposeType
Transpose type for expression template evaluations.
Definition: DenseVectorProxy.h:81
typename EnableIf< Condition, T >::Type EnableIf_
Auxiliary alias declaration for the EnableIf class template.The EnableIf_ alias declaration provides ...
Definition: EnableIf.h:223
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
void extend(size_t n, bool preserve=true) const
Extending the size of the represented vector.
Definition: DenseVectorProxy.h:421
size_t size() const
Returns the current size/dimension of the represented vector.
Definition: DenseVectorProxy.h:302
ConstPointer_< VT > ConstPointer
Pointer to a constant vector value.
Definition: DenseVectorProxy.h:88
ConstIterator cend() const
Returns an iterator just past the last element of the represented vector.
Definition: DenseVectorProxy.h:280
Reference operator[](size_t index) const
Subscript operator for the direct access to vector elements.
Definition: DenseVectorProxy.h:164
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.