Blaze 3.9
DVecNoSIMDExpr.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_EXPRESSIONS_DVECNOSIMDEXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_DVECNOSIMDEXPR_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <blaze/math/Aliases.h>
56#include <blaze/system/Inline.h>
58#include <blaze/util/Assert.h>
59#include <blaze/util/EnableIf.h>
62#include <blaze/util/mpl/If.h>
63#include <blaze/util/Types.h>
65
66
67namespace blaze {
68
69//=================================================================================================
70//
71// CLASS DVECNOSIMDEXPR
72//
73//=================================================================================================
74
75//*************************************************************************************************
82template< typename VT // Type of the dense vector
83 , bool TF > // Transpose flag
85 : public VecNoSIMDExpr< DenseVector< DVecNoSIMDExpr<VT,TF>, TF > >
86 , private Modification<VT>
87{
88 private:
89 //**Type definitions****************************************************************************
91 BLAZE_CREATE_GET_TYPE_MEMBER_TYPE_TRAIT( GetConstIterator, ConstIterator, INVALID_TYPE );
92 //**********************************************************************************************
93
94 //**Serial evaluation strategy******************************************************************
96
102 static constexpr bool useAssign = RequiresEvaluation_v<VT>;
103
106 template< typename VT2 >
107 static constexpr bool UseAssign_v = useAssign;
109 //**********************************************************************************************
110
111 //**Parallel evaluation strategy****************************************************************
113
119 template< typename VT2 >
120 static constexpr bool UseSMPAssign_v = ( VT2::smpAssignable && useAssign );
122 //**********************************************************************************************
123
124 public:
125 //**Type definitions****************************************************************************
128
131
136
139
141 using ConstIterator = GetConstIterator_t<VT>;
142
144 using Operand = If_t< IsExpression_v<VT>, const VT, const VT& >;
145 //**********************************************************************************************
146
147 //**Compilation flags***************************************************************************
149 static constexpr bool simdEnabled = false;
150
152 static constexpr bool smpAssignable = VT::smpAssignable;
153 //**********************************************************************************************
154
155 //**Constructor*********************************************************************************
160 explicit inline DVecNoSIMDExpr( const VT& dv ) noexcept
161 : dv_( dv ) // Dense vector of the no-SIMD expression
162 {}
163 //**********************************************************************************************
164
165 //**Subscript operator**************************************************************************
171 inline ReturnType operator[]( size_t index ) const {
172 return dv_[index];
173 }
174 //**********************************************************************************************
175
176 //**At function*********************************************************************************
183 inline ReturnType at( size_t index ) const {
184 return dv_.at( index );
185 }
186 //**********************************************************************************************
187
188 //**Low-level data access***********************************************************************
193 inline const ElementType* data() const noexcept {
194 return dv_.data();
195 }
196 //**********************************************************************************************
197
198 //**Begin function******************************************************************************
203 inline ConstIterator begin() const {
204 return ConstIterator( dv_.begin() );
205 }
206 //**********************************************************************************************
207
208 //**End function********************************************************************************
213 inline ConstIterator end() const {
214 return ConstIterator( dv_.end() );
215 }
216 //**********************************************************************************************
217
218 //**Size function*******************************************************************************
223 inline size_t size() const noexcept {
224 return dv_.size();
225 }
226 //**********************************************************************************************
227
228 //**Operand access******************************************************************************
233 inline Operand operand() const noexcept {
234 return dv_;
235 }
236 //**********************************************************************************************
237
238 //**********************************************************************************************
244 template< typename T >
245 inline bool canAlias( const T* alias ) const noexcept {
246 return dv_.canAlias( alias );
247 }
248 //**********************************************************************************************
249
250 //**********************************************************************************************
256 template< typename T >
257 inline bool isAliased( const T* alias ) const noexcept {
258 return dv_.isAliased( alias );
259 }
260 //**********************************************************************************************
261
262 //**********************************************************************************************
267 inline bool isAligned() const noexcept {
268 return dv_.isAligned();
269 }
270 //**********************************************************************************************
271
272 //**********************************************************************************************
277 inline bool canSMPAssign() const noexcept {
278 return dv_.canSMPAssign();
279 }
280 //**********************************************************************************************
281
282 private:
283 //**Member variables****************************************************************************
285 //**********************************************************************************************
286
287 //**Assignment to dense vectors*****************************************************************
301 template< typename VT2 > // Type of the target dense vector
302 friend inline auto assign( DenseVector<VT2,TF>& lhs, const DVecNoSIMDExpr& rhs )
304 {
306
307 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
308
309 assign( *lhs, rhs.dv_ );
310 }
312 //**********************************************************************************************
313
314 //**Assignment to sparse vectors****************************************************************
328 template< typename VT2 > // Type of the target sparse vector
329 friend inline auto assign( SparseVector<VT2,TF>& lhs, const DVecNoSIMDExpr& rhs )
331 {
333
334 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
335
336 assign( *lhs, rhs.dv_ );
337 }
339 //**********************************************************************************************
340
341 //**Addition assignment to dense vectors********************************************************
355 template< typename VT2 > // Type of the target dense vector
356 friend inline auto addAssign( DenseVector<VT2,TF>& lhs, const DVecNoSIMDExpr& rhs )
357 -> EnableIf_t< UseAssign_v<VT2> >
358 {
360
361 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
362
363 addAssign( *lhs, rhs.dv_ );
364 }
366 //**********************************************************************************************
367
368 //**Addition assignment to sparse vectors*******************************************************
369 // No special implementation for the addition assignment to sparse vectors.
370 //**********************************************************************************************
371
372 //**Subtraction assignment to dense vectors*****************************************************
386 template< typename VT2 > // Type of the target dense vector
387 friend inline auto subAssign( DenseVector<VT2,TF>& lhs, const DVecNoSIMDExpr& rhs )
388 -> EnableIf_t< UseAssign_v<VT2> >
389 {
391
392 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
393
394 subAssign( *lhs, rhs.dv_ );
395 }
397 //**********************************************************************************************
398
399 //**Subtraction assignment to sparse vectors****************************************************
400 // No special implementation for the subtraction assignment to sparse vectors.
401 //**********************************************************************************************
402
403 //**Multiplication assignment to dense vectors**************************************************
417 template< typename VT2 > // Type of the target dense vector
418 friend inline auto multAssign( DenseVector<VT2,TF>& lhs, const DVecNoSIMDExpr& rhs )
419 -> EnableIf_t< UseAssign_v<VT2> >
420 {
422
423 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
424
425 multAssign( *lhs, rhs.dv_ );
426 }
428 //**********************************************************************************************
429
430 //**Multiplication assignment to sparse vectors*************************************************
431 // No special implementation for the multiplication assignment to sparse vectors.
432 //**********************************************************************************************
433
434 //**Division assignment to dense vectors********************************************************
448 template< typename VT2 > // Type of the target dense vector
449 friend inline auto divAssign( DenseVector<VT2,TF>& lhs, const DVecNoSIMDExpr& rhs )
450 -> EnableIf_t< UseAssign_v<VT2> >
451 {
453
454 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
455
456 divAssign( *lhs, rhs.dv_ );
457 }
459 //**********************************************************************************************
460
461 //**Division assignment to sparse vectors*******************************************************
462 // No special implementation for the division assignment to sparse vectors.
463 //**********************************************************************************************
464
465 //**SMP assignment to dense vectors*************************************************************
479 template< typename VT2 > // Type of the target dense vector
480 friend inline auto smpAssign( DenseVector<VT2,TF>& lhs, const DVecNoSIMDExpr& rhs )
481 -> EnableIf_t< UseSMPAssign_v<VT2> >
482 {
484
485 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
486
487 smpAssign( *lhs, rhs.dv_ );
488 }
490 //**********************************************************************************************
491
492 //**SMP assignment to sparse vectors************************************************************
506 template< typename VT2 > // Type of the target sparse vector
507 friend inline auto smpAssign( SparseVector<VT2,TF>& lhs, const DVecNoSIMDExpr& rhs )
508 -> EnableIf_t< UseSMPAssign_v<VT2> >
509 {
511
512 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
513
514 smpAssign( *lhs, rhs.dv_ );
515 }
517 //**********************************************************************************************
518
519 //**SMP addition assignment to dense vectors****************************************************
533 template< typename VT2 > // Type of the target dense vector
534 friend inline auto smpAddAssign( DenseVector<VT2,TF>& lhs, const DVecNoSIMDExpr& rhs )
535 -> EnableIf_t< UseSMPAssign_v<VT2> >
536 {
538
539 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
540
541 smpAddAssign( *lhs, rhs.dv_ );
542 }
544 //**********************************************************************************************
545
546 //**SMP addition assignment to sparse vectors***************************************************
547 // No special implementation for the SMP addition assignment to sparse vectors.
548 //**********************************************************************************************
549
550 //**SMP subtraction assignment to dense vectors*************************************************
564 template< typename VT2 > // Type of the target dense vector
565 friend inline auto smpSubAssign( DenseVector<VT2,TF>& lhs, const DVecNoSIMDExpr& rhs )
566 -> EnableIf_t< UseSMPAssign_v<VT2> >
567 {
569
570 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
571
572 smpSubAssign( *lhs, rhs.dv_ );
573 }
575 //**********************************************************************************************
576
577 //**SMP subtraction assignment to sparse vectors************************************************
578 // No special implementation for the SMP subtraction assignment to sparse vectors.
579 //**********************************************************************************************
580
581 //**SMP multiplication assignment to dense vectors**********************************************
595 template< typename VT2 > // Type of the target dense vector
596 friend inline auto smpMultAssign( DenseVector<VT2,TF>& lhs, const DVecNoSIMDExpr& rhs )
597 -> EnableIf_t< UseSMPAssign_v<VT2> >
598 {
600
601 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
602
603 smpMultAssign( *lhs, rhs.dv_ );
604 }
606 //**********************************************************************************************
607
608 //**SMP multiplication assignment to sparse vectors*********************************************
609 // No special implementation for the SMP multiplication assignment to sparse vectors.
610 //**********************************************************************************************
611
612 //**SMP division assignment to dense vectors****************************************************
626 template< typename VT2 > // Type of the target dense vector
627 friend inline auto smpDivAssign( DenseVector<VT2,TF>& lhs, const DVecNoSIMDExpr& rhs )
628 -> EnableIf_t< UseSMPAssign_v<VT2> >
629 {
631
632 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
633
634 smpDivAssign( *lhs, rhs.dv_ );
635 }
637 //**********************************************************************************************
638
639 //**SMP division assignment to sparse vectors***************************************************
640 // No special implementation for the SMP division assignment to sparse vectors.
641 //**********************************************************************************************
642
643 //**Compile time checks*************************************************************************
648 //**********************************************************************************************
649};
650//*************************************************************************************************
651
652
653
654
655//=================================================================================================
656//
657// GLOBAL FUNCTIONS
658//
659//=================================================================================================
660
661//*************************************************************************************************
678template< typename VT // Type of the dense vector
679 , bool TF > // Transpose flag
680inline decltype(auto) nosimd( const DenseVector<VT,TF>& dv )
681{
683
684 using ReturnType = const DVecNoSIMDExpr<VT,TF>;
685 return ReturnType( *dv );
686}
687//*************************************************************************************************
688
689
690
691
692//=================================================================================================
693//
694// ISALIGNED SPECIALIZATIONS
695//
696//=================================================================================================
697
698//*************************************************************************************************
700template< typename VT, bool TF >
701struct HasConstDataAccess< DVecNoSIMDExpr<VT,TF> >
702 : public HasConstDataAccess<VT>
703{};
705//*************************************************************************************************
706
707
708
709
710//=================================================================================================
711//
712// ISALIGNED SPECIALIZATIONS
713//
714//=================================================================================================
715
716//*************************************************************************************************
718template< typename VT, bool TF >
719struct IsAligned< DVecNoSIMDExpr<VT,TF> >
720 : public IsAligned<VT>
721{};
723//*************************************************************************************************
724
725
726
727
728//=================================================================================================
729//
730// ISPADDED SPECIALIZATIONS
731//
732//=================================================================================================
733
734//*************************************************************************************************
736template< typename VT, bool TF >
737struct IsPadded< DVecNoSIMDExpr<VT,TF> >
738 : public IsPadded<VT>
739{};
741//*************************************************************************************************
742
743} // namespace blaze
744
745#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 EnableIf class template.
Header file for the function trace functionality.
Header file for the GetMemberType type trait.
Header file for the HasConstDataAccess type trait.
Header file for the If class template.
Utility type for generic codes.
Header file for the IsAligned type trait.
Header file for the IsExpression type trait class.
Header file for the IsPadded type trait.
Deactivation of problematic macros.
Expression object for the non-SIMD evaluation of dense vectors.
Definition: DVecNoSIMDExpr.h:87
If_t< IsExpression_v< VT >, const VT, const VT & > Operand
Composite data type of the dense vector expression.
Definition: DVecNoSIMDExpr.h:144
GetConstIterator_t< VT > ConstIterator
Iterator over the elements of the dense vector.
Definition: DVecNoSIMDExpr.h:141
ElementType_t< VT > ElementType
Resulting element type.
Definition: DVecNoSIMDExpr.h:134
const ElementType * data() const noexcept
Low-level data access to the vector elements.
Definition: DVecNoSIMDExpr.h:193
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: DVecNoSIMDExpr.h:257
bool isAligned() const noexcept
Returns whether the operands of the expression are properly aligned in memory.
Definition: DVecNoSIMDExpr.h:267
ReturnType_t< VT > ReturnType
Return type for expression template evaluations.
Definition: DVecNoSIMDExpr.h:135
TransposeType_t< VT > TransposeType
Transpose type for expression template evaluations.
Definition: DVecNoSIMDExpr.h:133
ConstIterator end() const
Returns an iterator just past the last non-zero element of the dense vector.
Definition: DVecNoSIMDExpr.h:213
ResultType_t< VT > ResultType
Result type for expression template evaluations.
Definition: DVecNoSIMDExpr.h:132
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: DVecNoSIMDExpr.h:245
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: DVecNoSIMDExpr.h:223
static constexpr bool simdEnabled
Compilation switch for the expression template evaluation strategy.
Definition: DVecNoSIMDExpr.h:149
DVecNoSIMDExpr(const VT &dv) noexcept
Constructor for the DVecNoSIMDExpr class.
Definition: DVecNoSIMDExpr.h:160
BLAZE_CREATE_GET_TYPE_MEMBER_TYPE_TRAIT(GetConstIterator, ConstIterator, INVALID_TYPE)
Definition of the GetConstIterator type trait.
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: DVecNoSIMDExpr.h:171
static constexpr bool useAssign
Compilation switch for the serial evaluation strategy of the no-SIMD expression.
Definition: DVecNoSIMDExpr.h:102
Operand dv_
Dense vector of the no-SIMD expression.
Definition: DVecNoSIMDExpr.h:284
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: DVecNoSIMDExpr.h:152
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: DVecNoSIMDExpr.h:277
If_t< useAssign, const ResultType, const DVecNoSIMDExpr & > CompositeType
Data type for composite expression templates.
Definition: DVecNoSIMDExpr.h:138
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: DVecNoSIMDExpr.h:183
Operand operand() const noexcept
Returns the dense vector operand.
Definition: DVecNoSIMDExpr.h:233
ConstIterator begin() const
Returns an iterator to the first non-zero element of the dense vector.
Definition: DVecNoSIMDExpr.h:203
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 DenseVector base class.
Header file for the Modification base class.
Header file for the VecNoSIMDExpr base class.
decltype(auto) nosimd(const DenseVector< VT, TF > &dv)
Disables the SIMD evaluation of the given dense vector expression dv.
Definition: DVecNoSIMDExpr.h:680
#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 EnableIf< Condition, T >::Type EnableIf_t
Auxiliary type for the EnableIf class template.
Definition: EnableIf.h:138
typename If< Condition >::template Type< T1, T2 > If_t
Auxiliary alias template for the If class template.
Definition: If.h:108
#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 modification expression templates.
Definition: Modification.h:76
Base class for all vector no-SIMD expression templates.
Definition: VecNoSIMDExpr.h:88
System settings for the inline keywords.
Header file for the RequiresEvaluation type trait.
Header file for basic type definitions.