All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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>
57 #include <blaze/util/Assert.h>
60 #include <blaze/util/SelectType.h>
61 #include <blaze/util/Types.h>
62 
63 
64 namespace blaze {
65 
66 //=================================================================================================
67 //
68 // CLASS DVECDVECCROSSEXPR
69 //
70 //=================================================================================================
71 
72 //*************************************************************************************************
79 template< typename VT1 // Type of the left-hand side dense vector
80  , typename VT2 > // Type of the right-hand side dense vector
81 class DVecDVecCrossExpr : public DenseVector< DVecDVecCrossExpr<VT1,VT2>, false >
82  , private CrossExpr
83  , private Computation
84 {
85  private:
86  //**Type definitions****************************************************************************
87  typedef typename VT1::ResultType RT1;
88  typedef typename VT2::ResultType RT2;
89  typedef typename VT1::ReturnType RN1;
90  typedef typename VT2::ReturnType RN2;
91  typedef typename VT1::CompositeType CT1;
92  typedef typename VT2::CompositeType CT2;
93  typedef typename VT1::ElementType ET1;
94  typedef typename VT2::ElementType ET2;
95  //**********************************************************************************************
96 
97  //**Return type evaluation**********************************************************************
99 
104  enum { returnExpr = !IsTemporary<RN1>::value && !IsTemporary<RN2>::value };
105 
109  //**********************************************************************************************
110 
111  public:
112  //**Type definitions****************************************************************************
117 
120 
122  typedef const ResultType CompositeType;
123 
125  typedef typename SelectType< IsExpression<VT1>::value, const VT1, const VT1& >::Type LeftOperand;
126 
128  typedef typename SelectType< IsExpression<VT2>::value, const VT2, const VT2& >::Type RightOperand;
129 
132 
135  //**********************************************************************************************
136 
137  //**Compilation flags***************************************************************************
139  enum { vectorizable = 0 };
140 
142  enum { smpAssignable = 0 };
143  //**********************************************************************************************
144 
145  //**Constructor*********************************************************************************
151  explicit inline DVecDVecCrossExpr( const VT1& lhs, const VT2& rhs )
152  : lhs_( lhs ) // Left-hand side dense vector of the cross product expression
153  , rhs_( rhs ) // Right-hand side dense vector of the cross product expression
154  {
155  BLAZE_INTERNAL_ASSERT( lhs.size() == 3UL, "Invalid vector size" );
156  BLAZE_INTERNAL_ASSERT( rhs.size() == 3UL, "Invalid vector size" );
157  }
158  //**********************************************************************************************
159 
160  //**Subscript operator**************************************************************************
166  inline ReturnType operator[]( size_t index ) const {
167  BLAZE_INTERNAL_ASSERT( index < 3UL, "Invalid vector access index" );
168 
169  if( index == 0UL )
170  return lhs_[1UL] * rhs_[2UL] - lhs_[2UL] * rhs_[1UL];
171  else if( index == 1UL )
172  return lhs_[2UL] * rhs_[0UL] - lhs_[0UL] * rhs_[2UL];
173  else
174  return lhs_[0UL] * rhs_[1UL] - lhs_[1UL] * rhs_[0UL];
175  }
176  //**********************************************************************************************
177 
178  //**Size function*******************************************************************************
183  inline size_t size() const {
184  return 3UL;
185  }
186  //**********************************************************************************************
187 
188  //**Left operand access*************************************************************************
193  inline LeftOperand leftOperand() const {
194  return lhs_;
195  }
196  //**********************************************************************************************
197 
198  //**Right operand access************************************************************************
203  inline RightOperand rightOperand() const {
204  return rhs_;
205  }
206  //**********************************************************************************************
207 
208  //**********************************************************************************************
214  template< typename T >
215  inline bool canAlias( const T* alias ) const {
216  return ( lhs_.canAlias( alias ) || rhs_.canAlias( alias ) );
217  }
218  //**********************************************************************************************
219 
220  //**********************************************************************************************
226  template< typename T >
227  inline bool isAliased( const T* alias ) const {
228  return ( lhs_.isAliased( alias ) || rhs_.isAliased( alias ) );
229  }
230  //**********************************************************************************************
231 
232  private:
233  //**Member variables****************************************************************************
236  //**********************************************************************************************
237 
238  //**Assignment to dense vectors*****************************************************************
250  template< typename VT > // Type of the target dense vector
251  friend inline void assign( DenseVector<VT,false>& lhs, const DVecDVecCrossExpr& rhs )
252  {
254 
255  BLAZE_INTERNAL_ASSERT( (~lhs).size() == 3UL, "Invalid vector size" );
256  BLAZE_INTERNAL_ASSERT( (~rhs).size() == 3UL, "Invalid vector size" );
257 
258  LT x( rhs.lhs_ ); // Evaluation of the left-hand side dense vector operand
259  RT y( rhs.rhs_ ); // Evaluation of the right-hand side dense vector operand
260 
261  (~lhs)[0] = x[1UL]*y[2UL] - x[2UL]*y[1UL];
262  (~lhs)[1] = x[2UL]*y[0UL] - x[0UL]*y[2UL];
263  (~lhs)[2] = x[0UL]*y[1UL] - x[1UL]*y[0UL];
264  }
266  //**********************************************************************************************
267 
268  //**Assignment to sparse vectors****************************************************************
280  template< typename VT > // Type of the target sparse vector
281  friend inline void assign( SparseVector<VT,false>& lhs, const DVecDVecCrossExpr& rhs )
282  {
284 
288 
289  BLAZE_INTERNAL_ASSERT( (~lhs).size() == 3UL, "Invalid vector size" );
290  BLAZE_INTERNAL_ASSERT( (~rhs).size() == 3UL, "Invalid vector size" );
291 
292  const ResultType tmp( rhs );
293  assign( ~lhs, tmp );
294  }
296  //**********************************************************************************************
297 
298  //**Addition assignment to dense vectors********************************************************
310  template< typename VT > // Type of the target dense vector
311  friend inline void addAssign( DenseVector<VT,false>& lhs, const DVecDVecCrossExpr& rhs )
312  {
314 
315  BLAZE_INTERNAL_ASSERT( (~lhs).size() == 3UL, "Invalid vector size" );
316  BLAZE_INTERNAL_ASSERT( (~rhs).size() == 3UL, "Invalid vector size" );
317 
318  LT x( rhs.lhs_ ); // Evaluation of the left-hand side dense vector operand
319  RT y( rhs.rhs_ ); // Evaluation of the right-hand side dense vector operand
320 
321  (~lhs)[0] += x[1UL]*y[2UL] - x[2UL]*y[1UL];
322  (~lhs)[1] += x[2UL]*y[0UL] - x[0UL]*y[2UL];
323  (~lhs)[2] += x[0UL]*y[1UL] - x[1UL]*y[0UL];
324  }
326  //**********************************************************************************************
327 
328  //**Addition assignment to sparse vectors*******************************************************
329  // No special implementation for the addition assignment to sparse vectors.
330  //**********************************************************************************************
331 
332  //**Subtraction assignment to dense vectors*****************************************************
344  template< typename VT > // Type of the target dense vector
345  friend inline void subAssign( DenseVector<VT,false>& lhs, const DVecDVecCrossExpr& rhs )
346  {
348 
349  BLAZE_INTERNAL_ASSERT( (~lhs).size() == 3UL, "Invalid vector size" );
350  BLAZE_INTERNAL_ASSERT( (~rhs).size() == 3UL, "Invalid vector size" );
351 
352  LT x( rhs.lhs_ ); // Evaluation of the left-hand side dense vector operand
353  RT y( rhs.rhs_ ); // Evaluation of the right-hand side dense vector operand
354 
355  (~lhs)[0] -= x[1UL]*y[2UL] - x[2UL]*y[1UL];
356  (~lhs)[1] -= x[2UL]*y[0UL] - x[0UL]*y[2UL];
357  (~lhs)[2] -= x[0UL]*y[1UL] - x[1UL]*y[0UL];
358  }
360  //**********************************************************************************************
361 
362  //**Subtraction assignment to sparse vectors****************************************************
363  // No special implementation for the subtraction assignment to sparse vectors.
364  //**********************************************************************************************
365 
366  //**Multiplication assignment to dense vectors**************************************************
378  template< typename VT > // Type of the target dense vector
379  friend inline void multAssign( DenseVector<VT,false>& lhs, const DVecDVecCrossExpr& rhs )
380  {
382 
383  BLAZE_INTERNAL_ASSERT( (~lhs).size() == 3UL, "Invalid vector size" );
384  BLAZE_INTERNAL_ASSERT( (~rhs).size() == 3UL, "Invalid vector size" );
385 
386  LT x( rhs.lhs_ ); // Evaluation of the left-hand side dense vector operand
387  RT y( rhs.rhs_ ); // Evaluation of the right-hand side dense vector operand
388 
389  (~lhs)[0] *= x[1UL]*y[2UL] - x[2UL]*y[1UL];
390  (~lhs)[1] *= x[2UL]*y[0UL] - x[0UL]*y[2UL];
391  (~lhs)[2] *= x[0UL]*y[1UL] - x[1UL]*y[0UL];
392  }
394  //**********************************************************************************************
395 
396  //**Multiplication assignment to sparse vectors*************************************************
397  // No special implementation for the multiplication assignment to sparse vectors.
398  //**********************************************************************************************
399 
400  //**Compile time checks*************************************************************************
407  //**********************************************************************************************
408 };
409 //*************************************************************************************************
410 
411 
412 
413 
414 //=================================================================================================
415 //
416 // GLOBAL BINARY ARITHMETIC OPERATORS
417 //
418 //=================================================================================================
419 
420 //*************************************************************************************************
445 template< typename T1 // Type of the left-hand side dense vector
446  , typename T2 > // Type of the right-hand side dense vector
447 inline const DVecDVecCrossExpr<T1,T2>
449 {
451 
452  if( (~lhs).size() != 3UL || (~rhs).size() != 3UL )
453  throw std::invalid_argument( "Invalid vector size for cross product" );
454 
455  return DVecDVecCrossExpr<T1,T2>( ~lhs, ~rhs );
456 }
457 //*************************************************************************************************
458 
459 } // namespace blaze
460 
461 #endif
RightOperand rightOperand() const
Returns the right-hand side dense vector operand.
Definition: DVecDVecCrossExpr.h:203
RightOperand rhs_
Right-hand side dense vector of the cross product expression.
Definition: DVecDVecCrossExpr.h:235
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:227
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:134
CrossTrait< RT1, RT2 >::Type ResultType
Result type for expression template evaluations.
Definition: DVecDVecCrossExpr.h:114
VT1::ElementType ET1
Element type of the left-hand side dense vector expression.
Definition: DVecDVecCrossExpr.h:93
#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:197
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:2384
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:249
Header file for the DenseVector base class.
Expression object for dense vector-dense vector cross products.The DVecDVecCrossExpr class represents...
Definition: DVecDVecCrossExpr.h:81
const SelectType< returnExpr, ExprReturnType, ElementType >::Type ReturnType
Return type for expression template evaluations.
Definition: DVecDVecCrossExpr.h:119
Header file for the Computation base class.
VT2::CompositeType CT2
Composite type of the right-hand side dense vector expression.
Definition: DVecDVecCrossExpr.h:92
SubExprTrait< typename MultExprTrait< RN1, RN2 >::Type, typename MultExprTrait< RN1, RN2 >::Type >::Type ExprReturnType
Expression return type for the subscript operator.
Definition: DVecDVecCrossExpr.h:108
LeftOperand lhs_
Left-hand side dense vector of the cross product expression.
Definition: DVecDVecCrossExpr.h:234
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: DVecDVecCrossExpr.h:215
VT1::CompositeType CT1
Composite type of the left-hand side dense vector expression.
Definition: DVecDVecCrossExpr.h:91
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
size_t size() const
Returns the current size/dimension of the vector.
Definition: DVecDVecCrossExpr.h:183
VT2::ElementType ET2
Element type of the right-hand side dense vector expression.
Definition: DVecDVecCrossExpr.h:94
DVecDVecCrossExpr< VT1, VT2 > This
Type of this DVecDVecCrossExpr instance.
Definition: DVecDVecCrossExpr.h:113
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:131
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
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
VT2::ResultType RT2
Result type of the right-hand side dense vector expression.
Definition: DVecDVecCrossExpr.h:88
ResultType::ElementType ElementType
Resulting element type.
Definition: DVecDVecCrossExpr.h:116
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:103
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2382
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.
VT2::ReturnType RN2
Return type of the right-hand side dense vector expression.
Definition: DVecDVecCrossExpr.h:90
Header file for the CrossExpr base class.
DVecDVecCrossExpr(const VT1 &lhs, const VT2 &rhs)
Constructor for the DVecDVecCrossExpr class.
Definition: DVecDVecCrossExpr.h:151
Header file for all forward declarations for dense vectors and matrices.
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2383
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
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
VT1::ResultType RT1
Result type of the left-hand side dense vector expression.
Definition: DVecDVecCrossExpr.h:87
SelectType< IsExpression< VT1 >::value, const VT1, const VT1 & >::Type LeftOperand
Composite type of the left-hand side dense vector expression.
Definition: DVecDVecCrossExpr.h:125
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: DVecDVecCrossExpr.h:115
#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:128
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:2379
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: DVecDVecCrossExpr.h:166
Header file for basic type definitions.
LeftOperand leftOperand() const
Returns the left-hand side dense vector operand.
Definition: DVecDVecCrossExpr.h:193
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
const ResultType CompositeType
Data type for composite expression templates.
Definition: DVecDVecCrossExpr.h:122
#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:89
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.