All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DVecSVecCrossExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_DVECSVECCROSSEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_DVECSVECCROSSEXPR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <stdexcept>
58 #include <blaze/util/Assert.h>
61 #include <blaze/util/SelectType.h>
62 #include <blaze/util/Types.h>
63 
64 
65 namespace blaze {
66 
67 //=================================================================================================
68 //
69 // CLASS DVECSVECCROSSEXPR
70 //
71 //=================================================================================================
72 
73 //*************************************************************************************************
80 template< typename VT1 // Type of the left-hand side dense vector
81  , typename VT2 > // Type of the right-hand side sparse vector
82 class DVecSVecCrossExpr : public DenseVector< DVecSVecCrossExpr<VT1,VT2>, false >
83  , private CrossExpr
84  , private Computation
85 {
86  private:
87  //**Type definitions****************************************************************************
88  typedef typename VT1::ResultType RT1;
89  typedef typename VT2::ResultType RT2;
90  typedef typename VT1::ReturnType RN1;
91  typedef typename VT2::ReturnType RN2;
92  typedef typename VT1::CompositeType CT1;
93  typedef typename VT2::CompositeType CT2;
94  typedef typename VT1::ElementType ET1;
95  typedef typename VT2::ElementType ET2;
96  //**********************************************************************************************
97 
98  //**Return type evaluation**********************************************************************
100 
105  enum { returnExpr = !IsTemporary<RN1>::value && !IsTemporary<RN2>::value };
106 
110  //**********************************************************************************************
111 
112  public:
113  //**Type definitions****************************************************************************
118 
121 
123  typedef const ResultType CompositeType;
124 
126  typedef typename SelectType< IsExpression<VT1>::value, const VT1, const VT1& >::Type LeftOperand;
127 
129  typedef typename SelectType< IsExpression<VT2>::value, const VT2, const VT2& >::Type RightOperand;
130 
133 
136  //**********************************************************************************************
137 
138  //**Compilation flags***************************************************************************
140  enum { vectorizable = 0 };
141 
143  enum { smpAssignable = 0 };
144  //**********************************************************************************************
145 
146  //**Constructor*********************************************************************************
152  explicit inline DVecSVecCrossExpr( const VT1& lhs, const VT2& rhs )
153  : lhs_( lhs ) // Left-hand side dense vector of the cross product expression
154  , rhs_( rhs ) // Right-hand side sparse vector of the cross product expression
155  {
156  BLAZE_INTERNAL_ASSERT( lhs.size() == 3UL, "Invalid vector size" );
157  BLAZE_INTERNAL_ASSERT( rhs.size() == 3UL, "Invalid vector size" );
158  }
159  //**********************************************************************************************
160 
161  //**Subscript operator**************************************************************************
167  inline ReturnType operator[]( size_t index ) const {
168  BLAZE_INTERNAL_ASSERT( index < 3UL, "Invalid vector access index" );
169 
170  if( index == 0UL )
171  return lhs_[1UL] * rhs_[2UL] - lhs_[2UL] * rhs_[1UL];
172  else if( index == 1UL )
173  return lhs_[2UL] * rhs_[0UL] - lhs_[0UL] * rhs_[2UL];
174  else
175  return lhs_[0UL] * rhs_[1UL] - lhs_[1UL] * rhs_[0UL];
176  }
177  //**********************************************************************************************
178 
179  //**Size function*******************************************************************************
184  inline size_t size() const {
185  return 3UL;
186  }
187  //**********************************************************************************************
188 
189  //**Left operand access*************************************************************************
194  inline LeftOperand leftOperand() const {
195  return lhs_;
196  }
197  //**********************************************************************************************
198 
199  //**Right operand access************************************************************************
204  inline RightOperand rightOperand() const {
205  return rhs_;
206  }
207  //**********************************************************************************************
208 
209  //**********************************************************************************************
215  template< typename T >
216  inline bool canAlias( const T* alias ) const {
217  return ( lhs_.canAlias( alias ) || rhs_.canAlias( alias ) );
218  }
219  //**********************************************************************************************
220 
221  //**********************************************************************************************
227  template< typename T >
228  inline bool isAliased( const T* alias ) const {
229  return ( lhs_.isAliased( alias ) || rhs_.isAliased( alias ) );
230  }
231  //**********************************************************************************************
232 
233  private:
234  //**Member variables****************************************************************************
237  //**********************************************************************************************
238 
239  //**Assignment to dense vectors*****************************************************************
251  template< typename VT > // Type of the target dense vector
252  friend inline void assign( DenseVector<VT,false>& lhs, const DVecSVecCrossExpr& rhs )
253  {
255 
256  BLAZE_INTERNAL_ASSERT( (~lhs).size() == 3UL, "Invalid vector size" );
257  BLAZE_INTERNAL_ASSERT( (~rhs).size() == 3UL, "Invalid vector size" );
258 
259  LT x( rhs.lhs_ ); // Evaluation of the left-hand side dense vector operand
260  RT y( rhs.rhs_ ); // Evaluation of the right-hand side sparse vector operand
261 
262  (~lhs)[0] = x[1UL]*y[2UL] - x[2UL]*y[1UL];
263  (~lhs)[1] = x[2UL]*y[0UL] - x[0UL]*y[2UL];
264  (~lhs)[2] = x[0UL]*y[1UL] - x[1UL]*y[0UL];
265  }
267  //**********************************************************************************************
268 
269  //**Assignment to sparse vectors****************************************************************
281  template< typename VT > // Type of the target sparse vector
282  friend inline void assign( SparseVector<VT,false>& lhs, const DVecSVecCrossExpr& rhs )
283  {
285 
289 
290  BLAZE_INTERNAL_ASSERT( (~lhs).size() == 3UL, "Invalid vector size" );
291  BLAZE_INTERNAL_ASSERT( (~rhs).size() == 3UL, "Invalid vector size" );
292 
293  const ResultType tmp( rhs );
294  assign( ~lhs, tmp );
295  }
297  //**********************************************************************************************
298 
299  //**Addition assignment to dense vectors********************************************************
311  template< typename VT > // Type of the target dense vector
312  friend inline void addAssign( DenseVector<VT,false>& lhs, const DVecSVecCrossExpr& rhs )
313  {
315 
316  BLAZE_INTERNAL_ASSERT( (~lhs).size() == 3UL, "Invalid vector size" );
317  BLAZE_INTERNAL_ASSERT( (~rhs).size() == 3UL, "Invalid vector size" );
318 
319  LT x( rhs.lhs_ ); // Evaluation of the left-hand side dense vector operand
320  RT y( rhs.rhs_ ); // Evaluation of the right-hand side sparse vector operand
321 
322  (~lhs)[0] += x[1UL]*y[2UL] - x[2UL]*y[1UL];
323  (~lhs)[1] += x[2UL]*y[0UL] - x[0UL]*y[2UL];
324  (~lhs)[2] += x[0UL]*y[1UL] - x[1UL]*y[0UL];
325  }
327  //**********************************************************************************************
328 
329  //**Addition assignment to sparse vectors*******************************************************
330  // No special implementation for the addition assignment to sparse vectors.
331  //**********************************************************************************************
332 
333  //**Subtraction assignment to dense vectors*****************************************************
345  template< typename VT > // Type of the target dense vector
346  friend inline void subAssign( DenseVector<VT,false>& lhs, const DVecSVecCrossExpr& rhs )
347  {
349 
350  BLAZE_INTERNAL_ASSERT( (~lhs).size() == 3UL, "Invalid vector size" );
351  BLAZE_INTERNAL_ASSERT( (~rhs).size() == 3UL, "Invalid vector size" );
352 
353  LT x( rhs.lhs_ ); // Evaluation of the left-hand side dense vector operand
354  RT y( rhs.rhs_ ); // Evaluation of the right-hand side sparse vector operand
355 
356  (~lhs)[0] -= x[1UL]*y[2UL] - x[2UL]*y[1UL];
357  (~lhs)[1] -= x[2UL]*y[0UL] - x[0UL]*y[2UL];
358  (~lhs)[2] -= x[0UL]*y[1UL] - x[1UL]*y[0UL];
359  }
361  //**********************************************************************************************
362 
363  //**Subtraction assignment to sparse vectors****************************************************
364  // No special implementation for the subtraction assignment to sparse vectors.
365  //**********************************************************************************************
366 
367  //**Multiplication assignment to dense vectors**************************************************
379  template< typename VT > // Type of the target dense vector
380  friend inline void multAssign( DenseVector<VT,false>& lhs, const DVecSVecCrossExpr& rhs )
381  {
383 
384  BLAZE_INTERNAL_ASSERT( (~lhs).size() == 3UL, "Invalid vector size" );
385  BLAZE_INTERNAL_ASSERT( (~rhs).size() == 3UL, "Invalid vector size" );
386 
387  LT x( rhs.lhs_ ); // Evaluation of the left-hand side dense vector operand
388  RT y( rhs.rhs_ ); // Evaluation of the right-hand side sparse vector operand
389 
390  (~lhs)[0] *= x[1UL]*y[2UL] - x[2UL]*y[1UL];
391  (~lhs)[1] *= x[2UL]*y[0UL] - x[0UL]*y[2UL];
392  (~lhs)[2] *= x[0UL]*y[1UL] - x[1UL]*y[0UL];
393  }
395  //**********************************************************************************************
396 
397  //**Multiplication assignment to sparse vectors*************************************************
398  // No special implementation for the multiplication assignment to sparse vectors.
399  //**********************************************************************************************
400 
401  //**Compile time checks*************************************************************************
408  //**********************************************************************************************
409 };
410 //*************************************************************************************************
411 
412 
413 
414 
415 //=================================================================================================
416 //
417 // GLOBAL BINARY ARITHMETIC OPERATORS
418 //
419 //=================================================================================================
420 
421 //*************************************************************************************************
448 template< typename T1 // Type of the left-hand side dense vector
449  , typename T2 > // Type of the right-hand side sparse vector
450 inline const DVecSVecCrossExpr<T1,T2>
452 {
454 
455  if( (~lhs).size() != 3UL || (~rhs).size() != 3UL )
456  throw std::invalid_argument( "Invalid vector size for cross product" );
457 
458  return DVecSVecCrossExpr<T1,T2>( ~lhs, ~rhs );
459 }
460 //*************************************************************************************************
461 
462 } // namespace blaze
463 
464 #endif
Expression object for dense vector-sparse vector cross products.The DVecSVecCrossExpr class represent...
Definition: DVecSVecCrossExpr.h:82
Compile time check whether the given type is a temporary vector or matrix type.This type trait class ...
Definition: IsTemporary.h:87
const StaticVector< ET2, 3UL, false > RT
Composite type of the right-hand side sparse vector expression.
Definition: DVecSVecCrossExpr.h:135
const SelectType< returnExpr, ExprReturnType, ElementType >::Type ReturnType
Return type for expression template evaluations.
Definition: DVecSVecCrossExpr.h:120
#define BLAZE_CONSTRAINT_MUST_BE_COLUMN_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a column dense or sparse vector type...
Definition: TransposeFlag.h:159
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:196
Base class for all cross product expression templates.The CrossExpr class serves as a tag for all exp...
Definition: CrossExpr.h:65
DVecSVecCrossExpr(const VT1 &lhs, const VT2 &rhs)
Constructor for the DVecSVecCrossExpr class.
Definition: DVecSVecCrossExpr.h:152
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2375
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:248
Header file for the DenseVector base class.
VT2::ReturnType RN2
Return type of the right-hand side sparse vector expression.
Definition: DVecSVecCrossExpr.h:91
SelectType< IsComputation< VT1 >::value, const StaticVector< ET1, 3UL, false >, CT1 >::Type LT
Composite type of the left-hand side dense vector expression.
Definition: DVecSVecCrossExpr.h:132
Header file for the Computation base class.
CrossTrait< RT1, RT2 >::Type ResultType
Result type for expression template evaluations.
Definition: DVecSVecCrossExpr.h:115
VT2::CompositeType CT2
Composite type of the right-hand side sparse vector expression.
Definition: DVecSVecCrossExpr.h:93
RightOperand rightOperand() const
Returns the right-hand side sparse vector operand.
Definition: DVecSVecCrossExpr.h:204
Constraint on the data type.
Base template for the CrossTrait class.
Definition: CrossTrait.h:110
Efficient implementation of a fixed-sized vector.The StaticVector class template is the representatio...
Definition: Forward.h:51
Header file for the MultExprTrait class template.
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: DVecSVecCrossExpr.h:116
ResultType::ElementType ElementType
Resulting element type.
Definition: DVecSVecCrossExpr.h:117
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.
SubExprTrait< typename MultExprTrait< RN1, RN2 >::Type, typename MultExprTrait< RN1, RN2 >::Type >::Type ExprReturnType
Expression return type for the subscript operator.
Definition: DVecSVecCrossExpr.h:109
VT2::ElementType ET2
Element type of the right-hand side sparse vector expression.
Definition: DVecSVecCrossExpr.h:95
VT1::ResultType RT1
Result type of the left-hand side dense vector expression.
Definition: DVecSVecCrossExpr.h:88
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 DVecDVecCrossExpr< T1, T2 > operator%(const DenseVector< T1, false > &lhs, const DenseVector< T2, false > &rhs)
Operator for the cross product of two dense vectors ( ).
Definition: DVecDVecCrossExpr.h:448
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.
VT2::ResultType RT2
Result type of the right-hand side sparse vector expression.
Definition: DVecSVecCrossExpr.h:89
#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
VT1::ReturnType RN1
Return type of the left-hand side dense vector expression.
Definition: DVecSVecCrossExpr.h:90
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
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2373
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.
Header file for the CrossExpr base class.
SelectType< IsExpression< VT2 >::value, const VT2, const VT2 & >::Type RightOperand
Composite type of the right-hand side sparse vector expression.
Definition: DVecSVecCrossExpr.h:129
LeftOperand leftOperand() const
Returns the left-hand side dense vector operand.
Definition: DVecSVecCrossExpr.h:194
Header file for all forward declarations for dense vectors and matrices.
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2374
RightOperand rhs_
Right-hand side sparse vector of the cross product expression.
Definition: DVecSVecCrossExpr.h:236
Header file for run time assertion macros.
Header file for the cross product 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
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: DVecSVecCrossExpr.h:228
const ResultType CompositeType
Data type for composite expression templates.
Definition: DVecSVecCrossExpr.h:123
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
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: DVecSVecCrossExpr.h:167
VT1::ElementType ET1
Element type of the left-hand side dense vector expression.
Definition: DVecSVecCrossExpr.h:94
VT1::CompositeType CT1
Composite type of the left-hand side dense vector expression.
Definition: DVecSVecCrossExpr.h:92
#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
SelectType< IsExpression< VT1 >::value, const VT1, const VT1 & >::Type LeftOperand
Composite type of the left-hand side dense vector expression.
Definition: DVecSVecCrossExpr.h:126
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: DVecSVecCrossExpr.h:216
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
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:2370
Header file for basic type definitions.
size_t size() const
Returns the current size/dimension of the vector.
Definition: DVecSVecCrossExpr.h:184
LeftOperand lhs_
Left-hand side dense vector of the cross product expression.
Definition: DVecSVecCrossExpr.h:235
Header file for the SubExprTrait class template.
Evaluation of the resulting expression type of a multiplication.Via this type trait it is possible to...
Definition: MultExprTrait.h:137
#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
DVecSVecCrossExpr< VT1, VT2 > This
Type of this DVecSVecCrossExpr instance.
Definition: DVecSVecCrossExpr.h:114
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.