All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SVecDVecCrossExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_SVECDVECCROSSEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_SVECDVECCROSSEXPR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <stdexcept>
59 #include <blaze/util/Assert.h>
62 #include <blaze/util/SelectType.h>
63 #include <blaze/util/Types.h>
64 
65 
66 namespace blaze {
67 
68 //=================================================================================================
69 //
70 // CLASS SVECDVECCROSSEXPR
71 //
72 //=================================================================================================
73 
74 //*************************************************************************************************
81 template< typename VT1 // Type of the left-hand side sparse vector
82  , typename VT2 > // Type of the right-hand side dense vector
83 class SVecDVecCrossExpr : public DenseVector< SVecDVecCrossExpr<VT1,VT2>, false >
84  , private CrossExpr
85  , private Computation
86 {
87  private:
88  //**Type definitions****************************************************************************
89  typedef typename VT1::ResultType RT1;
90  typedef typename VT2::ResultType RT2;
91  typedef typename VT1::ReturnType RN1;
92  typedef typename VT2::ReturnType RN2;
93  typedef typename VT1::CompositeType CT1;
94  typedef typename VT2::CompositeType CT2;
95  typedef typename VT1::ElementType ET1;
96  typedef typename VT2::ElementType ET2;
97  //**********************************************************************************************
98 
99  //**Return type evaluation**********************************************************************
101 
106  enum { returnExpr = !IsTemporary<RN1>::value && !IsTemporary<RN2>::value };
107 
111  //**********************************************************************************************
112 
113  public:
114  //**Type definitions****************************************************************************
119 
122 
124  typedef const ResultType CompositeType;
125 
127  typedef typename SelectType< IsExpression<VT1>::value, const VT1, const VT1& >::Type LeftOperand;
128 
130  typedef typename SelectType< IsExpression<VT2>::value, const VT2, const VT2& >::Type RightOperand;
131 
134 
137  //**********************************************************************************************
138 
139  //**Compilation flags***************************************************************************
141  enum { vectorizable = 0 };
142 
144  enum { smpAssignable = 0 };
145  //**********************************************************************************************
146 
147  //**Constructor*********************************************************************************
153  explicit inline SVecDVecCrossExpr( const VT1& lhs, const VT2& rhs )
154  : lhs_( lhs ) // Left-hand side sparse vector of the cross product expression
155  , rhs_( rhs ) // Right-hand side dense vector of the cross product expression
156  {
157  BLAZE_INTERNAL_ASSERT( lhs.size() == 3UL, "Invalid vector size" );
158  BLAZE_INTERNAL_ASSERT( rhs.size() == 3UL, "Invalid vector size" );
159  }
160  //**********************************************************************************************
161 
162  //**Subscript operator**************************************************************************
168  inline ReturnType operator[]( size_t index ) const {
169  BLAZE_INTERNAL_ASSERT( index < 3UL, "Invalid vector access index" );
170 
171  if( index == 0UL )
172  return lhs_[1UL] * rhs_[2UL] - lhs_[2UL] * rhs_[1UL];
173  else if( index == 1UL )
174  return lhs_[2UL] * rhs_[0UL] - lhs_[0UL] * rhs_[2UL];
175  else
176  return lhs_[0UL] * rhs_[1UL] - lhs_[1UL] * rhs_[0UL];
177  }
178  //**********************************************************************************************
179 
180  //**Size function*******************************************************************************
185  inline size_t size() const {
186  return 3UL;
187  }
188  //**********************************************************************************************
189 
190  //**Left operand access*************************************************************************
195  inline LeftOperand leftOperand() const {
196  return lhs_;
197  }
198  //**********************************************************************************************
199 
200  //**Right operand access************************************************************************
205  inline RightOperand rightOperand() const {
206  return rhs_;
207  }
208  //**********************************************************************************************
209 
210  //**********************************************************************************************
216  template< typename T >
217  inline bool canAlias( const T* alias ) const {
218  return ( lhs_.canAlias( alias ) || rhs_.canAlias( alias ) );
219  }
220  //**********************************************************************************************
221 
222  //**********************************************************************************************
228  template< typename T >
229  inline bool isAliased( const T* alias ) const {
230  return ( lhs_.isAliased( alias ) || rhs_.isAliased( alias ) );
231  }
232  //**********************************************************************************************
233 
234  private:
235  //**Member variables****************************************************************************
238  //**********************************************************************************************
239 
240  //**Assignment to dense vectors*****************************************************************
252  template< typename VT > // Type of the target dense vector
253  friend inline void assign( DenseVector<VT,false>& lhs, const SVecDVecCrossExpr& rhs )
254  {
256 
257  BLAZE_INTERNAL_ASSERT( (~lhs).size() == 3UL, "Invalid vector size" );
258  BLAZE_INTERNAL_ASSERT( (~rhs).size() == 3UL, "Invalid vector size" );
259 
260  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse vector operand
261  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense vector operand
262 
263  (~lhs)[0] = x[1UL]*y[2UL] - x[2UL]*y[1UL];
264  (~lhs)[1] = x[2UL]*y[0UL] - x[0UL]*y[2UL];
265  (~lhs)[2] = x[0UL]*y[1UL] - x[1UL]*y[0UL];
266  }
268  //**********************************************************************************************
269 
270  //**Assignment to sparse vectors****************************************************************
282  template< typename VT > // Type of the target sparse vector
283  friend inline void assign( SparseVector<VT,false>& lhs, const SVecDVecCrossExpr& rhs )
284  {
286 
290 
291  BLAZE_INTERNAL_ASSERT( (~lhs).size() == 3UL, "Invalid vector size" );
292  BLAZE_INTERNAL_ASSERT( (~rhs).size() == 3UL, "Invalid vector size" );
293 
294  const ResultType tmp( serial( rhs ) );
295  assign( ~lhs, tmp );
296  }
298  //**********************************************************************************************
299 
300  //**Addition assignment to dense vectors********************************************************
312  template< typename VT > // Type of the target dense vector
313  friend inline void addAssign( DenseVector<VT,false>& lhs, const SVecDVecCrossExpr& rhs )
314  {
316 
317  BLAZE_INTERNAL_ASSERT( (~lhs).size() == 3UL, "Invalid vector size" );
318  BLAZE_INTERNAL_ASSERT( (~rhs).size() == 3UL, "Invalid vector size" );
319 
320  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse vector operand
321  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense vector operand
322 
323  (~lhs)[0] += x[1UL]*y[2UL] - x[2UL]*y[1UL];
324  (~lhs)[1] += x[2UL]*y[0UL] - x[0UL]*y[2UL];
325  (~lhs)[2] += x[0UL]*y[1UL] - x[1UL]*y[0UL];
326  }
328  //**********************************************************************************************
329 
330  //**Addition assignment to sparse vectors*******************************************************
331  // No special implementation for the addition assignment to sparse vectors.
332  //**********************************************************************************************
333 
334  //**Subtraction assignment to dense vectors*****************************************************
346  template< typename VT > // Type of the target dense vector
347  friend inline void subAssign( DenseVector<VT,false>& lhs, const SVecDVecCrossExpr& rhs )
348  {
350 
351  BLAZE_INTERNAL_ASSERT( (~lhs).size() == 3UL, "Invalid vector size" );
352  BLAZE_INTERNAL_ASSERT( (~rhs).size() == 3UL, "Invalid vector size" );
353 
354  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse vector operand
355  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense vector operand
356 
357  (~lhs)[0] -= x[1UL]*y[2UL] - x[2UL]*y[1UL];
358  (~lhs)[1] -= x[2UL]*y[0UL] - x[0UL]*y[2UL];
359  (~lhs)[2] -= x[0UL]*y[1UL] - x[1UL]*y[0UL];
360  }
362  //**********************************************************************************************
363 
364  //**Subtraction assignment to sparse vectors****************************************************
365  // No special implementation for the subtraction assignment to sparse vectors.
366  //**********************************************************************************************
367 
368  //**Multiplication assignment to dense vectors**************************************************
380  template< typename VT > // Type of the target dense vector
381  friend inline void multAssign( DenseVector<VT,false>& lhs, const SVecDVecCrossExpr& rhs )
382  {
384 
385  BLAZE_INTERNAL_ASSERT( (~lhs).size() == 3UL, "Invalid vector size" );
386  BLAZE_INTERNAL_ASSERT( (~rhs).size() == 3UL, "Invalid vector size" );
387 
388  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse vector operand
389  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense vector operand
390 
391  (~lhs)[0] *= x[1UL]*y[2UL] - x[2UL]*y[1UL];
392  (~lhs)[1] *= x[2UL]*y[0UL] - x[0UL]*y[2UL];
393  (~lhs)[2] *= x[0UL]*y[1UL] - x[1UL]*y[0UL];
394  }
396  //**********************************************************************************************
397 
398  //**Multiplication assignment to sparse vectors*************************************************
399  // No special implementation for the multiplication assignment to sparse vectors.
400  //**********************************************************************************************
401 
402  //**Compile time checks*************************************************************************
409  //**********************************************************************************************
410 };
411 //*************************************************************************************************
412 
413 
414 
415 
416 //=================================================================================================
417 //
418 // GLOBAL BINARY ARITHMETIC OPERATORS
419 //
420 //=================================================================================================
421 
422 //*************************************************************************************************
449 template< typename T1 // Type of the left-hand side sparse vector
450  , typename T2 > // Type of the right-hand side dense vector
451 inline const SVecDVecCrossExpr<T1,T2>
453 {
455 
456  if( (~lhs).size() != 3UL || (~rhs).size() != 3UL )
457  throw std::invalid_argument( "Invalid vector size for cross product" );
458 
459  return SVecDVecCrossExpr<T1,T2>( ~lhs, ~rhs );
460 }
461 //*************************************************************************************************
462 
463 } // namespace blaze
464 
465 #endif
Compile time check whether the given type is a temporary vector or matrix type.This type trait class ...
Definition: IsTemporary.h:87
SVecDVecCrossExpr(const VT1 &lhs, const VT2 &rhs)
Constructor for the SVecDVecCrossExpr class.
Definition: SVecDVecCrossExpr.h:153
#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:199
RightOperand rhs_
Right-hand side dense vector of the cross product expression.
Definition: SVecDVecCrossExpr.h:237
VT2::ReturnType RN2
Return type of the right-hand side dense vector expression.
Definition: SVecDVecCrossExpr.h:92
Expression object for sparse vector-dense vector cross products.The SVecDVecCrossExpr class represent...
Definition: Forward.h:110
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2408
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:251
Header file for the DenseVector base class.
VT1::ReturnType RN1
Return type of the left-hand side sparse vector expression.
Definition: SVecDVecCrossExpr.h:91
const DMatSerialExpr< MT, SO > serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:690
Header file for the Computation base class.
SubExprTrait< typename MultExprTrait< RN1, RN2 >::Type, typename MultExprTrait< RN1, RN2 >::Type >::Type ExprReturnType
Expression return type for the subscript operator.
Definition: SVecDVecCrossExpr.h:110
VT1::ResultType RT1
Result type of the left-hand side sparse vector expression.
Definition: SVecDVecCrossExpr.h:89
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:52
VT2::CompositeType CT2
Composite type of the right-hand side dense vector expression.
Definition: SVecDVecCrossExpr.h:94
Header file for the MultExprTrait class template.
VT2::ResultType RT2
Result type of the right-hand side dense vector expression.
Definition: SVecDVecCrossExpr.h:90
Compile time type selection.The SelectType class template selects one of the two given types T1 and T...
Definition: SelectType.h:59
const StaticVector< ET1, 3UL, false > LT
Composite type of the left-hand side sparse vector expression.
Definition: SVecDVecCrossExpr.h:133
Header file for the IsTemporary type trait class.
VT1::CompositeType CT1
Composite type of the left-hand side sparse vector expression.
Definition: SVecDVecCrossExpr.h:93
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: SVecDVecCrossExpr.h:229
LeftOperand lhs_
Left-hand side sparse vector of the cross product expression.
Definition: SVecDVecCrossExpr.h:236
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:271
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:449
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
SelectType< IsComputation< VT2 >::value, const StaticVector< ET2, 3UL, false >, CT2 >::Type RT
Composite type of the right-hand side dense vector expression.
Definition: SVecDVecCrossExpr.h:136
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:2406
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:361
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.
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: SVecDVecCrossExpr.h:217
const ResultType CompositeType
Data type for composite expression templates.
Definition: SVecDVecCrossExpr.h:124
Header file for the CrossExpr base class.
const SelectType< returnExpr, ExprReturnType, ElementType >::Type ReturnType
Return type for expression template evaluations.
Definition: SVecDVecCrossExpr.h:121
ResultType::ElementType ElementType
Resulting element type.
Definition: SVecDVecCrossExpr.h:118
Header file for all forward declarations for dense vectors and matrices.
SelectType< IsExpression< VT1 >::value, const VT1, const VT1 & >::Type LeftOperand
Composite type of the left-hand side sparse vector expression.
Definition: SVecDVecCrossExpr.h:127
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2407
Header file for run time assertion macros.
Header file for the cross product trait.
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: SVecDVecCrossExpr.h:117
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:301
VT1::ElementType ET1
Element type of the left-hand side sparse vector expression.
Definition: SVecDVecCrossExpr.h:95
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:331
SelectType< IsExpression< VT2 >::value, const VT2, const VT2 & >::Type RightOperand
Composite type of the right-hand side dense vector expression.
Definition: SVecDVecCrossExpr.h:130
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: SVecDVecCrossExpr.h:168
#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
CrossTrait< RT1, RT2 >::Type ResultType
Result type for expression template evaluations.
Definition: SVecDVecCrossExpr.h:116
Header file for the IsComputation type trait class.
size_t size() const
Returns the current size/dimension of the vector.
Definition: SVecDVecCrossExpr.h:185
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:2403
Header file for basic type definitions.
Header file for the SubExprTrait class template.
SVecDVecCrossExpr< VT1, VT2 > This
Type of this SVecDVecCrossExpr instance.
Definition: SVecDVecCrossExpr.h:115
RightOperand rightOperand() const
Returns the right-hand side dense vector operand.
Definition: SVecDVecCrossExpr.h:205
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
LeftOperand leftOperand() const
Returns the left-hand side sparse vector operand.
Definition: SVecDVecCrossExpr.h:195
Header file for the IsExpression type trait class.
VT2::ElementType ET2
Element type of the right-hand side dense vector expression.
Definition: SVecDVecCrossExpr.h:96
Header file for the FunctionTrace class.