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>
59 #include <blaze/util/Assert.h>
60 #include <blaze/util/EmptyType.h>
61 #include <blaze/util/EnableIf.h>
63 #include <blaze/util/SelectType.h>
64 #include <blaze/util/Types.h>
65 
66 
67 namespace blaze {
68 
69 //=================================================================================================
70 //
71 // CLASS DVECTRANSEXPR
72 //
73 //=================================================================================================
74 
75 //*************************************************************************************************
82 template< typename VT // Type of the dense vector
83  , bool TF > // Transpose flag
84 class DVecTransExpr : public DenseVector< DVecTransExpr<VT,TF>, TF >
85  , private VecTransExpr
86  , private SelectType< IsComputation<VT>::value, Computation, EmptyType >::Type
87 {
88  private:
89  //**Type definitions****************************************************************************
90  typedef typename VT::CompositeType CT;
91  //**********************************************************************************************
92 
93  //**********************************************************************************************
95 
101  enum { useAssign = RequiresEvaluation<VT>::value };
102  //**********************************************************************************************
103 
104  //**********************************************************************************************
106  template< typename VT2 >
108  struct UseAssign {
109  enum { value = useAssign };
110  };
112  //**********************************************************************************************
113 
114  public:
115  //**Type definitions****************************************************************************
117  typedef typename VT::TransposeType ResultType;
118  typedef typename VT::ResultType TransposeType;
119  typedef typename VT::ElementType ElementType;
120  typedef typename VT::ReturnType ReturnType;
121 
124 
127 
129  typedef typename SelectType< IsExpression<VT>::value, const VT, const VT& >::Type Operand;
130  //**********************************************************************************************
131 
132  //**ConstIterator class definition**************************************************************
136  {
137  public:
138  //**Type definitions*************************************************************************
139  typedef std::random_access_iterator_tag IteratorCategory;
144 
145  // STL iterator requirements
151 
153  typedef typename VT::ConstIterator IteratorType;
154  //*******************************************************************************************
155 
156  //**Constructor******************************************************************************
161  explicit inline ConstIterator( IteratorType iterator )
162  : iterator_( iterator ) // Iterator to the current element
163  {}
164  //*******************************************************************************************
165 
166  //**Addition assignment operator*************************************************************
172  inline ConstIterator& operator+=( size_t inc ) {
173  iterator_ += inc;
174  return *this;
175  }
176  //*******************************************************************************************
177 
178  //**Subtraction assignment operator**********************************************************
184  inline ConstIterator& operator-=( size_t dec ) {
185  iterator_ -= dec;
186  return *this;
187  }
188  //*******************************************************************************************
189 
190  //**Prefix increment operator****************************************************************
196  ++iterator_;
197  return *this;
198  }
199  //*******************************************************************************************
200 
201  //**Postfix increment operator***************************************************************
206  inline const ConstIterator operator++( int ) {
207  return ConstIterator( iterator_++ );
208  }
209  //*******************************************************************************************
210 
211  //**Prefix decrement operator****************************************************************
217  --iterator_;
218  return *this;
219  }
220  //*******************************************************************************************
221 
222  //**Postfix decrement operator***************************************************************
227  inline const ConstIterator operator--( int ) {
228  return ConstIterator( iterator_-- );
229  }
230  //*******************************************************************************************
231 
232  //**Element access operator******************************************************************
237  inline ReturnType operator*() const {
238  return *iterator_;
239  }
240  //*******************************************************************************************
241 
242  //**Load function****************************************************************************
247  inline IntrinsicType load() const {
248  return iterator_.load();
249  }
250  //*******************************************************************************************
251 
252  //**Equality operator************************************************************************
258  inline bool operator==( const ConstIterator& rhs ) const {
259  return iterator_ == rhs.iterator_;
260  }
261  //*******************************************************************************************
262 
263  //**Inequality operator**********************************************************************
269  inline bool operator!=( const ConstIterator& rhs ) const {
270  return iterator_ != rhs.iterator_;
271  }
272  //*******************************************************************************************
273 
274  //**Less-than operator***********************************************************************
280  inline bool operator<( const ConstIterator& rhs ) const {
281  return iterator_ < rhs.iterator_;
282  }
283  //*******************************************************************************************
284 
285  //**Greater-than operator********************************************************************
291  inline bool operator>( const ConstIterator& rhs ) const {
292  return iterator_ > rhs.iterator_;
293  }
294  //*******************************************************************************************
295 
296  //**Less-or-equal-than operator**************************************************************
302  inline bool operator<=( const ConstIterator& rhs ) const {
303  return iterator_ <= rhs.iterator_;
304  }
305  //*******************************************************************************************
306 
307  //**Greater-or-equal-than operator***********************************************************
313  inline bool operator>=( const ConstIterator& rhs ) const {
314  return iterator_ >= rhs.iterator_;
315  }
316  //*******************************************************************************************
317 
318  //**Subtraction operator*********************************************************************
324  inline DifferenceType operator-( const ConstIterator& rhs ) const {
325  return iterator_ - rhs.iterator_;
326  }
327  //*******************************************************************************************
328 
329  //**Addition operator************************************************************************
336  friend inline const ConstIterator operator+( const ConstIterator& it, size_t inc ) {
337  return ConstIterator( it.iterator_ + inc );
338  }
339  //*******************************************************************************************
340 
341  //**Addition operator************************************************************************
348  friend inline const ConstIterator operator+( size_t inc, const ConstIterator& it ) {
349  return ConstIterator( it.iterator_ + inc );
350  }
351  //*******************************************************************************************
352 
353  //**Subtraction operator*********************************************************************
360  friend inline const ConstIterator operator-( const ConstIterator& it, size_t dec ) {
361  return ConstIterator( it.iterator_ - dec );
362  }
363  //*******************************************************************************************
364 
365  private:
366  //**Member variables*************************************************************************
368  //*******************************************************************************************
369  };
370  //**********************************************************************************************
371 
372  //**Compilation flags***************************************************************************
374  enum { vectorizable = VT::vectorizable };
375 
377  enum { smpAssignable = VT::smpAssignable };
378  //**********************************************************************************************
379 
380  //**Constructor*********************************************************************************
385  explicit inline DVecTransExpr( const VT& dv )
386  : dv_( dv ) // Dense vector of the transposition expression
387  {}
388  //**********************************************************************************************
389 
390  //**Subscript operator**************************************************************************
396  inline ReturnType operator[]( size_t index ) const {
397  BLAZE_INTERNAL_ASSERT( index < dv_.size(), "Invalid vector access index" );
398  return dv_[index];
399  }
400  //**********************************************************************************************
401 
402  //**Load function*******************************************************************************
408  inline IntrinsicType load( size_t index ) const {
409  typedef IntrinsicTrait<ElementType> IT;
410  BLAZE_INTERNAL_ASSERT( index < dv_.size() , "Invalid vector access index" );
411  BLAZE_INTERNAL_ASSERT( index % IT::size == 0UL , "Invalid vector access index" );
412  return dv_.load( index );
413  }
414  //**********************************************************************************************
415 
416  //**Low-level data access***********************************************************************
421  inline const ElementType* data() const {
422  return dv_.data();
423  }
424  //**********************************************************************************************
425 
426  //**Begin function******************************************************************************
431  inline ConstIterator begin() const {
432  return ConstIterator( dv_.begin() );
433  }
434  //**********************************************************************************************
435 
436  //**End function********************************************************************************
441  inline ConstIterator end() const {
442  return ConstIterator( dv_.end() );
443  }
444  //**********************************************************************************************
445 
446  //**Size function*******************************************************************************
451  inline size_t size() const {
452  return dv_.size();
453  }
454  //**********************************************************************************************
455 
456  //**Operand access******************************************************************************
461  inline Operand operand() const {
462  return dv_;
463  }
464  //**********************************************************************************************
465 
466  //**********************************************************************************************
472  template< typename T >
473  inline bool canAlias( const T* alias ) const {
474  return dv_.canAlias( alias );
475  }
476  //**********************************************************************************************
477 
478  //**********************************************************************************************
484  template< typename T >
485  inline bool isAliased( const T* alias ) const {
486  return dv_.isAliased( alias );
487  }
488  //**********************************************************************************************
489 
490  //**********************************************************************************************
495  inline bool isAligned() const {
496  return dv_.isAligned();
497  }
498  //**********************************************************************************************
499 
500  //**********************************************************************************************
505  inline bool canSMPAssign() const {
506  return dv_.canSMPAssign();
507  }
508  //**********************************************************************************************
509 
510  private:
511  //**Member variables****************************************************************************
513  //**********************************************************************************************
514 
515  //**Assignment to dense vectors*****************************************************************
529  template< typename VT2 > // Type of the target dense vector
530  friend inline typename EnableIf< UseAssign<VT2> >::Type
531  assign( DenseVector<VT2,TF>& lhs, const DVecTransExpr& rhs )
532  {
534 
535  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
536 
537  DVecTransposer<VT2,!TF> tmp( ~lhs );
538  assign( tmp, rhs.dv_ );
539  }
541  //**********************************************************************************************
542 
543  //**Assignment to sparse vectors****************************************************************
557  template< typename VT2 > // Type of the target sparse vector
558  friend inline typename EnableIf< UseAssign<VT2> >::Type
559  assign( SparseVector<VT2,TF>& lhs, const DVecTransExpr& rhs )
560  {
562 
563  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
564 
565  SVecTransposer<VT2,!TF> tmp( ~lhs );
566  assign( tmp, rhs.dv_ );
567  }
569  //**********************************************************************************************
570 
571  //**Addition assignment to dense vectors********************************************************
585  template< typename VT2 > // Type of the target dense vector
586  friend inline typename EnableIf< UseAssign<VT2> >::Type
587  addAssign( DenseVector<VT2,TF>& lhs, const DVecTransExpr& rhs )
588  {
590 
591  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
592 
593  DVecTransposer<VT2,!TF> tmp( ~lhs );
594  addAssign( tmp, rhs.dv_ );
595  }
597  //**********************************************************************************************
598 
599  //**Addition assignment to sparse vectors*******************************************************
600  // No special implementation for the addition assignment to sparse vectors.
601  //**********************************************************************************************
602 
603  //**Subtraction assignment to dense vectors*****************************************************
617  template< typename VT2 > // Type of the target dense vector
618  friend inline typename EnableIf< UseAssign<VT2> >::Type
619  subAssign( DenseVector<VT2,TF>& lhs, const DVecTransExpr& rhs )
620  {
622 
623  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
624 
625  DVecTransposer<VT2,!TF> tmp( ~lhs );
626  subAssign( tmp, rhs.dv_ );
627  }
629  //**********************************************************************************************
630 
631  //**Subtraction assignment to sparse vectors****************************************************
632  // No special implementation for the subtraction assignment to sparse vectors.
633  //**********************************************************************************************
634 
635  //**Multiplication assignment to dense vectors**************************************************
649  template< typename VT2 > // Type of the target dense vector
650  friend inline typename EnableIf< UseAssign<VT2> >::Type
651  multAssign( DenseVector<VT2,TF>& lhs, const DVecTransExpr& rhs )
652  {
654 
655  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
656 
657  DVecTransposer<VT2,!TF> tmp( ~lhs );
658  multAssign( tmp, rhs.dv_ );
659  }
661  //**********************************************************************************************
662 
663  //**Multiplication assignment to sparse vectors*************************************************
664  // No special implementation for the multiplication assignment to sparse vectors.
665  //**********************************************************************************************
666 
667  //**Trans function******************************************************************************
685  template< typename VT2 // Type of the dense vector
686  , bool TF2 > // Transpose flag of the dense vector
687  friend inline Operand trans( const DVecTransExpr<VT2,TF2>& dv )
688  {
690 
691  return dv.dv_;
692  }
694  //**********************************************************************************************
695 
696  //**Compile time checks*************************************************************************
701  //**********************************************************************************************
702 };
703 //*************************************************************************************************
704 
705 
706 
707 
708 //=================================================================================================
709 //
710 // GLOBAL OPERATORS
711 //
712 //=================================================================================================
713 
714 //*************************************************************************************************
733 template< typename VT // Type of the dense vector
734  , bool TF > // Transpose flag
736 {
738 
739  return DVecTransExpr<VT,!TF>( ~dv );
740 }
741 //*************************************************************************************************
742 
743 
744 
745 
746 //=================================================================================================
747 //
748 // EXPRESSION TRAIT SPECIALIZATIONS
749 //
750 //=================================================================================================
751 
752 //*************************************************************************************************
754 template< typename VT, bool TF, bool AF >
755 struct SubvectorExprTrait< DVecTransExpr<VT,TF>, AF >
756 {
757  public:
758  //**********************************************************************************************
759  typedef typename TransExprTrait< typename SubvectorExprTrait<const VT,AF>::Type >::Type Type;
760  //**********************************************************************************************
761 };
763 //*************************************************************************************************
764 
765 } // namespace blaze
766 
767 #endif
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: DVecTransExpr.h:485
Pointer difference type of the Blaze library.
VT::TransposeType ResultType
Result type for expression template evaluations.
Definition: DVecTransExpr.h:117
ElementType & ReferenceType
Reference return type.
Definition: DVecTransExpr.h:142
const ElementType * data() const
Low-level data access to the vector elements.
Definition: DVecTransExpr.h:421
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:206
const DMatTransExpr< MT,!SO > trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:751
VT::ConstIterator IteratorType
ConstIterator type of the dense vector expression.
Definition: DVecTransExpr.h:153
std::random_access_iterator_tag IteratorCategory
The iterator category.
Definition: DVecTransExpr.h:139
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2384
ConstIterator end() const
Returns an iterator just past the last non-zero element of the dense vector.
Definition: DVecTransExpr.h:441
ConstIterator & operator--()
Pre-decrement operator.
Definition: DVecTransExpr.h:216
ConstIterator & operator+=(size_t inc)
Addition assignment operator.
Definition: DVecTransExpr.h:172
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:348
Header file for the Computation base class.
Iterator over the elements of the dense vector.
Definition: DVecTransExpr.h:135
IntrinsicTrait< ElementType >::Type IntrinsicType
Resulting intrinsic element type.
Definition: DVecTransExpr.h:123
Header file for the RequiresEvaluation type trait.
SelectType< useAssign, const ResultType, const DVecTransExpr & >::Type CompositeType
Data type for composite expression templates.
Definition: DVecTransExpr.h:126
ConstIterator(IteratorType iterator)
Constructor for the ConstIterator class.
Definition: DVecTransExpr.h:161
IntrinsicType load(size_t index) const
Access to the intrinsic elements of the vector.
Definition: DVecTransExpr.h:408
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:512
VT::ReturnType ReturnType
Return type for expression template evaluations.
Definition: DVecTransExpr.h:120
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:129
ReferenceType reference
Reference return type.
Definition: DVecTransExpr.h:149
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 dense vector SMP implementation.
IntrinsicType load() const
Access to the intrinsic elements of the vector.
Definition: DVecTransExpr.h:247
bool operator!=(const ConstIterator &rhs) const
Inequality comparison between two ConstIterator objects.
Definition: DVecTransExpr.h:269
ElementType ValueType
Type of the underlying elements.
Definition: DVecTransExpr.h:140
Header file for the dense vector transposer.
bool canSMPAssign() const
Returns whether the expression can be used in SMP assignments.
Definition: DVecTransExpr.h:505
ConstIterator & operator-=(size_t dec)
Subtraction assignment operator.
Definition: DVecTransExpr.h:184
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2388
VT::ResultType TransposeType
Transpose type for expression template evaluations.
Definition: DVecTransExpr.h:118
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:473
bool operator>(const ConstIterator &rhs) const
Greater-than comparison between two ConstIterator objects.
Definition: DVecTransExpr.h:291
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: DVecTransExpr.h:143
Constraint on the data type.
bool operator>=(const ConstIterator &rhs) const
Greater-than comparison between two ConstIterator objects.
Definition: DVecTransExpr.h:313
CompressedMatrix< Type, false > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:2381
Constraint on the data type.
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2382
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:237
bool operator==(const ConstIterator &rhs) const
Equality comparison between two ConstIterator objects.
Definition: DVecTransExpr.h:258
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:324
bool operator<=(const ConstIterator &rhs) const
Less-than comparison between two ConstIterator objects.
Definition: DVecTransExpr.h:302
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2383
Header file for the VecTransExpr base class.
Intrinsic characteristics of data types.The IntrinsicTrait class template provides the intrinsic char...
Definition: IntrinsicTrait.h:748
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:119
friend const ConstIterator operator+(const ConstIterator &it, size_t inc)
Addition between a ConstIterator and an integral value.
Definition: DVecTransExpr.h:336
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:148
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:90
DVecTransExpr(const VT &dv)
Constructor for the DVecTransExpr class.
Definition: DVecTransExpr.h:385
DifferenceType difference_type
Difference between two iterators.
Definition: DVecTransExpr.h:150
ElementType * PointerType
Pointer return type.
Definition: DVecTransExpr.h:141
const ConstIterator operator--(int)
Post-decrement operator.
Definition: DVecTransExpr.h:227
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:195
bool isAligned() const
Returns whether the operands of the expression are properly aligned in memory.
Definition: DVecTransExpr.h:495
Header file for the IsComputation type trait class.
Header file for the sparse vector SMP implementation.
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:2379
bool operator<(const ConstIterator &rhs) const
Less-than comparison between two ConstIterator objects.
Definition: DVecTransExpr.h:280
IteratorCategory iterator_category
The iterator category.
Definition: DVecTransExpr.h:146
size_t size() const
Returns the current size/dimension of the vector.
Definition: DVecTransExpr.h:451
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:84
IteratorType iterator_
Iterator to the current element.
Definition: DVecTransExpr.h:367
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: DVecTransExpr.h:396
ConstIterator begin() const
Returns an iterator to the first non-zero element of the dense vector.
Definition: DVecTransExpr.h:431
Header file for the empty type.
ValueType value_type
Type of the underlying elements.
Definition: DVecTransExpr.h:147
friend const ConstIterator operator-(const ConstIterator &it, size_t dec)
Subtraction between a ConstIterator and an integral value.
Definition: DVecTransExpr.h:360
#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:461
#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:116
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.