All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SVecTransExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_SVECTRANSEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_SVECTRANSEXPR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <iterator>
55 #include <blaze/util/Assert.h>
56 #include <blaze/util/EmptyType.h>
57 #include <blaze/util/EnableIf.h>
59 #include <blaze/util/SelectType.h>
60 #include <blaze/util/Types.h>
62 
63 
64 namespace blaze {
65 
66 //=================================================================================================
67 //
68 // CLASS SVECTRANSEXPR
69 //
70 //=================================================================================================
71 
72 //*************************************************************************************************
79 template< typename VT // Type of the sparse vector
80  , bool TF > // Transpose flag
81 class SVecTransExpr : public SparseVector< SVecTransExpr<VT,TF>, TF >
82  , private VecTransExpr
83  , private SelectType< IsComputation<VT>::value, Computation, EmptyType >::Type
84 {
85  private:
86  //**Type definitions****************************************************************************
87  typedef typename VT::CompositeType CT;
88  //**********************************************************************************************
89 
90  //**********************************************************************************************
92 
98  enum { useAssign = RequiresEvaluation<VT>::value };
99  //**********************************************************************************************
100 
101  //**********************************************************************************************
103  template< typename VT2 >
105  struct UseAssign {
106  enum { value = useAssign };
107  };
109  //**********************************************************************************************
110 
111  public:
112  //**Type definitions****************************************************************************
114  typedef typename VT::TransposeType ResultType;
115  typedef typename VT::ResultType TransposeType;
116  typedef typename VT::ElementType ElementType;
117  typedef typename VT::ReturnType ReturnType;
118 
121 
123  typedef typename SelectType< IsExpression<VT>::value, const VT, const VT& >::Type Operand;
124  //**********************************************************************************************
125 
126  //**Compilation flags***************************************************************************
128  enum { smpAssignable = VT::smpAssignable };
129  //**********************************************************************************************
130 
131  //**ConstIterator class definition**************************************************************
135  {
136  public:
137  //**Type definitions*************************************************************************
140 
141  typedef std::forward_iterator_tag IteratorCategory;
142  typedef typename std::iterator_traits<IteratorType>::value_type ValueType;
143  typedef typename std::iterator_traits<IteratorType>::pointer PointerType;
144  typedef typename std::iterator_traits<IteratorType>::reference ReferenceType;
145  typedef typename std::iterator_traits<IteratorType>::difference_type DifferenceType;
146 
147  // STL iterator requirements
153  //*******************************************************************************************
154 
155  //**Constructor******************************************************************************
159  : it_( it ) // Iterator over the elements of the sparse vector expression
160  {}
161  //*******************************************************************************************
162 
163  //**Prefix increment operator****************************************************************
169  ++it_;
170  return *this;
171  }
172  //*******************************************************************************************
173 
174  //**Element access operator******************************************************************
179  inline const ValueType operator*() const {
180  return *it_;
181  }
182  //*******************************************************************************************
183 
184  //**Element access operator******************************************************************
189  inline const ConstIterator* operator->() const {
190  return this;
191  }
192  //*******************************************************************************************
193 
194  //**Value function***************************************************************************
199  inline ReturnType value() const {
200  return it_->value();
201  }
202  //*******************************************************************************************
203 
204  //**Index function***************************************************************************
209  inline size_t index() const {
210  return it_->index();
211  }
212  //*******************************************************************************************
213 
214  //**Equality operator************************************************************************
220  inline bool operator==( const ConstIterator& rhs ) const {
221  return it_ == rhs.it_;
222  }
223  //*******************************************************************************************
224 
225  //**Inequality operator**********************************************************************
231  inline bool operator!=( const ConstIterator& rhs ) const {
232  return it_ != rhs.it_;
233  }
234  //*******************************************************************************************
235 
236  //**Subtraction operator*********************************************************************
242  inline DifferenceType operator-( const ConstIterator& rhs ) const {
243  return it_ - rhs.it_;
244  }
245  //*******************************************************************************************
246 
247  private:
248  //**Member variables*************************************************************************
250  //*******************************************************************************************
251  };
252  //**********************************************************************************************
253 
254  //**Constructor*********************************************************************************
259  explicit inline SVecTransExpr( const VT& sv )
260  : sv_( sv ) // Sparse vector of the transposition expression
261  {}
262  //**********************************************************************************************
263 
264  //**Subscript operator**************************************************************************
270  inline ReturnType operator[]( size_t index ) const {
271  BLAZE_INTERNAL_ASSERT( index < sv_.size(), "Invalid vector access index" );
272  return sv_[index];
273  }
274  //**********************************************************************************************
275 
276  //**Begin function******************************************************************************
281  inline ConstIterator begin() const {
282  return ConstIterator( sv_.begin() );
283  }
284  //**********************************************************************************************
285 
286  //**End function********************************************************************************
291  inline ConstIterator end() const {
292  return ConstIterator( sv_.end() );
293  }
294  //**********************************************************************************************
295 
296  //**Size function*******************************************************************************
301  inline size_t size() const {
302  return sv_.size();
303  }
304  //**********************************************************************************************
305 
306  //**NonZeros function***************************************************************************
311  inline size_t nonZeros() const {
312  return sv_.nonZeros();
313  }
314  //**********************************************************************************************
315 
316  //**Operand access******************************************************************************
321  inline Operand operand() const {
322  return sv_;
323  }
324  //**********************************************************************************************
325 
326  //**********************************************************************************************
332  template< typename T >
333  inline bool canAlias( const T* alias ) const {
334  return sv_.canAlias( alias );
335  }
336  //**********************************************************************************************
337 
338  //**********************************************************************************************
344  template< typename T >
345  inline bool isAliased( const T* alias ) const {
346  return sv_.isAliased( alias );
347  }
348  //**********************************************************************************************
349 
350  //**********************************************************************************************
355  inline bool canSMPAssign() const {
356  return sv_.canSMPAssign();
357  }
358  //**********************************************************************************************
359 
360  private:
361  //**Member variables****************************************************************************
363  //**********************************************************************************************
364 
365  //**Assignment to dense vectors*****************************************************************
379  template< typename VT2 > // Type of the target dense vector
380  friend inline typename EnableIf< UseAssign<VT2> >::Type
381  assign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
382  {
384 
385  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
386 
387  DVecTransposer<VT2,!TF> tmp( ~lhs );
388  assign( tmp, rhs.sv_ );
389  }
391  //**********************************************************************************************
392 
393  //**Assignment to sparse vectors****************************************************************
407  template< typename VT2 > // Type of the target sparse vector
408  friend inline typename EnableIf< UseAssign<VT2> >::Type
409  assign( SparseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
410  {
412 
413  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
414 
415  SVecTransposer<VT2,!TF> tmp( ~lhs );
416  assign( tmp, rhs.sv_ );
417  }
419  //**********************************************************************************************
420 
421  //**Addition assignment to dense vectors********************************************************
435  template< typename VT2 > // Type of the target dense vector
436  friend inline typename EnableIf< UseAssign<VT2> >::Type
437  addAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
438  {
440 
441  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
442 
443  DVecTransposer<VT2,!TF> tmp( ~lhs );
444  addAssign( tmp, rhs.sv_ );
445  }
447  //**********************************************************************************************
448 
449  //**Addition assignment to sparse vectors*******************************************************
450  // No special implementation for the addition assignment to sparse vectors.
451  //**********************************************************************************************
452 
453  //**Subtraction assignment to dense vectors*****************************************************
467  template< typename VT2 > // Type of the target dense vector
468  friend inline typename EnableIf< UseAssign<VT2> >::Type
469  subAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
470  {
472 
473  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
474 
475  DVecTransposer<VT2,!TF> tmp( ~lhs );
476  subAssign( tmp, rhs.sv_ );
477  }
479  //**********************************************************************************************
480 
481  //**Subtraction assignment to sparse vectors****************************************************
482  // No special implementation for the subtraction assignment to sparse vectors.
483  //**********************************************************************************************
484 
485  //**Multiplication assignment to dense vectors**************************************************
499  template< typename VT2 > // Type of the target dense vector
500  friend inline typename EnableIf< UseAssign<VT2> >::Type
501  multAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
502  {
504 
505  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
506 
507  DVecTransposer<VT2,!TF> tmp( ~lhs );
508  multAssign( tmp, rhs.sv_ );
509  }
511  //**********************************************************************************************
512 
513  //**Multiplication assignment to sparse vectors*************************************************
514  // No special implementation for the multiplication assignment to sparse vectors.
515  //**********************************************************************************************
516 
517  //**Trans function******************************************************************************
535  template< typename VT2 // Type of the sparse vector
536  , bool TF2 > // Transpose flag of the sparse vector
537  friend inline Operand trans( const SVecTransExpr<VT2,TF2>& sv )
538  {
540 
541  return sv.sv_;
542  }
544  //**********************************************************************************************
545 
546  //**Compile time checks*************************************************************************
550  //**********************************************************************************************
551 };
552 //*************************************************************************************************
553 
554 
555 
556 
557 //=================================================================================================
558 //
559 // GLOBAL OPERATORS
560 //
561 //=================================================================================================
562 
563 //*************************************************************************************************
582 template< typename VT // Type of the sparse vector
583  , bool TF > // Transpose flag
585 {
587 
588  return SVecTransExpr<VT,!TF>( ~sv );
589 }
590 //*************************************************************************************************
591 
592 
593 
594 
595 //=================================================================================================
596 //
597 // EXPRESSION TRAIT SPECIALIZATIONS
598 //
599 //=================================================================================================
600 
601 //*************************************************************************************************
603 template< typename VT, bool TF, bool AF >
604 struct SubvectorExprTrait< SVecTransExpr<VT,TF>, AF >
605 {
606  public:
607  //**********************************************************************************************
608  typedef typename TransExprTrait< typename SubvectorExprTrait<const VT,AF>::Type >::Type Type;
609  //**********************************************************************************************
610 };
612 //*************************************************************************************************
613 
614 } // namespace blaze
615 
616 #endif
RemoveReference< Operand >::Type::ConstIterator IteratorType
Iterator type of the sparse vector expression.
Definition: SVecTransExpr.h:139
ConstIterator end() const
Returns an iterator just past the last non-zero element of the sparse vector.
Definition: SVecTransExpr.h:291
size_t size() const
Returns the current size/dimension of the vector.
Definition: SVecTransExpr.h:301
Header file for the SparseVector base class.
ConstIterator(IteratorType it)
Constructor for the ConstIterator class.
Definition: SVecTransExpr.h:158
const DMatTransExpr< MT,!SO > trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:751
ConstIterator & operator++()
Pre-increment operator.
Definition: SVecTransExpr.h:168
IteratorCategory iterator_category
The iterator category.
Definition: SVecTransExpr.h:148
SelectType< IsExpression< VT >::value, const VT, const VT & >::Type Operand
Composite data type of the sparse vector expression.
Definition: SVecTransExpr.h:123
VT::ReturnType ReturnType
Return type for expression template evaluations.
Definition: SVecTransExpr.h:117
size_t nonZeros() const
Returns the number of non-zero elements in the sparse vector.
Definition: SVecTransExpr.h:311
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2384
ValueType value_type
Type of the underlying pointers.
Definition: SVecTransExpr.h:149
Operand sv_
Sparse vector of the transposition expression.
Definition: SVecTransExpr.h:362
Expression object for sparse vector transpositions.The SVecTransExpr class represents the compile tim...
Definition: Forward.h:118
Header file for the Computation base class.
Header file for the RequiresEvaluation type trait.
IteratorType it_
Iterator over the elements of the sparse vector expression.
Definition: SVecTransExpr.h:249
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: SVecTransExpr.h:333
VT::ResultType TransposeType
Transpose type for expression template evaluations.
Definition: SVecTransExpr.h:115
DifferenceType difference_type
Difference between two iterators.
Definition: SVecTransExpr.h:152
VT::TransposeType ResultType
Result type for expression template evaluations.
Definition: SVecTransExpr.h:114
Expression object for the transposition of a dense vector.The DVecTransposer class is a wrapper objec...
Definition: DVecTransposer.h:71
size_t index() const
Access to the current index of the sparse element.
Definition: SVecTransExpr.h:209
Compile time check to query the requirement to evaluate an expression.Via this type trait it is possi...
Definition: RequiresEvaluation.h:90
ConstIterator begin() const
Returns an iterator to the first non-zero element of the sparse vector.
Definition: SVecTransExpr.h:281
VT::CompositeType CT
Composite type of the sparse vector expression.
Definition: SVecTransExpr.h:87
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 transposer.
ReferenceType reference
Reference return type.
Definition: SVecTransExpr.h:151
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2388
const ValueType operator*() const
Direct access to the sparse vector element at the current iterator position.
Definition: SVecTransExpr.h:179
Iterator over the elements of the sparse vector absolute value expression.
Definition: SVecTransExpr.h:134
SelectType< useAssign, const ResultType, const SVecTransExpr & >::Type CompositeType
Data type for composite expression templates.
Definition: SVecTransExpr.h:120
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
VT::ElementType ElementType
Resulting element type.
Definition: SVecTransExpr.h:116
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
std::iterator_traits< IteratorType >::value_type ValueType
Type of the underlying pointers.
Definition: SVecTransExpr.h:142
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: SVecTransExpr.h:270
CompressedMatrix< Type, false > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:2381
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2382
std::iterator_traits< IteratorType >::difference_type DifferenceType
Difference between two iterators.
Definition: SVecTransExpr.h:145
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
Header file for the SelectType class template.
Header file for all forward declarations for expression class templates.
Constraint on the data type.
ReturnType value() const
Access to the current value of the sparse element.
Definition: SVecTransExpr.h:199
Header file for the EnableIf class template.
std::iterator_traits< IteratorType >::pointer PointerType
Pointer return type.
Definition: SVecTransExpr.h:143
bool operator==(const ConstIterator &rhs) const
Equality comparison between two ConstIterator objects.
Definition: SVecTransExpr.h:220
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2383
Removal of reference modifiers.The RemoveCV type trait removes any reference modifiers from the given...
Definition: RemoveReference.h:69
Header file for the VecTransExpr base class.
bool operator!=(const ConstIterator &rhs) const
Inequality comparison between two ConstIterator objects.
Definition: SVecTransExpr.h:231
Header file for run time assertion macros.
DifferenceType operator-(const ConstIterator &rhs) const
Calculating the number of elements between two expression iterators.
Definition: SVecTransExpr.h:242
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
Substitution Failure Is Not An Error (SFINAE) class.The EnableIf class template is an auxiliary tool ...
Definition: EnableIf.h:184
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
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: SVecTransExpr.h:345
Header file for the TransExprTrait class template.
PointerType pointer
Pointer return type.
Definition: SVecTransExpr.h:150
SVecTransExpr(const VT &sv)
Constructor for the SVecTransExpr class.
Definition: SVecTransExpr.h:259
Header file for the RemoveReference type trait.
Operand operand() const
Returns the sparse vector operand.
Definition: SVecTransExpr.h:321
Header file for the sparse vector transposer.
SVecTransExpr< VT, TF > This
Type of this SVecTransExpr instance.
Definition: SVecTransExpr.h:113
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
std::forward_iterator_tag IteratorCategory
The iterator category.
Definition: SVecTransExpr.h:141
bool canSMPAssign() const
Returns whether the expression can be used in SMP assignments.
Definition: SVecTransExpr.h:355
Header file for basic type definitions.
Header file for the SubvectorExprTrait class template.
const ConstIterator * operator->() const
Direct access to the sparse vector element at the current iterator position.
Definition: SVecTransExpr.h:189
Header file for the empty type.
#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
std::iterator_traits< IteratorType >::reference ReferenceType
Reference return type.
Definition: SVecTransExpr.h:144
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.