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
77  : public DenseVector< PT, IsRowVector_v<VT> >
78 {
79  public:
80  //**Type definitions****************************************************************************
92  //**********************************************************************************************
93 
94  //**Compilation flags***************************************************************************
96  static constexpr bool simdEnabled = VT::simdEnabled;
97 
99  static constexpr bool smpAssignable = VT::smpAssignable;
100  //**********************************************************************************************
101 
102  //**Data access functions***********************************************************************
105  inline Reference operator[]( size_t index ) const;
106  inline Reference at( size_t index ) const;
107 
108  inline Pointer data () const;
109  inline Iterator begin () const;
110  inline ConstIterator cbegin() const;
111  inline Iterator end () const;
112  inline ConstIterator cend () const;
114  //**********************************************************************************************
115 
116  //**Utility functions***************************************************************************
119  inline size_t size() const;
120  inline size_t capacity() const;
121  inline size_t nonZeros() const;
122  inline void reset() const;
123  inline void clear() const;
124  inline void resize( size_t n, bool preserve=true ) const;
125  inline void extend( size_t n, bool preserve=true ) const;
126  inline void reserve( size_t n ) const;
128  //**********************************************************************************************
129 
130  //**Numeric functions***************************************************************************
133  template< typename Other > inline void scale( const Other& scalar ) const;
135  //**********************************************************************************************
136 
137  private:
138  //**Compile time checks*************************************************************************
142  //**********************************************************************************************
143 };
144 //*************************************************************************************************
145 
146 
147 
148 
149 //=================================================================================================
150 //
151 // DATA ACCESS FUNCTIONS
152 //
153 //=================================================================================================
154 
155 //*************************************************************************************************
162 template< typename PT // Type of the proxy
163  , typename VT > // Type of the dense vector
166 {
167  if( (~*this).isRestricted() ) {
168  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
169  }
170 
171  return (~*this).get()[index];
172 }
173 //*************************************************************************************************
174 
175 
176 //*************************************************************************************************
187 template< typename PT // Type of the proxy
188  , typename VT > // Type of the dense vector
190  DenseVectorProxy<PT,VT>::at( size_t index ) const
191 {
192  if( (~*this).isRestricted() ) {
193  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
194  }
195 
196  return (~*this).get().at( index );
197 }
198 //*************************************************************************************************
199 
200 
201 //*************************************************************************************************
209 template< typename PT // Type of the proxy
210  , typename VT > // Type of the dense vector
212 {
213  if( (~*this).isRestricted() ) {
214  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
215  }
216 
217  return (~*this).get().data();
218 }
219 //*************************************************************************************************
220 
221 
222 //*************************************************************************************************
228 template< typename PT // Type of the proxy
229  , typename VT > // Type of the dense vector
231 {
232  if( (~*this).isRestricted() ) {
233  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
234  }
235 
236  return (~*this).get().begin();
237 }
238 //*************************************************************************************************
239 
240 
241 //*************************************************************************************************
246 template< typename PT // Type of the proxy
247  , typename VT > // Type of the dense vector
249 {
250  return (~*this).get().cbegin();
251 }
252 //*************************************************************************************************
253 
254 
255 //*************************************************************************************************
261 template< typename PT // Type of the proxy
262  , typename VT > // Type of the dense vector
264 {
265  if( (~*this).isRestricted() ) {
266  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
267  }
268 
269  return (~*this).get().end();
270 }
271 //*************************************************************************************************
272 
273 
274 //*************************************************************************************************
279 template< typename PT // Type of the proxy
280  , typename VT > // Type of the dense vector
282 {
283  return (~*this).get().cend();
284 }
285 //*************************************************************************************************
286 
287 
288 
289 
290 //=================================================================================================
291 //
292 // UTILITY FUNCTIONS
293 //
294 //=================================================================================================
295 
296 //*************************************************************************************************
301 template< typename PT // Type of the proxy
302  , typename VT > // Type of the dense vector
303 inline size_t DenseVectorProxy<PT,VT>::size() const
304 {
305  return (~*this).get().size();
306 }
307 //*************************************************************************************************
308 
309 
310 //*************************************************************************************************
315 template< typename PT // Type of the proxy
316  , typename VT > // Type of the dense vector
318 {
319  return (~*this).get().capacity();
320 }
321 //*************************************************************************************************
322 
323 
324 //*************************************************************************************************
332 template< typename PT // Type of the proxy
333  , typename VT > // Type of the dense vector
335 {
336  return (~*this).get().nonZeros();
337 }
338 //*************************************************************************************************
339 
340 
341 //*************************************************************************************************
348 template< typename PT // Type of the proxy
349  , typename VT > // Type of the dense vector
351 {
352  using blaze::reset;
353 
354  reset( (~*this).get() );
355 }
356 //*************************************************************************************************
357 
358 
359 //*************************************************************************************************
366 template< typename PT // Type of the proxy
367  , typename VT > // Type of the dense vector
369 {
370  using blaze::clear;
371 
372  clear( (~*this).get() );
373 }
374 //*************************************************************************************************
375 
376 
377 //*************************************************************************************************
393 template< typename PT // Type of the proxy
394  , typename VT > // Type of the dense vector
395 inline void DenseVectorProxy<PT,VT>::resize( size_t n, bool preserve ) const
396 {
397  if( (~*this).isRestricted() ) {
398  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
399  }
400 
401  (~*this).get().resize( n, preserve );
402 }
403 //*************************************************************************************************
404 
405 
406 //*************************************************************************************************
420 template< typename PT // Type of the proxy
421  , typename VT > // Type of the dense vector
422 inline void DenseVectorProxy<PT,VT>::extend( size_t n, bool preserve ) const
423 {
424  if( (~*this).isRestricted() ) {
425  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
426  }
427 
428  (~*this).get().extend( n, preserve );
429 }
430 //*************************************************************************************************
431 
432 
433 //*************************************************************************************************
443 template< typename PT // Type of the proxy
444  , typename VT > // Type of the dense vector
445 inline void DenseVectorProxy<PT,VT>::reserve( size_t n ) const
446 {
447  if( (~*this).isRestricted() ) {
448  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
449  }
450 
451  (~*this).get().reserve( n );
452 }
453 //*************************************************************************************************
454 
455 
456 //*************************************************************************************************
467 template< typename PT // Type of the proxy
468  , typename VT > // Type of the dense vector
469 template< typename Other > // Data type of the scalar value
470 inline void DenseVectorProxy<PT,VT>::scale( const Other& scalar ) const
471 {
472  if( (~*this).isRestricted() ) {
473  BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
474  }
475 
476  (~*this).get().scale( scalar );
477 }
478 //*************************************************************************************************
479 
480 
481 
482 
483 //=================================================================================================
484 //
485 // GLOBAL FUNCTIONS
486 //
487 //=================================================================================================
488 
489 //*************************************************************************************************
492 template< typename PT, typename VT >
494  begin( const DenseVectorProxy<PT,VT>& proxy );
495 
496 template< typename PT, typename VT >
498  cbegin( const DenseVectorProxy<PT,VT>& proxy );
499 
500 template< typename PT, typename VT >
502  end( const DenseVectorProxy<PT,VT>& proxy );
503 
504 template< typename PT, typename VT >
506  cend( const DenseVectorProxy<PT,VT>& proxy );
507 
508 template< typename PT, typename VT >
509 size_t size( const DenseVectorProxy<PT,VT>& proxy );
510 
511 template< typename PT, typename VT >
512 size_t capacity( const DenseVectorProxy<PT,VT>& proxy );
513 
514 template< typename PT, typename VT >
515 size_t nonZeros( const DenseVectorProxy<PT,VT>& proxy );
516 
517 template< typename PT, typename VT >
518 void resize( const DenseVectorProxy<PT,VT>& proxy, size_t n, bool preserve=true );
519 
520 template< typename PT, typename VT >
521 void reset( const DenseVectorProxy<PT,VT>& proxy );
522 
523 template< typename PT, typename VT >
524 void clear( const DenseVectorProxy<PT,VT>& proxy );
526 //*************************************************************************************************
527 
528 
529 //*************************************************************************************************
536 template< typename PT // Type of the proxy
537  , typename VT > // Type of the dense vector
540 {
541  return proxy.begin();
542 }
543 //*************************************************************************************************
544 
545 
546 //*************************************************************************************************
553 template< typename PT // Type of the proxy
554  , typename VT > // Type of the dense vector
557 {
558  return proxy.cbegin();
559 }
560 //*************************************************************************************************
561 
562 
563 //*************************************************************************************************
570 template< typename PT // Type of the proxy
571  , typename VT > // Type of the dense vector
573  end( const DenseVectorProxy<PT,VT>& proxy )
574 {
575  return proxy.end();
576 }
577 //*************************************************************************************************
578 
579 
580 //*************************************************************************************************
587 template< typename PT // Type of the proxy
588  , typename VT > // Type of the dense vector
591 {
592  return proxy.cend();
593 }
594 //*************************************************************************************************
595 
596 
597 //*************************************************************************************************
604 template< typename PT // Type of the proxy
605  , typename VT > // Type of the dense vector
607 {
608  return proxy.size();
609 }
610 //*************************************************************************************************
611 
612 
613 //*************************************************************************************************
620 template< typename PT // Type of the proxy
621  , typename VT > // Type of the dense vector
623 {
624  return proxy.capacity();
625 }
626 //*************************************************************************************************
627 
628 
629 //*************************************************************************************************
639 template< typename PT // Type of the proxy
640  , typename VT > // Type of the dense vector
642 {
643  return proxy.nonZeros();
644 }
645 //*************************************************************************************************
646 
647 
648 //*************************************************************************************************
663 template< typename PT // Type of the proxy
664  , typename VT > // Type of the dense vector
665 BLAZE_ALWAYS_INLINE DisableIf_t< IsResizable_v<VT> >
666  resize_backend( const DenseVectorProxy<PT,VT>& proxy, size_t n, bool preserve )
667 {
668  UNUSED_PARAMETER( preserve );
669 
670  if( proxy.size() != n ) {
671  BLAZE_THROW_INVALID_ARGUMENT( "Vector cannot be resized" );
672  }
673 }
675 //*************************************************************************************************
676 
677 
678 //*************************************************************************************************
690 template< typename PT // Type of the proxy
691  , typename VT > // Type of the dense vector
692 BLAZE_ALWAYS_INLINE EnableIf_t< IsResizable_v<VT> >
693  resize_backend( const DenseVectorProxy<PT,VT>& proxy, size_t n, bool preserve )
694 {
695  proxy.resize( n, preserve );
696 }
698 //*************************************************************************************************
699 
700 
701 //*************************************************************************************************
721 template< typename PT // Type of the proxy
722  , typename VT > // Type of the dense vector
723 BLAZE_ALWAYS_INLINE void resize( const DenseVectorProxy<PT,VT>& proxy, size_t n, bool preserve )
724 {
725  resize_backend( proxy, n, preserve );
726 }
727 //*************************************************************************************************
728 
729 
730 //*************************************************************************************************
739 template< typename PT // Type of the proxy
740  , typename VT > // Type of the dense vector
742 {
743  proxy.reset();
744 }
745 //*************************************************************************************************
746 
747 
748 //*************************************************************************************************
757 template< typename PT // Type of the proxy
758  , typename VT > // Type of the dense vector
760 {
761  proxy.clear();
762 }
763 //*************************************************************************************************
764 
765 } // namespace blaze
766 
767 #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.
size_t capacity(const Matrix< MT, SO > &matrix) noexcept
Returns the maximum capacity of the matrix.
Definition: Matrix.h:546
Header file for basic type definitions.
typename T::ResultType ResultType_t
Alias declaration for nested ResultType type definitions.The ResultType_t alias declaration provides ...
Definition: Aliases.h:390
typename T::Reference Reference_t
Alias declaration for nested Reference type definitions.The Reference_t alias declaration provides a ...
Definition: Aliases.h:330
MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:372
static constexpr bool smpAssignable
Compilation flag for SMP assignments.
Definition: DenseVectorProxy.h:99
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:591
static constexpr bool smpAssignable
Compilation flag for SMP assignments.
Definition: CompressedMatrix.h:3113
void resize(size_t n, bool preserve=true) const
Changing the size of the represented vector.
Definition: DenseVectorProxy.h:395
ConstPointer_t< VT > ConstPointer
Pointer to a constant vector value.
Definition: DenseVectorProxy.h:89
Header file for the IsRowVector type trait.
Header file for the DenseVector base class.
size_t nonZeros(const Matrix< MT, SO > &matrix)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:584
Header file for the reset shim.
ReturnType_t< VT > ReturnType
Return type for expression template evaluations.
Definition: DenseVectorProxy.h:84
constexpr void UNUSED_PARAMETER(const Args &...)
Suppression of unused parameter warnings.
Definition: Unused.h:81
typename T::ReturnType ReturnType_t
Alias declaration for nested ReturnType type definitions.The ReturnType_t alias declaration provides ...
Definition: Aliases.h:410
size_t capacity() const
Returns the maximum capacity of the represented vector.
Definition: DenseVectorProxy.h:317
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:482
ConstReference_t< VT > ConstReference
Reference to a constant vector value.
Definition: DenseVectorProxy.h:87
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:416
typename T::Pointer Pointer_t
Alias declaration for nested Pointer type definitions.The Pointer_t alias declaration provides a conv...
Definition: Aliases.h:290
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.The ElementType_t alias declaration provide...
Definition: Aliases.h:170
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:211
void clear() const
Clearing the represented vector.
Definition: DenseVectorProxy.h:368
Header file for the DisableIf class template.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
#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:350
TransposeType_t< VT > TransposeType
Transpose type for expression template evaluations.
Definition: DenseVectorProxy.h:82
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:76
void scale(const Other &scalar) const
Scaling of the vector by the scalar value scalar ( ).
Definition: DenseVectorProxy.h:470
Constraint on the data type.
CompositeType_t< VT > CompositeType
Data type for composite expression templates.
Definition: DenseVectorProxy.h:85
Header file for the exception macros of the math module.
Reference_t< VT > Reference
Reference to a non-constant vector value.
Definition: DenseVectorProxy.h:86
void resize(Matrix< MT, SO > &matrix, size_t rows, size_t columns, bool preserve=true)
Changing the size of the matrix.
Definition: Matrix.h:738
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:438
Iterator_t< VT > Iterator
Iterator over non-constant elements.
Definition: DenseVectorProxy.h:90
ConstIterator cbegin() const
Returns an iterator to the first element of the represented vector.
Definition: DenseVectorProxy.h:248
Iterator begin() const
Returns an iterator to the first element of the represented vector.
Definition: DenseVectorProxy.h:230
Header file for the EnableIf class template.
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:611
ElementType_t< VT > ElementType
Type of the vector elements.
Definition: DenseVectorProxy.h:83
Reference at(size_t index) const
Checked access to the vector elements.
Definition: DenseVectorProxy.h:190
Iterator end() const
Returns an iterator just past the last element of the represented vector.
Definition: DenseVectorProxy.h:263
typename T::Iterator Iterator_t
Alias declaration for nested Iterator type definitions.The Iterator_t alias declaration provides a co...
Definition: Aliases.h:190
typename T::TransposeType TransposeType_t
Alias declaration for nested TransposeType type definitions.The TransposeType_t alias declaration pro...
Definition: Aliases.h:470
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.The CompositeType_t alias declaration pro...
Definition: Aliases.h:90
void reserve(size_t n) const
Setting the minimum capacity of the represented vector.
Definition: DenseVectorProxy.h:445
typename T::ConstPointer ConstPointer_t
Alias declaration for nested ConstPointer type definitions.The ConstPointer_t alias declaration provi...
Definition: Aliases.h:130
constexpr size_t size(const Matrix< MT, SO > &matrix) noexcept
Returns the total number of elements of the matrix.
Definition: Matrix.h:530
ConstIterator_t< VT > ConstIterator
Iterator over constant elements.
Definition: DenseVectorProxy.h:91
typename T::ConstReference ConstReference_t
Alias declaration for nested ConstReference type definitions.The ConstReference_t alias declaration p...
Definition: Aliases.h:150
size_t nonZeros() const
Returns the number of non-zero elements in the represented vector.
Definition: DenseVectorProxy.h:334
static constexpr bool simdEnabled
Compilation flag for SIMD optimization.
Definition: DenseVectorProxy.h:96
typename T::ConstIterator ConstIterator_t
Alias declaration for nested ConstIterator type definitions.The ConstIterator_t alias declaration pro...
Definition: Aliases.h:110
#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
Pointer_t< VT > Pointer
Pointer to a non-constant vector value.
Definition: DenseVectorProxy.h:88
void extend(size_t n, bool preserve=true) const
Extending the size of the represented vector.
Definition: DenseVectorProxy.h:422
size_t size() const
Returns the current size/dimension of the represented vector.
Definition: DenseVectorProxy.h:303
ConstIterator cend() const
Returns an iterator just past the last element of the represented vector.
Definition: DenseVectorProxy.h:281
Reference operator[](size_t index) const
Subscript operator for the direct access to vector elements.
Definition: DenseVectorProxy.h:165
ResultType_t< VT > ResultType
Result type for expression template evaluations.
Definition: DenseVectorProxy.h:81
Header file for the IsResizable type trait.
System settings for the inline keywords.
Header file for the clear shim.