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>
58 #include <blaze/util/Assert.h>
59 #include <blaze/util/EnableIf.h>
60 #include <blaze/util/FalseType.h>
63 #include <blaze/util/InvalidType.h>
64 #include <blaze/util/mpl/If.h>
65 #include <blaze/util/TrueType.h>
66 #include <blaze/util/Types.h>
69 
70 
71 namespace blaze {
72 
73 //=================================================================================================
74 //
75 // CLASS SVECTRANSEXPR
76 //
77 //=================================================================================================
78 
79 //*************************************************************************************************
86 template< typename VT // Type of the sparse vector
87  , bool TF > // Transpose flag
88 class SVecTransExpr
89  : public VecTransExpr< SparseVector< SVecTransExpr<VT,TF>, TF > >
90  , private If< IsComputation<VT>, Computation, Transformation >::Type
91 {
92  private:
93  //**Type definitions****************************************************************************
95  //**********************************************************************************************
96 
97  //**Serial evaluation strategy******************************************************************
99 
105  enum : bool { useAssign = RequiresEvaluation<VT>::value };
106 
108  template< typename VT2 >
110  struct UseAssign {
111  enum : bool { value = useAssign };
112  };
114  //**********************************************************************************************
115 
116  //**Parallel evaluation strategy****************************************************************
118 
123  template< typename VT2 >
124  struct UseSMPAssign {
125  enum : bool { value = VT2::smpAssignable && useAssign };
126  };
128  //**********************************************************************************************
129 
130  //**********************************************************************************************
132 
136  template< typename VT2 >
137  struct GetConstIterator {
139  struct Success { using Type = typename VT2::ConstIterator; };
140  struct Failure { using Type = INVALID_TYPE; };
141  using Type = typename If_< HasConstIterator<VT2>, Success, Failure >::Type;
142  };
144  //**********************************************************************************************
145 
146  public:
147  //**Type definitions****************************************************************************
153 
156 
158  using ConstIterator = typename GetConstIterator<VT>::Type;
159 
161  using Operand = If_< IsExpression<VT>, const VT, const VT& >;
162  //**********************************************************************************************
163 
164  //**Compilation flags***************************************************************************
166  enum : bool { smpAssignable = VT::smpAssignable };
167  //**********************************************************************************************
168 
169  //**Constructor*********************************************************************************
174  explicit inline SVecTransExpr( const VT& sv ) noexcept
175  : sv_( sv ) // Sparse vector of the transposition expression
176  {}
177  //**********************************************************************************************
178 
179  //**Subscript operator**************************************************************************
185  inline ReturnType operator[]( size_t index ) const {
186  BLAZE_INTERNAL_ASSERT( index < sv_.size(), "Invalid vector access index" );
187  return sv_[index];
188  }
189  //**********************************************************************************************
190 
191  //**At function*********************************************************************************
198  inline ReturnType at( size_t index ) const {
199  if( index >= sv_.size() ) {
200  BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
201  }
202  return (*this)[index];
203  }
204  //**********************************************************************************************
205 
206  //**Begin function******************************************************************************
211  inline ConstIterator begin() const {
212  return ConstIterator( sv_.begin() );
213  }
214  //**********************************************************************************************
215 
216  //**End function********************************************************************************
221  inline ConstIterator end() const {
222  return ConstIterator( sv_.end() );
223  }
224  //**********************************************************************************************
225 
226  //**Size function*******************************************************************************
231  inline size_t size() const noexcept {
232  return sv_.size();
233  }
234  //**********************************************************************************************
235 
236  //**NonZeros function***************************************************************************
241  inline size_t nonZeros() const {
242  return sv_.nonZeros();
243  }
244  //**********************************************************************************************
245 
246  //**Find function*******************************************************************************
252  inline ConstIterator find( size_t index ) const {
254  return ConstIterator( sv_.find( index ) );
255  }
256  //**********************************************************************************************
257 
258  //**LowerBound function*************************************************************************
264  inline ConstIterator lowerBound( size_t index ) const {
266  return ConstIterator( sv_.lowerBound( index ) );
267  }
268  //**********************************************************************************************
269 
270  //**UpperBound function*************************************************************************
276  inline ConstIterator upperBound( size_t index ) const {
278  return ConstIterator( sv_.upperBound( index ) );
279  }
280  //**********************************************************************************************
281 
282  //**Operand access******************************************************************************
287  inline Operand operand() const noexcept {
288  return sv_;
289  }
290  //**********************************************************************************************
291 
292  //**********************************************************************************************
298  template< typename T >
299  inline bool canAlias( const T* alias ) const noexcept {
300  return sv_.canAlias( alias );
301  }
302  //**********************************************************************************************
303 
304  //**********************************************************************************************
310  template< typename T >
311  inline bool isAliased( const T* alias ) const noexcept {
312  return sv_.isAliased( alias );
313  }
314  //**********************************************************************************************
315 
316  //**********************************************************************************************
321  inline bool canSMPAssign() const noexcept {
322  return sv_.canSMPAssign();
323  }
324  //**********************************************************************************************
325 
326  private:
327  //**Member variables****************************************************************************
329  //**********************************************************************************************
330 
331  //**Assignment to dense vectors*****************************************************************
345  template< typename VT2 > // Type of the target dense vector
346  friend inline EnableIf_< UseAssign<VT2> >
347  assign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
348  {
350 
351  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
352 
353  DVecTransposer<VT2,!TF> tmp( ~lhs );
354  assign( tmp, rhs.sv_ );
355  }
357  //**********************************************************************************************
358 
359  //**Assignment to sparse vectors****************************************************************
373  template< typename VT2 > // Type of the target sparse vector
374  friend inline EnableIf_< UseAssign<VT2> >
375  assign( SparseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
376  {
378 
379  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
380 
381  SVecTransposer<VT2,!TF> tmp( ~lhs );
382  assign( tmp, rhs.sv_ );
383  }
385  //**********************************************************************************************
386 
387  //**Addition assignment to dense vectors********************************************************
401  template< typename VT2 > // Type of the target dense vector
402  friend inline EnableIf_< UseAssign<VT2> >
403  addAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
404  {
406 
407  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
408 
409  DVecTransposer<VT2,!TF> tmp( ~lhs );
410  addAssign( tmp, rhs.sv_ );
411  }
413  //**********************************************************************************************
414 
415  //**Addition assignment to sparse vectors*******************************************************
416  // No special implementation for the addition assignment to sparse vectors.
417  //**********************************************************************************************
418 
419  //**Subtraction assignment to dense vectors*****************************************************
433  template< typename VT2 > // Type of the target dense vector
434  friend inline EnableIf_< UseAssign<VT2> >
435  subAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
436  {
438 
439  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
440 
441  DVecTransposer<VT2,!TF> tmp( ~lhs );
442  subAssign( tmp, rhs.sv_ );
443  }
445  //**********************************************************************************************
446 
447  //**Subtraction assignment to sparse vectors****************************************************
448  // No special implementation for the subtraction assignment to sparse vectors.
449  //**********************************************************************************************
450 
451  //**Multiplication assignment to dense vectors**************************************************
465  template< typename VT2 > // Type of the target dense vector
466  friend inline EnableIf_< UseAssign<VT2> >
467  multAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
468  {
470 
471  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
472 
473  DVecTransposer<VT2,!TF> tmp( ~lhs );
474  multAssign( tmp, rhs.sv_ );
475  }
477  //**********************************************************************************************
478 
479  //**Multiplication assignment to sparse vectors*************************************************
480  // No special implementation for the multiplication assignment to sparse vectors.
481  //**********************************************************************************************
482 
483  //**SMP assignment to dense vectors*************************************************************
497  template< typename VT2 > // Type of the target dense vector
498  friend inline EnableIf_< UseSMPAssign<VT2> >
499  smpAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
500  {
502 
503  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
504 
505  DVecTransposer<VT2,!TF> tmp( ~lhs );
506  smpAssign( tmp, rhs.sv_ );
507  }
509  //**********************************************************************************************
510 
511  //**SMP assignment to sparse vectors************************************************************
525  template< typename VT2 > // Type of the target sparse vector
526  friend inline EnableIf_< UseSMPAssign<VT2> >
527  smpAssign( SparseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
528  {
530 
531  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
532 
533  SVecTransposer<VT2,!TF> tmp( ~lhs );
534  smpAssign( tmp, rhs.sv_ );
535  }
537  //**********************************************************************************************
538 
539  //**SMP addition assignment to dense vectors****************************************************
553  template< typename VT2 > // Type of the target dense vector
554  friend inline EnableIf_< UseSMPAssign<VT2> >
556  {
558 
559  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
560 
561  DVecTransposer<VT2,!TF> tmp( ~lhs );
562  smpAddAssign( tmp, rhs.sv_ );
563  }
565  //**********************************************************************************************
566 
567  //**SMP addition assignment to sparse vectors***************************************************
568  // No special implementation for the SMP addition assignment to sparse vectors.
569  //**********************************************************************************************
570 
571  //**SMP subtraction assignment to dense vectors*************************************************
585  template< typename VT2 > // Type of the target dense vector
586  friend inline EnableIf_< UseSMPAssign<VT2> >
588  {
590 
591  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
592 
593  DVecTransposer<VT2,!TF> tmp( ~lhs );
594  smpSubAssign( tmp, rhs.sv_ );
595  }
597  //**********************************************************************************************
598 
599  //**SMP subtraction assignment to sparse vectors************************************************
600  // No special implementation for the SMP subtraction assignment to sparse vectors.
601  //**********************************************************************************************
602 
603  //**SMP multiplication assignment to dense vectors**********************************************
618  template< typename VT2 > // Type of the target dense vector
619  friend inline EnableIf_< UseSMPAssign<VT2> >
621  {
623 
624  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
625 
626  DVecTransposer<VT2,!TF> tmp( ~lhs );
627  smpMultAssign( tmp, rhs.sv_ );
628  }
630  //**********************************************************************************************
631 
632  //**SMP multiplication assignment to sparse vectors*********************************************
633  // No special implementation for the SMP multiplication assignment to sparse vectors.
634  //**********************************************************************************************
635 
636  //**Compile time checks*************************************************************************
640  //**********************************************************************************************
641 };
642 //*************************************************************************************************
643 
644 
645 
646 
647 //=================================================================================================
648 //
649 // GLOBAL OPERATORS
650 //
651 //=================================================================================================
652 
653 //*************************************************************************************************
672 template< typename VT // Type of the sparse vector
673  , bool TF > // Transpose flag
674 inline decltype(auto) trans( const SparseVector<VT,TF>& sv )
675 {
677 
678  using ReturnType = const SVecTransExpr<VT,!TF>;
679  return ReturnType( ~sv );
680 }
681 //*************************************************************************************************
682 
683 
684 //*************************************************************************************************
692 template< typename VT // Type of the sparse vector
693  , bool TF > // Transpose flag
694 inline decltype(auto) transTo_backend( const SparseVector<VT,TF>& sv, FalseType )
695 {
696  return trans( ~sv );
697 }
699 //*************************************************************************************************
700 
701 
702 //*************************************************************************************************
710 template< typename VT // Type of the sparse vector
711  , bool TF > // Transpose flag
712 inline const VT& transTo_backend( const SparseVector<VT,TF>& sv, TrueType )
713 {
714  return ~sv;
715 }
717 //*************************************************************************************************
718 
719 
720 //*************************************************************************************************
732 template< bool TTF // Target transpose flag
733  , typename VT // Type of the sparse vector
734  , bool TF > // Current transpose flag of the sparse vector
735 inline decltype(auto) transTo( const SparseVector<VT,TF>& sv )
736 {
737  return transTo_backend( ~sv, BoolConstant<TTF == TF>() );
738 }
739 //*************************************************************************************************
740 
741 
742 
743 
744 //=================================================================================================
745 //
746 // GLOBAL RESTRUCTURING FUNCTIONS
747 //
748 //=================================================================================================
749 
750 //*************************************************************************************************
770 template< typename VT // Type of the sparse vector
771  , bool TF > // Transpose flag
772 inline decltype(auto) trans( const SVecTransExpr<VT,TF>& sv )
773 {
775 
776  return sv.operand();
777 }
779 //*************************************************************************************************
780 
781 
782 //*************************************************************************************************
794 template< typename VT // Type of the left-hand side sparse vector
795  , typename ST // Type of the right-hand side scalar value
796  , bool TF > // Transpose flag
797 inline decltype(auto) trans( const SVecScalarMultExpr<VT,ST,TF>& sv )
798 {
800 
801  return trans( sv.leftOperand() ) * sv.rightOperand();
802 }
804 //*************************************************************************************************
805 
806 
807 
808 
809 //=================================================================================================
810 //
811 // SIZE SPECIALIZATIONS
812 //
813 //=================================================================================================
814 
815 //*************************************************************************************************
817 template< typename VT, bool TF >
818 struct Size< SVecTransExpr<VT,TF>, 0UL >
819  : public Size<VT,0UL>
820 {};
822 //*************************************************************************************************
823 
824 } // namespace blaze
825 
826 #endif
RightOperand rightOperand() const noexcept
Returns the right-hand side scalar operand.
Definition: SVecScalarMultExpr.h:437
ConstIterator lowerBound(size_t index) const
Returns an iterator to the first index not less then the given index.
Definition: SVecTransExpr.h:264
Header file for auxiliary alias declarations.
Operand sv_
Sparse vector of the transposition expression.
Definition: SVecTransExpr.h:328
Header file for basic type definitions.
Header file for the SparseVector base class.
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: SVecTransExpr.h:321
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:164
Header file for the FalseType type/value trait base class.
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: SVecTransExpr.h:185
TransposeType_< VT > ResultType
Result type for expression template evaluations.
Definition: SVecTransExpr.h:149
Generic wrapper for a compile time constant integral value.The IntegralConstant class template repres...
Definition: IntegralConstant.h:71
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
#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:146
Header file for the Computation base class.
ResultType_< VT > TransposeType
Transpose type for expression template evaluations.
Definition: SVecTransExpr.h:150
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:343
ConstIterator upperBound(size_t index) const
Returns an iterator to the first index greater then the given index.
Definition: SVecTransExpr.h:276
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:133
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
typename T::ReturnType ReturnType_
Alias declaration for nested ReturnType type definitions.The ReturnType_ alias declaration provides a...
Definition: Aliases.h:363
Compile time check to query the requirement to evaluate an expression.Via this type trait it is possi...
Definition: RequiresEvaluation.h:71
typename T::CompositeType CompositeType_
Alias declaration for nested CompositeType type definitions.The CompositeType_ alias declaration prov...
Definition: Aliases.h:83
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for the If class template.
Header file for the dense vector transposer.
Header file for the Transformation base class.
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:102
#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
CompositeType_< VT > CT
Composite type of the sparse vector expression.
Definition: SVecTransExpr.h:94
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:3085
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:147
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:76
#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
decltype(auto) transTo(const DenseVector< VT, TF > &dv)
Conditional calculation of the transpose of the given dense vector.
Definition: DVecTransExpr.h:798
ConstIterator begin() const
Returns an iterator to the first non-zero element of the sparse vector.
Definition: SVecTransExpr.h:211
Header file for the exception macros of the math module.
Operand operand() const noexcept
Returns the sparse vector operand.
Definition: SVecTransExpr.h:287
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.
typename GetConstIterator< VT >::Type ConstIterator
Iterator over the elements of the dense vector.
Definition: SVecTransExpr.h:158
ConstIterator find(size_t index) const
Searches for a specific vector element.
Definition: SVecTransExpr.h:252
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:174
If_< IsExpression< VT >, const VT, const VT &> Operand
Composite data type of the sparse vector expression.
Definition: SVecTransExpr.h:161
Utility type for generic codes.
IfTrue_< useAssign, const ResultType, const SVecTransExpr &> CompositeType
Data type for composite expression templates.
Definition: SVecTransExpr.h:155
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:154
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:94
ElementType_< VT > ElementType
Resulting element type.
Definition: SVecTransExpr.h:151
size_t nonZeros() const
Returns the number of non-zero elements in the sparse vector.
Definition: SVecTransExpr.h:241
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:224
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:3080
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:789
Header file for the sparse vector transposer.
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: SVecTransExpr.h:231
Expression object for sparse vector-scalar multiplications.The SVecScalarMultExpr class represents th...
Definition: Forward.h:139
Compile time evaluation of the size of vectors and matrices.The Size type trait evaluates the size of...
Definition: Size.h:80
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:130
Header file for the IntegralConstant class template.
typename T::TransposeType TransposeType_
Alias declaration for nested TransposeType type definitions.The TransposeType_ alias declaration prov...
Definition: Aliases.h:423
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: SVecTransExpr.h:198
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SVecTransExpr.h:311
ReturnType_< VT > ReturnType
Return type for expression template evaluations.
Definition: SVecTransExpr.h:152
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
LeftOperand leftOperand() const noexcept
Returns the left-hand side sparse vector operand.
Definition: SVecScalarMultExpr.h:427
Header file for the TrueType type/value trait base class.
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:221
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SVecTransExpr.h:299