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>
44 #include <blaze/math/Aliases.h>
47 #include <blaze/math/Exception.h>
64 #include <blaze/util/Assert.h>
65 #include <blaze/util/EmptyType.h>
66 #include <blaze/util/EnableIf.h>
68 #include <blaze/util/InvalidType.h>
69 #include <blaze/util/mpl/And.h>
70 #include <blaze/util/mpl/If.h>
71 #include <blaze/util/Types.h>
74 
75 
76 namespace blaze {
77 
78 //=================================================================================================
79 //
80 // CLASS SVECTRANSEXPR
81 //
82 //=================================================================================================
83 
84 //*************************************************************************************************
91 template< typename VT // Type of the sparse vector
92  , bool TF > // Transpose flag
93 class SVecTransExpr : public SparseVector< SVecTransExpr<VT,TF>, TF >
94  , private VecTransExpr
95  , private If< IsComputation<VT>, Computation, EmptyType >::Type
96 {
97  private:
98  //**Type definitions****************************************************************************
100  //**********************************************************************************************
101 
102  //**Serial evaluation strategy******************************************************************
104 
110  enum : bool { useAssign = RequiresEvaluation<VT>::value };
111 
113  template< typename VT2 >
115  struct UseAssign {
116  enum : bool { value = useAssign };
117  };
119  //**********************************************************************************************
120 
121  //**Parallel evaluation strategy****************************************************************
123 
128  template< typename VT2 >
129  struct UseSMPAssign {
130  enum : bool { value = VT2::smpAssignable && useAssign };
131  };
133  //**********************************************************************************************
134 
135  //**********************************************************************************************
137 
141  template< typename VT2 >
142  struct GetConstIterator {
144  struct Success { using Type = typename VT2::ConstIterator; };
145  struct Failure { using Type = INVALID_TYPE; };
146  using Type = typename If_< HasConstIterator<VT2>, Success, Failure >::Type;
147  };
149  //**********************************************************************************************
150 
151  public:
152  //**Type definitions****************************************************************************
158 
161 
163  typedef typename GetConstIterator<VT>::Type ConstIterator;
164 
166  typedef If_< IsExpression<VT>, const VT, const VT& > Operand;
167  //**********************************************************************************************
168 
169  //**Compilation flags***************************************************************************
171  enum : bool { smpAssignable = VT::smpAssignable };
172  //**********************************************************************************************
173 
174  //**Constructor*********************************************************************************
179  explicit inline SVecTransExpr( const VT& sv ) noexcept
180  : sv_( sv ) // Sparse vector of the transposition expression
181  {}
182  //**********************************************************************************************
183 
184  //**Subscript operator**************************************************************************
190  inline ReturnType operator[]( size_t index ) const {
191  BLAZE_INTERNAL_ASSERT( index < sv_.size(), "Invalid vector access index" );
192  return sv_[index];
193  }
194  //**********************************************************************************************
195 
196  //**At function*********************************************************************************
203  inline ReturnType at( size_t index ) const {
204  if( index >= sv_.size() ) {
205  BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
206  }
207  return (*this)[index];
208  }
209  //**********************************************************************************************
210 
211  //**Begin function******************************************************************************
216  inline ConstIterator begin() const {
217  return ConstIterator( sv_.begin() );
218  }
219  //**********************************************************************************************
220 
221  //**End function********************************************************************************
226  inline ConstIterator end() const {
227  return ConstIterator( sv_.end() );
228  }
229  //**********************************************************************************************
230 
231  //**Size function*******************************************************************************
236  inline size_t size() const noexcept {
237  return sv_.size();
238  }
239  //**********************************************************************************************
240 
241  //**NonZeros function***************************************************************************
246  inline size_t nonZeros() const {
247  return sv_.nonZeros();
248  }
249  //**********************************************************************************************
250 
251  //**Find function*******************************************************************************
257  inline ConstIterator find( size_t index ) const {
259  return ConstIterator( sv_.find( index ) );
260  }
261  //**********************************************************************************************
262 
263  //**LowerBound function*************************************************************************
269  inline ConstIterator lowerBound( size_t index ) const {
271  return ConstIterator( sv_.lowerBound( index ) );
272  }
273  //**********************************************************************************************
274 
275  //**UpperBound function*************************************************************************
281  inline ConstIterator upperBound( size_t index ) const {
283  return ConstIterator( sv_.upperBound( index ) );
284  }
285  //**********************************************************************************************
286 
287  //**Operand access******************************************************************************
292  inline Operand operand() const noexcept {
293  return sv_;
294  }
295  //**********************************************************************************************
296 
297  //**********************************************************************************************
303  template< typename T >
304  inline bool canAlias( const T* alias ) const noexcept {
305  return sv_.canAlias( alias );
306  }
307  //**********************************************************************************************
308 
309  //**********************************************************************************************
315  template< typename T >
316  inline bool isAliased( const T* alias ) const noexcept {
317  return sv_.isAliased( alias );
318  }
319  //**********************************************************************************************
320 
321  //**********************************************************************************************
326  inline bool canSMPAssign() const noexcept {
327  return sv_.canSMPAssign();
328  }
329  //**********************************************************************************************
330 
331  private:
332  //**Member variables****************************************************************************
333  Operand sv_;
334  //**********************************************************************************************
335 
336  //**Assignment to dense vectors*****************************************************************
350  template< typename VT2 > // Type of the target dense vector
351  friend inline EnableIf_< UseAssign<VT2> >
352  assign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
353  {
355 
356  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
357 
358  DVecTransposer<VT2,!TF> tmp( ~lhs );
359  assign( tmp, rhs.sv_ );
360  }
362  //**********************************************************************************************
363 
364  //**Assignment to sparse vectors****************************************************************
378  template< typename VT2 > // Type of the target sparse vector
379  friend inline EnableIf_< UseAssign<VT2> >
380  assign( SparseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
381  {
383 
384  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
385 
386  SVecTransposer<VT2,!TF> tmp( ~lhs );
387  assign( tmp, rhs.sv_ );
388  }
390  //**********************************************************************************************
391 
392  //**Addition assignment to dense vectors********************************************************
406  template< typename VT2 > // Type of the target dense vector
407  friend inline EnableIf_< UseAssign<VT2> >
408  addAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
409  {
411 
412  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
413 
414  DVecTransposer<VT2,!TF> tmp( ~lhs );
415  addAssign( tmp, rhs.sv_ );
416  }
418  //**********************************************************************************************
419 
420  //**Addition assignment to sparse vectors*******************************************************
421  // No special implementation for the addition assignment to sparse vectors.
422  //**********************************************************************************************
423 
424  //**Subtraction assignment to dense vectors*****************************************************
438  template< typename VT2 > // Type of the target dense vector
439  friend inline EnableIf_< UseAssign<VT2> >
440  subAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
441  {
443 
444  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
445 
446  DVecTransposer<VT2,!TF> tmp( ~lhs );
447  subAssign( tmp, rhs.sv_ );
448  }
450  //**********************************************************************************************
451 
452  //**Subtraction assignment to sparse vectors****************************************************
453  // No special implementation for the subtraction assignment to sparse vectors.
454  //**********************************************************************************************
455 
456  //**Multiplication assignment to dense vectors**************************************************
470  template< typename VT2 > // Type of the target dense vector
471  friend inline EnableIf_< UseAssign<VT2> >
472  multAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
473  {
475 
476  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
477 
478  DVecTransposer<VT2,!TF> tmp( ~lhs );
479  multAssign( tmp, rhs.sv_ );
480  }
482  //**********************************************************************************************
483 
484  //**Multiplication assignment to sparse vectors*************************************************
485  // No special implementation for the multiplication assignment to sparse vectors.
486  //**********************************************************************************************
487 
488  //**SMP assignment to dense vectors*************************************************************
502  template< typename VT2 > // Type of the target dense vector
503  friend inline EnableIf_< UseSMPAssign<VT2> >
504  smpAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
505  {
507 
508  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
509 
510  DVecTransposer<VT2,!TF> tmp( ~lhs );
511  smpAssign( tmp, rhs.sv_ );
512  }
514  //**********************************************************************************************
515 
516  //**SMP assignment to sparse vectors************************************************************
530  template< typename VT2 > // Type of the target sparse vector
531  friend inline EnableIf_< UseSMPAssign<VT2> >
532  smpAssign( SparseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
533  {
535 
536  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
537 
538  SVecTransposer<VT2,!TF> tmp( ~lhs );
539  smpAssign( tmp, rhs.sv_ );
540  }
542  //**********************************************************************************************
543 
544  //**SMP addition assignment to dense vectors****************************************************
558  template< typename VT2 > // Type of the target dense vector
559  friend inline EnableIf_< UseSMPAssign<VT2> >
561  {
563 
564  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
565 
566  DVecTransposer<VT2,!TF> tmp( ~lhs );
567  smpAddAssign( tmp, rhs.sv_ );
568  }
570  //**********************************************************************************************
571 
572  //**SMP addition assignment to sparse vectors***************************************************
573  // No special implementation for the SMP addition assignment to sparse vectors.
574  //**********************************************************************************************
575 
576  //**SMP subtraction assignment to dense vectors*************************************************
590  template< typename VT2 > // Type of the target dense vector
591  friend inline EnableIf_< UseSMPAssign<VT2> >
593  {
595 
596  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
597 
598  DVecTransposer<VT2,!TF> tmp( ~lhs );
599  smpSubAssign( tmp, rhs.sv_ );
600  }
602  //**********************************************************************************************
603 
604  //**SMP subtraction assignment to sparse vectors************************************************
605  // No special implementation for the SMP subtraction assignment to sparse vectors.
606  //**********************************************************************************************
607 
608  //**SMP multiplication assignment to dense vectors**********************************************
623  template< typename VT2 > // Type of the target dense vector
624  friend inline EnableIf_< UseSMPAssign<VT2> >
626  {
628 
629  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
630 
631  DVecTransposer<VT2,!TF> tmp( ~lhs );
632  smpMultAssign( tmp, rhs.sv_ );
633  }
635  //**********************************************************************************************
636 
637  //**SMP multiplication assignment to sparse vectors*********************************************
638  // No special implementation for the SMP multiplication assignment to sparse vectors.
639  //**********************************************************************************************
640 
641  //**Compile time checks*************************************************************************
645  //**********************************************************************************************
646 };
647 //*************************************************************************************************
648 
649 
650 
651 
652 //=================================================================================================
653 //
654 // GLOBAL OPERATORS
655 //
656 //=================================================================================================
657 
658 //*************************************************************************************************
677 template< typename VT // Type of the sparse vector
678  , bool TF > // Transpose flag
680 {
682 
683  return SVecTransExpr<VT,!TF>( ~sv );
684 }
685 //*************************************************************************************************
686 
687 
688 
689 
690 //=================================================================================================
691 //
692 // GLOBAL RESTRUCTURING FUNCTIONS
693 //
694 //=================================================================================================
695 
696 //*************************************************************************************************
716 template< typename VT // Type of the sparse vector
717  , bool TF > // Transpose flag
718 inline typename SVecTransExpr<VT,TF>::Operand trans( const SVecTransExpr<VT,TF>& sv )
719 {
721 
722  return sv.operand();
723 }
725 //*************************************************************************************************
726 
727 
728 
729 
730 //=================================================================================================
731 //
732 // SIZE SPECIALIZATIONS
733 //
734 //=================================================================================================
735 
736 //*************************************************************************************************
738 template< typename VT, bool TF >
739 struct Size< SVecTransExpr<VT,TF> > : public Size<VT>
740 {};
742 //*************************************************************************************************
743 
744 
745 
746 
747 //=================================================================================================
748 //
749 // EXPRESSION TRAIT SPECIALIZATIONS
750 //
751 //=================================================================================================
752 
753 //*************************************************************************************************
755 template< typename VT >
756 struct SVecTransExprTrait< SVecTransExpr<VT,false> >
757 {
758  public:
759  //**********************************************************************************************
762  , INVALID_TYPE >;
763  //**********************************************************************************************
764 };
766 //*************************************************************************************************
767 
768 
769 //*************************************************************************************************
771 template< typename VT >
772 struct TSVecTransExprTrait< SVecTransExpr<VT,true> >
773 {
774  public:
775  //**********************************************************************************************
778  , INVALID_TYPE >;
779  //**********************************************************************************************
780 };
782 //*************************************************************************************************
783 
784 
785 //*************************************************************************************************
787 template< typename VT, bool TF, bool AF >
788 struct SubvectorExprTrait< SVecTransExpr<VT,TF>, AF >
789 {
790  public:
791  //**********************************************************************************************
793  //**********************************************************************************************
794 };
796 //*************************************************************************************************
797 
798 } // namespace blaze
799 
800 #endif
ConstIterator lowerBound(size_t index) const
Returns an iterator to the first index not less then the given index.
Definition: SVecTransExpr.h:269
Compile time check for row vector types.This type trait tests whether or not the given template argum...
Definition: IsRowVector.h:80
Header file for auxiliary alias declarations.
Operand sv_
Sparse vector of the transposition expression.
Definition: SVecTransExpr.h:333
Evaluation of the expression type type of a subvector operation.Via this type trait it is possible to...
Definition: SubvectorExprTrait.h:79
Header file for basic type definitions.
Header file for the SparseVector base class.
ResultType_< VT > TransposeType
Transpose type for expression template evaluations.
Definition: SVecTransExpr.h:155
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: SVecTransExpr.h:326
EnableIf_< IsDenseMatrix< MT1 > > smpSubAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP subtraction assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:160
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: SVecTransExpr.h:190
Evaluation of the expression type of a sparse vector transpose operation.Via this type trait it is po...
Definition: TSVecTransExprTrait.h:74
TransposeType_< VT > ResultType
Result type for expression template evaluations.
Definition: SVecTransExpr.h:154
Header file for the IsRowVector type trait.
EnableIf_< IsDenseVector< VT1 > > smpMultAssign(Vector< VT1, TF1 > &lhs, const Vector< VT2, TF2 > &rhs)
Default implementation of the SMP multiplication assignment of a vector to a dense vector...
Definition: DenseVector.h:193
Header file for the And class template.
#define BLAZE_CREATE_HAS_TYPE_MEMBER_TYPE_TRAIT(TYPE_TRAIT_NAME, MEMBER_NAME)
Macro for the creation of a type trait for compile time checks for member types.This macro creates th...
Definition: HasMember.h:182
Expression object for sparse vector transpositions.The SVecTransExpr class represents the compile tim...
Definition: Forward.h:136
Header file for the Computation base class.
Header file for the RequiresEvaluation type trait.
typename T::ResultType ResultType_
Alias declaration for nested ResultType type definitions.The ResultType_ alias declaration provides a...
Definition: Aliases.h:323
ConstIterator upperBound(size_t index) const
Returns an iterator to the first index greater then the given index.
Definition: SVecTransExpr.h:281
EnableIf_< IsDenseMatrix< MT1 > > smpAddAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP addition assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:129
Expression object for the transposition of a dense vector.The DVecTransposer class is a wrapper objec...
Definition: DVecTransposer.h:77
typename IfTrue< Condition, T1, T2 >::Type IfTrue_
Auxiliary alias declaration for the IfTrue class template.The IfTrue_ alias declaration provides a co...
Definition: If.h:109
ElementType_< VT > ElementType
Resulting element type.
Definition: SVecTransExpr.h:156
typename T::ReturnType ReturnType_
Alias declaration for nested ReturnType type definitions.The ReturnType_ alias declaration provides a...
Definition: Aliases.h:343
ReturnType_< VT > ReturnType
Return type for expression template evaluations.
Definition: SVecTransExpr.h:157
GetConstIterator< VT >::Type ConstIterator
Iterator over the elements of the dense vector.
Definition: SVecTransExpr.h:163
Compile time check to query the requirement to evaluate an expression.Via this type trait it is possi...
Definition: RequiresEvaluation.h:72
typename T::CompositeType CompositeType_
Alias declaration for nested CompositeType type definitions.The CompositeType_ alias declaration prov...
Definition: Aliases.h:83
typename TransExprTrait< T >::Type TransExprTrait_
Auxiliary alias declaration for the TransExprTrait class template.The TransExprTrait_ alias declarati...
Definition: TransExprTrait.h:143
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Header file for the If class template.
Evaluation of the expression type of a sparse vector transpose operation.Via this type trait it is po...
Definition: SVecTransExprTrait.h:74
Header file for the dense vector transposer.
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2939
CompositeType_< VT > CT
Composite type of the sparse vector expression.
Definition: SVecTransExpr.h:99
EnableIf_< IsDenseMatrix< MT1 > > smpAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:98
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.This macro encapsulates the default way of Bl...
Definition: Exception.h:331
typename T::ElementType ElementType_
Alias declaration for nested ElementType type definitions.The ElementType_ alias declaration provides...
Definition: Aliases.h:163
Expression object for the transposition of a sparse vector.The SVecTransposer class is a wrapper obje...
Definition: Forward.h:137
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:61
If_< IsExpression< VT >, const VT, const VT &> Operand
Composite data type of the sparse vector expression.
Definition: SVecTransExpr.h:166
Compile time check for column vector types.This type trait tests whether or not the given template ar...
Definition: IsColumnVector.h:80
ConstIterator begin() const
Returns an iterator to the first non-zero element of the sparse vector.
Definition: SVecTransExpr.h:216
Header file for the exception macros of the math module.
Operand operand() const noexcept
Returns the sparse vector operand.
Definition: SVecTransExpr.h:292
Constraint on the data type.
Header file for all forward declarations for expression class templates.
Constraint on the data type.
Header file for the EnableIf class template.
ConstIterator find(size_t index) const
Searches for a specific vector element.
Definition: SVecTransExpr.h:257
Header file for the IsSparseVector type trait.
Header file for the VecTransExpr base class.
Header file for run time assertion macros.
SVecTransExpr(const VT &sv) noexcept
Constructor for the SVecTransExpr class.
Definition: SVecTransExpr.h:179
IfTrue_< useAssign, const ResultType, const SVecTransExpr &> CompositeType
Data type for composite expression templates.
Definition: SVecTransExpr.h:160
Utility type for generic codes.
typename If< T1, T2, T3 >::Type If_
Auxiliary alias declaration for the If class template.The If_ alias declaration provides a convenient...
Definition: If.h:160
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:93
Header file for the TransExprTrait class template.
size_t nonZeros() const
Returns the number of non-zero elements in the sparse vector.
Definition: SVecTransExpr.h:246
Header file for the HasMember type traits.
#define BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION(T)
Constraint on the data type.In case the given data type T requires an intermediate evaluation within ...
Definition: RequiresEvaluation.h:81
Header file for the RemoveReference type trait.
typename EnableIf< Condition, T >::Type EnableIf_
Auxiliary alias declaration for the EnableIf class template.The EnableIf_ alias declaration provides ...
Definition: EnableIf.h:223
Header file for the SVecTransExprTrait class template.
Header file for the sparse vector transposer.
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: SVecTransExpr.h:236
const DMatTransExpr< MT,!SO > trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:733
Compile time evaluation of the size of a vector.The Size type trait evaluates the size of the given v...
Definition: Size.h:75
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:120
Header file for the SubvectorExprTrait class template.
Header file for the TSVecTransExprTrait class template.
SVecTransExpr< VT, TF > This
Type of this SVecTransExpr instance.
Definition: SVecTransExpr.h:153
typename T::TransposeType TransposeType_
Alias declaration for nested TransposeType type definitions.The TransposeType_ alias declaration prov...
Definition: Aliases.h:403
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: SVecTransExpr.h:203
Header file for the IsColumnVector type trait.
Header file for the empty type.
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SVecTransExpr.h:316
Header file for the Size type trait.
#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
typename T::Operand Operand_
Alias declaration for nested Operand type definitions.The Operand_ alias declaration provides a conve...
Definition: Aliases.h:223
Header file for the IsExpression type trait class.
Header file for the function trace functionality.
ConstIterator end() const
Returns an iterator just past the last non-zero element of the sparse vector.
Definition: SVecTransExpr.h:226
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SVecTransExpr.h:304