Blaze 3.9
DVecNoAliasExpr.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_EXPRESSIONS_DVECNOALIASEXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_DVECNOALIASEXPR_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <blaze/math/Aliases.h>
57#include <blaze/system/Inline.h>
59#include <blaze/util/Assert.h>
63#include <blaze/util/mpl/If.h>
64#include <blaze/util/Types.h>
66
67
68namespace blaze {
69
70//=================================================================================================
71//
72// CLASS DVECNOALIASEXPR
73//
74//=================================================================================================
75
76//*************************************************************************************************
83template< typename VT // Type of the dense vector
84 , bool TF > // Transpose flag
86 : public VecNoAliasExpr< DenseVector< DVecNoAliasExpr<VT,TF>, TF > >
87 , private Modification<VT>
88{
89 private:
90 //**Type definitions****************************************************************************
92 BLAZE_CREATE_GET_TYPE_MEMBER_TYPE_TRAIT( GetConstIterator, ConstIterator, INVALID_TYPE );
93 //**********************************************************************************************
94
95 public:
96 //**Type definitions****************************************************************************
99
102
107
110
112 using ConstIterator = GetConstIterator_t<VT>;
113
115 using Operand = If_t< IsExpression_v<VT>, const VT, const VT& >;
116 //**********************************************************************************************
117
118 //**Compilation flags***************************************************************************
120 static constexpr bool simdEnabled = VT::simdEnabled;
121
123 static constexpr bool smpAssignable = VT::smpAssignable;
124 //**********************************************************************************************
125
126 //**SIMD properties*****************************************************************************
128 static constexpr size_t SIMDSIZE = SIMDTrait<ElementType>::size;
129 //**********************************************************************************************
130
131 //**Constructor*********************************************************************************
136 explicit inline DVecNoAliasExpr( const VT& dv ) noexcept
137 : dv_( dv ) // Dense vector of the no-alias expression
138 {}
139 //**********************************************************************************************
140
141 //**Subscript operator**************************************************************************
147 inline ReturnType operator[]( size_t index ) const {
148 return dv_[index];
149 }
150 //**********************************************************************************************
151
152 //**At function*********************************************************************************
159 inline ReturnType at( size_t index ) const {
160 return dv_.at( index );
161 }
162 //**********************************************************************************************
163
164 //**Load function*******************************************************************************
170 BLAZE_ALWAYS_INLINE auto load( size_t index ) const noexcept {
171 return dv_.load( index );
172 }
173 //**********************************************************************************************
174
175 //**Low-level data access***********************************************************************
180 inline const ElementType* data() const noexcept {
181 return dv_.data();
182 }
183 //**********************************************************************************************
184
185 //**Begin function******************************************************************************
190 inline ConstIterator begin() const {
191 return ConstIterator( dv_.begin() );
192 }
193 //**********************************************************************************************
194
195 //**End function********************************************************************************
200 inline ConstIterator end() const {
201 return ConstIterator( dv_.end() );
202 }
203 //**********************************************************************************************
204
205 //**Size function*******************************************************************************
210 inline size_t size() const noexcept {
211 return dv_.size();
212 }
213 //**********************************************************************************************
214
215 //**Operand access******************************************************************************
220 inline Operand operand() const noexcept {
221 return dv_;
222 }
223 //**********************************************************************************************
224
225 //**********************************************************************************************
231 template< typename T >
232 inline bool canAlias( const T* alias ) const noexcept {
233 MAYBE_UNUSED( alias );
234 return false;
235 }
236 //**********************************************************************************************
237
238 //**********************************************************************************************
244 template< typename T >
245 inline bool isAliased( const T* alias ) const noexcept {
246 MAYBE_UNUSED( alias );
247 return false;
248 }
249 //**********************************************************************************************
250
251 //**********************************************************************************************
256 inline bool isAligned() const noexcept {
257 return dv_.isAligned();
258 }
259 //**********************************************************************************************
260
261 //**********************************************************************************************
266 inline bool canSMPAssign() const noexcept {
267 return dv_.canSMPAssign();
268 }
269 //**********************************************************************************************
270
271 private:
272 //**Member variables****************************************************************************
274 //**********************************************************************************************
275
276 //**Assignment to dense vectors*****************************************************************
290 template< typename VT2 > // Type of the target dense vector
291 friend inline void assign( DenseVector<VT2,TF>& lhs, const DVecNoAliasExpr& rhs )
292 {
294
295 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
296
297 assign( *lhs, rhs.dv_ );
298 }
300 //**********************************************************************************************
301
302 //**Assignment to sparse vectors****************************************************************
316 template< typename VT2 > // Type of the target sparse vector
317 friend inline void assign( SparseVector<VT2,TF>& lhs, const DVecNoAliasExpr& rhs )
318 {
320
321 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
322
323 assign( *lhs, rhs.dv_ );
324 }
326 //**********************************************************************************************
327
328 //**Addition assignment to dense vectors********************************************************
342 template< typename VT2 > // Type of the target dense vector
343 friend inline void addAssign( DenseVector<VT2,TF>& lhs, const DVecNoAliasExpr& rhs )
344 {
346
347 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
348
349 addAssign( *lhs, rhs.dv_ );
350 }
352 //**********************************************************************************************
353
354 //**Addition assignment to sparse vectors*******************************************************
355 // No special implementation for the addition assignment to sparse vectors.
356 //**********************************************************************************************
357
358 //**Subtraction assignment to dense vectors*****************************************************
372 template< typename VT2 > // Type of the target dense vector
373 friend inline void subAssign( DenseVector<VT2,TF>& lhs, const DVecNoAliasExpr& rhs )
374 {
376
377 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
378
379 subAssign( *lhs, rhs.dv_ );
380 }
382 //**********************************************************************************************
383
384 //**Subtraction assignment to sparse vectors****************************************************
385 // No special implementation for the subtraction assignment to sparse vectors.
386 //**********************************************************************************************
387
388 //**Multiplication assignment to dense vectors**************************************************
402 template< typename VT2 > // Type of the target dense vector
403 friend inline void multAssign( DenseVector<VT2,TF>& lhs, const DVecNoAliasExpr& rhs )
404 {
406
407 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
408
409 multAssign( *lhs, rhs.dv_ );
410 }
412 //**********************************************************************************************
413
414 //**Multiplication assignment to sparse vectors*************************************************
415 // No special implementation for the multiplication assignment to sparse vectors.
416 //**********************************************************************************************
417
418 //**Division assignment to dense vectors********************************************************
432 template< typename VT2 > // Type of the target dense vector
433 friend inline void divAssign( DenseVector<VT2,TF>& lhs, const DVecNoAliasExpr& rhs )
434 {
436
437 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
438
439 divAssign( *lhs, rhs.dv_ );
440 }
442 //**********************************************************************************************
443
444 //**Division assignment to sparse vectors*******************************************************
445 // No special implementation for the division assignment to sparse vectors.
446 //**********************************************************************************************
447
448 //**SMP assignment to dense vectors*************************************************************
462 template< typename VT2 > // Type of the target dense vector
463 friend inline void smpAssign( DenseVector<VT2,TF>& lhs, const DVecNoAliasExpr& rhs )
464 {
466
467 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
468
469 smpAssign( *lhs, rhs.dv_ );
470 }
472 //**********************************************************************************************
473
474 //**SMP assignment to sparse vectors************************************************************
488 template< typename VT2 > // Type of the target sparse vector
489 friend inline void smpAssign( SparseVector<VT2,TF>& lhs, const DVecNoAliasExpr& rhs )
490 {
492
493 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
494
495 smpAssign( *lhs, rhs.dv_ );
496 }
498 //**********************************************************************************************
499
500 //**SMP addition assignment to dense vectors****************************************************
514 template< typename VT2 > // Type of the target dense vector
515 friend inline void smpAddAssign( DenseVector<VT2,TF>& lhs, const DVecNoAliasExpr& rhs )
516 {
518
519 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
520
521 smpAddAssign( *lhs, rhs.dv_ );
522 }
524 //**********************************************************************************************
525
526 //**SMP addition assignment to sparse vectors***************************************************
527 // No special implementation for the SMP addition assignment to sparse vectors.
528 //**********************************************************************************************
529
530 //**SMP subtraction assignment to dense vectors*************************************************
544 template< typename VT2 > // Type of the target dense vector
545 friend inline void smpSubAssign( DenseVector<VT2,TF>& lhs, const DVecNoAliasExpr& rhs )
546 {
548
549 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
550
551 smpSubAssign( *lhs, rhs.dv_ );
552 }
554 //**********************************************************************************************
555
556 //**SMP subtraction assignment to sparse vectors************************************************
557 // No special implementation for the SMP subtraction assignment to sparse vectors.
558 //**********************************************************************************************
559
560 //**SMP multiplication assignment to dense vectors**********************************************
574 template< typename VT2 > // Type of the target dense vector
575 friend inline void smpMultAssign( DenseVector<VT2,TF>& lhs, const DVecNoAliasExpr& rhs )
576 {
578
579 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
580
581 smpMultAssign( *lhs, rhs.dv_ );
582 }
584 //**********************************************************************************************
585
586 //**SMP multiplication assignment to sparse vectors*********************************************
587 // No special implementation for the SMP multiplication assignment to sparse vectors.
588 //**********************************************************************************************
589
590 //**SMP division assignment to dense vectors****************************************************
604 template< typename VT2 > // Type of the target dense vector
605 friend inline void smpDivAssign( DenseVector<VT2,TF>& lhs, const DVecNoAliasExpr& rhs )
606 {
608
609 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
610
611 smpDivAssign( *lhs, rhs.dv_ );
612 }
614 //**********************************************************************************************
615
616 //**SMP division assignment to sparse vectors***************************************************
617 // No special implementation for the SMP division assignment to sparse vectors.
618 //**********************************************************************************************
619
620 //**Compile time checks*************************************************************************
625 //**********************************************************************************************
626};
627//*************************************************************************************************
628
629
630
631
632//=================================================================================================
633//
634// GLOBAL FUNCTIONS
635//
636//=================================================================================================
637
638//*************************************************************************************************
655template< typename VT // Type of the dense vector
656 , bool TF > // Transpose flag
657inline decltype(auto) noalias( const DenseVector<VT,TF>& dv )
658{
660
661 using ReturnType = const DVecNoAliasExpr<VT,TF>;
662 return ReturnType( *dv );
663}
664//*************************************************************************************************
665
666
667
668
669//=================================================================================================
670//
671// ISALIGNED SPECIALIZATIONS
672//
673//=================================================================================================
674
675//*************************************************************************************************
677template< typename VT, bool TF >
678struct HasConstDataAccess< DVecNoAliasExpr<VT,TF> >
679 : public HasConstDataAccess<VT>
680{};
682//*************************************************************************************************
683
684
685
686
687//=================================================================================================
688//
689// ISALIGNED SPECIALIZATIONS
690//
691//=================================================================================================
692
693//*************************************************************************************************
695template< typename VT, bool TF >
696struct IsAligned< DVecNoAliasExpr<VT,TF> >
697 : public IsAligned<VT>
698{};
700//*************************************************************************************************
701
702
703
704
705//=================================================================================================
706//
707// ISPADDED SPECIALIZATIONS
708//
709//=================================================================================================
710
711//*************************************************************************************************
713template< typename VT, bool TF >
714struct IsPadded< DVecNoAliasExpr<VT,TF> >
715 : public IsPadded<VT>
716{};
718//*************************************************************************************************
719
720} // namespace blaze
721
722#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 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.
Header file for the MAYBE_UNUSED function template.
Header file for the SIMD trait.
Expression object for the non-aliased evaluation of dense vectors.
Definition: DVecNoAliasExpr.h:88
ReturnType_t< VT > ReturnType
Return type for expression template evaluations.
Definition: DVecNoAliasExpr.h:106
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: DVecNoAliasExpr.h:123
DVecNoAliasExpr(const VT &dv) noexcept
Constructor for the DVecNoAliasExpr class.
Definition: DVecNoAliasExpr.h:136
bool isAligned() const noexcept
Returns whether the operands of the expression are properly aligned in memory.
Definition: DVecNoAliasExpr.h:256
Operand operand() const noexcept
Returns the dense vector operand.
Definition: DVecNoAliasExpr.h:220
const ElementType * data() const noexcept
Low-level data access to the vector elements.
Definition: DVecNoAliasExpr.h:180
static constexpr size_t SIMDSIZE
The number of elements packed within a single SIMD element.
Definition: DVecNoAliasExpr.h:128
BLAZE_CREATE_GET_TYPE_MEMBER_TYPE_TRAIT(GetConstIterator, ConstIterator, INVALID_TYPE)
Definition of the GetConstIterator type trait.
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: DVecNoAliasExpr.h:266
TransposeType_t< VT > TransposeType
Transpose type for expression template evaluations.
Definition: DVecNoAliasExpr.h:104
ResultType_t< VT > ResultType
Result type for expression template evaluations.
Definition: DVecNoAliasExpr.h:103
ElementType_t< VT > ElementType
Resulting element type.
Definition: DVecNoAliasExpr.h:105
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: DVecNoAliasExpr.h:147
static constexpr bool simdEnabled
Compilation switch for the expression template evaluation strategy.
Definition: DVecNoAliasExpr.h:120
ConstIterator end() const
Returns an iterator just past the last non-zero element of the dense vector.
Definition: DVecNoAliasExpr.h:200
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: DVecNoAliasExpr.h:210
GetConstIterator_t< VT > ConstIterator
Iterator over the elements of the dense vector.
Definition: DVecNoAliasExpr.h:112
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: DVecNoAliasExpr.h:245
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: DVecNoAliasExpr.h:159
If_t< IsExpression_v< VT >, const VT, const VT & > Operand
Composite data type of the dense vector expression.
Definition: DVecNoAliasExpr.h:115
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: DVecNoAliasExpr.h:232
If_t< RequiresEvaluation_v< VT >, const ResultType, const DVecNoAliasExpr & > CompositeType
Data type for composite expression templates.
Definition: DVecNoAliasExpr.h:109
BLAZE_ALWAYS_INLINE auto load(size_t index) const noexcept
Access to the SIMD elements of the vector.
Definition: DVecNoAliasExpr.h:170
ConstIterator begin() const
Returns an iterator to the first non-zero element of the dense vector.
Definition: DVecNoAliasExpr.h:190
Operand dv_
Dense vector of the no-alias expression.
Definition: DVecNoAliasExpr.h:273
Base class for N-dimensional dense vectors.
Definition: DenseVector.h:77
SIMD characteristics of data types.
Definition: SIMDTrait.h:297
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 VecNoAliasExpr base class.
decltype(auto) noalias(const DenseVector< VT, TF > &dv)
Forces the non-aliased evaluation of the given dense vector expression dv.
Definition: DVecNoAliasExpr.h:657
#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
#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 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-alias expression templates.
Definition: VecNoAliasExpr.h:68
System settings for the inline keywords.
Header file for the RequiresEvaluation type trait.
Header file for basic type definitions.