All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DVecSVecAddExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_DVECSVECADDEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_DVECSVECADDEXPR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <stdexcept>
64 #include <blaze/util/Assert.h>
67 #include <blaze/util/SelectType.h>
68 #include <blaze/util/Types.h>
69 
70 
71 namespace blaze {
72 
73 //=================================================================================================
74 //
75 // CLASS DVECSVECADDEXPR
76 //
77 //=================================================================================================
78 
79 //*************************************************************************************************
86 template< typename VT1 // Type of the left-hand side dense vector
87  , typename VT2 // Type of the right-hand side sparse vector
88  , bool TF > // Transpose flag
89 class DVecSVecAddExpr : public DenseVector< DVecSVecAddExpr<VT1,VT2,TF>, TF >
90  , private VecVecAddExpr
91  , private Computation
92 {
93  private:
94  //**Type definitions****************************************************************************
95  typedef typename VT1::ResultType RT1;
96  typedef typename VT2::ResultType RT2;
97  typedef typename VT1::ReturnType RN1;
98  typedef typename VT2::ReturnType RN2;
99  typedef typename VT1::CompositeType CT1;
100  typedef typename VT2::CompositeType CT2;
101  typedef typename VT1::TransposeType TT1;
102  typedef typename VT2::TransposeType TT2;
103  //**********************************************************************************************
104 
105  //**Return type evaluation**********************************************************************
107 
112  enum { returnExpr = !IsTemporary<RN1>::value && !IsTemporary<RN2>::value };
113 
116  //**********************************************************************************************
117 
118  public:
119  //**Type definitions****************************************************************************
124 
127 
129  typedef const ResultType CompositeType;
130 
132  typedef typename SelectType< IsExpression<VT1>::value, const VT1, const VT1& >::Type LeftOperand;
133 
135  typedef typename SelectType< IsExpression<VT2>::value, const VT2, const VT2& >::Type RightOperand;
136  //**********************************************************************************************
137 
138  //**Compilation flags***************************************************************************
140  enum { vectorizable = 0 };
141 
143  enum { smpAssignable = 0 };
144  //**********************************************************************************************
145 
146  //**Constructor*********************************************************************************
152  explicit inline DVecSVecAddExpr( const VT1& lhs, const VT2& rhs )
153  : lhs_( lhs ) // Left-hand side dense vector of the addition expression
154  , rhs_( rhs ) // Right-hand side sparse vector of the addition expression
155  {
156  BLAZE_INTERNAL_ASSERT( lhs.size() == rhs.size(), "Invalid vector sizes" );
157  }
158  //**********************************************************************************************
159 
160  //**Subscript operator**************************************************************************
166  inline ReturnType operator[]( size_t index ) const {
167  BLAZE_INTERNAL_ASSERT( index < lhs_.size(), "Invalid vector access index" );
168  return lhs_[index] + rhs_[index];
169  }
170  //**********************************************************************************************
171 
172  //**Size function*******************************************************************************
177  inline size_t size() const {
178  return lhs_.size();
179  }
180  //**********************************************************************************************
181 
182  //**Left operand access*************************************************************************
187  inline LeftOperand leftOperand() const {
188  return lhs_;
189  }
190  //**********************************************************************************************
191 
192  //**Right operand access************************************************************************
197  inline RightOperand rightOperand() const {
198  return rhs_;
199  }
200  //**********************************************************************************************
201 
202  //**********************************************************************************************
208  template< typename T >
209  inline bool canAlias( const T* alias ) const {
210  return ( IsComputation<VT1>::value && lhs_.canAlias( alias ) ) ||
211  ( rhs_.canAlias( alias ) );
212  }
213  //**********************************************************************************************
214 
215  //**********************************************************************************************
221  template< typename T >
222  inline bool isAliased( const T* alias ) const {
223  return ( lhs_.isAliased( alias ) || rhs_.isAliased( alias ) );
224  }
225  //**********************************************************************************************
226 
227  private:
228  //**Member variables****************************************************************************
231  //**********************************************************************************************
232 
233  //**Assignment to dense vectors*****************************************************************
245  template< typename VT > // Type of the target dense vector
246  friend inline void assign( DenseVector<VT,TF>& lhs, const DVecSVecAddExpr& rhs )
247  {
249 
250  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
251 
252  if( !IsComputation<VT1>::value && (~lhs).isAliased( &rhs.lhs_ ) ) {
253  smpAddAssign( ~lhs, rhs.rhs_ );
254  }
255  else {
256  smpAssign ( ~lhs, rhs.lhs_ );
257  smpAddAssign( ~lhs, rhs.rhs_ );
258  }
259  }
261  //**********************************************************************************************
262 
263  //**Assignment to sparse vectors****************************************************************
275  template< typename VT > // Type of the target sparse vector
276  friend inline void assign( SparseVector<VT,TF>& lhs, const DVecSVecAddExpr& rhs )
277  {
279 
283 
284  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
285 
286  const ResultType tmp( rhs );
287  smpAssign( ~lhs, tmp );
288  }
290  //**********************************************************************************************
291 
292  //**Addition assignment to dense vectors********************************************************
304  template< typename VT > // Type of the target dense vector
305  friend inline void addAssign( DenseVector<VT,TF>& lhs, const DVecSVecAddExpr& rhs )
306  {
308 
309  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
310 
311  smpAddAssign( ~lhs, rhs.lhs_ );
312  smpAddAssign( ~lhs, rhs.rhs_ );
313  }
315  //**********************************************************************************************
316 
317  //**Addition assignment to sparse vectors*******************************************************
318  // No special implementation for the addition assignment to sparse vectors.
319  //**********************************************************************************************
320 
321  //**Subtraction assignment to dense vectors*****************************************************
333  template< typename VT > // Type of the target dense vector
334  friend inline void subAssign( DenseVector<VT,TF>& lhs, const DVecSVecAddExpr& rhs )
335  {
337 
338  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
339 
340  smpSubAssign( ~lhs, rhs.lhs_ );
341  smpSubAssign( ~lhs, rhs.rhs_ );
342  }
344  //**********************************************************************************************
345 
346  //**Subtraction assignment to sparse vectors****************************************************
347  // No special implementation for the subtraction assignment to sparse vectors.
348  //**********************************************************************************************
349 
350  //**Multiplication assignment to dense vectors**************************************************
362  template< typename VT > // Type of the target dense vector
363  friend inline void multAssign( DenseVector<VT,TF>& lhs, const DVecSVecAddExpr& rhs )
364  {
366 
370 
371  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
372 
373  const ResultType tmp( rhs );
374  smpMultAssign( ~lhs, tmp );
375  }
377  //**********************************************************************************************
378 
379  //**Multiplication assignment to sparse vectors*************************************************
380  // No special implementation for the multiplication assignment to sparse vectors.
381  //**********************************************************************************************
382 
383  //**Compile time checks*************************************************************************
390  //**********************************************************************************************
391 };
392 //*************************************************************************************************
393 
394 
395 
396 
397 //=================================================================================================
398 //
399 // GLOBAL BINARY ARITHMETIC OPERATORS
400 //
401 //=================================================================================================
402 
403 //*************************************************************************************************
429 template< typename T1 // Type of the left-hand side dense vector
430  , typename T2 // Type of the right-hand side sparse vector
431  , bool TF > // Transpose flag
432 inline const DVecSVecAddExpr<T1,T2,TF>
434 {
436 
437  if( (~lhs).size() != (~rhs).size() )
438  throw std::invalid_argument( "Vector sizes do not match" );
439 
440  return DVecSVecAddExpr<T1,T2,TF>( ~lhs, ~rhs );
441 }
442 //*************************************************************************************************
443 
444 
445 //*************************************************************************************************
471 template< typename T1 // Type of the left-hand side sparse vector
472  , typename T2 // Type of the right-hand side dense vector
473  , bool TF > // Transpose flag
474 inline const DVecSVecAddExpr<T2,T1,TF>
476 {
478 
479  if( (~lhs).size() != (~rhs).size() )
480  throw std::invalid_argument( "Vector sizes do not match" );
481 
482  return DVecSVecAddExpr<T2,T1,TF>( ~rhs, ~lhs );
483 }
484 //*************************************************************************************************
485 
486 
487 
488 
489 //=================================================================================================
490 //
491 // GLOBAL RESTRUCTURING BINARY ARITHMETIC OPERATORS
492 //
493 //=================================================================================================
494 
495 //*************************************************************************************************
508 template< typename T1 // Type of the dense vector of the left-hand side expression
509  , typename T2 // Type of the sparse vector of the left-hand side expression
510  , bool TF // Transpose flag of the left-hand side expression
511  , typename T3 > // Type of the right-hand side dense vector
512 inline const typename AddExprTrait< DVecSVecAddExpr<T1,T2,TF>, T3 >::Type
513  operator+( const DVecSVecAddExpr<T1,T2,TF>& lhs, const DenseVector<T3,TF>& rhs )
514 {
516 
517  return ( lhs.leftOperand() + (~rhs) ) + lhs.rightOperand();
518 }
520 //*************************************************************************************************
521 
522 
523 //*************************************************************************************************
536 template< typename T1 // Type of the dense vector of the left-hand side expression
537  , typename T2 // Type of the sparse vector of the left-hand side expression
538  , bool TF // Transpose flag of the left-hand side expression
539  , typename T3 > // Type of the right-hand side dense vector
540 inline const typename SubExprTrait< DVecSVecAddExpr<T1,T2,TF>, T3 >::Type
541  operator-( const DVecSVecAddExpr<T1,T2,TF>& lhs, const DenseVector<T3,TF>& rhs )
542 {
544 
545  return ( lhs.leftOperand() - (~rhs) ) + lhs.rightOperand();
546 }
548 //*************************************************************************************************
549 
550 
551 
552 
553 //=================================================================================================
554 //
555 // EXPRESSION TRAIT SPECIALIZATIONS
556 //
557 //=================================================================================================
558 
559 //*************************************************************************************************
561 template< typename VT1, typename VT2, typename VT3 >
562 struct DVecDVecAddExprTrait< DVecSVecAddExpr<VT1,VT2,false>, VT3 >
563 {
564  public:
565  //**********************************************************************************************
567  typedef typename SelectType< IsDenseVector<VT1>::value && IsColumnVector<VT1>::value &&
568  IsSparseVector<VT2>::value && IsColumnVector<VT2>::value &&
569  IsDenseVector<VT3>::value && IsColumnVector<VT3>::value
570  , typename DVecSVecAddExprTrait< typename DVecDVecAddExprTrait<VT1,VT3>::Type, VT2 >::Type
571  , INVALID_TYPE >::Type Type;
573  //**********************************************************************************************
574 };
576 //*************************************************************************************************
577 
578 
579 //*************************************************************************************************
581 template< typename VT1, typename VT2, typename VT3 >
582 struct TDVecTDVecAddExprTrait< DVecSVecAddExpr<VT1,VT2,true>, VT3 >
583 {
584  public:
585  //**********************************************************************************************
587  typedef typename SelectType< IsDenseVector<VT1>::value && IsRowVector<VT1>::value &&
588  IsSparseVector<VT2>::value && IsRowVector<VT2>::value &&
589  IsDenseVector<VT3>::value && IsRowVector<VT3>::value
590  , typename TDVecTSVecAddExprTrait< typename TDVecTDVecAddExprTrait<VT1,VT3>::Type, VT2 >::Type
591  , INVALID_TYPE >::Type Type;
593  //**********************************************************************************************
594 };
596 //*************************************************************************************************
597 
598 
599 //*************************************************************************************************
601 template< typename VT1, typename VT2, typename VT3 >
602 struct DVecDVecSubExprTrait< DVecSVecAddExpr<VT1,VT2,false>, VT3 >
603 {
604  public:
605  //**********************************************************************************************
607  typedef typename SelectType< IsDenseVector<VT1>::value && IsColumnVector<VT1>::value &&
608  IsSparseVector<VT2>::value && IsColumnVector<VT2>::value &&
609  IsDenseVector<VT3>::value && IsColumnVector<VT3>::value
610  , typename DVecSVecAddExprTrait< typename DVecDVecSubExprTrait<VT1,VT3>::Type, VT2 >::Type
611  , INVALID_TYPE >::Type Type;
613  //**********************************************************************************************
614 };
616 //*************************************************************************************************
617 
618 
619 //*************************************************************************************************
621 template< typename VT1, typename VT2, typename VT3 >
622 struct TDVecTDVecSubExprTrait< DVecSVecAddExpr<VT1,VT2,true>, VT3 >
623 {
624  public:
625  //**********************************************************************************************
627  typedef typename SelectType< IsDenseVector<VT1>::value && IsRowVector<VT1>::value &&
628  IsSparseVector<VT2>::value && IsRowVector<VT2>::value &&
629  IsDenseVector<VT3>::value && IsRowVector<VT3>::value
630  , typename TDVecTSVecAddExprTrait< typename TDVecTDVecSubExprTrait<VT1,VT3>::Type, VT2 >::Type
631  , INVALID_TYPE >::Type Type;
633  //**********************************************************************************************
634 };
636 //*************************************************************************************************
637 
638 
639 //*************************************************************************************************
641 template< typename VT1, typename VT2, bool TF, bool AF >
642 struct SubvectorExprTrait< DVecSVecAddExpr<VT1,VT2,TF>, AF >
643 {
644  public:
645  //**********************************************************************************************
646  typedef typename AddExprTrait< typename SubvectorExprTrait<const VT1,AF>::Type
647  , typename SubvectorExprTrait<const VT2,AF>::Type >::Type Type;
648  //**********************************************************************************************
649 };
651 //*************************************************************************************************
652 
653 } // namespace blaze
654 
655 #endif
VT2::ResultType RT2
Result type of the right-hand side sparse vector expression.
Definition: DVecSVecAddExpr.h:96
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: DVecSVecAddExpr.h:222
Compile time check whether the given type is a computational expression template.This type trait clas...
Definition: IsComputation.h:89
RightOperand rhs_
Right-hand side sparse vector of the addition expression.
Definition: DVecSVecAddExpr.h:230
Evaluation of the return type of an addition expression.Via this type trait it is possible to evaluat...
Definition: AddExprTrait.h:103
Compile time check whether the given type is a temporary vector or matrix type.This type trait class ...
Definition: IsTemporary.h:87
VT2::ReturnType RN2
Return type of the right-hand side sparse vector expression.
Definition: DVecSVecAddExpr.h:98
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: DVecSVecAddExpr.h:122
VT1::ResultType RT1
Result type of the left-hand side dense vector expression.
Definition: DVecSVecAddExpr.h:95
void smpSubAssign(DenseMatrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP subtraction assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:151
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:197
VT1::CompositeType CT1
Composite type of the left-hand side dense vector expression.
Definition: DVecSVecAddExpr.h:99
void smpMultAssign(DenseVector< 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:178
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2384
Header file for the IsRowVector type trait.
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:249
Header file for the DenseVector base class.
Header file for the AddExprTrait class template.
Header file for the Computation base class.
Expression object for dense vector-sparse vector additions.The DVecSVecAddExpr class represents the c...
Definition: DVecSVecAddExpr.h:89
RightOperand rightOperand() const
Returns the right-hand side sparse vector operand.
Definition: DVecSVecAddExpr.h:197
Constraint on the data type.
VT1::TransposeType TT1
Transpose type of the left-hand side dense vector expression.
Definition: DVecSVecAddExpr.h:101
void smpAddAssign(DenseMatrix< 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:121
LeftOperand leftOperand() const
Returns the left-hand side dense vector operand.
Definition: DVecSVecAddExpr.h:187
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:251
VT2::TransposeType TT2
Transpose type of the right-hand side sparse vector expression.
Definition: DVecSVecAddExpr.h:102
Compile time type selection.The SelectType class template selects one of the two given types T1 and T...
Definition: SelectType.h:59
Header file for the IsTemporary type trait class.
Header file for the dense vector SMP implementation.
Header file for the VecVecAddExpr base class.
DVecSVecAddExpr< VT1, VT2, TF > This
Type of this DVecSVecAddExpr instance.
Definition: DVecSVecAddExpr.h:120
ResultType::ElementType ElementType
Resulting element type.
Definition: DVecSVecAddExpr.h:123
const ResultType CompositeType
Data type for composite expression templates.
Definition: DVecSVecAddExpr.h:129
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:179
const DenseIterator< Type > operator+(const DenseIterator< Type > &it, ptrdiff_t inc)
Addition between a DenseIterator and an integral value.
Definition: DenseIterator.h:556
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a sparse, N-dimensional vector type...
Definition: SparseVector.h:79
Constraint on the data type.
LeftOperand lhs_
Left-hand side dense vector of the addition expression.
Definition: DVecSVecAddExpr.h:229
#define BLAZE_CONSTRAINT_MUST_BE_REFERENCE_TYPE(T)
Constraint on the data type.In case the given data type T is not a reference type, a compilation error is created.
Definition: Reference.h:78
CompressedMatrix< Type, false > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:2381
Constraint on the data type.
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: DVecSVecAddExpr.h:209
VT2::CompositeType CT2
Composite type of the right-hand side sparse vector expression.
Definition: DVecSVecAddExpr.h:100
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:269
Header file for the SelectType class template.
Header file for all forward declarations for expression class templates.
Constraint on the data type.
Base class for all vector/vector addition expression templates.The VecVecAddExpr class serves as a ta...
Definition: VecVecAddExpr.h:65
void smpAssign(DenseMatrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:91
Header file for the IsSparseVector type trait.
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2383
AddExprTrait< RN1, RN2 >::Type ExprReturnType
Expression return type for the subscript operator.
Definition: DVecSVecAddExpr.h:115
Header file for run time assertion macros.
Base template for the AddTrait class.
Definition: AddTrait.h:141
Header file for the addition trait.
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:209
const DenseIterator< Type > operator-(const DenseIterator< Type > &it, ptrdiff_t inc)
Subtraction between a DenseIterator and an integral value.
Definition: DenseIterator.h:585
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:239
SelectType< IsExpression< VT1 >::value, const VT1, const VT1 & >::Type LeftOperand
Composite type of the left-hand side dense vector expression.
Definition: DVecSVecAddExpr.h:132
DVecSVecAddExpr(const VT1 &lhs, const VT2 &rhs)
Constructor for the DVecSVecAddExpr class.
Definition: DVecSVecAddExpr.h:152
const SelectType< returnExpr, ExprReturnType, ElementType >::Type ReturnType
Return type for expression template evaluations.
Definition: DVecSVecAddExpr.h:126
size_t size() const
Returns the current size/dimension of the vector.
Definition: DVecSVecAddExpr.h:177
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
AddTrait< RT1, RT2 >::Type ResultType
Result type for expression template evaluations.
Definition: DVecSVecAddExpr.h:121
Header file for the IsComputation type trait class.
Base class for all compute expression templates.The Computation class serves as a tag for all computa...
Definition: Computation.h:59
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: DVecSVecAddExpr.h:166
Header file for the sparse vector SMP implementation.
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:105
#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:2379
Header file for basic type definitions.
Header file for the SubvectorExprTrait class template.
SelectType< IsExpression< VT2 >::value, const VT2, const VT2 & >::Type RightOperand
Composite type of the right-hand side sparse vector expression.
Definition: DVecSVecAddExpr.h:135
VT1::ReturnType RN1
Return type of the left-hand side dense vector expression.
Definition: DVecSVecAddExpr.h:97
Header file for the IsColumnVector type trait.
Header file for the SubExprTrait class template.
#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.