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 
59 #include <blaze/util/Assert.h>
61 #include <blaze/util/Exception.h>
63 #include <blaze/util/mpl/SizeT.h>
64 #include <blaze/util/SelectType.h>
65 #include <blaze/util/Types.h>
66 
67 
68 namespace blaze {
69 
70 //=================================================================================================
71 //
72 // CLASS DVECSVECCROSSEXPR
73 //
74 //=================================================================================================
75 
76 //*************************************************************************************************
83 template< typename VT1 // Type of the left-hand side dense vector
84  , typename VT2 > // Type of the right-hand side sparse vector
85 class DVecSVecCrossExpr : public DenseVector< DVecSVecCrossExpr<VT1,VT2>, false >
86  , private CrossExpr
87  , private Computation
88 {
89  private:
90  //**Type definitions****************************************************************************
91  typedef typename VT1::ResultType RT1;
92  typedef typename VT2::ResultType RT2;
93  typedef typename VT1::ReturnType RN1;
94  typedef typename VT2::ReturnType RN2;
95  typedef typename VT1::CompositeType CT1;
96  typedef typename VT2::CompositeType CT2;
97  typedef typename VT1::ElementType ET1;
98  typedef typename VT2::ElementType ET2;
99  //**********************************************************************************************
100 
101  //**Return type evaluation**********************************************************************
103 
108  enum { returnExpr = !IsTemporary<RN1>::value && !IsTemporary<RN2>::value };
109 
113  //**********************************************************************************************
114 
115  public:
116  //**Type definitions****************************************************************************
121 
124 
126  typedef const ResultType CompositeType;
127 
129  typedef typename SelectType< IsExpression<VT1>::value, const VT1, const VT1& >::Type LeftOperand;
130 
132  typedef typename SelectType< IsExpression<VT2>::value, const VT2, const VT2& >::Type RightOperand;
133 
136 
139  //**********************************************************************************************
140 
141  //**Compilation flags***************************************************************************
143  enum { vectorizable = 0 };
144 
146  enum { smpAssignable = 0 };
147  //**********************************************************************************************
148 
149  //**Constructor*********************************************************************************
155  explicit inline DVecSVecCrossExpr( const VT1& lhs, const VT2& rhs )
156  : lhs_( lhs ) // Left-hand side dense vector of the cross product expression
157  , rhs_( rhs ) // Right-hand side sparse vector of the cross product expression
158  {
159  BLAZE_INTERNAL_ASSERT( lhs.size() == 3UL, "Invalid vector size" );
160  BLAZE_INTERNAL_ASSERT( rhs.size() == 3UL, "Invalid vector size" );
161  }
162  //**********************************************************************************************
163 
164  //**Subscript operator**************************************************************************
170  inline ReturnType operator[]( size_t index ) const {
171  BLAZE_INTERNAL_ASSERT( index < 3UL, "Invalid vector access index" );
172 
173  if( index == 0UL )
174  return lhs_[1UL] * rhs_[2UL] - lhs_[2UL] * rhs_[1UL];
175  else if( index == 1UL )
176  return lhs_[2UL] * rhs_[0UL] - lhs_[0UL] * rhs_[2UL];
177  else
178  return lhs_[0UL] * rhs_[1UL] - lhs_[1UL] * rhs_[0UL];
179  }
180  //**********************************************************************************************
181 
182  //**At function*********************************************************************************
189  inline ReturnType at( size_t index ) const {
190  if( index >= 3UL ) {
191  BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
192  }
193  return (*this)[index];
194  }
195  //**********************************************************************************************
196 
197  //**Size function*******************************************************************************
202  inline size_t size() const {
203  return 3UL;
204  }
205  //**********************************************************************************************
206 
207  //**Left operand access*************************************************************************
212  inline LeftOperand leftOperand() const {
213  return lhs_;
214  }
215  //**********************************************************************************************
216 
217  //**Right operand access************************************************************************
222  inline RightOperand rightOperand() const {
223  return rhs_;
224  }
225  //**********************************************************************************************
226 
227  //**********************************************************************************************
233  template< typename T >
234  inline bool canAlias( const T* alias ) const {
235  return ( lhs_.canAlias( alias ) || rhs_.canAlias( alias ) );
236  }
237  //**********************************************************************************************
238 
239  //**********************************************************************************************
245  template< typename T >
246  inline bool isAliased( const T* alias ) const {
247  return ( lhs_.isAliased( alias ) || rhs_.isAliased( alias ) );
248  }
249  //**********************************************************************************************
250 
251  private:
252  //**Member variables****************************************************************************
253  LeftOperand lhs_;
254  RightOperand rhs_;
255  //**********************************************************************************************
256 
257  //**Assignment to dense vectors*****************************************************************
269  template< typename VT > // Type of the target dense vector
270  friend inline void assign( DenseVector<VT,false>& lhs, const DVecSVecCrossExpr& rhs )
271  {
273 
274  BLAZE_INTERNAL_ASSERT( (~lhs).size() == 3UL, "Invalid vector size" );
275  BLAZE_INTERNAL_ASSERT( (~rhs).size() == 3UL, "Invalid vector size" );
276 
277  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
278  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse vector operand
279 
280  (~lhs)[0] = x[1UL]*y[2UL] - x[2UL]*y[1UL];
281  (~lhs)[1] = x[2UL]*y[0UL] - x[0UL]*y[2UL];
282  (~lhs)[2] = x[0UL]*y[1UL] - x[1UL]*y[0UL];
283  }
285  //**********************************************************************************************
286 
287  //**Assignment to sparse vectors****************************************************************
299  template< typename VT > // Type of the target sparse vector
300  friend inline void assign( SparseVector<VT,false>& lhs, const DVecSVecCrossExpr& rhs )
301  {
303 
307 
308  BLAZE_INTERNAL_ASSERT( (~lhs).size() == 3UL, "Invalid vector size" );
309  BLAZE_INTERNAL_ASSERT( (~rhs).size() == 3UL, "Invalid vector size" );
310 
311  const ResultType tmp( serial( rhs ) );
312  assign( ~lhs, tmp );
313  }
315  //**********************************************************************************************
316 
317  //**Addition assignment to dense vectors********************************************************
329  template< typename VT > // Type of the target dense vector
330  friend inline void addAssign( DenseVector<VT,false>& lhs, const DVecSVecCrossExpr& rhs )
331  {
333 
334  BLAZE_INTERNAL_ASSERT( (~lhs).size() == 3UL, "Invalid vector size" );
335  BLAZE_INTERNAL_ASSERT( (~rhs).size() == 3UL, "Invalid vector size" );
336 
337  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
338  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse vector operand
339 
340  (~lhs)[0] += x[1UL]*y[2UL] - x[2UL]*y[1UL];
341  (~lhs)[1] += x[2UL]*y[0UL] - x[0UL]*y[2UL];
342  (~lhs)[2] += x[0UL]*y[1UL] - x[1UL]*y[0UL];
343  }
345  //**********************************************************************************************
346 
347  //**Addition assignment to sparse vectors*******************************************************
348  // No special implementation for the addition assignment to sparse vectors.
349  //**********************************************************************************************
350 
351  //**Subtraction assignment to dense vectors*****************************************************
363  template< typename VT > // Type of the target dense vector
364  friend inline void subAssign( DenseVector<VT,false>& lhs, const DVecSVecCrossExpr& rhs )
365  {
367 
368  BLAZE_INTERNAL_ASSERT( (~lhs).size() == 3UL, "Invalid vector size" );
369  BLAZE_INTERNAL_ASSERT( (~rhs).size() == 3UL, "Invalid vector size" );
370 
371  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
372  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse vector operand
373 
374  (~lhs)[0] -= x[1UL]*y[2UL] - x[2UL]*y[1UL];
375  (~lhs)[1] -= x[2UL]*y[0UL] - x[0UL]*y[2UL];
376  (~lhs)[2] -= x[0UL]*y[1UL] - x[1UL]*y[0UL];
377  }
379  //**********************************************************************************************
380 
381  //**Subtraction assignment to sparse vectors****************************************************
382  // No special implementation for the subtraction assignment to sparse vectors.
383  //**********************************************************************************************
384 
385  //**Multiplication assignment to dense vectors**************************************************
397  template< typename VT > // Type of the target dense vector
398  friend inline void multAssign( DenseVector<VT,false>& lhs, const DVecSVecCrossExpr& rhs )
399  {
401 
402  BLAZE_INTERNAL_ASSERT( (~lhs).size() == 3UL, "Invalid vector size" );
403  BLAZE_INTERNAL_ASSERT( (~rhs).size() == 3UL, "Invalid vector size" );
404 
405  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
406  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse vector operand
407 
408  (~lhs)[0] *= x[1UL]*y[2UL] - x[2UL]*y[1UL];
409  (~lhs)[1] *= x[2UL]*y[0UL] - x[0UL]*y[2UL];
410  (~lhs)[2] *= x[0UL]*y[1UL] - x[1UL]*y[0UL];
411  }
413  //**********************************************************************************************
414 
415  //**Multiplication assignment to sparse vectors*************************************************
416  // No special implementation for the multiplication assignment to sparse vectors.
417  //**********************************************************************************************
418 
419  //**Compile time checks*************************************************************************
426  //**********************************************************************************************
427 };
428 //*************************************************************************************************
429 
430 
431 
432 
433 //=================================================================================================
434 //
435 // GLOBAL BINARY ARITHMETIC OPERATORS
436 //
437 //=================================================================================================
438 
439 //*************************************************************************************************
466 template< typename T1 // Type of the left-hand side dense vector
467  , typename T2 > // Type of the right-hand side sparse vector
468 inline const DVecSVecCrossExpr<T1,T2>
470 {
472 
473  if( (~lhs).size() != 3UL || (~rhs).size() != 3UL ) {
474  BLAZE_THROW_INVALID_ARGUMENT( "Invalid vector size for cross product" );
475  }
476 
477  return DVecSVecCrossExpr<T1,T2>( ~lhs, ~rhs );
478 }
479 //*************************************************************************************************
480 
481 
482 
483 
484 //=================================================================================================
485 //
486 // SIZE SPECIALIZATIONS
487 //
488 //=================================================================================================
489 
490 //*************************************************************************************************
492 template< typename VT1, typename VT2 >
493 struct Size< DVecSVecCrossExpr<VT1,VT2> > : public SizeT<3UL>
494 {};
496 //*************************************************************************************************
497 
498 } // namespace blaze
499 
500 #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
Expression object for dense vector-sparse vector cross products.The DVecSVecCrossExpr class represent...
Definition: DVecSVecCrossExpr.h:85
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 basic type definitions.
const StaticVector< ET2, 3UL, false > RT
Composite type of the right-hand side sparse vector expression.
Definition: DVecSVecCrossExpr.h:138
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector)
Returns the current size/dimension of the vector.
Definition: Vector.h:252
const SelectType< returnExpr, ExprReturnType, ElementType >::Type ReturnType
Return type for expression template evaluations.
Definition: DVecSVecCrossExpr.h:123
#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
DVecSVecCrossExpr(const VT1 &lhs, const VT2 &rhs)
Constructor for the DVecSVecCrossExpr class.
Definition: DVecSVecCrossExpr.h:155
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.
VT2::ReturnType RN2
Return type of the right-hand side sparse vector expression.
Definition: DVecSVecCrossExpr.h:94
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
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:135
Header file for the Computation base class.
Header file for the SizeT class template.
CrossTrait< RT1, RT2 >::Type ResultType
Result type for expression template evaluations.
Definition: DVecSVecCrossExpr.h:118
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: DVecSVecCrossExpr.h:189
VT2::CompositeType CT2
Composite type of the right-hand side sparse vector expression.
Definition: DVecSVecCrossExpr.h:96
RightOperand rightOperand() const
Returns the right-hand side sparse vector operand.
Definition: DVecSVecCrossExpr.h:222
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
Constraint on the transpose flag of vector types.
Header file for the MultExprTrait class template.
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: DVecSVecCrossExpr.h:119
ResultType::ElementType ElementType
Resulting element type.
Definition: DVecSVecCrossExpr.h:120
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:112
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
VT2::ElementType ET2
Element type of the right-hand side sparse vector expression.
Definition: DVecSVecCrossExpr.h:98
VT1::ResultType RT1
Result type of the left-hand side dense vector expression.
Definition: DVecSVecCrossExpr.h:91
#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
#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
VT2::ResultType RT2
Result type of the right-hand side sparse vector expression.
Definition: DVecSVecCrossExpr.h:92
#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:93
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.
Constraint on the data type.
Header file for the serial shim.
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:132
LeftOperand leftOperand() const
Returns the left-hand side dense vector operand.
Definition: DVecSVecCrossExpr.h:212
Header file for all forward declarations for dense vectors and matrices.
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2587
RightOperand rhs_
Right-hand side sparse vector of the cross product expression.
Definition: DVecSVecCrossExpr.h:254
Header file for run time assertion macros.
Header file for the cross product trait.
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: DVecSVecCrossExpr.h:246
const ResultType CompositeType
Data type for composite expression templates.
Definition: DVecSVecCrossExpr.h:126
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: DVecSVecCrossExpr.h:170
VT1::ElementType ET1
Element type of the left-hand side dense vector expression.
Definition: DVecSVecCrossExpr.h:97
VT1::CompositeType CT1
Composite type of the left-hand side dense vector expression.
Definition: DVecSVecCrossExpr.h:95
#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:129
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: DVecSVecCrossExpr.h:234
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
size_t size() const
Returns the current size/dimension of the vector.
Definition: DVecSVecCrossExpr.h:202
Header file for exception macros.
LeftOperand lhs_
Left-hand side dense vector of the cross product expression.
Definition: DVecSVecCrossExpr.h:253
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
#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:117
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.