All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DVecTransExpr.h
Go to the documentation of this file.
1 //=================================================================================================
20 //=================================================================================================
21 
22 #ifndef _BLAZE_MATH_EXPRESSIONS_DVECTRANSEXPR_H_
23 #define _BLAZE_MATH_EXPRESSIONS_DVECTRANSEXPR_H_
24 
25 
26 //*************************************************************************************************
27 // Includes
28 //*************************************************************************************************
29 
38 #include <blaze/math/Intrinsics.h>
42 #include <blaze/util/Assert.h>
43 #include <blaze/util/EmptyType.h>
44 #include <blaze/util/EnableIf.h>
46 #include <blaze/util/SelectType.h>
47 #include <blaze/util/Types.h>
48 
49 
50 namespace blaze {
51 
52 //=================================================================================================
53 //
54 // CLASS DVECTRANSEXPR
55 //
56 //=================================================================================================
57 
58 //*************************************************************************************************
65 template< typename VT // Type of the dense vector
66  , bool TF > // Transpose flag
67 class DVecTransExpr : public DenseVector< DVecTransExpr<VT,TF>, TF >
68  , private Expression
69  , private SelectType< IsComputation<VT>::value, Computation, EmptyType >::Type
70 {
71  private:
72  //**Type definitions****************************************************************************
73  typedef typename VT::CompositeType CT;
74  //**********************************************************************************************
75 
76  //**********************************************************************************************
78 
84  enum { useAssign = RequiresEvaluation<VT>::value };
85  //**********************************************************************************************
86 
87  //**********************************************************************************************
89 
90  template< typename VT2 >
91  struct UseAssign {
92  enum { value = useAssign };
93  };
95  //**********************************************************************************************
96 
97  public:
98  //**Type definitions****************************************************************************
100  typedef typename VT::TransposeType ResultType;
101  typedef typename VT::ResultType TransposeType;
102  typedef typename VT::ElementType ElementType;
103  typedef typename VT::ReturnType ReturnType;
104 
107 
110 
112  typedef typename SelectType< IsExpression<VT>::value, const VT, const VT& >::Type Operand;
113  //**********************************************************************************************
114 
115  //**Compilation flags***************************************************************************
117  enum { vectorizable = VT::vectorizable };
118  //**********************************************************************************************
119 
120  //**Constructor*********************************************************************************
125  explicit inline DVecTransExpr( const VT& dv )
126  : dv_( dv ) // Dense vector of the transposition expression
127  {}
128  //**********************************************************************************************
129 
130  //**Subscript operator**************************************************************************
136  inline ReturnType operator[]( size_t index ) const {
137  BLAZE_INTERNAL_ASSERT( index < dv_.size(), "Invalid vector access index" );
138  return dv_[index];
139  }
140  //**********************************************************************************************
141 
142  //**Get function********************************************************************************
148  inline IntrinsicType get( size_t index ) const {
149  typedef IntrinsicTrait<ElementType> IT;
150  BLAZE_INTERNAL_ASSERT( index < dv_.size() , "Invalid vector access index" );
151  BLAZE_INTERNAL_ASSERT( index % IT::size == 0UL , "Invalid vector access index" );
152  return dv_.get( index );
153  }
154  //**********************************************************************************************
155 
156  //**Low-level data access***********************************************************************
161  inline const ElementType* data() const {
162  return dv_.data();
163  }
164  //**********************************************************************************************
165 
166  //**Size function*******************************************************************************
171  inline size_t size() const {
172  return dv_.size();
173  }
174  //**********************************************************************************************
175 
176  //**Operand access******************************************************************************
181  inline Operand operand() const {
182  return dv_;
183  }
184  //**********************************************************************************************
185 
186  //**********************************************************************************************
192  template< typename T >
193  inline bool canAlias( const T* alias ) const {
194  return dv_.canAlias( alias );
195  }
196  //**********************************************************************************************
197 
198  //**********************************************************************************************
204  template< typename T >
205  inline bool isAliased( const T* alias ) const {
206  return dv_.isAliased( alias );
207  }
208  //**********************************************************************************************
209 
210  private:
211  //**Member variables****************************************************************************
213  //**********************************************************************************************
214 
215  //**Assignment to dense vectors*****************************************************************
229  template< typename VT2 > // Type of the target dense vector
230  friend inline typename EnableIf< UseAssign<VT2> >::Type
231  assign( DenseVector<VT2,TF>& lhs, const DVecTransExpr& rhs )
232  {
234 
235  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
236 
237  DVecTransposer<VT2,!TF> tmp( ~lhs );
238  assign( tmp, rhs.dv_ );
239  }
241  //**********************************************************************************************
242 
243  //**Assignment to sparse vectors****************************************************************
257  template< typename VT2 > // Type of the target sparse vector
258  friend inline typename EnableIf< UseAssign<VT2> >::Type
259  assign( SparseVector<VT2,TF>& lhs, const DVecTransExpr& rhs )
260  {
262 
263  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
264 
265  SVecTransposer<VT2,!TF> tmp( ~lhs );
266  assign( tmp, rhs.dv_ );
267  }
269  //**********************************************************************************************
270 
271  //**Addition assignment to dense vectors********************************************************
285  template< typename VT2 > // Type of the target dense vector
286  friend inline typename EnableIf< UseAssign<VT2> >::Type
287  addAssign( DenseVector<VT2,TF>& lhs, const DVecTransExpr& rhs )
288  {
290 
291  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
292 
293  DVecTransposer<VT2,!TF> tmp( ~lhs );
294  addAssign( tmp, rhs.dv_ );
295  }
297  //**********************************************************************************************
298 
299  //**Addition assignment to sparse vectors*******************************************************
300  // No special implementation for the addition assignment to sparse vectors.
301  //**********************************************************************************************
302 
303  //**Subtraction assignment to dense vectors*****************************************************
317  template< typename VT2 > // Type of the target dense vector
318  friend inline typename EnableIf< UseAssign<VT2> >::Type
319  subAssign( DenseVector<VT2,TF>& lhs, const DVecTransExpr& rhs )
320  {
322 
323  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
324 
325  DVecTransposer<VT2,!TF> tmp( ~lhs );
326  subAssign( tmp, rhs.dv_ );
327  }
329  //**********************************************************************************************
330 
331  //**Subtraction assignment to sparse vectors****************************************************
332  // No special implementation for the subtraction assignment to sparse vectors.
333  //**********************************************************************************************
334 
335  //**Multiplication assignment to dense vectors**************************************************
349  template< typename VT2 > // Type of the target dense vector
350  friend inline typename EnableIf< UseAssign<VT2> >::Type
351  multAssign( DenseVector<VT2,TF>& lhs, const DVecTransExpr& rhs )
352  {
354 
355  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
356 
357  DVecTransposer<VT2,!TF> tmp( ~lhs );
358  multAssign( tmp, rhs.dv_ );
359  }
361  //**********************************************************************************************
362 
363  //**Multiplication assignment to sparse vectors*************************************************
364  // No special implementation for the multiplication assignment to sparse vectors.
365  //**********************************************************************************************
366 
367  //**Trans function******************************************************************************
385  template< typename VT2 // Type of the dense vector
386  , bool TF2 > // Transpose flag of the dense vector
387  friend inline Operand trans( const DVecTransExpr<VT2,TF2>& dv )
388  {
390 
391  return dv.dv_;
392  }
394  //**********************************************************************************************
395 
396  //**Compile time checks*************************************************************************
401  //**********************************************************************************************
402 };
403 //*************************************************************************************************
404 
405 
406 
407 
408 //=================================================================================================
409 //
410 // GLOBAL OPERATORS
411 //
412 //=================================================================================================
413 
414 //*************************************************************************************************
433 template< typename VT // Type of the dense vector
434  , bool TF > // Transpose flag
436 {
438 
439  return DVecTransExpr<VT,!TF>( ~dv );
440 }
441 //*************************************************************************************************
442 
443 } // namespace blaze
444 
445 #endif