All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DVecTransExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_DVECTRANSEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_DVECTRANSEXPR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
51 #include <blaze/math/Intrinsics.h>
57 #include <blaze/util/Assert.h>
58 #include <blaze/util/EmptyType.h>
59 #include <blaze/util/EnableIf.h>
61 #include <blaze/util/SelectType.h>
62 #include <blaze/util/Types.h>
63 
64 
65 namespace blaze {
66 
67 //=================================================================================================
68 //
69 // CLASS DVECTRANSEXPR
70 //
71 //=================================================================================================
72 
73 //*************************************************************************************************
80 template< typename VT // Type of the dense vector
81  , bool TF > // Transpose flag
82 class DVecTransExpr : public DenseVector< DVecTransExpr<VT,TF>, TF >
83  , private VecTransExpr
84  , private SelectType< IsComputation<VT>::value, Computation, EmptyType >::Type
85 {
86  private:
87  //**Type definitions****************************************************************************
88  typedef typename VT::CompositeType CT;
89  //**********************************************************************************************
90 
91  //**********************************************************************************************
93 
99  enum { useAssign = RequiresEvaluation<VT>::value };
100  //**********************************************************************************************
101 
102  //**********************************************************************************************
104  template< typename VT2 >
106  struct UseAssign {
107  enum { value = useAssign };
108  };
110  //**********************************************************************************************
111 
112  public:
113  //**Type definitions****************************************************************************
115  typedef typename VT::TransposeType ResultType;
116  typedef typename VT::ResultType TransposeType;
117  typedef typename VT::ElementType ElementType;
118  typedef typename VT::ReturnType ReturnType;
119 
122 
125 
127  typedef typename SelectType< IsExpression<VT>::value, const VT, const VT& >::Type Operand;
128  //**********************************************************************************************
129 
130  //**ConstIterator class definition**************************************************************
134  {
135  public:
136  //**Type definitions*************************************************************************
137  typedef std::random_access_iterator_tag IteratorCategory;
142 
143  // STL iterator requirements
149 
151  typedef typename VT::ConstIterator IteratorType;
152  //*******************************************************************************************
153 
154  //**Constructor******************************************************************************
159  explicit inline ConstIterator( IteratorType iterator )
160  : iterator_( iterator ) // Iterator to the current element
161  {}
162  //*******************************************************************************************
163 
164  //**Addition assignment operator*************************************************************
170  inline ConstIterator& operator+=( size_t inc ) {
171  iterator_ += inc;
172  return *this;
173  }
174  //*******************************************************************************************
175 
176  //**Subtraction assignment operator**********************************************************
182  inline ConstIterator& operator-=( size_t dec ) {
183  iterator_ -= dec;
184  return *this;
185  }
186  //*******************************************************************************************
187 
188  //**Prefix increment operator****************************************************************
194  ++iterator_;
195  return *this;
196  }
197  //*******************************************************************************************
198 
199  //**Postfix increment operator***************************************************************
204  inline const ConstIterator operator++( int ) {
205  return ConstIterator( iterator_++ );
206  }
207  //*******************************************************************************************
208 
209  //**Prefix decrement operator****************************************************************
215  --iterator_;
216  return *this;
217  }
218  //*******************************************************************************************
219 
220  //**Postfix decrement operator***************************************************************
225  inline const ConstIterator operator--( int ) {
226  return ConstIterator( iterator_-- );
227  }
228  //*******************************************************************************************
229 
230  //**Element access operator******************************************************************
235  inline ReturnType operator*() const {
236  return *iterator_;
237  }
238  //*******************************************************************************************
239 
240  //**Load function****************************************************************************
245  inline IntrinsicType load() const {
246  return iterator_.load();
247  }
248  //*******************************************************************************************
249 
250  //**Equality operator************************************************************************
256  inline bool operator==( const ConstIterator& rhs ) const {
257  return iterator_ == rhs.iterator_;
258  }
259  //*******************************************************************************************
260 
261  //**Inequality operator**********************************************************************
267  inline bool operator!=( const ConstIterator& rhs ) const {
268  return iterator_ != rhs.iterator_;
269  }
270  //*******************************************************************************************
271 
272  //**Less-than operator***********************************************************************
278  inline bool operator<( const ConstIterator& rhs ) const {
279  return iterator_ < rhs.iterator_;
280  }
281  //*******************************************************************************************
282 
283  //**Greater-than operator********************************************************************
289  inline bool operator>( const ConstIterator& rhs ) const {
290  return iterator_ > rhs.iterator_;
291  }
292  //*******************************************************************************************
293 
294  //**Less-or-equal-than operator**************************************************************
300  inline bool operator<=( const ConstIterator& rhs ) const {
301  return iterator_ <= rhs.iterator_;
302  }
303  //*******************************************************************************************
304 
305  //**Greater-or-equal-than operator***********************************************************
311  inline bool operator>=( const ConstIterator& rhs ) const {
312  return iterator_ >= rhs.iterator_;
313  }
314  //*******************************************************************************************
315 
316  //**Subtraction operator*********************************************************************
322  inline DifferenceType operator-( const ConstIterator& rhs ) const {
323  return iterator_ - rhs.iterator_;
324  }
325  //*******************************************************************************************
326 
327  //**Addition operator************************************************************************
334  friend inline const ConstIterator operator+( const ConstIterator& it, size_t inc ) {
335  return ConstIterator( it.iterator_ + inc );
336  }
337  //*******************************************************************************************
338 
339  //**Addition operator************************************************************************
346  friend inline const ConstIterator operator+( size_t inc, const ConstIterator& it ) {
347  return ConstIterator( it.iterator_ + inc );
348  }
349  //*******************************************************************************************
350 
351  //**Subtraction operator*********************************************************************
358  friend inline const ConstIterator operator-( const ConstIterator& it, size_t dec ) {
359  return ConstIterator( it.iterator_ - dec );
360  }
361  //*******************************************************************************************
362 
363  private:
364  //**Member variables*************************************************************************
366  //*******************************************************************************************
367  };
368  //**********************************************************************************************
369 
370  //**Compilation flags***************************************************************************
372  enum { vectorizable = VT::vectorizable };
373 
375  enum { smpAssignable = VT::smpAssignable };
376  //**********************************************************************************************
377 
378  //**Constructor*********************************************************************************
383  explicit inline DVecTransExpr( const VT& dv )
384  : dv_( dv ) // Dense vector of the transposition expression
385  {}
386  //**********************************************************************************************
387 
388  //**Subscript operator**************************************************************************
394  inline ReturnType operator[]( size_t index ) const {
395  BLAZE_INTERNAL_ASSERT( index < dv_.size(), "Invalid vector access index" );
396  return dv_[index];
397  }
398  //**********************************************************************************************
399 
400  //**Load function*******************************************************************************
406  inline IntrinsicType load( size_t index ) const {
407  typedef IntrinsicTrait<ElementType> IT;
408  BLAZE_INTERNAL_ASSERT( index < dv_.size() , "Invalid vector access index" );
409  BLAZE_INTERNAL_ASSERT( index % IT::size == 0UL , "Invalid vector access index" );
410  return dv_.load( index );
411  }
412  //**********************************************************************************************
413 
414  //**Low-level data access***********************************************************************
419  inline const ElementType* data() const {
420  return dv_.data();
421  }
422  //**********************************************************************************************
423 
424  //**Begin function******************************************************************************
429  inline ConstIterator begin() const {
430  return ConstIterator( dv_.begin() );
431  }
432  //**********************************************************************************************
433 
434  //**End function********************************************************************************
439  inline ConstIterator end() const {
440  return ConstIterator( dv_.end() );
441  }
442  //**********************************************************************************************
443 
444  //**Size function*******************************************************************************
449  inline size_t size() const {
450  return dv_.size();
451  }
452  //**********************************************************************************************
453 
454  //**Operand access******************************************************************************
459  inline Operand operand() const {
460  return dv_;
461  }
462  //**********************************************************************************************
463 
464  //**********************************************************************************************
470  template< typename T >
471  inline bool canAlias( const T* alias ) const {
472  return dv_.canAlias( alias );
473  }
474  //**********************************************************************************************
475 
476  //**********************************************************************************************
482  template< typename T >
483  inline bool isAliased( const T* alias ) const {
484  return dv_.isAliased( alias );
485  }
486  //**********************************************************************************************
487 
488  private:
489  //**Member variables****************************************************************************
491  //**********************************************************************************************
492 
493  //**Assignment to dense vectors*****************************************************************
507  template< typename VT2 > // Type of the target dense vector
508  friend inline typename EnableIf< UseAssign<VT2> >::Type
509  assign( DenseVector<VT2,TF>& lhs, const DVecTransExpr& rhs )
510  {
512 
513  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
514 
515  DVecTransposer<VT2,!TF> tmp( ~lhs );
516  assign( tmp, rhs.dv_ );
517  }
519  //**********************************************************************************************
520 
521  //**Assignment to sparse vectors****************************************************************
535  template< typename VT2 > // Type of the target sparse vector
536  friend inline typename EnableIf< UseAssign<VT2> >::Type
537  assign( SparseVector<VT2,TF>& lhs, const DVecTransExpr& rhs )
538  {
540 
541  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
542 
543  SVecTransposer<VT2,!TF> tmp( ~lhs );
544  assign( tmp, rhs.dv_ );
545  }
547  //**********************************************************************************************
548 
549  //**Addition assignment to dense vectors********************************************************
563  template< typename VT2 > // Type of the target dense vector
564  friend inline typename EnableIf< UseAssign<VT2> >::Type
565  addAssign( DenseVector<VT2,TF>& lhs, const DVecTransExpr& rhs )
566  {
568 
569  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
570 
571  DVecTransposer<VT2,!TF> tmp( ~lhs );
572  addAssign( tmp, rhs.dv_ );
573  }
575  //**********************************************************************************************
576 
577  //**Addition assignment to sparse vectors*******************************************************
578  // No special implementation for the addition assignment to sparse vectors.
579  //**********************************************************************************************
580 
581  //**Subtraction assignment to dense vectors*****************************************************
595  template< typename VT2 > // Type of the target dense vector
596  friend inline typename EnableIf< UseAssign<VT2> >::Type
597  subAssign( DenseVector<VT2,TF>& lhs, const DVecTransExpr& rhs )
598  {
600 
601  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
602 
603  DVecTransposer<VT2,!TF> tmp( ~lhs );
604  subAssign( tmp, rhs.dv_ );
605  }
607  //**********************************************************************************************
608 
609  //**Subtraction assignment to sparse vectors****************************************************
610  // No special implementation for the subtraction assignment to sparse vectors.
611  //**********************************************************************************************
612 
613  //**Multiplication assignment to dense vectors**************************************************
627  template< typename VT2 > // Type of the target dense vector
628  friend inline typename EnableIf< UseAssign<VT2> >::Type
629  multAssign( DenseVector<VT2,TF>& lhs, const DVecTransExpr& rhs )
630  {
632 
633  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
634 
635  DVecTransposer<VT2,!TF> tmp( ~lhs );
636  multAssign( tmp, rhs.dv_ );
637  }
639  //**********************************************************************************************
640 
641  //**Multiplication assignment to sparse vectors*************************************************
642  // No special implementation for the multiplication assignment to sparse vectors.
643  //**********************************************************************************************
644 
645  //**Trans function******************************************************************************
663  template< typename VT2 // Type of the dense vector
664  , bool TF2 > // Transpose flag of the dense vector
665  friend inline Operand trans( const DVecTransExpr<VT2,TF2>& dv )
666  {
668 
669  return dv.dv_;
670  }
672  //**********************************************************************************************
673 
674  //**Compile time checks*************************************************************************
679  //**********************************************************************************************
680 };
681 //*************************************************************************************************
682 
683 
684 
685 
686 //=================================================================================================
687 //
688 // GLOBAL OPERATORS
689 //
690 //=================================================================================================
691 
692 //*************************************************************************************************
711 template< typename VT // Type of the dense vector
712  , bool TF > // Transpose flag
714 {
716 
717  return DVecTransExpr<VT,!TF>( ~dv );
718 }
719 //*************************************************************************************************
720 
721 
722 
723 
724 //=================================================================================================
725 //
726 // EXPRESSION TRAIT SPECIALIZATIONS
727 //
728 //=================================================================================================
729 
730 //*************************************************************************************************
732 template< typename VT, bool TF >
733 struct SubvectorExprTrait< DVecTransExpr<VT,TF> >
734 {
735  public:
736  //**********************************************************************************************
737  typedef typename TransExprTrait< typename SubvectorExprTrait<const VT>::Type >::Type Type;
738  //**********************************************************************************************
739 };
741 //*************************************************************************************************
742 
743 } // namespace blaze
744 
745 #endif
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: DVecTransExpr.h:483
Pointer difference type of the Blaze library.
VT::TransposeType ResultType
Result type for expression template evaluations.
Definition: DVecTransExpr.h:115
ElementType & ReferenceType
Reference return type.
Definition: DVecTransExpr.h:140
const ElementType * data() const
Low-level data access to the vector elements.
Definition: DVecTransExpr.h:419
Base class for all vector transposition expression templates.The VecTransExpr class serves as a tag f...
Definition: VecTransExpr.h:65
const ConstIterator operator++(int)
Post-increment operator.
Definition: DVecTransExpr.h:204
const DMatTransExpr< MT,!SO > trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:446
VT::ConstIterator IteratorType
ConstIterator type of the dense vector expression.
Definition: DVecTransExpr.h:151
std::random_access_iterator_tag IteratorCategory
The iterator category.
Definition: DVecTransExpr.h:137
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2375
ConstIterator end() const
Returns an iterator just past the last non-zero element of the dense vector.
Definition: DVecTransExpr.h:439
ConstIterator & operator--()
Pre-decrement operator.
Definition: DVecTransExpr.h:214
ConstIterator & operator+=(size_t inc)
Addition assignment operator.
Definition: DVecTransExpr.h:170
Header file for the DenseVector base class.
friend const ConstIterator operator+(size_t inc, const ConstIterator &it)
Addition between an integral value and a ConstIterator.
Definition: DVecTransExpr.h:346
Header file for the Computation base class.
Iterator over the elements of the dense vector.
Definition: DVecTransExpr.h:133
IntrinsicTrait< ElementType >::Type IntrinsicType
Resulting intrinsic element type.
Definition: DVecTransExpr.h:121
Header file for the RequiresEvaluation type trait.
SelectType< useAssign, const ResultType, const DVecTransExpr & >::Type CompositeType
Data type for composite expression templates.
Definition: DVecTransExpr.h:124
ConstIterator(IteratorType iterator)
Constructor for the ConstIterator class.
Definition: DVecTransExpr.h:159
IntrinsicType load(size_t index) const
Access to the intrinsic elements of the vector.
Definition: DVecTransExpr.h:406
Expression object for the transposition of a dense vector.The DVecTransposer class is a wrapper objec...
Definition: DVecTransposer.h:71
Operand dv_
Dense vector of the transposition expression.
Definition: DVecTransExpr.h:490
VT::ReturnType ReturnType
Return type for expression template evaluations.
Definition: DVecTransExpr.h:118
Compile time check to query the requirement to evaluate an expression.Via this type trait it is possi...
Definition: RequiresEvaluation.h:90
SelectType< IsExpression< VT >::value, const VT, const VT & >::Type Operand
Composite data type of the dense vector expression.
Definition: DVecTransExpr.h:127
ReferenceType reference
Reference return type.
Definition: DVecTransExpr.h:147
Compile time type selection.The SelectType class template selects one of the two given types T1 and T...
Definition: SelectType.h:59
IntrinsicType load() const
Access to the intrinsic elements of the vector.
Definition: DVecTransExpr.h:245
bool operator!=(const ConstIterator &rhs) const
Inequality comparison between two ConstIterator objects.
Definition: DVecTransExpr.h:267
ElementType ValueType
Type of the underlying elements.
Definition: DVecTransExpr.h:138
Header file for the dense vector transposer.
ConstIterator & operator-=(size_t dec)
Subtraction assignment operator.
Definition: DVecTransExpr.h:182
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2379
VT::ResultType TransposeType
Transpose type for expression template evaluations.
Definition: DVecTransExpr.h:116
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
Expression object for the transposition of a sparse vector.The SVecTransposer class is a wrapper obje...
Definition: Forward.h:119
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: DVecTransExpr.h:471
bool operator>(const ConstIterator &rhs) const
Greater-than comparison between two ConstIterator objects.
Definition: DVecTransExpr.h:289
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: DVecTransExpr.h:141
Constraint on the data type.
bool operator>=(const ConstIterator &rhs) const
Greater-than comparison between two ConstIterator objects.
Definition: DVecTransExpr.h:311
CompressedMatrix< Type, false > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:2372
Constraint on the data type.
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2373
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
ReturnType operator*() const
Direct access to the element at the current iterator position.
Definition: DVecTransExpr.h:235
bool operator==(const ConstIterator &rhs) const
Equality comparison between two ConstIterator objects.
Definition: DVecTransExpr.h:256
Header file for the SelectType class template.
Header file for all forward declarations for expression class templates.
Header file for the EnableIf class template.
DifferenceType operator-(const ConstIterator &rhs) const
Calculating the number of elements between two iterators.
Definition: DVecTransExpr.h:322
bool operator<=(const ConstIterator &rhs) const
Less-than comparison between two ConstIterator objects.
Definition: DVecTransExpr.h:300
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2374
Header file for the VecTransExpr base class.
Intrinsic characteristics of data types.The IntrinsicTrait class template provides the intrinsic char...
Definition: IntrinsicTrait.h:648
Header file for run time assertion macros.
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
VT::ElementType ElementType
Resulting element type.
Definition: DVecTransExpr.h:117
friend const ConstIterator operator+(const ConstIterator &it, size_t inc)
Addition between a ConstIterator and an integral value.
Definition: DVecTransExpr.h:334
Substitution Failure Is Not An Error (SFINAE) class.The EnableIf class template is an auxiliary tool ...
Definition: EnableIf.h:184
PointerType pointer
Pointer return type.
Definition: DVecTransExpr.h:146
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
Header file for the TransExprTrait class template.
VT::CompositeType CT
Composite type of the dense vector expression.
Definition: DVecTransExpr.h:88
DVecTransExpr(const VT &dv)
Constructor for the DVecTransExpr class.
Definition: DVecTransExpr.h:383
DifferenceType difference_type
Difference between two iterators.
Definition: DVecTransExpr.h:148
ElementType * PointerType
Pointer return type.
Definition: DVecTransExpr.h:139
const ConstIterator operator--(int)
Post-decrement operator.
Definition: DVecTransExpr.h:225
Header file for all intrinsic functionality.
#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
Header file for the sparse vector transposer.
ConstIterator & operator++()
Pre-increment operator.
Definition: DVecTransExpr.h:193
Header file for the IsComputation type trait class.
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:2370
bool operator<(const ConstIterator &rhs) const
Less-than comparison between two ConstIterator objects.
Definition: DVecTransExpr.h:278
IteratorCategory iterator_category
The iterator category.
Definition: DVecTransExpr.h:144
size_t size() const
Returns the current size/dimension of the vector.
Definition: DVecTransExpr.h:449
Header file for basic type definitions.
Header file for the SubvectorExprTrait class template.
Expression object for dense vector transpositions.The DVecTransExpr class represents the compile time...
Definition: DVecTransExpr.h:82
IteratorType iterator_
Iterator to the current element.
Definition: DVecTransExpr.h:365
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: DVecTransExpr.h:394
ConstIterator begin() const
Returns an iterator to the first non-zero element of the dense vector.
Definition: DVecTransExpr.h:429
Header file for the empty type.
ValueType value_type
Type of the underlying elements.
Definition: DVecTransExpr.h:145
friend const ConstIterator operator-(const ConstIterator &it, size_t dec)
Subtraction between a ConstIterator and an integral value.
Definition: DVecTransExpr.h:358
#define BLAZE_CONSTRAINT_MUST_BE_VECTOR_WITH_TRANSPOSE_FLAG(T, TF)
Constraint on the data type.In case the given data type T is not a dense or sparse vector type and in...
Definition: TransposeFlag.h:238
Operand operand() const
Returns the dense vector operand.
Definition: DVecTransExpr.h:459
#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
DVecTransExpr< VT, TF > This
Type of this DVecTransExpr instance.
Definition: DVecTransExpr.h:114
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.