Blaze 3.9
DVecEvalExpr.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_EXPRESSIONS_DVECEVALEXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_DVECEVALEXPR_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 DVECEVALEXPR
65//
66//=================================================================================================
67
68//*************************************************************************************************
75template< typename VT // Type of the dense vector
76 , bool TF > // Transpose flag
78 : public VecEvalExpr< DenseVector< DVecEvalExpr<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 DVecEvalExpr( const VT& dv ) noexcept
115 : dv_( dv ) // Dense vector of the 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 //**********************************************************************************************
172 template< typename T >
173 inline bool canAlias( const T* alias ) const noexcept {
174 return dv_.canAlias( alias );
175 }
176 //**********************************************************************************************
177
178 //**********************************************************************************************
184 template< typename T >
185 inline bool isAliased( const T* alias ) const noexcept {
186 return dv_.isAliased( alias );
187 }
188 //**********************************************************************************************
189
190 //**********************************************************************************************
195 inline bool isAligned() const noexcept {
196 return dv_.isAligned();
197 }
198 //**********************************************************************************************
199
200 //**********************************************************************************************
205 inline bool canSMPAssign() const noexcept {
206 return dv_.canSMPAssign();
207 }
208 //**********************************************************************************************
209
210 private:
211 //**Member variables****************************************************************************
213 //**********************************************************************************************
214
215 //**Assignment to dense vectors*****************************************************************
227 template< typename VT2 > // Type of the target dense vector
228 friend inline void assign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
229 {
231
232 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
233
234 assign( *lhs, rhs.dv_ );
235 }
237 //**********************************************************************************************
238
239 //**Assignment to sparse vectors****************************************************************
251 template< typename VT2 > // Type of the target sparse vector
252 friend inline void assign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
253 {
255
256 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
257
258 assign( *lhs, rhs.dv_ );
259 }
261 //**********************************************************************************************
262
263 //**Addition assignment to dense vectors********************************************************
275 template< typename VT2 > // Type of the target dense vector
276 friend inline void addAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
277 {
279
280 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
281
282 addAssign( *lhs, rhs.dv_ );
283 }
285 //**********************************************************************************************
286
287 //**Addition assignment to sparse vectors*******************************************************
299 template< typename VT2 > // Type of the target sparse vector
300 friend inline void addAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
301 {
303
304 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
305
306 addAssign( *lhs, rhs.dv_ );
307 }
309 //**********************************************************************************************
310
311 //**Subtraction assignment to dense vectors*****************************************************
323 template< typename VT2 > // Type of the target dense vector
324 friend inline void subAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
325 {
327
328 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
329
330 subAssign( *lhs, rhs.dv_ );
331 }
333 //**********************************************************************************************
334
335 //**Subtraction assignment to sparse vectors****************************************************
347 template< typename VT2 > // Type of the target sparse vector
348 friend inline void subAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
349 {
351
352 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
353
354 subAssign( *lhs, rhs.dv_ );
355 }
357 //**********************************************************************************************
358
359 //**Multiplication assignment to dense vectors**************************************************
371 template< typename VT2 > // Type of the target dense vector
372 friend inline void multAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
373 {
375
376 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
377
378 multAssign( *lhs, rhs.dv_ );
379 }
381 //**********************************************************************************************
382
383 //**Multiplication assignment to sparse vectors*************************************************
395 template< typename VT2 > // Type of the target sparse vector
396 friend inline void multAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
397 {
399
400 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
401
402 multAssign( *lhs, rhs.dv_ );
403 }
405 //**********************************************************************************************
406
407 //**Division assignment to dense vectors********************************************************
419 template< typename VT2 > // Type of the target dense vector
420 friend inline void divAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
421 {
423
424 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
425
426 divAssign( *lhs, rhs.dv_ );
427 }
429 //**********************************************************************************************
430
431 //**Division assignment to sparse vectors*******************************************************
443 template< typename VT2 > // Type of the target sparse vector
444 friend inline void divAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
445 {
447
448 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
449
450 divAssign( *lhs, rhs.dv_ );
451 }
453 //**********************************************************************************************
454
455 //**SMP assignment to dense vectors*************************************************************
467 template< typename VT2 > // Type of the target dense vector
468 friend inline void smpAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
469 {
471
472 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
473
474 smpAssign( *lhs, rhs.dv_ );
475 }
477 //**********************************************************************************************
478
479 //**SMP assignment to sparse vectors************************************************************
491 template< typename VT2 > // Type of the target sparse vector
492 friend inline void smpAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
493 {
495
496 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
497
498 smpAssign( *lhs, rhs.dv_ );
499 }
501 //**********************************************************************************************
502
503 //**SMP addition assignment to dense vectors****************************************************
515 template< typename VT2 > // Type of the target dense vector
516 friend inline void smpAddAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
517 {
519
520 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
521
522 smpAddAssign( *lhs, rhs.dv_ );
523 }
525 //**********************************************************************************************
526
527 //**SMP addition assignment to sparse vectors***************************************************
539 template< typename VT2 > // Type of the target sparse vector
540 friend inline void smpAddAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
541 {
543
544 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
545
546 smpAddAssign( *lhs, rhs.dv_ );
547 }
549 //**********************************************************************************************
550
551 //**SMP subtraction assignment to dense vectors*************************************************
563 template< typename VT2 > // Type of the target dense vector
564 friend inline void smpSubAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
565 {
567
568 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
569
570 smpSubAssign( *lhs, rhs.dv_ );
571 }
573 //**********************************************************************************************
574
575 //**SMP subtraction assignment to sparse vectors************************************************
587 template< typename VT2 > // Type of the target sparse vector
588 friend inline void smpSubAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
589 {
591
592 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
593
594 smpSubAssign( *lhs, rhs.dv_ );
595 }
597 //**********************************************************************************************
598
599 //**SMP multiplication assignment to dense vectors**********************************************
611 template< typename VT2 > // Type of the target dense vector
612 friend inline void smpMultAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
613 {
615
616 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
617
618 smpMultAssign( *lhs, rhs.dv_ );
619 }
621 //**********************************************************************************************
622
623 //**SMP multiplication assignment to sparse vectors*********************************************
635 template< typename VT2 > // Type of the target sparse vector
636 friend inline void smpMultAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
637 {
639
640 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
641
642 smpMultAssign( *lhs, rhs.dv_ );
643 }
645 //**********************************************************************************************
646
647 //**SMP division assignment to dense vectors****************************************************
659 template< typename VT2 > // Type of the target dense vector
660 friend inline void smpDivAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
661 {
663
664 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
665
666 smpDivAssign( *lhs, rhs.dv_ );
667 }
669 //**********************************************************************************************
670
671 //**SMP division assignment to sparse vectors***************************************************
683 template< typename VT2 > // Type of the target sparse vector
684 friend inline void smpDivAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
685 {
687
688 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
689
690 smpDivAssign( *lhs, rhs.dv_ );
691 }
693 //**********************************************************************************************
694
695 //**Compile time checks*************************************************************************
700 //**********************************************************************************************
701};
702//*************************************************************************************************
703
704
705
706
707//=================================================================================================
708//
709// GLOBAL FUNCTIONS
710//
711//=================================================================================================
712
713//*************************************************************************************************
730template< typename VT // Type of the dense vector
731 , bool TF > // Transpose flag
732inline decltype(auto) eval( const DenseVector<VT,TF>& dv )
733{
735
736 using ReturnType = const DVecEvalExpr<VT,TF>;
737 return ReturnType( *dv );
738}
739//*************************************************************************************************
740
741
742
743
744//=================================================================================================
745//
746// ISALIGNED SPECIALIZATIONS
747//
748//=================================================================================================
749
750//*************************************************************************************************
752template< typename VT, bool TF >
753struct IsAligned< DVecEvalExpr<VT,TF> >
754 : public IsAligned<VT>
755{};
757//*************************************************************************************************
758
759} // namespace blaze
760
761#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 evaluation of dense vectors.
Definition: DVecEvalExpr.h:80
ElementType_t< VT > ElementType
Resulting element type.
Definition: DVecEvalExpr.h:91
Operand operand() const noexcept
Returns the dense vector operand.
Definition: DVecEvalExpr.h:161
DVecEvalExpr(const VT &dv) noexcept
Constructor for the DVecEvalExpr class.
Definition: DVecEvalExpr.h:114
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: DVecEvalExpr.h:106
Operand dv_
Dense vector of the evaluation expression.
Definition: DVecEvalExpr.h:212
ResultType_t< VT > ResultType
Result type for expression template evaluations.
Definition: DVecEvalExpr.h:89
bool isAligned() const noexcept
Returns whether the operands of the expression are properly aligned in memory.
Definition: DVecEvalExpr.h:195
If_t< IsExpression_v< VT >, const VT, const VT & > Operand
Composite data type of the dense vector expression.
Definition: DVecEvalExpr.h:98
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: DVecEvalExpr.h:173
static constexpr bool simdEnabled
Compilation switch for the expression template evaluation strategy.
Definition: DVecEvalExpr.h:103
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: DVecEvalExpr.h:205
ReturnType_t< VT > ReturnType
Return type for expression template evaluations.
Definition: DVecEvalExpr.h:92
TransposeType_t< VT > TransposeType
Transpose type for expression template evaluations.
Definition: DVecEvalExpr.h:90
const ResultType CompositeType
Data type for composite expression templates.
Definition: DVecEvalExpr.h:95
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: DVecEvalExpr.h:125
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: DVecEvalExpr.h:138
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: DVecEvalExpr.h:151
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: DVecEvalExpr.h:185
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 VecEvalExpr base class.
decltype(auto) eval(const DenseVector< VT, TF > &dv)
Forces the evaluation of the given dense vector expression dv.
Definition: DVecEvalExpr.h:732
#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 evaluation expression templates.
Definition: VecEvalExpr.h:69
Header file for basic type definitions.