All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SVecDVecSubExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_SVECDVECSUBEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_SVECDVECSUBEXPR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <stdexcept>
62 #include <blaze/util/Assert.h>
65 #include <blaze/util/SelectType.h>
66 #include <blaze/util/Types.h>
67 
68 
69 namespace blaze {
70 
71 //=================================================================================================
72 //
73 // CLASS SVECDVECSUBEXPR
74 //
75 //=================================================================================================
76 
77 //*************************************************************************************************
84 template< typename VT1 // Type of the left-hand side sparse vector
85  , typename VT2 // Type of the right-hand side dense vector
86  , bool TF > // Transpose flag
87 class SVecDVecSubExpr : public DenseVector< SVecDVecSubExpr<VT1,VT2,TF>, TF >
88  , private VecVecSubExpr
89  , private Computation
90 {
91  private:
92  //**Type definitions****************************************************************************
93  typedef typename VT1::ResultType RT1;
94  typedef typename VT2::ResultType RT2;
95  typedef typename VT1::ReturnType RN1;
96  typedef typename VT2::ReturnType RN2;
97  typedef typename VT1::CompositeType CT1;
98  typedef typename VT2::CompositeType CT2;
99  typedef typename VT1::TransposeType TT1;
100  typedef typename VT2::TransposeType TT2;
101  //**********************************************************************************************
102 
103  //**Return type evaluation**********************************************************************
105 
110  enum { returnExpr = !IsTemporary<RN1>::value && !IsTemporary<RN2>::value };
111 
114  //**********************************************************************************************
115 
116  public:
117  //**Type definitions****************************************************************************
122 
125 
127  typedef const ResultType CompositeType;
128 
130  typedef typename SelectType< IsExpression<VT1>::value, const VT1, const VT1& >::Type LeftOperand;
131 
133  typedef typename SelectType< IsExpression<VT2>::value, const VT2, const VT2& >::Type RightOperand;
134  //**********************************************************************************************
135 
136  //**Compilation flags***************************************************************************
138  enum { vectorizable = 0 };
139 
141  enum { smpAssignable = 0 };
142  //**********************************************************************************************
143 
144  //**Constructor*********************************************************************************
150  explicit inline SVecDVecSubExpr( const VT1& lhs, const VT2& rhs )
151  : lhs_( lhs ) // Left-hand side sparse vector of the subtraction expression
152  , rhs_( rhs ) // Right-hand side dense vector of the subtraction expression
153  {
154  BLAZE_INTERNAL_ASSERT( lhs.size() == rhs.size(), "Invalid vector sizes" );
155  }
156  //**********************************************************************************************
157 
158  //**Subscript operator**************************************************************************
164  inline ReturnType operator[]( size_t index ) const {
165  BLAZE_INTERNAL_ASSERT( index < lhs_.size(), "Invalid vector access index" );
166  return lhs_[index] - rhs_[index];
167  }
168  //**********************************************************************************************
169 
170  //**Size function*******************************************************************************
175  inline size_t size() const {
176  return lhs_.size();
177  }
178  //**********************************************************************************************
179 
180  //**Left operand access*************************************************************************
185  inline LeftOperand leftOperand() const {
186  return lhs_;
187  }
188  //**********************************************************************************************
189 
190  //**Right operand access************************************************************************
195  inline RightOperand rightOperand() const {
196  return rhs_;
197  }
198  //**********************************************************************************************
199 
200  //**********************************************************************************************
206  template< typename T >
207  inline bool canAlias( const T* alias ) const {
208  return ( lhs_.canAlias( alias ) || rhs_.canAlias( alias ) );
209  }
210  //**********************************************************************************************
211 
212  //**********************************************************************************************
218  template< typename T >
219  inline bool isAliased( const T* alias ) const {
220  return ( lhs_.isAliased( alias ) || rhs_.isAliased( alias ) );
221  }
222  //**********************************************************************************************
223 
224  private:
225  //**Member variables****************************************************************************
228  //**********************************************************************************************
229 
230  //**Assignment to dense vectors*****************************************************************
242  template< typename VT > // Type of the target dense vector
243  friend inline void assign( DenseVector<VT,TF>& lhs, const SVecDVecSubExpr& rhs )
244  {
246 
247  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
248 
249  assign ( ~lhs, -rhs.rhs_ );
250  addAssign( ~lhs, rhs.lhs_ );
251  }
253  //**********************************************************************************************
254 
255  //**Assignment to sparse vectors****************************************************************
267  template< typename VT > // Type of the target sparse vector
268  friend inline void assign( SparseVector<VT,TF>& lhs, const SVecDVecSubExpr& rhs )
269  {
271 
275 
276  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
277 
278  const ResultType tmp( rhs );
279  assign( ~lhs, tmp );
280  }
282  //**********************************************************************************************
283 
284  //**Addition assignment to dense vectors********************************************************
296  template< typename VT > // Type of the target dense vector
297  friend inline void addAssign( DenseVector<VT,TF>& lhs, const SVecDVecSubExpr& rhs )
298  {
300 
301  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
302 
303  subAssign( ~lhs, rhs.rhs_ );
304  addAssign( ~lhs, rhs.lhs_ );
305  }
307  //**********************************************************************************************
308 
309  //**Addition assignment to sparse vectors*******************************************************
310  // No special implementation for the addition assignment to sparse vectors.
311  //**********************************************************************************************
312 
313  //**Subtraction assignment to dense vectors*****************************************************
325  template< typename VT > // Type of the target dense vector
326  friend inline void subAssign( DenseVector<VT,TF>& lhs, const SVecDVecSubExpr& rhs )
327  {
329 
330  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
331 
332  addAssign( ~lhs, rhs.rhs_ );
333  subAssign( ~lhs, rhs.lhs_ );
334  }
336  //**********************************************************************************************
337 
338  //**Subtraction assignment to sparse vectors****************************************************
339  // No special implementation for the subtraction assignment to sparse vectors.
340  //**********************************************************************************************
341 
342  //**Multiplication assignment to dense vectors**************************************************
354  template< typename VT > // Type of the target dense vector
355  friend inline void multAssign( DenseVector<VT,TF>& lhs, const SVecDVecSubExpr& rhs )
356  {
358 
362 
363  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
364 
365  const ResultType tmp( rhs );
366  multAssign( ~lhs, tmp );
367  }
369  //**********************************************************************************************
370 
371  //**Multiplication assignment to sparse vectors*************************************************
372  // No special implementation for the multiplication assignment to sparse vectors.
373  //**********************************************************************************************
374 
375  //**Compile time checks*************************************************************************
382  //**********************************************************************************************
383 };
384 //*************************************************************************************************
385 
386 
387 
388 
389 //=================================================================================================
390 //
391 // GLOBAL BINARY ARITHMETIC OPERATORS
392 //
393 //=================================================================================================
394 
395 //*************************************************************************************************
421 template< typename T1 // Type of the left-hand side sparse vector
422  , typename T2 // Type of the right-hand side dense vector
423  , bool TF > // Transpose flag
424 inline const SVecDVecSubExpr<T1,T2,TF>
426 {
428 
429  if( (~lhs).size() != (~rhs).size() )
430  throw std::invalid_argument( "Vector sizes do not match" );
431 
432  return SVecDVecSubExpr<T1,T2,TF>( ~lhs, ~rhs );
433 }
434 //*************************************************************************************************
435 
436 
437 
438 
439 //=================================================================================================
440 //
441 // GLOBAL RESTRUCTURING BINARY ARITHMETIC OPERATORS
442 //
443 //=================================================================================================
444 
445 //*************************************************************************************************
458 template< typename T1 // Type of the sparse vector of the left-hand side expression
459  , typename T2 // Type of the dense vector of the left-hand side expression
460  , bool TF // Transpose flag of the left-hand side expression
461  , typename T3 > // Type of right-hand side dense vector
462 inline const typename AddExprTrait< SVecDVecSubExpr<T1,T2,TF>, T3 >::Type
463  operator+( const SVecDVecSubExpr<T1,T2,TF>& lhs, const DenseVector<T3,TF>& rhs )
464 {
466 
467  return ( (~rhs) - lhs.rightOperand() ) + lhs.leftOperand();
468 }
470 //*************************************************************************************************
471 
472 
473 //*************************************************************************************************
486 template< typename T1 // Type of the sparse vector of the left-hand side expression
487  , typename T2 // Type of the dense vector of the left-hand side expression
488  , bool TF // Transpose flag of the left-hand side expression
489  , typename T3 > // Type of right-hand side dense vector
490 inline const typename SubExprTrait< SVecDVecSubExpr<T1,T2,TF>, T3 >::Type
491  operator-( const SVecDVecSubExpr<T1,T2,TF>& lhs, const DenseVector<T3,TF>& rhs )
492 {
494 
495  return lhs.leftOperand() - ( lhs.rightOperand() + (~rhs) );
496 }
498 //*************************************************************************************************
499 
500 
501 
502 
503 //=================================================================================================
504 //
505 // EXPRESSION TRAIT SPECIALIZATIONS
506 //
507 //=================================================================================================
508 
509 //*************************************************************************************************
511 template< typename VT1, typename VT2, typename VT3 >
512 struct DVecDVecAddExprTrait< SVecDVecSubExpr<VT1,VT2,false>, VT3 >
513 {
514  public:
515  //**********************************************************************************************
517  typedef typename SelectType< IsSparseVector<VT1>::value && IsColumnVector<VT1>::value &&
518  IsDenseVector<VT2>::value && IsColumnVector<VT2>::value &&
519  IsDenseVector<VT3>::value && IsColumnVector<VT3>::value
520  , typename DVecSVecAddExprTrait< typename DVecDVecSubExprTrait<VT3,VT2>::Type, VT1 >::Type
521  , INVALID_TYPE >::Type Type;
523  //**********************************************************************************************
524 };
526 //*************************************************************************************************
527 
528 
529 //*************************************************************************************************
531 template< typename VT1, typename VT2, typename VT3 >
532 struct TDVecTDVecAddExprTrait< SVecDVecSubExpr<VT1,VT2,true>, VT3 >
533 {
534  public:
535  //**********************************************************************************************
537  typedef typename SelectType< IsSparseVector<VT1>::value && IsRowVector<VT1>::value &&
538  IsDenseVector<VT2>::value && IsRowVector<VT2>::value &&
539  IsDenseVector<VT3>::value && IsRowVector<VT3>::value
540  , typename TDVecTSVecAddExprTrait< typename TDVecTDVecSubExprTrait<VT3,VT2>::Type, VT1 >::Type
541  , INVALID_TYPE >::Type Type;
543  //**********************************************************************************************
544 };
546 //*************************************************************************************************
547 
548 
549 //*************************************************************************************************
551 template< typename VT1, typename VT2, typename VT3 >
552 struct DVecDVecSubExprTrait< SVecDVecSubExpr<VT1,VT2,false>, VT3 >
553 {
554  public:
555  //**********************************************************************************************
557  typedef typename SelectType< IsSparseVector<VT1>::value && IsColumnVector<VT1>::value &&
558  IsDenseVector<VT2>::value && IsColumnVector<VT2>::value &&
559  IsDenseVector<VT3>::value && IsColumnVector<VT3>::value
560  , typename SVecDVecSubExprTrait< VT1, typename DVecDVecAddExprTrait<VT2,VT3>::Type >::Type
561  , INVALID_TYPE >::Type Type;
563  //**********************************************************************************************
564 };
566 //*************************************************************************************************
567 
568 
569 //*************************************************************************************************
571 template< typename VT1, typename VT2, typename VT3 >
572 struct TDVecTDVecSubExprTrait< SVecDVecSubExpr<VT1,VT2,true>, VT3 >
573 {
574  public:
575  //**********************************************************************************************
577  typedef typename SelectType< IsSparseVector<VT1>::value && IsRowVector<VT1>::value &&
578  IsDenseVector<VT2>::value && IsRowVector<VT2>::value &&
579  IsDenseVector<VT3>::value && IsRowVector<VT3>::value
580  , typename TSVecTDVecSubExprTrait< VT1, typename TDVecTDVecAddExprTrait<VT2,VT3>::Type >::Type
581  , INVALID_TYPE >::Type Type;
583  //**********************************************************************************************
584 };
586 //*************************************************************************************************
587 
588 
589 //*************************************************************************************************
591 template< typename VT1, typename VT2, bool TF >
592 struct SubvectorExprTrait< SVecDVecSubExpr<VT1,VT2,TF> >
593 {
594  public:
595  //**********************************************************************************************
596  typedef typename SubExprTrait< typename SubvectorExprTrait<const VT1>::Type
597  , typename SubvectorExprTrait<const VT2>::Type >::Type Type;
598  //**********************************************************************************************
599 };
601 //*************************************************************************************************
602 
603 } // namespace blaze
604 
605 #endif
SVecDVecSubExpr(const VT1 &lhs, const VT2 &rhs)
Constructor for the SVecDVecSubExpr class.
Definition: SVecDVecSubExpr.h:150
Expression object for sparse vector-dense vector subtractions.The SVecDVecSubExpr class represents th...
Definition: Forward.h:109
Compile time check whether the given type is a temporary vector or matrix type.This type trait class ...
Definition: IsTemporary.h:87
Header file for the subtraction trait.
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: SVecDVecSubExpr.h:219
const ResultType CompositeType
Data type for composite expression templates.
Definition: SVecDVecSubExpr.h:127
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:196
VT2::ResultType RT2
Result type of the right-hand side dense vector expression.
Definition: SVecDVecSubExpr.h:94
SubExprTrait< RN1, RN2 >::Type ExprReturnType
Expression return type for the subscript operator.
Definition: SVecDVecSubExpr.h:113
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2375
Header file for the IsRowVector type trait.
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:248
Header file for the DenseVector base class.
Header file for the AddExprTrait class template.
Header file for the Computation base class.
SelectType< IsExpression< VT1 >::value, const VT1, const VT1 & >::Type LeftOperand
Composite type of the left-hand side sparse vector expression.
Definition: SVecDVecSubExpr.h:130
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: SVecDVecSubExpr.h:120
Constraint on the data type.
VT1::ResultType RT1
Result type of the left-hand side sparse vector expression.
Definition: SVecDVecSubExpr.h:93
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:250
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.
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
SubTrait< RT1, RT2 >::Type ResultType
Result type for expression template evaluations.
Definition: SVecDVecSubExpr.h:119
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
size_t size() const
Returns the current size/dimension of the vector.
Definition: SVecDVecSubExpr.h:175
RightOperand rightOperand() const
Returns the right-hand side dense vector operand.
Definition: SVecDVecSubExpr.h:195
LeftOperand leftOperand() const
Returns the left-hand side sparse vector operand.
Definition: SVecDVecSubExpr.h:185
const SelectType< returnExpr, ExprReturnType, ElementType >::Type ReturnType
Return type for expression template evaluations.
Definition: SVecDVecSubExpr.h:124
#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.
VT2::CompositeType CT2
Composite type of the right-hand side dense vector expression.
Definition: SVecDVecSubExpr.h:98
#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:2372
Constraint on the data type.
Evaluation of the return type of a subtraction expression.Via this type trait it is possible to evalu...
Definition: SubExprTrait.h:103
VT1::CompositeType CT1
Composite type of the left-hand side sparse vector expression.
Definition: SVecDVecSubExpr.h:97
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 VecVecSubExpr base class.
Header file for the SelectType class template.
Header file for all forward declarations for expression class templates.
Constraint on the data type.
LeftOperand lhs_
Left-hand side sparse vector of the subtraction expression.
Definition: SVecDVecSubExpr.h:226
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: SVecDVecSubExpr.h:164
VT1::ReturnType RN1
Return type of the left-hand side sparse vector expression.
Definition: SVecDVecSubExpr.h:95
VT2::ReturnType RN2
Return type of the right-hand side dense vector expression.
Definition: SVecDVecSubExpr.h:96
Header file for the IsSparseVector type trait.
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2374
Header file for run time assertion macros.
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: SVecDVecSubExpr.h:207
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
SVecDVecSubExpr< VT1, VT2, TF > This
Type of this SVecDVecSubExpr instance.
Definition: SVecDVecSubExpr.h:118
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
ResultType::ElementType ElementType
Resulting element type.
Definition: SVecDVecSubExpr.h:121
VT1::TransposeType TT1
Transpose type of the left-hand side sparse vector expression.
Definition: SVecDVecSubExpr.h:99
Header file for the IsDenseVector type trait.
VT2::TransposeType TT2
Transpose type of the right-hand side dense vector expression.
Definition: SVecDVecSubExpr.h:100
#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 IsComputation type trait class.
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
SelectType< IsExpression< VT2 >::value, const VT2, const VT2 & >::Type RightOperand
Composite type of the right-hand side dense vector expression.
Definition: SVecDVecSubExpr.h:133
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2370
RightOperand rhs_
Right-hand side dense vector of the subtraction expression.
Definition: SVecDVecSubExpr.h:227
Header file for basic type definitions.
Header file for the SubvectorExprTrait class template.
Base template for the SubTrait class.
Definition: SubTrait.h:141
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.