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>
60 #include <blaze/util/Assert.h>
62 #include <blaze/util/Exception.h>
63 #include <blaze/util/InvalidType.h>
65 #include <blaze/util/SelectType.h>
66 #include <blaze/util/Types.h>
67 
68 
69 namespace blaze {
70 
71 //=================================================================================================
72 //
73 // CLASS DVECSERIALEXPR
74 //
75 //=================================================================================================
76 
77 //*************************************************************************************************
84 template< typename VT // Type of the dense vector
85  , bool TF > // Transpose flag
86 class DVecSerialExpr : public DenseVector< DVecSerialExpr<VT,TF>, TF >
87  , private VecSerialExpr
88  , private Computation
89 {
90  public:
91  //**Type definitions****************************************************************************
93  typedef typename VT::ResultType ResultType;
94  typedef typename VT::TransposeType TransposeType;
95  typedef typename VT::ElementType ElementType;
96  typedef typename VT::ReturnType ReturnType;
97 
99  typedef const ResultType CompositeType;
100 
102  typedef typename SelectType< IsExpression<VT>::value, const VT, const VT& >::Type Operand;
103  //**********************************************************************************************
104 
105  //**Compilation flags***************************************************************************
107  enum { vectorizable = 0 };
108 
110  enum { smpAssignable = VT::smpAssignable };
111  //**********************************************************************************************
112 
113  //**Constructor*********************************************************************************
118  explicit inline DVecSerialExpr( const VT& dv )
119  : dv_( dv ) // Dense vector of the serial evaluation expression
120  {}
121  //**********************************************************************************************
122 
123  //**Subscript operator**************************************************************************
129  inline ReturnType operator[]( size_t index ) const {
130  BLAZE_INTERNAL_ASSERT( index < dv_.size(), "Invalid vector access index" );
131  return dv_[index];
132  }
133  //**********************************************************************************************
134 
135  //**At function*********************************************************************************
142  inline ReturnType at( size_t index ) const {
143  if( index >= dv_.size() ) {
144  BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
145  }
146  return (*this)[index];
147  }
148  //**********************************************************************************************
149 
150  //**Size function*******************************************************************************
155  inline size_t size() const {
156  return dv_.size();
157  }
158  //**********************************************************************************************
159 
160  //**Operand access******************************************************************************
165  inline Operand operand() const {
166  return dv_;
167  }
168  //**********************************************************************************************
169 
170  //**Conversion operator*************************************************************************
175  inline operator Operand() const {
176  return dv_;
177  }
178  //**********************************************************************************************
179 
180  //**********************************************************************************************
186  template< typename T >
187  inline bool canAlias( const T* alias ) const {
188  return dv_.canAlias( alias );
189  }
190  //**********************************************************************************************
191 
192  //**********************************************************************************************
198  template< typename T >
199  inline bool isAliased( const T* alias ) const {
200  return dv_.isAliased( alias );
201  }
202  //**********************************************************************************************
203 
204  //**********************************************************************************************
209  inline bool isAligned() const {
210  return dv_.isAligned();
211  }
212  //**********************************************************************************************
213 
214  //**********************************************************************************************
219  inline bool canSMPAssign() const {
220  return dv_.canSMPAssign();
221  }
222  //**********************************************************************************************
223 
224  private:
225  //**Member variables****************************************************************************
226  Operand dv_;
227  //**********************************************************************************************
228 
229  //**Assignment to dense vectors*****************************************************************
241  template< typename VT2 > // Type of the target dense vector
242  friend inline void assign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
243  {
245 
246  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
247 
248  assign( ~lhs, rhs.dv_ );
249  }
251  //**********************************************************************************************
252 
253  //**Assignment to sparse vectors****************************************************************
265  template< typename VT2 > // Type of the target sparse vector
266  friend inline void assign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
267  {
269 
270  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
271 
272  assign( ~lhs, rhs.dv_ );
273  }
275  //**********************************************************************************************
276 
277  //**Addition assignment to dense vectors********************************************************
289  template< typename VT2 > // Type of the target dense vector
290  friend inline void addAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
291  {
293 
294  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
295 
296  addAssign( ~lhs, rhs.dv_ );
297  }
299  //**********************************************************************************************
300 
301  //**Addition assignment to sparse vectors*******************************************************
313  template< typename VT2 > // Type of the target sparse vector
314  friend inline void addAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
315  {
317 
318  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
319 
320  addAssign( ~lhs, rhs.dv_ );
321  }
323  //**********************************************************************************************
324 
325  //**Subtraction assignment to dense vectors*****************************************************
338  template< typename VT2 > // Type of the target dense vector
339  friend inline void subAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
340  {
342 
343  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
344 
345  subAssign( ~lhs, rhs.dv_ );
346  }
348  //**********************************************************************************************
349 
350  //**Subtraction assignment to sparse vectors****************************************************
363  template< typename VT2 > // Type of the target sparse vector
364  friend inline void subAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
365  {
367 
368  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
369 
370  subAssign( ~lhs, rhs.dv_ );
371  }
373  //**********************************************************************************************
374 
375  //**Multiplication assignment to dense vectors**************************************************
388  template< typename VT2 > // Type of the target dense vector
389  friend inline void multAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
390  {
392 
393  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
394 
395  multAssign( ~lhs, rhs.dv_ );
396  }
398  //**********************************************************************************************
399 
400  //**Multiplication assignment to sparse vectors*************************************************
413  template< typename VT2 > // Type of the target sparse vector
414  friend inline void multAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
415  {
417 
418  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
419 
420  multAssign( ~lhs, rhs.dv_ );
421  }
423  //**********************************************************************************************
424 
425  //**SMP assignment to dense vectors*************************************************************
437  template< typename VT2 > // Type of the target dense vector
438  friend inline void smpAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
439  {
441 
442  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
443 
444  assign( ~lhs, rhs.dv_ );
445  }
447  //**********************************************************************************************
448 
449  //**SMP assignment to sparse vectors************************************************************
461  template< typename VT2 > // Type of the target sparse vector
462  friend inline void smpAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
463  {
465 
466  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
467 
468  assign( ~lhs, rhs.dv_ );
469  }
471  //**********************************************************************************************
472 
473  //**SMP addition assignment to dense vectors****************************************************
486  template< typename VT2 > // Type of the target dense vector
487  friend inline void smpAddAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
488  {
490 
491  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
492 
493  addAssign( ~lhs, rhs.dv_ );
494  }
496  //**********************************************************************************************
497 
498  //**SMP addition assignment to sparse vectors***************************************************
511  template< typename VT2 > // Type of the target sparse vector
512  friend inline void smpAddAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
513  {
515 
516  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
517 
518  addAssign( ~lhs, rhs.dv_ );
519  }
521  //**********************************************************************************************
522 
523  //**SMP subtraction assignment to dense vectors*************************************************
536  template< typename VT2 > // Type of the target dense vector
537  friend inline void smpSubAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
538  {
540 
541  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
542 
543  subAssign( ~lhs, rhs.dv_ );
544  }
546  //**********************************************************************************************
547 
548  //**SMP subtraction assignment to sparse vectors************************************************
561  template< typename VT2 > // Type of the target sparse vector
562  friend inline void smpSubAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
563  {
565 
566  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
567 
568  subAssign( ~lhs, rhs.dv_ );
569  }
571  //**********************************************************************************************
572 
573  //**SMP multiplication assignment to dense vectors**********************************************
586  template< typename VT2 > // Type of the target dense vector
587  friend inline void smpMultAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
588  {
590 
591  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
592 
593  multAssign( ~lhs, rhs.dv_ );
594  }
596  //**********************************************************************************************
597 
598  //**SMP multiplication assignment to sparse vectors*********************************************
611  template< typename VT2 > // Type of the target sparse vector
612  friend inline void smpMultAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
613  {
615 
616  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
617 
618  multAssign( ~lhs, rhs.dv_ );
619  }
621  //**********************************************************************************************
622 
623  //**Compile time checks*************************************************************************
628  //**********************************************************************************************
629 };
630 //*************************************************************************************************
631 
632 
633 
634 
635 //=================================================================================================
636 //
637 // GLOBAL FUNCTIONS
638 //
639 //=================================================================================================
640 
641 //*************************************************************************************************
658 template< typename VT // Type of the dense vector
659  , bool TF > // Transpose flag
661 {
663 
664  return DVecSerialExpr<VT,TF>( ~dv );
665 }
666 //*************************************************************************************************
667 
668 
669 
670 
671 //=================================================================================================
672 //
673 // GLOBAL RESTRUCTURING FUNCTIONS
674 //
675 //=================================================================================================
676 
677 //*************************************************************************************************
688 template< typename VT // Type of the dense vector
689  , bool TF > // Transpose flag
690 inline const DVecSerialExpr<VT,TF> serial( const DVecSerialExpr<VT,TF>& dv )
691 {
692  return dv;
693 }
695 //*************************************************************************************************
696 
697 
698 
699 
700 //=================================================================================================
701 //
702 // SIZE SPECIALIZATIONS
703 //
704 //=================================================================================================
705 
706 //*************************************************************************************************
708 template< typename VT, bool TF >
709 struct Size< DVecSerialExpr<VT,TF> > : public Size<VT>
710 {};
712 //*************************************************************************************************
713 
714 
715 
716 
717 //=================================================================================================
718 //
719 // ISALIGNED SPECIALIZATIONS
720 //
721 //=================================================================================================
722 
723 //*************************************************************************************************
725 template< typename VT, bool TF >
726 struct IsAligned< DVecSerialExpr<VT,TF> > : public IsTrue< IsAligned<VT>::value >
727 {};
729 //*************************************************************************************************
730 
731 
732 
733 
734 //=================================================================================================
735 //
736 // EXPRESSION TRAIT SPECIALIZATIONS
737 //
738 //=================================================================================================
739 
740 //*************************************************************************************************
742 template< typename VT >
743 struct DVecSerialExprTrait< DVecSerialExpr<VT,false> >
744 {
745  public:
746  //**********************************************************************************************
747  typedef typename SelectType< IsDenseVector<VT>::value && IsColumnVector<VT>::value
748  , DVecSerialExpr<VT,false>
749  , INVALID_TYPE >::Type Type;
750  //**********************************************************************************************
751 };
753 //*************************************************************************************************
754 
755 
756 //*************************************************************************************************
758 template< typename VT >
759 struct TDVecSerialExprTrait< DVecSerialExpr<VT,true> >
760 {
761  public:
762  //**********************************************************************************************
763  typedef typename SelectType< IsDenseVector<VT>::value && IsRowVector<VT>::value
764  , DVecSerialExpr<VT,true>
765  , INVALID_TYPE >::Type Type;
766  //**********************************************************************************************
767 };
769 //*************************************************************************************************
770 
771 
772 //*************************************************************************************************
774 template< typename VT, bool TF, bool AF >
775 struct SubvectorExprTrait< DVecSerialExpr<VT,TF>, AF >
776 {
777  public:
778  //**********************************************************************************************
779  typedef typename SerialExprTrait< typename SubvectorExprTrait<const VT,AF>::Type >::Type Type;
780  //**********************************************************************************************
781 };
783 //*************************************************************************************************
784 
785 } // namespace blaze
786 
787 #endif
Expression object for the forced serial evaluation of dense vectors.The DVecSerialExpr class represen...
Definition: DVecSerialExpr.h:86
VT::ElementType ElementType
Resulting element type.
Definition: DVecSerialExpr.h:95
SelectType< IsExpression< VT >::value, const VT, const VT & >::Type Operand
Composite data type of the dense vector expression.
Definition: DVecSerialExpr.h:102
Header file for the TDVecSerialExprTrait class template.
bool isAligned() const
Returns whether the operands of the expression are properly aligned in memory.
Definition: DVecSerialExpr.h:209
Header file for basic type definitions.
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: DVecSerialExpr.h:187
const ResultType CompositeType
Data type for composite expression templates.
Definition: DVecSerialExpr.h:99
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:721
Header file for the Computation base class.
Operand dv_
Dense vector of the serial evaluation expression.
Definition: DVecSerialExpr.h:226
VT::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: DVecSerialExpr.h:94
DVecSerialExpr(const VT &dv)
Constructor for the DVecSerialExpr class.
Definition: DVecSerialExpr.h:118
Constraint on the data type.
bool canSMPAssign() const
Returns whether the expression can be used in SMP assignments.
Definition: DVecSerialExpr.h:219
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: DVecSerialExpr.h:199
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:93
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exceptionThis macro encapsulates the default way of Bla...
Definition: Exception.h:331
size_t size() const
Returns the current size/dimension of the vector.
Definition: DVecSerialExpr.h:155
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: DVecSerialExpr.h:142
Header file for the IsAligned type trait.
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:2585
Constraint on the data type.
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2586
VT::ReturnType ReturnType
Return type for expression template evaluations.
Definition: DVecSerialExpr.h:96
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:165
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:2587
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.
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:118
#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:2583
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: DVecSerialExpr.h:129
Header file for the SubvectorExprTrait class template.
Header file for exception macros.
Header file for the IsColumnVector type trait.
DVecSerialExpr< VT, TF > This
Type of this DVecSerialExpr instance.
Definition: DVecSerialExpr.h:92
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:81
#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.