Blaze 3.9
DVecSerialExpr.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_EXPRESSIONS_DVECSERIALEXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_DVECSERIALEXPR_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <blaze/math/Aliases.h>
54#include <blaze/util/Assert.h>
56#include <blaze/util/mpl/If.h>
57#include <blaze/util/Types.h>
58
59
60namespace blaze {
61
62//=================================================================================================
63//
64// CLASS DVECSERIALEXPR
65//
66//=================================================================================================
67
68//*************************************************************************************************
75template< typename VT // Type of the dense vector
76 , bool TF > // Transpose flag
78 : public VecSerialExpr< DenseVector< DVecSerialExpr<VT,TF>, TF > >
79 , private Computation
80{
81 public:
82 //**Type definitions****************************************************************************
85
88
93
96
98 using Operand = If_t< IsExpression_v<VT>, const VT, const VT& >;
99 //**********************************************************************************************
100
101 //**Compilation flags***************************************************************************
103 static constexpr bool simdEnabled = false;
104
106 static constexpr bool smpAssignable = VT::smpAssignable;
107 //**********************************************************************************************
108
109 //**Constructor*********************************************************************************
114 explicit inline DVecSerialExpr( const VT& dv ) noexcept
115 : dv_( dv ) // Dense vector of the serial evaluation expression
116 {}
117 //**********************************************************************************************
118
119 //**Subscript operator**************************************************************************
125 inline ReturnType operator[]( size_t index ) const {
126 BLAZE_INTERNAL_ASSERT( index < dv_.size(), "Invalid vector access index" );
127 return dv_[index];
128 }
129 //**********************************************************************************************
130
131 //**At function*********************************************************************************
138 inline ReturnType at( size_t index ) const {
139 if( index >= dv_.size() ) {
140 BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
141 }
142 return (*this)[index];
143 }
144 //**********************************************************************************************
145
146 //**Size function*******************************************************************************
151 inline size_t size() const noexcept {
152 return dv_.size();
153 }
154 //**********************************************************************************************
155
156 //**Operand access******************************************************************************
161 inline Operand operand() const noexcept {
162 return dv_;
163 }
164 //**********************************************************************************************
165
166 //**Conversion operator*************************************************************************
171 inline operator Operand() const noexcept {
172 return dv_;
173 }
174 //**********************************************************************************************
175
176 //**********************************************************************************************
182 template< typename T >
183 inline bool canAlias( const T* alias ) const noexcept {
184 return dv_.canAlias( alias );
185 }
186 //**********************************************************************************************
187
188 //**********************************************************************************************
194 template< typename T >
195 inline bool isAliased( const T* alias ) const noexcept {
196 return dv_.isAliased( alias );
197 }
198 //**********************************************************************************************
199
200 //**********************************************************************************************
205 inline bool isAligned() const noexcept {
206 return dv_.isAligned();
207 }
208 //**********************************************************************************************
209
210 //**********************************************************************************************
215 inline bool canSMPAssign() const noexcept {
216 return dv_.canSMPAssign();
217 }
218 //**********************************************************************************************
219
220 private:
221 //**Member variables****************************************************************************
223 //**********************************************************************************************
224
225 //**Assignment to dense vectors*****************************************************************
237 template< typename VT2 > // Type of the target dense vector
238 friend inline void assign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
239 {
241
242 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
243
244 assign( *lhs, rhs.dv_ );
245 }
247 //**********************************************************************************************
248
249 //**Assignment to sparse vectors****************************************************************
261 template< typename VT2 > // Type of the target sparse vector
262 friend inline void assign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
263 {
265
266 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
267
268 assign( *lhs, rhs.dv_ );
269 }
271 //**********************************************************************************************
272
273 //**Addition assignment to dense vectors********************************************************
285 template< typename VT2 > // Type of the target dense vector
286 friend inline void addAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
287 {
289
290 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
291
292 addAssign( *lhs, rhs.dv_ );
293 }
295 //**********************************************************************************************
296
297 //**Addition assignment to sparse vectors*******************************************************
309 template< typename VT2 > // Type of the target sparse vector
310 friend inline void addAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
311 {
313
314 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
315
316 addAssign( *lhs, rhs.dv_ );
317 }
319 //**********************************************************************************************
320
321 //**Subtraction assignment to dense vectors*****************************************************
334 template< typename VT2 > // Type of the target dense vector
335 friend inline void subAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
336 {
338
339 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
340
341 subAssign( *lhs, rhs.dv_ );
342 }
344 //**********************************************************************************************
345
346 //**Subtraction assignment to sparse vectors****************************************************
359 template< typename VT2 > // Type of the target sparse vector
360 friend inline void subAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
361 {
363
364 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
365
366 subAssign( *lhs, rhs.dv_ );
367 }
369 //**********************************************************************************************
370
371 //**Multiplication assignment to dense vectors**************************************************
384 template< typename VT2 > // Type of the target dense vector
385 friend inline void multAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
386 {
388
389 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
390
391 multAssign( *lhs, rhs.dv_ );
392 }
394 //**********************************************************************************************
395
396 //**Multiplication assignment to sparse vectors*************************************************
409 template< typename VT2 > // Type of the target sparse vector
410 friend inline void multAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
411 {
413
414 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
415
416 multAssign( *lhs, rhs.dv_ );
417 }
419 //**********************************************************************************************
420
421 //**Division assignment to dense vectors********************************************************
433 template< typename VT2 > // Type of the target dense vector
434 friend inline void divAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
435 {
437
438 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
439
440 divAssign( *lhs, rhs.dv_ );
441 }
443 //**********************************************************************************************
444
445 //**Division assignment to sparse vectors*******************************************************
457 template< typename VT2 > // Type of the target sparse vector
458 friend inline void divAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
459 {
461
462 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
463
464 divAssign( *lhs, rhs.dv_ );
465 }
467 //**********************************************************************************************
468
469 //**SMP assignment to dense vectors*************************************************************
481 template< typename VT2 > // Type of the target dense vector
482 friend inline void smpAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
483 {
485
486 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
487
488 assign( *lhs, rhs.dv_ );
489 }
491 //**********************************************************************************************
492
493 //**SMP assignment to sparse vectors************************************************************
505 template< typename VT2 > // Type of the target sparse vector
506 friend inline void smpAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
507 {
509
510 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
511
512 assign( *lhs, rhs.dv_ );
513 }
515 //**********************************************************************************************
516
517 //**SMP addition assignment to dense vectors****************************************************
530 template< typename VT2 > // Type of the target dense vector
531 friend inline void smpAddAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
532 {
534
535 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
536
537 addAssign( *lhs, rhs.dv_ );
538 }
540 //**********************************************************************************************
541
542 //**SMP addition assignment to sparse vectors***************************************************
555 template< typename VT2 > // Type of the target sparse vector
556 friend inline void smpAddAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
557 {
559
560 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
561
562 addAssign( *lhs, rhs.dv_ );
563 }
565 //**********************************************************************************************
566
567 //**SMP subtraction assignment to dense vectors*************************************************
580 template< typename VT2 > // Type of the target dense vector
581 friend inline void smpSubAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
582 {
584
585 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
586
587 subAssign( *lhs, rhs.dv_ );
588 }
590 //**********************************************************************************************
591
592 //**SMP subtraction assignment to sparse vectors************************************************
605 template< typename VT2 > // Type of the target sparse vector
606 friend inline void smpSubAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
607 {
609
610 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
611
612 subAssign( *lhs, rhs.dv_ );
613 }
615 //**********************************************************************************************
616
617 //**SMP multiplication assignment to dense vectors**********************************************
630 template< typename VT2 > // Type of the target dense vector
631 friend inline void smpMultAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
632 {
634
635 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
636
637 multAssign( *lhs, rhs.dv_ );
638 }
640 //**********************************************************************************************
641
642 //**SMP multiplication assignment to sparse vectors*********************************************
655 template< typename VT2 > // Type of the target sparse vector
656 friend inline void smpMultAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
657 {
659
660 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
661
662 multAssign( *lhs, rhs.dv_ );
663 }
665 //**********************************************************************************************
666
667 //**SMP division assignment to dense vectors****************************************************
680 template< typename VT2 > // Type of the target dense vector
681 friend inline void smpDivAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
682 {
684
685 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
686
687 divAssign( *lhs, rhs.dv_ );
688 }
690 //**********************************************************************************************
691
692 //**SMP division assignment to sparse vectors***************************************************
705 template< typename VT2 > // Type of the target sparse vector
706 friend inline void smpDivAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
707 {
709
710 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
711
712 divAssign( *lhs, rhs.dv_ );
713 }
715 //**********************************************************************************************
716
717 //**Compile time checks*************************************************************************
722 //**********************************************************************************************
723};
724//*************************************************************************************************
725
726
727
728
729//=================================================================================================
730//
731// GLOBAL FUNCTIONS
732//
733//=================================================================================================
734
735//*************************************************************************************************
752template< typename VT // Type of the dense vector
753 , bool TF > // Transpose flag
754inline decltype(auto) serial( const DenseVector<VT,TF>& dv )
755{
757
758 using ReturnType = const DVecSerialExpr<VT,TF>;
759 return ReturnType( *dv );
760}
761//*************************************************************************************************
762
763
764
765
766//=================================================================================================
767//
768// ISALIGNED SPECIALIZATIONS
769//
770//=================================================================================================
771
772//*************************************************************************************************
774template< typename VT, bool TF >
775struct IsAligned< DVecSerialExpr<VT,TF> >
776 : public IsAligned<VT>
777{};
779//*************************************************************************************************
780
781} // namespace blaze
782
783#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::ResultType ResultType_t
Alias declaration for nested ResultType type definitions.
Definition: Aliases.h:450
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.
Definition: Aliases.h:190
typename T::TransposeType TransposeType_t
Alias declaration for nested TransposeType type definitions.
Definition: Aliases.h:550
Header file for run time assertion macros.
Header file for the function trace functionality.
Header file for the If class template.
Header file for the IsAligned type trait.
Header file for the IsExpression type trait class.
Deactivation of problematic macros.
Expression object for the forced serial evaluation of dense vectors.
Definition: DVecSerialExpr.h:80
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: DVecSerialExpr.h:125
const ResultType CompositeType
Data type for composite expression templates.
Definition: DVecSerialExpr.h:95
Operand operand() const noexcept
Returns the dense vector operand.
Definition: DVecSerialExpr.h:161
ResultType_t< VT > ResultType
Result type for expression template evaluations.
Definition: DVecSerialExpr.h:89
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: DVecSerialExpr.h:215
static constexpr bool simdEnabled
Compilation switch for the expression template evaluation strategy.
Definition: DVecSerialExpr.h:103
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: DVecSerialExpr.h:138
TransposeType_t< VT > TransposeType
Transpose type for expression template evaluations.
Definition: DVecSerialExpr.h:90
ElementType_t< VT > ElementType
Resulting element type.
Definition: DVecSerialExpr.h:91
ReturnType_t< VT > ReturnType
Return type for expression template evaluations.
Definition: DVecSerialExpr.h:92
bool isAligned() const noexcept
Returns whether the operands of the expression are properly aligned in memory.
Definition: DVecSerialExpr.h:205
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: DVecSerialExpr.h:195
DVecSerialExpr(const VT &dv) noexcept
Constructor for the DVecSerialExpr class.
Definition: DVecSerialExpr.h:114
If_t< IsExpression_v< VT >, const VT, const VT & > Operand
Composite data type of the dense vector expression.
Definition: DVecSerialExpr.h:98
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: DVecSerialExpr.h:106
Operand dv_
Dense vector of the serial evaluation expression.
Definition: DVecSerialExpr.h:222
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: DVecSerialExpr.h:151
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: DVecSerialExpr.h:183
Base class for N-dimensional dense vectors.
Definition: DenseVector.h:77
Base class for sparse vectors.
Definition: SparseVector.h:72
Constraint on the data type.
Header file for the Computation base class.
Header file for the DenseVector base class.
Header file for the VecSerialExpr base class.
decltype(auto) serial(const DenseVector< VT, TF > &dv)
Forces the serial evaluation of the given dense vector expression dv.
Definition: DVecSerialExpr.h:754
#define BLAZE_CONSTRAINT_MUST_BE_VECTOR_WITH_TRANSPOSE_FLAG(T, TF)
Constraint on the data type.
Definition: TransposeFlag.h:63
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE(T)
Constraint on the data type.
Definition: DenseVector.h:61
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.
Definition: Assert.h:101
auto smpDivAssign(Vector< VT1, TF1 > &lhs, const Vector< VT2, TF2 > &rhs) -> EnableIf_t< IsDenseVector_v< VT1 > >
Default implementation of the SMP division assignment of a vector to a dense vector.
Definition: DenseVector.h:221
auto smpSubAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP subtraction assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:162
auto smpAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:100
auto smpMultAssign(Vector< VT1, TF1 > &lhs, const Vector< VT2, TF2 > &rhs) -> EnableIf_t< IsDenseVector_v< VT1 > >
Default implementation of the SMP multiplication assignment of a vector to a dense vector.
Definition: DenseVector.h:192
auto smpAddAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP addition assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:131
typename If< Condition >::template Type< T1, T2 > If_t
Auxiliary alias template for the If class template.
Definition: If.h:108
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.
Definition: Exception.h:331
#define BLAZE_FUNCTION_TRACE
Function trace macro.
Definition: FunctionTrace.h:94
Header file for the exception macros of the math module.
Constraint on the data type.
Header file for all forward declarations for expression class templates.
Base class for all compute expression templates.
Definition: Computation.h:68
Base class for all vector serial evaluation expression templates.
Definition: VecSerialExpr.h:69
Header file for basic type definitions.