All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 <cmath>
59 #include <blaze/util/Assert.h>
61 #include <blaze/util/InvalidType.h>
63 #include <blaze/util/SelectType.h>
64 #include <blaze/util/Types.h>
65 
66 
67 namespace blaze {
68 
69 //=================================================================================================
70 //
71 // CLASS DVECSERIALEXPR
72 //
73 //=================================================================================================
74 
75 //*************************************************************************************************
82 template< typename VT // Type of the dense vector
83  , bool TF > // Transpose flag
84 class DVecSerialExpr : public DenseVector< DVecSerialExpr<VT,TF>, TF >
85  , private VecSerialExpr
86  , private Computation
87 {
88  public:
89  //**Type definitions****************************************************************************
91  typedef typename VT::ResultType ResultType;
92  typedef typename VT::TransposeType TransposeType;
93  typedef typename VT::ElementType ElementType;
94  typedef typename VT::ReturnType ReturnType;
95 
97  typedef const ResultType CompositeType;
98 
100  typedef typename SelectType< IsExpression<VT>::value, const VT, const VT& >::Type Operand;
101  //**********************************************************************************************
102 
103  //**Compilation flags***************************************************************************
105  enum { vectorizable = 0 };
106 
108  enum { smpAssignable = VT::smpAssignable };
109  //**********************************************************************************************
110 
111  //**Constructor*********************************************************************************
116  explicit inline DVecSerialExpr( const VT& dv )
117  : dv_( dv ) // Dense vector of the serial evaluation expression
118  {}
119  //**********************************************************************************************
120 
121  //**Subscript operator**************************************************************************
127  inline ReturnType operator[]( size_t index ) const {
128  BLAZE_INTERNAL_ASSERT( index < dv_.size(), "Invalid vector access index" );
129  return dv_[index];
130  }
131  //**********************************************************************************************
132 
133  //**Size function*******************************************************************************
138  inline size_t size() const {
139  return dv_.size();
140  }
141  //**********************************************************************************************
142 
143  //**Operand access******************************************************************************
148  inline Operand operand() const {
149  return dv_;
150  }
151  //**********************************************************************************************
152 
153  //**Conversion operator*************************************************************************
158  inline operator Operand() const {
159  return dv_;
160  }
161  //**********************************************************************************************
162 
163  //**********************************************************************************************
169  template< typename T >
170  inline bool canAlias( const T* alias ) const {
171  return dv_.canAlias( alias );
172  }
173  //**********************************************************************************************
174 
175  //**********************************************************************************************
181  template< typename T >
182  inline bool isAliased( const T* alias ) const {
183  return dv_.isAliased( alias );
184  }
185  //**********************************************************************************************
186 
187  //**********************************************************************************************
192  inline bool isAligned() const {
193  return dv_.isAligned();
194  }
195  //**********************************************************************************************
196 
197  //**********************************************************************************************
202  inline bool canSMPAssign() const {
203  return dv_.canSMPAssign();
204  }
205  //**********************************************************************************************
206 
207  private:
208  //**Member variables****************************************************************************
210  //**********************************************************************************************
211 
212  //**Assignment to dense vectors*****************************************************************
224  template< typename VT2 > // Type of the target dense vector
225  friend inline void assign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
226  {
228 
229  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
230 
231  assign( ~lhs, rhs.dv_ );
232  }
234  //**********************************************************************************************
235 
236  //**Assignment to sparse vectors****************************************************************
248  template< typename VT2 > // Type of the target sparse vector
249  friend inline void assign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
250  {
252 
253  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
254 
255  assign( ~lhs, rhs.dv_ );
256  }
258  //**********************************************************************************************
259 
260  //**Addition assignment to dense vectors********************************************************
272  template< typename VT2 > // Type of the target dense vector
273  friend inline void addAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
274  {
276 
277  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
278 
279  addAssign( ~lhs, rhs.dv_ );
280  }
282  //**********************************************************************************************
283 
284  //**Addition assignment to sparse vectors*******************************************************
296  template< typename VT2 > // Type of the target sparse vector
297  friend inline void addAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
298  {
300 
301  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
302 
303  addAssign( ~lhs, rhs.dv_ );
304  }
306  //**********************************************************************************************
307 
308  //**Subtraction assignment to dense vectors*****************************************************
321  template< typename VT2 > // Type of the target dense vector
322  friend inline void subAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
323  {
325 
326  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
327 
328  subAssign( ~lhs, rhs.dv_ );
329  }
331  //**********************************************************************************************
332 
333  //**Subtraction assignment to sparse vectors****************************************************
346  template< typename VT2 > // Type of the target sparse vector
347  friend inline void subAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
348  {
350 
351  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
352 
353  subAssign( ~lhs, rhs.dv_ );
354  }
356  //**********************************************************************************************
357 
358  //**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 DVecSerialExpr& 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*************************************************
396  template< typename VT2 > // Type of the target sparse vector
397  friend inline void multAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
398  {
400 
401  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
402 
403  multAssign( ~lhs, rhs.dv_ );
404  }
406  //**********************************************************************************************
407 
408  //**SMP assignment to dense vectors*************************************************************
420  template< typename VT2 > // Type of the target dense vector
421  friend inline void smpAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
422  {
424 
425  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
426 
427  assign( ~lhs, rhs.dv_ );
428  }
430  //**********************************************************************************************
431 
432  //**SMP assignment to sparse vectors************************************************************
444  template< typename VT2 > // Type of the target sparse vector
445  friend inline void smpAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
446  {
448 
449  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
450 
451  assign( ~lhs, rhs.dv_ );
452  }
454  //**********************************************************************************************
455 
456  //**SMP addition assignment to dense vectors****************************************************
469  template< typename VT2 > // Type of the target dense vector
470  friend inline void smpAddAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
471  {
473 
474  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
475 
476  addAssign( ~lhs, rhs.dv_ );
477  }
479  //**********************************************************************************************
480 
481  //**SMP addition assignment to sparse vectors***************************************************
494  template< typename VT2 > // Type of the target sparse vector
495  friend inline void smpAddAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
496  {
498 
499  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
500 
501  addAssign( ~lhs, rhs.dv_ );
502  }
504  //**********************************************************************************************
505 
506  //**SMP subtraction assignment to dense vectors*************************************************
519  template< typename VT2 > // Type of the target dense vector
520  friend inline void smpSubAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
521  {
523 
524  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
525 
526  subAssign( ~lhs, rhs.dv_ );
527  }
529  //**********************************************************************************************
530 
531  //**SMP subtraction assignment to sparse vectors************************************************
544  template< typename VT2 > // Type of the target sparse vector
545  friend inline void smpSubAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
546  {
548 
549  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
550 
551  subAssign( ~lhs, rhs.dv_ );
552  }
554  //**********************************************************************************************
555 
556  //**SMP multiplication assignment to dense vectors**********************************************
569  template< typename VT2 > // Type of the target dense vector
570  friend inline void smpMultAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
571  {
573 
574  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
575 
576  multAssign( ~lhs, rhs.dv_ );
577  }
579  //**********************************************************************************************
580 
581  //**SMP multiplication assignment to sparse vectors*********************************************
594  template< typename VT2 > // Type of the target sparse vector
595  friend inline void smpMultAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
596  {
598 
599  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
600 
601  multAssign( ~lhs, rhs.dv_ );
602  }
604  //**********************************************************************************************
605 
606  //**Compile time checks*************************************************************************
611  //**********************************************************************************************
612 };
613 //*************************************************************************************************
614 
615 
616 
617 
618 //=================================================================================================
619 //
620 // GLOBAL FUNCTIONS
621 //
622 //=================================================================================================
623 
624 //*************************************************************************************************
641 template< typename VT // Type of the dense vector
642  , bool TF > // Transpose flag
644 {
646 
647  return DVecSerialExpr<VT,TF>( ~dv );
648 }
649 //*************************************************************************************************
650 
651 
652 
653 
654 //=================================================================================================
655 //
656 // GLOBAL RESTRUCTURING FUNCTIONS
657 //
658 //=================================================================================================
659 
660 //*************************************************************************************************
671 template< typename VT // Type of the dense vector
672  , bool TF > // Transpose flag
673 inline const DVecSerialExpr<VT,TF> serial( const DVecSerialExpr<VT,TF>& dv )
674 {
675  return dv;
676 }
678 //*************************************************************************************************
679 
680 
681 
682 
683 //=================================================================================================
684 //
685 // SIZE SPECIALIZATIONS
686 //
687 //=================================================================================================
688 
689 //*************************************************************************************************
691 template< typename VT, bool TF >
692 struct Size< DVecSerialExpr<VT,TF> >
693  : public Size<VT>
694 {};
696 //*************************************************************************************************
697 
698 
699 
700 //=================================================================================================
701 //
702 // EXPRESSION TRAIT SPECIALIZATIONS
703 //
704 //=================================================================================================
705 
706 //*************************************************************************************************
708 template< typename VT >
709 struct DVecSerialExprTrait< DVecSerialExpr<VT,false> >
710 {
711  public:
712  //**********************************************************************************************
713  typedef typename SelectType< IsDenseVector<VT>::value && IsColumnVector<VT>::value
714  , DVecSerialExpr<VT,false>
715  , INVALID_TYPE >::Type Type;
716  //**********************************************************************************************
717 };
719 //*************************************************************************************************
720 
721 
722 //*************************************************************************************************
724 template< typename VT >
725 struct TDVecSerialExprTrait< DVecSerialExpr<VT,true> >
726 {
727  public:
728  //**********************************************************************************************
729  typedef typename SelectType< IsDenseVector<VT>::value && IsRowVector<VT>::value
730  , DVecSerialExpr<VT,true>
731  , INVALID_TYPE >::Type Type;
732  //**********************************************************************************************
733 };
735 //*************************************************************************************************
736 
737 
738 //*************************************************************************************************
740 template< typename VT, bool TF, bool AF >
741 struct SubvectorExprTrait< DVecSerialExpr<VT,TF>, AF >
742 {
743  public:
744  //**********************************************************************************************
745  typedef typename SerialExprTrait< typename SubvectorExprTrait<const VT,AF>::Type >::Type Type;
746  //**********************************************************************************************
747 };
749 //*************************************************************************************************
750 
751 } // namespace blaze
752 
753 #endif
Expression object for the forced serial evaluation of dense vectors.The DVecSerialExpr class represen...
Definition: DVecSerialExpr.h:84
VT::ElementType ElementType
Resulting element type.
Definition: DVecSerialExpr.h:93
SelectType< IsExpression< VT >::value, const VT, const VT & >::Type Operand
Composite data type of the dense vector expression.
Definition: DVecSerialExpr.h:100
Header file for the TDVecSerialExprTrait class template.
BLAZE_ALWAYS_INLINE void multAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the multiplication assignment of a matrix to a matrix.
Definition: Matrix.h:879
bool isAligned() const
Returns whether the operands of the expression are properly aligned in memory.
Definition: DVecSerialExpr.h:192
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: DVecSerialExpr.h:170
const ResultType CompositeType
Data type for composite expression templates.
Definition: DVecSerialExpr.h:97
Base class for all vector serial evaluation expression templates.The VecSerialExpr class serves as a ...
Definition: VecSerialExpr.h:65
Header file for the IsRowVector type trait.
Header file for the DenseVector base class.
const DMatSerialExpr< MT, SO > serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:695
Header file for the Computation base class.
Operand dv_
Dense vector of the serial evaluation expression.
Definition: DVecSerialExpr.h:209
VT::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: DVecSerialExpr.h:92
DVecSerialExpr(const VT &dv)
Constructor for the DVecSerialExpr class.
Definition: DVecSerialExpr.h:116
Constraint on the data type.
bool canSMPAssign() const
Returns whether the expression can be used in SMP assignments.
Definition: DVecSerialExpr.h:202
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: DVecSerialExpr.h:182
Compile time type selection.The SelectType class template selects one of the two given types T1 and T...
Definition: SelectType.h:59
VT::ResultType ResultType
Result type for expression template evaluations.
Definition: DVecSerialExpr.h:91
size_t size() const
Returns the current size/dimension of the vector.
Definition: DVecSerialExpr.h:138
BLAZE_ALWAYS_INLINE void assign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the assignment of a matrix to a matrix.
Definition: Matrix.h:635
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
Header file for the SerialExprTrait class template.
Constraint on the data type.
CompressedMatrix< Type, false > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:2475
Constraint on the data type.
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2476
VT::ReturnType ReturnType
Return type for expression template evaluations.
Definition: DVecSerialExpr.h:94
Header file for the SelectType class template.
Header file for all forward declarations for expression class templates.
Operand operand() const
Returns the dense vector operand.
Definition: DVecSerialExpr.h:148
Header file for the VecSerialExpr base class.
EnableIf< IsDenseMatrix< MT1 > >::Type smpSubAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP subtraction assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:160
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2477
Header file for run time assertion macros.
EnableIf< IsDenseMatrix< MT1 > >::Type smpAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:98
Utility type for generic codes.
BLAZE_ALWAYS_INLINE void addAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the addition assignment of a matrix to a matrix.
Definition: Matrix.h:742
Header file for the IsDenseVector type trait.
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a dense, N-dimensional vector type...
Definition: DenseVector.h:79
Header file for the DVecSerialExprTrait class template.
Base class for all compute expression templates.The Computation class serves as a tag for all computa...
Definition: Computation.h:59
EnableIf< IsDenseMatrix< MT1 > >::Type smpAddAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP addition assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:129
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:108
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:157
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2473
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: DVecSerialExpr.h:127
Header file for basic type definitions.
Header file for the SubvectorExprTrait class template.
Header file for the IsColumnVector type trait.
DVecSerialExpr< VT, TF > This
Type of this DVecSerialExpr instance.
Definition: DVecSerialExpr.h:90
EnableIf< IsDenseVector< VT1 > >::Type smpMultAssign(Vector< VT1, TF1 > &lhs, const Vector< VT2, TF2 > &rhs)
Default implementation of the SMP multiplication assignment of a vector to a dense vector...
Definition: DenseVector.h:189
Header file for the Size type trait.
#define BLAZE_CONSTRAINT_MUST_BE_VECTOR_WITH_TRANSPOSE_FLAG(T, TF)
Constraint on the data type.In case the given data type T is not a dense or sparse vector type and in...
Definition: TransposeFlag.h:238
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_INTERNAL_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERTION flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:101
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.
BLAZE_ALWAYS_INLINE void subAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the subtraction assignment of a matrix to matrix.
Definition: Matrix.h:849