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 
58 #include <blaze/util/Assert.h>
60 #include <blaze/util/Exception.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  //**At function*********************************************************************************
188  inline ReturnType at( size_t index ) const {
189  if( index >= 3UL ) {
190  BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
191  }
192  return (*this)[index];
193  }
194  //**********************************************************************************************
195 
196  //**Size function*******************************************************************************
201  inline size_t size() const {
202  return 3UL;
203  }
204  //**********************************************************************************************
205 
206  //**Left operand access*************************************************************************
211  inline LeftOperand leftOperand() const {
212  return lhs_;
213  }
214  //**********************************************************************************************
215 
216  //**Right operand access************************************************************************
221  inline RightOperand rightOperand() const {
222  return rhs_;
223  }
224  //**********************************************************************************************
225 
226  //**********************************************************************************************
232  template< typename T >
233  inline bool canAlias( const T* alias ) const {
234  return ( lhs_.canAlias( alias ) || rhs_.canAlias( alias ) );
235  }
236  //**********************************************************************************************
237 
238  //**********************************************************************************************
244  template< typename T >
245  inline bool isAliased( const T* alias ) const {
246  return ( lhs_.isAliased( alias ) || rhs_.isAliased( alias ) );
247  }
248  //**********************************************************************************************
249 
250  private:
251  //**Member variables****************************************************************************
252  LeftOperand lhs_;
253  RightOperand rhs_;
254  //**********************************************************************************************
255 
256  //**Assignment to dense vectors*****************************************************************
268  template< typename VT > // Type of the target dense vector
269  friend inline void assign( DenseVector<VT,false>& lhs, const DVecDVecCrossExpr& rhs )
270  {
272 
273  BLAZE_INTERNAL_ASSERT( (~lhs).size() == 3UL, "Invalid vector size" );
274  BLAZE_INTERNAL_ASSERT( (~rhs).size() == 3UL, "Invalid vector size" );
275 
276  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
277  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense vector operand
278 
279  (~lhs)[0] = x[1UL]*y[2UL] - x[2UL]*y[1UL];
280  (~lhs)[1] = x[2UL]*y[0UL] - x[0UL]*y[2UL];
281  (~lhs)[2] = x[0UL]*y[1UL] - x[1UL]*y[0UL];
282  }
284  //**********************************************************************************************
285 
286  //**Assignment to sparse vectors****************************************************************
298  template< typename VT > // Type of the target sparse vector
299  friend inline void assign( SparseVector<VT,false>& lhs, const DVecDVecCrossExpr& rhs )
300  {
302 
306 
307  BLAZE_INTERNAL_ASSERT( (~lhs).size() == 3UL, "Invalid vector size" );
308  BLAZE_INTERNAL_ASSERT( (~rhs).size() == 3UL, "Invalid vector size" );
309 
310  const ResultType tmp( serial( rhs ) );
311  assign( ~lhs, tmp );
312  }
314  //**********************************************************************************************
315 
316  //**Addition assignment to dense vectors********************************************************
328  template< typename VT > // Type of the target dense vector
329  friend inline void addAssign( DenseVector<VT,false>& lhs, const DVecDVecCrossExpr& rhs )
330  {
332 
333  BLAZE_INTERNAL_ASSERT( (~lhs).size() == 3UL, "Invalid vector size" );
334  BLAZE_INTERNAL_ASSERT( (~rhs).size() == 3UL, "Invalid vector size" );
335 
336  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
337  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense vector operand
338 
339  (~lhs)[0] += x[1UL]*y[2UL] - x[2UL]*y[1UL];
340  (~lhs)[1] += x[2UL]*y[0UL] - x[0UL]*y[2UL];
341  (~lhs)[2] += x[0UL]*y[1UL] - x[1UL]*y[0UL];
342  }
344  //**********************************************************************************************
345 
346  //**Addition assignment to sparse vectors*******************************************************
347  // No special implementation for the addition assignment to sparse vectors.
348  //**********************************************************************************************
349 
350  //**Subtraction assignment to dense vectors*****************************************************
362  template< typename VT > // Type of the target dense vector
363  friend inline void subAssign( DenseVector<VT,false>& lhs, const DVecDVecCrossExpr& rhs )
364  {
366 
367  BLAZE_INTERNAL_ASSERT( (~lhs).size() == 3UL, "Invalid vector size" );
368  BLAZE_INTERNAL_ASSERT( (~rhs).size() == 3UL, "Invalid vector size" );
369 
370  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
371  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense vector operand
372 
373  (~lhs)[0] -= x[1UL]*y[2UL] - x[2UL]*y[1UL];
374  (~lhs)[1] -= x[2UL]*y[0UL] - x[0UL]*y[2UL];
375  (~lhs)[2] -= x[0UL]*y[1UL] - x[1UL]*y[0UL];
376  }
378  //**********************************************************************************************
379 
380  //**Subtraction assignment to sparse vectors****************************************************
381  // No special implementation for the subtraction assignment to sparse vectors.
382  //**********************************************************************************************
383 
384  //**Multiplication assignment to dense vectors**************************************************
396  template< typename VT > // Type of the target dense vector
397  friend inline void multAssign( DenseVector<VT,false>& lhs, const DVecDVecCrossExpr& rhs )
398  {
400 
401  BLAZE_INTERNAL_ASSERT( (~lhs).size() == 3UL, "Invalid vector size" );
402  BLAZE_INTERNAL_ASSERT( (~rhs).size() == 3UL, "Invalid vector size" );
403 
404  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
405  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense vector operand
406 
407  (~lhs)[0] *= x[1UL]*y[2UL] - x[2UL]*y[1UL];
408  (~lhs)[1] *= x[2UL]*y[0UL] - x[0UL]*y[2UL];
409  (~lhs)[2] *= x[0UL]*y[1UL] - x[1UL]*y[0UL];
410  }
412  //**********************************************************************************************
413 
414  //**Multiplication assignment to sparse vectors*************************************************
415  // No special implementation for the multiplication assignment to sparse vectors.
416  //**********************************************************************************************
417 
418  //**Compile time checks*************************************************************************
425  //**********************************************************************************************
426 };
427 //*************************************************************************************************
428 
429 
430 
431 
432 //=================================================================================================
433 //
434 // GLOBAL BINARY ARITHMETIC OPERATORS
435 //
436 //=================================================================================================
437 
438 //*************************************************************************************************
463 template< typename T1 // Type of the left-hand side dense vector
464  , typename T2 > // Type of the right-hand side dense vector
465 inline const DVecDVecCrossExpr<T1,T2>
467 {
469 
470  if( (~lhs).size() != 3UL || (~rhs).size() != 3UL ) {
471  BLAZE_THROW_INVALID_ARGUMENT( "Invalid vector size for cross product" );
472  }
473 
474  return DVecDVecCrossExpr<T1,T2>( ~lhs, ~rhs );
475 }
476 //*************************************************************************************************
477 
478 
479 
480 
481 //=================================================================================================
482 //
483 // SIZE SPECIALIZATIONS
484 //
485 //=================================================================================================
486 
487 //*************************************************************************************************
489 template< typename VT1, typename VT2 >
490 struct Size< DVecDVecCrossExpr<VT1,VT2> > : public SizeT<3UL>
491 {};
493 //*************************************************************************************************
494 
495 } // namespace blaze
496 
497 #endif
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exceptionThis macro encapsulates the default way of...
Definition: Exception.h:187
RightOperand rightOperand() const
Returns the right-hand side dense vector operand.
Definition: DVecDVecCrossExpr.h:221
RightOperand rhs_
Right-hand side dense vector of the cross product expression.
Definition: DVecDVecCrossExpr.h:253
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:245
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
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: DVecDVecCrossExpr.h:188
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector)
Returns the current size/dimension of the vector.
Definition: Vector.h:252
#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: ColumnVector.h:79
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:207
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:2588
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:259
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:721
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:252
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: DVecDVecCrossExpr.h:233
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:61
size_t size() const
Returns the current size/dimension of the vector.
Definition: DVecDVecCrossExpr.h:201
Constraint on the transpose flag of vector types.
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
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exceptionThis macro encapsulates the default way of Bla...
Definition: Exception.h:331
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:466
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
#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:2586
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:2587
Header file for run time assertion macros.
Header file for the cross product trait.
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:118
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:157
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2583
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: DVecDVecCrossExpr.h:169
LeftOperand leftOperand() const
Returns the left-hand side dense vector operand.
Definition: DVecDVecCrossExpr.h:211
Header file for exception macros.
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.