Blaze 3.9
Loading...
Searching...
No Matches
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>
51#include <blaze/system/Inline.h>
52#include <blaze/util/EnableIf.h>
54#include <blaze/util/Types.h>
55
56
57namespace blaze {
58
59//=================================================================================================
60//
61// CLASS DEFINITION
62//
63//=================================================================================================
64
65//*************************************************************************************************
73template< typename PT // Type of the proxy
74 , typename VT > // Type of the dense vector
75class DenseVectorProxy
76 : public DenseVector< PT, IsRowVector_v<VT> >
77{
78 public:
79 //**Type definitions****************************************************************************
91 //**********************************************************************************************
92
93 //**Compilation flags***************************************************************************
95 static constexpr bool simdEnabled = VT::simdEnabled;
96
98 static constexpr 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 protected:
137 //**Special member functions********************************************************************
140 DenseVectorProxy() = default;
141 DenseVectorProxy( const DenseVectorProxy& ) = default;
142 DenseVectorProxy( DenseVectorProxy&& ) = default;
143 ~DenseVectorProxy() = default;
144 DenseVectorProxy& operator=( const DenseVectorProxy& ) = default;
145 DenseVectorProxy& operator=( DenseVectorProxy&& ) = default;
147 //**********************************************************************************************
148
149 private:
150 //**Compile time checks*************************************************************************
154 //**********************************************************************************************
155};
156//*************************************************************************************************
157
158
159
160
161//=================================================================================================
162//
163// DATA ACCESS FUNCTIONS
164//
165//=================================================================================================
166
167//*************************************************************************************************
174template< typename PT // Type of the proxy
175 , typename VT > // Type of the dense vector
178{
179 if( (**this).isRestricted() ) {
180 BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
181 }
182
183 return (**this).get()[index];
184}
185//*************************************************************************************************
186
187
188//*************************************************************************************************
199template< typename PT // Type of the proxy
200 , typename VT > // Type of the dense vector
202 DenseVectorProxy<PT,VT>::at( size_t index ) const
203{
204 if( (**this).isRestricted() ) {
205 BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
206 }
207
208 return (**this).get().at( index );
209}
210//*************************************************************************************************
211
212
213//*************************************************************************************************
221template< typename PT // Type of the proxy
222 , typename VT > // Type of the dense vector
224{
225 if( (**this).isRestricted() ) {
226 BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
227 }
228
229 return (**this).get().data();
230}
231//*************************************************************************************************
232
233
234//*************************************************************************************************
240template< typename PT // Type of the proxy
241 , typename VT > // Type of the dense vector
243{
244 if( (**this).isRestricted() ) {
245 BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
246 }
247
248 return (**this).get().begin();
249}
250//*************************************************************************************************
251
252
253//*************************************************************************************************
258template< typename PT // Type of the proxy
259 , typename VT > // Type of the dense vector
261{
262 return (**this).get().cbegin();
263}
264//*************************************************************************************************
265
266
267//*************************************************************************************************
273template< typename PT // Type of the proxy
274 , typename VT > // Type of the dense vector
276{
277 if( (**this).isRestricted() ) {
278 BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
279 }
280
281 return (**this).get().end();
282}
283//*************************************************************************************************
284
285
286//*************************************************************************************************
291template< typename PT // Type of the proxy
292 , typename VT > // Type of the dense vector
294{
295 return (**this).get().cend();
296}
297//*************************************************************************************************
298
299
300
301
302//=================================================================================================
303//
304// UTILITY FUNCTIONS
305//
306//=================================================================================================
307
308//*************************************************************************************************
313template< typename PT // Type of the proxy
314 , typename VT > // Type of the dense vector
315inline size_t DenseVectorProxy<PT,VT>::size() const
316{
317 return (**this).get().size();
318}
319//*************************************************************************************************
320
321
322//*************************************************************************************************
327template< typename PT // Type of the proxy
328 , typename VT > // Type of the dense vector
330{
331 return (**this).get().capacity();
332}
333//*************************************************************************************************
334
335
336//*************************************************************************************************
344template< typename PT // Type of the proxy
345 , typename VT > // Type of the dense vector
347{
348 return (**this).get().nonZeros();
349}
350//*************************************************************************************************
351
352
353//*************************************************************************************************
360template< typename PT // Type of the proxy
361 , typename VT > // Type of the dense vector
363{
364 using blaze::reset;
365
366 reset( (**this).get() );
367}
368//*************************************************************************************************
369
370
371//*************************************************************************************************
378template< typename PT // Type of the proxy
379 , typename VT > // Type of the dense vector
381{
382 using blaze::clear;
383
384 clear( (**this).get() );
385}
386//*************************************************************************************************
387
388
389//*************************************************************************************************
405template< typename PT // Type of the proxy
406 , typename VT > // Type of the dense vector
407inline void DenseVectorProxy<PT,VT>::resize( size_t n, bool preserve ) const
408{
409 if( (**this).isRestricted() ) {
410 BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
411 }
412
413 (**this).get().resize( n, preserve );
414}
415//*************************************************************************************************
416
417
418//*************************************************************************************************
432template< typename PT // Type of the proxy
433 , typename VT > // Type of the dense vector
434inline void DenseVectorProxy<PT,VT>::extend( size_t n, bool preserve ) const
435{
436 if( (**this).isRestricted() ) {
437 BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
438 }
439
440 (**this).get().extend( n, preserve );
441}
442//*************************************************************************************************
443
444
445//*************************************************************************************************
455template< typename PT // Type of the proxy
456 , typename VT > // Type of the dense vector
457inline void DenseVectorProxy<PT,VT>::reserve( size_t n ) const
458{
459 if( (**this).isRestricted() ) {
460 BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
461 }
462
463 (**this).get().reserve( n );
464}
465//*************************************************************************************************
466
467
468//*************************************************************************************************
479template< typename PT // Type of the proxy
480 , typename VT > // Type of the dense vector
481template< typename Other > // Data type of the scalar value
482inline void DenseVectorProxy<PT,VT>::scale( const Other& scalar ) const
483{
484 if( (**this).isRestricted() ) {
485 BLAZE_THROW_INVALID_ARGUMENT( "Invalid access to restricted element" );
486 }
487
488 (**this).get().scale( scalar );
489}
490//*************************************************************************************************
491
492
493
494
495//=================================================================================================
496//
497// GLOBAL FUNCTIONS
498//
499//=================================================================================================
500
501//*************************************************************************************************
504template< typename PT, typename VT >
506 begin( const DenseVectorProxy<PT,VT>& proxy );
507
508template< typename PT, typename VT >
510 cbegin( const DenseVectorProxy<PT,VT>& proxy );
511
512template< typename PT, typename VT >
514 end( const DenseVectorProxy<PT,VT>& proxy );
515
516template< typename PT, typename VT >
518 cend( const DenseVectorProxy<PT,VT>& proxy );
519
520template< typename PT, typename VT >
521size_t size( const DenseVectorProxy<PT,VT>& proxy );
522
523template< typename PT, typename VT >
524size_t capacity( const DenseVectorProxy<PT,VT>& proxy );
525
526template< typename PT, typename VT >
527size_t nonZeros( const DenseVectorProxy<PT,VT>& proxy );
528
529template< typename PT, typename VT >
530void resize( const DenseVectorProxy<PT,VT>& proxy, size_t n, bool preserve=true );
532//*************************************************************************************************
533
534
535//*************************************************************************************************
542template< typename PT // Type of the proxy
543 , typename VT > // Type of the dense vector
546{
547 return proxy.begin();
548}
549//*************************************************************************************************
550
551
552//*************************************************************************************************
559template< typename PT // Type of the proxy
560 , typename VT > // Type of the dense vector
563{
564 return proxy.cbegin();
565}
566//*************************************************************************************************
567
568
569//*************************************************************************************************
576template< typename PT // Type of the proxy
577 , typename VT > // Type of the dense vector
580{
581 return proxy.end();
582}
583//*************************************************************************************************
584
585
586//*************************************************************************************************
593template< typename PT // Type of the proxy
594 , typename VT > // Type of the dense vector
597{
598 return proxy.cend();
599}
600//*************************************************************************************************
601
602
603//*************************************************************************************************
610template< typename PT // Type of the proxy
611 , typename VT > // Type of the dense vector
613{
614 return proxy.size();
615}
616//*************************************************************************************************
617
618
619//*************************************************************************************************
626template< typename PT // Type of the proxy
627 , typename VT > // Type of the dense vector
629{
630 return proxy.capacity();
631}
632//*************************************************************************************************
633
634
635//*************************************************************************************************
645template< typename PT // Type of the proxy
646 , typename VT > // Type of the dense vector
648{
649 return proxy.nonZeros();
650}
651//*************************************************************************************************
652
653
654//*************************************************************************************************
669template< typename PT // Type of the proxy
670 , typename VT > // Type of the dense vector
672 resize_backend( const DenseVectorProxy<PT,VT>& proxy, size_t n, bool preserve )
673{
674 MAYBE_UNUSED( preserve );
675
676 if( proxy.size() != n ) {
677 BLAZE_THROW_INVALID_ARGUMENT( "Vector cannot be resized" );
678 }
679}
681//*************************************************************************************************
682
683
684//*************************************************************************************************
696template< typename PT // Type of the proxy
697 , typename VT > // Type of the dense vector
699 resize_backend( const DenseVectorProxy<PT,VT>& proxy, size_t n, bool preserve )
700{
701 proxy.resize( n, preserve );
702}
704//*************************************************************************************************
705
706
707//*************************************************************************************************
727template< typename PT // Type of the proxy
728 , typename VT > // Type of the dense vector
729BLAZE_ALWAYS_INLINE void resize( const DenseVectorProxy<PT,VT>& proxy, size_t n, bool preserve )
730{
731 resize_backend( proxy, n, preserve );
732}
733//*************************************************************************************************
734
735} // namespace blaze
736
737#endif
Header file for auxiliary alias declarations.
typename T::ReturnType ReturnType_t
Alias declaration for nested ReturnType type definitions.
Definition Aliases.h:470
typename T::ConstPointer ConstPointer_t
Alias declaration for nested ConstPointer type definitions.
Definition Aliases.h:150
typename T::ConstReference ConstReference_t
Alias declaration for nested ConstReference type definitions.
Definition Aliases.h:170
typename T::ConstIterator ConstIterator_t
Alias declaration for nested ConstIterator type definitions.
Definition Aliases.h:130
typename T::Reference Reference_t
Alias declaration for nested Reference type definitions.
Definition Aliases.h:390
typename T::Iterator Iterator_t
Alias declaration for nested Iterator type definitions.
Definition Aliases.h:210
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.
Definition Aliases.h:110
typename T::TransposeType TransposeType_t
Alias declaration for nested TransposeType type definitions.
Definition Aliases.h:550
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.
Definition Aliases.h:190
typename T::ResultType ResultType_t
Alias declaration for nested ResultType type definitions.
Definition Aliases.h:450
typename T::Pointer Pointer_t
Alias declaration for nested Pointer type definitions.
Definition Aliases.h:330
Header file for the EnableIf class template.
Header file for the IsResizable type trait.
Header file for the IsRowVector type trait.
Header file for the MAYBE_UNUSED function template.
Proxy backend for dense vector types.
Definition DenseVectorProxy.h:77
ConstPointer_t< VT > ConstPointer
Pointer to a constant vector value.
Definition DenseVectorProxy.h:88
ConstIterator cbegin() const
Returns an iterator to the first element of the represented vector.
Definition DenseVectorProxy.h:260
size_t capacity() const
Returns the maximum capacity of the represented vector.
Definition DenseVectorProxy.h:329
ElementType_t< VT > ElementType
Type of the vector elements.
Definition DenseVectorProxy.h:82
size_t nonZeros() const
Returns the number of non-zero elements in the represented vector.
Definition DenseVectorProxy.h:346
void reserve(size_t n) const
Setting the minimum capacity of the represented vector.
Definition DenseVectorProxy.h:457
static constexpr bool simdEnabled
Compilation flag for SIMD optimization.
Definition DenseVectorProxy.h:95
Reference operator[](size_t index) const
Subscript operator for the direct access to vector elements.
Definition DenseVectorProxy.h:177
ResultType_t< VT > ResultType
Result type for expression template evaluations.
Definition DenseVectorProxy.h:80
void scale(const Other &scalar) const
Scaling of the vector by the scalar value scalar ( ).
Definition DenseVectorProxy.h:482
ConstReference_t< VT > ConstReference
Reference to a constant vector value.
Definition DenseVectorProxy.h:86
Pointer data() const
Low-level data access to vector elements.
Definition DenseVectorProxy.h:223
Reference at(size_t index) const
Checked access to the vector elements.
Definition DenseVectorProxy.h:202
Iterator_t< VT > Iterator
Iterator over non-constant elements.
Definition DenseVectorProxy.h:89
void clear() const
Clearing the represented vector.
Definition DenseVectorProxy.h:380
void reset() const
Reset to the default initial value.
Definition DenseVectorProxy.h:362
static constexpr bool smpAssignable
Compilation flag for SMP assignments.
Definition DenseVectorProxy.h:98
size_t size() const
Returns the current size/dimension of the represented vector.
Definition DenseVectorProxy.h:315
Pointer_t< VT > Pointer
Pointer to a non-constant vector value.
Definition DenseVectorProxy.h:87
void resize(size_t n, bool preserve=true) const
Changing the size of the represented vector.
Definition DenseVectorProxy.h:407
void extend(size_t n, bool preserve=true) const
Extending the size of the represented vector.
Definition DenseVectorProxy.h:434
Iterator end() const
Returns an iterator just past the last element of the represented vector.
Definition DenseVectorProxy.h:275
ConstIterator_t< VT > ConstIterator
Iterator over constant elements.
Definition DenseVectorProxy.h:90
TransposeType_t< VT > TransposeType
Transpose type for expression template evaluations.
Definition DenseVectorProxy.h:81
Iterator begin() const
Returns an iterator to the first element of the represented vector.
Definition DenseVectorProxy.h:242
CompositeType_t< VT > CompositeType
Data type for composite expression templates.
Definition DenseVectorProxy.h:84
Reference_t< VT > Reference
Reference to a non-constant vector value.
Definition DenseVectorProxy.h:85
ConstIterator cend() const
Returns an iterator just past the last element of the represented vector.
Definition DenseVectorProxy.h:293
ReturnType_t< VT > ReturnType
Return type for expression template evaluations.
Definition DenseVectorProxy.h:83
Constraint on the data type.
Header file for the DenseVector base class.
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE(T)
Constraint on the data type.
Definition DenseVector.h:61
constexpr void clear(Matrix< MT, SO > &matrix)
Clearing the given matrix.
Definition Matrix.h:960
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:628
size_t nonZeros(const Matrix< MT, SO > &matrix)
Returns the total number of non-zero elements in the matrix.
Definition Matrix.h:730
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:562
size_t capacity(const Matrix< MT, SO > &matrix) noexcept
Returns the maximum capacity of the matrix.
Definition Matrix.h:692
constexpr void reset(Matrix< MT, SO > &matrix)
Resetting the given matrix.
Definition Matrix.h:806
void resize(Matrix< MT, SO > &matrix, size_t rows, size_t columns, bool preserve=true)
Changing the size of the matrix.
Definition Matrix.h:1108
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:584
MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition Matrix.h:518
constexpr size_t size(const Matrix< MT, SO > &matrix) noexcept
Returns the total number of elements of the matrix.
Definition Matrix.h:676
#define BLAZE_ALWAYS_INLINE
Platform dependent setup of an enforced inline keyword.
Definition Inline.h:85
constexpr void MAYBE_UNUSED(const Args &...)
Suppression of unused parameter warnings.
Definition MaybeUnused.h:81
typename EnableIf< Condition, T >::Type EnableIf_t
Auxiliary type for the EnableIf class template.
Definition EnableIf.h:138
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.
Definition Exception.h:235
typename EnableIf<!Condition, T >::Type DisableIf_t
Auxiliary type for the EnableIf class template.
Definition EnableIf.h:175
Header file for the exception macros of the math module.
Header file for the clear shim.
Header file for the reset shim.
System settings for the inline keywords.
Header file for basic type definitions.