DVecDVecCrossExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_DVECDVECCROSSEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_DVECDVECCROSSEXPR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <stdexcept>
59 #include <blaze/util/Assert.h>
62 #include <blaze/util/mpl/SizeT.h>
63 #include <blaze/util/SelectType.h>
64 #include <blaze/util/Types.h>
65 
66 
67 namespace blaze {
68 
69 //=================================================================================================
70 //
71 // CLASS DVECDVECCROSSEXPR
72 //
73 //=================================================================================================
74 
75 //*************************************************************************************************
82 template< typename VT1 // Type of the left-hand side dense vector
83  , typename VT2 > // Type of the right-hand side dense vector
84 class DVecDVecCrossExpr : public DenseVector< DVecDVecCrossExpr<VT1,VT2>, false >
85  , private CrossExpr
86  , private Computation
87 {
88  private:
89  //**Type definitions****************************************************************************
90  typedef typename VT1::ResultType RT1;
91  typedef typename VT2::ResultType RT2;
92  typedef typename VT1::ReturnType RN1;
93  typedef typename VT2::ReturnType RN2;
94  typedef typename VT1::CompositeType CT1;
95  typedef typename VT2::CompositeType CT2;
96  typedef typename VT1::ElementType ET1;
97  typedef typename VT2::ElementType ET2;
98  //**********************************************************************************************
99 
100  //**Return type evaluation**********************************************************************
102 
107  enum { returnExpr = !IsTemporary<RN1>::value && !IsTemporary<RN2>::value };
108 
112  //**********************************************************************************************
113 
114  public:
115  //**Type definitions****************************************************************************
120 
123 
125  typedef const ResultType CompositeType;
126 
128  typedef typename SelectType< IsExpression<VT1>::value, const VT1, const VT1& >::Type LeftOperand;
129 
131  typedef typename SelectType< IsExpression<VT2>::value, const VT2, const VT2& >::Type RightOperand;
132 
135 
138  //**********************************************************************************************
139 
140  //**Compilation flags***************************************************************************
142  enum { vectorizable = 0 };
143 
145  enum { smpAssignable = 0 };
146  //**********************************************************************************************
147 
148  //**Constructor*********************************************************************************
154  explicit inline DVecDVecCrossExpr( const VT1& lhs, const VT2& rhs )
155  : lhs_( lhs ) // Left-hand side dense vector of the cross product expression
156  , rhs_( rhs ) // Right-hand side dense vector of the cross product expression
157  {
158  BLAZE_INTERNAL_ASSERT( lhs.size() == 3UL, "Invalid vector size" );
159  BLAZE_INTERNAL_ASSERT( rhs.size() == 3UL, "Invalid vector size" );
160  }
161  //**********************************************************************************************
162 
163  //**Subscript operator**************************************************************************
169  inline ReturnType operator[]( size_t index ) const {
170  BLAZE_INTERNAL_ASSERT( index < 3UL, "Invalid vector access index" );
171 
172  if( index == 0UL )
173  return lhs_[1UL] * rhs_[2UL] - lhs_[2UL] * rhs_[1UL];
174  else if( index == 1UL )
175  return lhs_[2UL] * rhs_[0UL] - lhs_[0UL] * rhs_[2UL];
176  else
177  return lhs_[0UL] * rhs_[1UL] - lhs_[1UL] * rhs_[0UL];
178  }
179  //**********************************************************************************************
180 
181  //**Size function*******************************************************************************
186  inline size_t size() const {
187  return 3UL;
188  }
189  //**********************************************************************************************
190 
191  //**Left operand access*************************************************************************
196  inline LeftOperand leftOperand() const {
197  return lhs_;
198  }
199  //**********************************************************************************************
200 
201  //**Right operand access************************************************************************
206  inline RightOperand rightOperand() const {
207  return rhs_;
208  }
209  //**********************************************************************************************
210 
211  //**********************************************************************************************
217  template< typename T >
218  inline bool canAlias( const T* alias ) const {
219  return ( lhs_.canAlias( alias ) || rhs_.canAlias( alias ) );
220  }
221  //**********************************************************************************************
222 
223  //**********************************************************************************************
229  template< typename T >
230  inline bool isAliased( const T* alias ) const {
231  return ( lhs_.isAliased( alias ) || rhs_.isAliased( alias ) );
232  }
233  //**********************************************************************************************
234 
235  private:
236  //**Member variables****************************************************************************
237  LeftOperand lhs_;
238  RightOperand rhs_;
239  //**********************************************************************************************
240 
241  //**Assignment to dense vectors*****************************************************************
253  template< typename VT > // Type of the target dense vector
254  friend inline void assign( DenseVector<VT,false>& lhs, const DVecDVecCrossExpr& rhs )
255  {
257 
258  BLAZE_INTERNAL_ASSERT( (~lhs).size() == 3UL, "Invalid vector size" );
259  BLAZE_INTERNAL_ASSERT( (~rhs).size() == 3UL, "Invalid vector size" );
260 
261  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
262  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense vector operand
263 
264  (~lhs)[0] = x[1UL]*y[2UL] - x[2UL]*y[1UL];
265  (~lhs)[1] = x[2UL]*y[0UL] - x[0UL]*y[2UL];
266  (~lhs)[2] = x[0UL]*y[1UL] - x[1UL]*y[0UL];
267  }
269  //**********************************************************************************************
270 
271  //**Assignment to sparse vectors****************************************************************
283  template< typename VT > // Type of the target sparse vector
284  friend inline void assign( SparseVector<VT,false>& lhs, const DVecDVecCrossExpr& rhs )
285  {
287 
291 
292  BLAZE_INTERNAL_ASSERT( (~lhs).size() == 3UL, "Invalid vector size" );
293  BLAZE_INTERNAL_ASSERT( (~rhs).size() == 3UL, "Invalid vector size" );
294 
295  const ResultType tmp( serial( rhs ) );
296  assign( ~lhs, tmp );
297  }
299  //**********************************************************************************************
300 
301  //**Addition assignment to dense vectors********************************************************
313  template< typename VT > // Type of the target dense vector
314  friend inline void addAssign( DenseVector<VT,false>& lhs, const DVecDVecCrossExpr& rhs )
315  {
317 
318  BLAZE_INTERNAL_ASSERT( (~lhs).size() == 3UL, "Invalid vector size" );
319  BLAZE_INTERNAL_ASSERT( (~rhs).size() == 3UL, "Invalid vector size" );
320 
321  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
322  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense vector operand
323 
324  (~lhs)[0] += x[1UL]*y[2UL] - x[2UL]*y[1UL];
325  (~lhs)[1] += x[2UL]*y[0UL] - x[0UL]*y[2UL];
326  (~lhs)[2] += x[0UL]*y[1UL] - x[1UL]*y[0UL];
327  }
329  //**********************************************************************************************
330 
331  //**Addition assignment to sparse vectors*******************************************************
332  // No special implementation for the addition assignment to sparse vectors.
333  //**********************************************************************************************
334 
335  //**Subtraction assignment to dense vectors*****************************************************
347  template< typename VT > // Type of the target dense vector
348  friend inline void subAssign( DenseVector<VT,false>& lhs, const DVecDVecCrossExpr& rhs )
349  {
351 
352  BLAZE_INTERNAL_ASSERT( (~lhs).size() == 3UL, "Invalid vector size" );
353  BLAZE_INTERNAL_ASSERT( (~rhs).size() == 3UL, "Invalid vector size" );
354 
355  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
356  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense vector operand
357 
358  (~lhs)[0] -= x[1UL]*y[2UL] - x[2UL]*y[1UL];
359  (~lhs)[1] -= x[2UL]*y[0UL] - x[0UL]*y[2UL];
360  (~lhs)[2] -= x[0UL]*y[1UL] - x[1UL]*y[0UL];
361  }
363  //**********************************************************************************************
364 
365  //**Subtraction assignment to sparse vectors****************************************************
366  // No special implementation for the subtraction assignment to sparse vectors.
367  //**********************************************************************************************
368 
369  //**Multiplication assignment to dense vectors**************************************************
381  template< typename VT > // Type of the target dense vector
382  friend inline void multAssign( DenseVector<VT,false>& lhs, const DVecDVecCrossExpr& rhs )
383  {
385 
386  BLAZE_INTERNAL_ASSERT( (~lhs).size() == 3UL, "Invalid vector size" );
387  BLAZE_INTERNAL_ASSERT( (~rhs).size() == 3UL, "Invalid vector size" );
388 
389  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
390  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense vector operand
391 
392  (~lhs)[0] *= x[1UL]*y[2UL] - x[2UL]*y[1UL];
393  (~lhs)[1] *= x[2UL]*y[0UL] - x[0UL]*y[2UL];
394  (~lhs)[2] *= x[0UL]*y[1UL] - x[1UL]*y[0UL];
395  }
397  //**********************************************************************************************
398 
399  //**Multiplication assignment to sparse vectors*************************************************
400  // No special implementation for the multiplication assignment to sparse vectors.
401  //**********************************************************************************************
402 
403  //**Compile time checks*************************************************************************
410  //**********************************************************************************************
411 };
412 //*************************************************************************************************
413 
414 
415 
416 
417 //=================================================================================================
418 //
419 // GLOBAL BINARY ARITHMETIC OPERATORS
420 //
421 //=================================================================================================
422 
423 //*************************************************************************************************
448 template< typename T1 // Type of the left-hand side dense vector
449  , typename T2 > // Type of the right-hand side dense vector
450 inline const DVecDVecCrossExpr<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 DVecDVecCrossExpr<T1,T2>( ~lhs, ~rhs );
459 }
460 //*************************************************************************************************
461 
462 
463 
464 
465 //=================================================================================================
466 //
467 // SIZE SPECIALIZATIONS
468 //
469 //=================================================================================================
470 
471 //*************************************************************************************************
473 template< typename VT1, typename VT2 >
474 struct Size< DVecDVecCrossExpr<VT1,VT2> >
475  : public SizeT<3UL>
476 {};
478 //*************************************************************************************************
479 
480 } // namespace blaze
481 
482 #endif
RightOperand rightOperand() const
Returns the right-hand side dense vector operand.
Definition: DVecDVecCrossExpr.h:206
RightOperand rhs_
Right-hand side dense vector of the cross product expression.
Definition: DVecDVecCrossExpr.h:238
BLAZE_ALWAYS_INLINE void multAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the multiplication assignment of a matrix to a matrix.
Definition: Matrix.h:879
Compile time check whether the given type is a temporary vector or matrix type.This type trait class ...
Definition: IsTemporary.h:87
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: DVecDVecCrossExpr.h:230
SelectType< IsComputation< VT2 >::value, const StaticVector< ET2, 3UL, false >, CT2 >::Type RT
Composite type of the right-hand side dense vector expression.
Definition: DVecDVecCrossExpr.h:137
Header file for basic type definitions.
CrossTrait< RT1, RT2 >::Type ResultType
Result type for expression template evaluations.
Definition: DVecDVecCrossExpr.h:117
VT1::ElementType ET1
Element type of the left-hand side dense vector expression.
Definition: DVecDVecCrossExpr.h:96
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector)
Returns the current size/dimension of the vector.
Definition: Vector.h:264
#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:209
Base class for all cross product expression templates.The CrossExpr class serves as a tag for all exp...
Definition: CrossExpr.h:65
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2507
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:261
Header file for the DenseVector base class.
Expression object for dense vector-dense vector cross products.The DVecDVecCrossExpr class represents...
Definition: DVecDVecCrossExpr.h:84
const SelectType< returnExpr, ExprReturnType, ElementType >::Type ReturnType
Return type for expression template evaluations.
Definition: DVecDVecCrossExpr.h:122
const DMatSerialExpr< MT, SO > serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:699
Header file for the Computation base class.
Header file for the SizeT class template.
VT2::CompositeType CT2
Composite type of the right-hand side dense vector expression.
Definition: DVecDVecCrossExpr.h:95
SubExprTrait< typename MultExprTrait< RN1, RN2 >::Type, typename MultExprTrait< RN1, RN2 >::Type >::Type ExprReturnType
Expression return type for the subscript operator.
Definition: DVecDVecCrossExpr.h:111
LeftOperand lhs_
Left-hand side dense vector of the cross product expression.
Definition: DVecDVecCrossExpr.h:237
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: DVecDVecCrossExpr.h:218
VT1::CompositeType CT1
Composite type of the left-hand side dense vector expression.
Definition: DVecDVecCrossExpr.h:94
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:59
size_t size() const
Returns the current size/dimension of the vector.
Definition: DVecDVecCrossExpr.h:186
VT2::ElementType ET2
Element type of the right-hand side dense vector expression.
Definition: DVecDVecCrossExpr.h:97
DVecDVecCrossExpr< VT1, VT2 > This
Type of this DVecDVecCrossExpr instance.
Definition: DVecDVecCrossExpr.h:116
Header file for the MultExprTrait class template.
SelectType< IsComputation< VT1 >::value, const StaticVector< ET1, 3UL, false >, CT1 >::Type LT
Composite type of the left-hand side dense vector expression.
Definition: DVecDVecCrossExpr.h:134
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.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
BLAZE_ALWAYS_INLINE void assign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the assignment of a matrix to a matrix.
Definition: Matrix.h:635
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:451
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
VT2::ResultType RT2
Result type of the right-hand side dense vector expression.
Definition: DVecDVecCrossExpr.h:91
ResultType::ElementType ElementType
Resulting element type.
Definition: DVecDVecCrossExpr.h:119
Constraint on the data type.
#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
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:104
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2505
Header file for the SelectType class template.
Header file for all forward declarations for expression class templates.
VT2::ReturnType RN2
Return type of the right-hand side dense vector expression.
Definition: DVecDVecCrossExpr.h:93
Header file for the serial shim.
Header file for the CrossExpr base class.
DVecDVecCrossExpr(const VT1 &lhs, const VT2 &rhs)
Constructor for the DVecDVecCrossExpr class.
Definition: DVecDVecCrossExpr.h:154
Header file for all forward declarations for dense vectors and matrices.
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2506
Header file for run time assertion macros.
Header file for the cross product trait.
BLAZE_ALWAYS_INLINE void addAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the addition assignment of a matrix to a matrix.
Definition: Matrix.h:742
VT1::ResultType RT1
Result type of the left-hand side dense vector expression.
Definition: DVecDVecCrossExpr.h:90
SelectType< IsExpression< VT1 >::value, const VT1, const VT1 & >::Type LeftOperand
Composite type of the left-hand side dense vector expression.
Definition: DVecDVecCrossExpr.h:128
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: DVecDVecCrossExpr.h:118
#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< VT2 >::value, const VT2, const VT2 & >::Type RightOperand
Composite type of the right-hand side dense vector expression.
Definition: DVecDVecCrossExpr.h:131
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:108
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:157
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2502
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: DVecDVecCrossExpr.h:169
LeftOperand leftOperand() const
Returns the left-hand side dense vector operand.
Definition: DVecDVecCrossExpr.h:196
Header file for the SubExprTrait class template.
Header file for the Size type trait.
Evaluation of the resulting expression type of a multiplication.Via this type trait it is possible to...
Definition: MultExprTrait.h:137
const ResultType CompositeType
Data type for composite expression templates.
Definition: DVecDVecCrossExpr.h:125
#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
VT1::ReturnType RN1
Return type of the left-hand side dense vector expression.
Definition: DVecDVecCrossExpr.h:92
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.
BLAZE_ALWAYS_INLINE void subAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the subtraction assignment of a matrix to matrix.
Definition: Matrix.h:849