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>
43 #include <blaze/util/Assert.h>
44 #include <blaze/util/EmptyType.h>
45 #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 
120  enum { canAlias = CanAlias<VT>::value };
121  //**********************************************************************************************
122 
123  //**Constructor*********************************************************************************
128  explicit inline DVecTransExpr( const VT& dv )
129  : dv_( dv ) // Dense vector of the transposition expression
130  {}
131  //**********************************************************************************************
132 
133  //**Subscript operator**************************************************************************
139  inline ReturnType operator[]( size_t index ) const {
140  BLAZE_INTERNAL_ASSERT( index < dv_.size(), "Invalid vector access index" );
141  return dv_[index];
142  }
143  //**********************************************************************************************
144 
145  //**Get function********************************************************************************
151  inline IntrinsicType get( size_t index ) const {
152  typedef IntrinsicTrait<ElementType> IT;
153  BLAZE_INTERNAL_ASSERT( index < dv_.size() , "Invalid vector access index" );
154  BLAZE_INTERNAL_ASSERT( index % IT::size == 0UL , "Invalid vector access index" );
155  return dv_.get( index );
156  }
157  //**********************************************************************************************
158 
159  //**Low-level data access***********************************************************************
164  inline const ElementType* data() const {
165  return dv_.data();
166  }
167  //**********************************************************************************************
168 
169  //**Size function*******************************************************************************
174  inline size_t size() const {
175  return dv_.size();
176  }
177  //**********************************************************************************************
178 
179  //**Operand access******************************************************************************
184  inline Operand operand() const {
185  return dv_;
186  }
187  //**********************************************************************************************
188 
189  //**********************************************************************************************
195  template< typename T >
196  inline bool isAliased( const T* alias ) const {
197  return CanAlias<VT>::value && dv_.isAliased( alias );
198  }
199  //**********************************************************************************************
200 
201  private:
202  //**Member variables****************************************************************************
204  //**********************************************************************************************
205 
206  //**Assignment to dense vectors*****************************************************************
220  template< typename VT2 > // Type of the target dense vector
221  friend inline typename EnableIf< UseAssign<VT2> >::Type
222  assign( DenseVector<VT2,TF>& lhs, const DVecTransExpr& rhs )
223  {
224  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
225 
226  DVecTransposer<VT2,!TF> tmp( ~lhs );
227  assign( tmp, rhs.dv_ );
228  }
230  //**********************************************************************************************
231 
232  //**Assignment to sparse vectors****************************************************************
246  template< typename VT2 > // Type of the target sparse vector
247  friend inline typename EnableIf< UseAssign<VT2> >::Type
248  assign( SparseVector<VT2,TF>& lhs, const DVecTransExpr& rhs )
249  {
250  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
251 
252  SVecTransposer<VT2,!TF> tmp( ~lhs );
253  assign( tmp, rhs.dv_ );
254  }
256  //**********************************************************************************************
257 
258  //**Addition assignment to dense vectors********************************************************
272  template< typename VT2 > // Type of the target dense vector
273  friend inline typename EnableIf< UseAssign<VT2> >::Type
274  addAssign( DenseVector<VT2,TF>& lhs, const DVecTransExpr& rhs )
275  {
276  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
277 
278  DVecTransposer<VT2,!TF> tmp( ~lhs );
279  addAssign( tmp, rhs.dv_ );
280  }
282  //**********************************************************************************************
283 
284  //**Addition assignment to sparse vectors*******************************************************
285  // No special implementation for the addition assignment to sparse vectors.
286  //**********************************************************************************************
287 
288  //**Subtraction assignment to dense vectors*****************************************************
302  template< typename VT2 > // Type of the target dense vector
303  friend inline typename EnableIf< UseAssign<VT2> >::Type
304  subAssign( DenseVector<VT2,TF>& lhs, const DVecTransExpr& rhs )
305  {
306  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
307 
308  DVecTransposer<VT2,!TF> tmp( ~lhs );
309  subAssign( tmp, rhs.dv_ );
310  }
312  //**********************************************************************************************
313 
314  //**Subtraction assignment to sparse vectors****************************************************
315  // No special implementation for the subtraction assignment to sparse vectors.
316  //**********************************************************************************************
317 
318  //**Multiplication assignment to dense vectors**************************************************
332  template< typename VT2 > // Type of the target dense vector
333  friend inline typename EnableIf< UseAssign<VT2> >::Type
334  multAssign( DenseVector<VT2,TF>& lhs, const DVecTransExpr& rhs )
335  {
336  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
337 
338  DVecTransposer<VT2,!TF> tmp( ~lhs );
339  multAssign( tmp, rhs.dv_ );
340  }
342  //**********************************************************************************************
343 
344  //**Multiplication assignment to sparse vectors*************************************************
345  // No special implementation for the multiplication assignment to sparse vectors.
346  //**********************************************************************************************
347 
348  //**Trans function******************************************************************************
366  template< typename VT2 // Type of the dense vector
367  , bool TF2 > // Transpose flag of the dense vector
368  friend inline Operand trans( const DVecTransExpr<VT2,TF2>& dv )
369  {
370  return dv.dv_;
371  }
373  //**********************************************************************************************
374 
375  //**Compile time checks*************************************************************************
380  //**********************************************************************************************
381 };
382 //*************************************************************************************************
383 
384 
385 
386 
387 //=================================================================================================
388 //
389 // GLOBAL OPERATORS
390 //
391 //=================================================================================================
392 
393 //*************************************************************************************************
412 template< typename VT // Type of the dense vector
413  , bool TF > // Transpose flag
415 {
416  return DVecTransExpr<VT,!TF>( ~dv );
417 }
418 //*************************************************************************************************
419 
420 } // namespace blaze
421 
422 #endif