Blaze  3.6
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>
57 #include <blaze/util/Assert.h>
58 #include <blaze/util/EnableIf.h>
61 #include <blaze/util/InvalidType.h>
62 #include <blaze/util/mpl/If.h>
63 #include <blaze/util/Types.h>
65 
66 
67 namespace blaze {
68 
69 //=================================================================================================
70 //
71 // CLASS SVECTRANSEXPR
72 //
73 //=================================================================================================
74 
75 //*************************************************************************************************
82 template< typename VT // Type of the sparse vector
83  , bool TF > // Transpose flag
84 class SVecTransExpr
85  : public VecTransExpr< SparseVector< SVecTransExpr<VT,TF>, TF > >
86  , private If< IsComputation_v<VT>, Computation, Transformation >::Type
87 {
88  private:
89  //**Type definitions****************************************************************************
91 
93  BLAZE_CREATE_GET_TYPE_MEMBER_TYPE_TRAIT( GetConstIterator, ConstIterator, INVALID_TYPE );
94  //**********************************************************************************************
95 
96  //**Serial evaluation strategy******************************************************************
98 
104  static constexpr bool useAssign = RequiresEvaluation_v<VT>;
105 
107  template< typename VT2 >
109  static constexpr bool UseAssign_v = useAssign;
111  //**********************************************************************************************
112 
113  //**Parallel evaluation strategy****************************************************************
115 
121  template< typename VT2 >
122  static constexpr bool UseSMPAssign_v = ( VT2::smpAssignable && useAssign );
124  //**********************************************************************************************
125 
126  public:
127  //**Type definitions****************************************************************************
134 
137 
139  using ConstIterator = GetConstIterator_t<VT>;
140 
142  using Operand = If_t< IsExpression_v<VT>, const VT, const VT& >;
143  //**********************************************************************************************
144 
145  //**Compilation flags***************************************************************************
147  static constexpr bool smpAssignable = VT::smpAssignable;
148  //**********************************************************************************************
149 
150  //**Constructor*********************************************************************************
155  explicit inline SVecTransExpr( const VT& sv ) noexcept
156  : sv_( sv ) // Sparse vector of the transposition expression
157  {}
158  //**********************************************************************************************
159 
160  //**Subscript operator**************************************************************************
166  inline ReturnType operator[]( size_t index ) const {
167  BLAZE_INTERNAL_ASSERT( index < sv_.size(), "Invalid vector access index" );
168  return sv_[index];
169  }
170  //**********************************************************************************************
171 
172  //**At function*********************************************************************************
179  inline ReturnType at( size_t index ) const {
180  if( index >= sv_.size() ) {
181  BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
182  }
183  return (*this)[index];
184  }
185  //**********************************************************************************************
186 
187  //**Begin function******************************************************************************
192  inline ConstIterator begin() const {
193  return ConstIterator( sv_.begin() );
194  }
195  //**********************************************************************************************
196 
197  //**End function********************************************************************************
202  inline ConstIterator end() const {
203  return ConstIterator( sv_.end() );
204  }
205  //**********************************************************************************************
206 
207  //**Size function*******************************************************************************
212  inline size_t size() const noexcept {
213  return sv_.size();
214  }
215  //**********************************************************************************************
216 
217  //**NonZeros function***************************************************************************
222  inline size_t nonZeros() const {
223  return sv_.nonZeros();
224  }
225  //**********************************************************************************************
226 
227  //**Find function*******************************************************************************
233  inline ConstIterator find( size_t index ) const {
235  return ConstIterator( sv_.find( index ) );
236  }
237  //**********************************************************************************************
238 
239  //**LowerBound function*************************************************************************
245  inline ConstIterator lowerBound( size_t index ) const {
247  return ConstIterator( sv_.lowerBound( index ) );
248  }
249  //**********************************************************************************************
250 
251  //**UpperBound function*************************************************************************
257  inline ConstIterator upperBound( size_t index ) const {
259  return ConstIterator( sv_.upperBound( index ) );
260  }
261  //**********************************************************************************************
262 
263  //**Operand access******************************************************************************
268  inline Operand operand() const noexcept {
269  return sv_;
270  }
271  //**********************************************************************************************
272 
273  //**********************************************************************************************
279  template< typename T >
280  inline bool canAlias( const T* alias ) const noexcept {
281  return sv_.canAlias( alias );
282  }
283  //**********************************************************************************************
284 
285  //**********************************************************************************************
291  template< typename T >
292  inline bool isAliased( const T* alias ) const noexcept {
293  return sv_.isAliased( alias );
294  }
295  //**********************************************************************************************
296 
297  //**********************************************************************************************
302  inline bool canSMPAssign() const noexcept {
303  return sv_.canSMPAssign();
304  }
305  //**********************************************************************************************
306 
307  private:
308  //**Member variables****************************************************************************
310  //**********************************************************************************************
311 
312  //**Assignment to dense vectors*****************************************************************
326  template< typename VT2 > // Type of the target dense vector
327  friend inline auto assign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
329  {
331 
332  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
333 
334  DVecTransposer<VT2,!TF> tmp( ~lhs );
335  assign( tmp, rhs.sv_ );
336  }
338  //**********************************************************************************************
339 
340  //**Assignment to sparse vectors****************************************************************
354  template< typename VT2 > // Type of the target sparse vector
355  friend inline auto assign( SparseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
357  {
359 
360  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
361 
362  SVecTransposer<VT2,!TF> tmp( ~lhs );
363  assign( tmp, rhs.sv_ );
364  }
366  //**********************************************************************************************
367 
368  //**Addition assignment to dense vectors********************************************************
382  template< typename VT2 > // Type of the target dense vector
383  friend inline auto addAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
384  -> EnableIf_t< UseAssign_v<VT2> >
385  {
387 
388  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
389 
390  DVecTransposer<VT2,!TF> tmp( ~lhs );
391  addAssign( tmp, rhs.sv_ );
392  }
394  //**********************************************************************************************
395 
396  //**Addition assignment to sparse vectors*******************************************************
397  // No special implementation for the addition assignment to sparse vectors.
398  //**********************************************************************************************
399 
400  //**Subtraction assignment to dense vectors*****************************************************
414  template< typename VT2 > // Type of the target dense vector
415  friend inline auto subAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
416  -> EnableIf_t< UseAssign_v<VT2> >
417  {
419 
420  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
421 
422  DVecTransposer<VT2,!TF> tmp( ~lhs );
423  subAssign( tmp, rhs.sv_ );
424  }
426  //**********************************************************************************************
427 
428  //**Subtraction assignment to sparse vectors****************************************************
429  // No special implementation for the subtraction assignment to sparse vectors.
430  //**********************************************************************************************
431 
432  //**Multiplication assignment to dense vectors**************************************************
446  template< typename VT2 > // Type of the target dense vector
447  friend inline auto multAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
448  -> EnableIf_t< UseAssign_v<VT2> >
449  {
451 
452  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
453 
454  DVecTransposer<VT2,!TF> tmp( ~lhs );
455  multAssign( tmp, rhs.sv_ );
456  }
458  //**********************************************************************************************
459 
460  //**Multiplication assignment to sparse vectors*************************************************
461  // No special implementation for the multiplication assignment to sparse vectors.
462  //**********************************************************************************************
463 
464  //**SMP assignment to dense vectors*************************************************************
478  template< typename VT2 > // Type of the target dense vector
479  friend inline auto smpAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
480  -> EnableIf_t< UseSMPAssign_v<VT2> >
481  {
483 
484  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
485 
486  DVecTransposer<VT2,!TF> tmp( ~lhs );
487  smpAssign( tmp, rhs.sv_ );
488  }
490  //**********************************************************************************************
491 
492  //**SMP assignment to sparse vectors************************************************************
506  template< typename VT2 > // Type of the target sparse vector
507  friend inline auto smpAssign( SparseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
508  -> EnableIf_t< UseSMPAssign_v<VT2> >
509  {
511 
512  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
513 
514  SVecTransposer<VT2,!TF> tmp( ~lhs );
515  smpAssign( tmp, rhs.sv_ );
516  }
518  //**********************************************************************************************
519 
520  //**SMP addition assignment to dense vectors****************************************************
534  template< typename VT2 > // Type of the target dense vector
535  friend inline auto smpAddAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
536  -> EnableIf_t< UseSMPAssign_v<VT2> >
537  {
539 
540  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
541 
542  DVecTransposer<VT2,!TF> tmp( ~lhs );
543  smpAddAssign( tmp, rhs.sv_ );
544  }
546  //**********************************************************************************************
547 
548  //**SMP addition assignment to sparse vectors***************************************************
549  // No special implementation for the SMP addition assignment to sparse vectors.
550  //**********************************************************************************************
551 
552  //**SMP subtraction assignment to dense vectors*************************************************
566  template< typename VT2 > // Type of the target dense vector
567  friend inline auto smpSubAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
568  -> EnableIf_t< UseSMPAssign_v<VT2> >
569  {
571 
572  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
573 
574  DVecTransposer<VT2,!TF> tmp( ~lhs );
575  smpSubAssign( tmp, rhs.sv_ );
576  }
578  //**********************************************************************************************
579 
580  //**SMP subtraction assignment to sparse vectors************************************************
581  // No special implementation for the SMP subtraction assignment to sparse vectors.
582  //**********************************************************************************************
583 
584  //**SMP multiplication assignment to dense vectors**********************************************
599  template< typename VT2 > // Type of the target dense vector
600  friend inline auto smpMultAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
601  -> EnableIf_t< UseSMPAssign_v<VT2> >
602  {
604 
605  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
606 
607  DVecTransposer<VT2,!TF> tmp( ~lhs );
608  smpMultAssign( tmp, rhs.sv_ );
609  }
611  //**********************************************************************************************
612 
613  //**SMP multiplication assignment to sparse vectors*********************************************
614  // No special implementation for the SMP multiplication assignment to sparse vectors.
615  //**********************************************************************************************
616 
617  //**Compile time checks*************************************************************************
621  //**********************************************************************************************
622 };
623 //*************************************************************************************************
624 
625 
626 
627 
628 //=================================================================================================
629 //
630 // GLOBAL OPERATORS
631 //
632 //=================================================================================================
633 
634 //*************************************************************************************************
653 template< typename VT // Type of the sparse vector
654  , bool TF > // Transpose flag
655 inline decltype(auto) trans( const SparseVector<VT,TF>& sv )
656 {
658 
659  using ReturnType = const SVecTransExpr<VT,!TF>;
660  return ReturnType( ~sv );
661 }
662 //*************************************************************************************************
663 
664 
665 //*************************************************************************************************
673 template< typename VT // Type of the sparse vector
674  , bool TF > // Transpose flag
675 inline decltype(auto) transTo_backend( const SparseVector<VT,TF>& sv, FalseType )
676 {
677  return trans( ~sv );
678 }
680 //*************************************************************************************************
681 
682 
683 //*************************************************************************************************
691 template< typename VT // Type of the sparse vector
692  , bool TF > // Transpose flag
693 inline const VT& transTo_backend( const SparseVector<VT,TF>& sv, TrueType )
694 {
695  return ~sv;
696 }
698 //*************************************************************************************************
699 
700 
701 //*************************************************************************************************
713 template< bool TTF // Target transpose flag
714  , typename VT // Type of the sparse vector
715  , bool TF > // Current transpose flag of the sparse vector
716 inline decltype(auto) transTo( const SparseVector<VT,TF>& sv )
717 {
718  return transTo_backend( ~sv, BoolConstant<TTF == TF>() );
719 }
720 //*************************************************************************************************
721 
722 
723 
724 
725 //=================================================================================================
726 //
727 // GLOBAL RESTRUCTURING FUNCTIONS
728 //
729 //=================================================================================================
730 
731 //*************************************************************************************************
751 template< typename VT // Type of the sparse vector
752  , bool TF > // Transpose flag
753 inline decltype(auto) trans( const SVecTransExpr<VT,TF>& sv )
754 {
756 
757  return sv.operand();
758 }
760 //*************************************************************************************************
761 
762 
763 //*************************************************************************************************
775 template< typename VT // Type of the left-hand side sparse vector
776  , typename ST // Type of the right-hand side scalar value
777  , bool TF > // Transpose flag
778 inline decltype(auto) trans( const SVecScalarMultExpr<VT,ST,TF>& sv )
779 {
781 
782  return trans( sv.leftOperand() ) * sv.rightOperand();
783 }
785 //*************************************************************************************************
786 
787 } // namespace blaze
788 
789 #endif
BoolConstant< false > FalseType
Type/value traits base class.The FalseType class is used as base class for type traits and value trai...
Definition: IntegralConstant.h:121
ConstIterator lowerBound(size_t index) const
Returns an iterator to the first index not less then the given index.
Definition: SVecTransExpr.h:245
Header file for auxiliary alias declarations.
Operand sv_
Sparse vector of the transposition expression.
Definition: SVecTransExpr.h:309
Header file for basic type definitions.
Header file for the SparseVector base class.
typename If< Condition, T1, T2 >::Type If_t
Auxiliary alias template for the If class template.The If_t alias template provides a convenient shor...
Definition: If.h:109
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: SVecTransExpr.h:302
typename T::ResultType ResultType_t
Alias declaration for nested ResultType type definitions.The ResultType_t alias declaration provides ...
Definition: Aliases.h:390
GetConstIterator_t< VT > ConstIterator
Iterator over the elements of the dense vector.
Definition: SVecTransExpr.h:139
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: SVecTransExpr.h:166
Generic wrapper for a compile time constant integral value.The IntegralConstant class template repres...
Definition: IntegralConstant.h:72
Expression object for sparse vector transpositions.The SVecTransExpr class represents the compile tim...
Definition: Forward.h:165
Header file for the Computation base class.
BoolConstant< true > TrueType
Type traits base class.The TrueType class is used as base class for type traits and value traits that...
Definition: IntegralConstant.h:132
Header file for the RequiresEvaluation type trait.
typename T::ReturnType ReturnType_t
Alias declaration for nested ReturnType type definitions.The ReturnType_t alias declaration provides ...
Definition: Aliases.h:410
ConstIterator upperBound(size_t index) const
Returns an iterator to the first index greater then the given index.
Definition: SVecTransExpr.h:257
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.The ElementType_t alias declaration provide...
Definition: Aliases.h:170
Expression object for the transposition of a dense vector.The DVecTransposer class is a wrapper objec...
Definition: DVecTransposer.h:78
CompositeType_t< VT > CT
Composite type of the sparse vector expression.
Definition: SVecTransExpr.h:90
typename EnableIf< Condition, T >::Type EnableIf_t
Auxiliary type for the EnableIf class template.The EnableIf_t alias declaration provides a convenient...
Definition: EnableIf.h:138
TransposeType_t< VT > ResultType
Result type for expression template evaluations.
Definition: SVecTransExpr.h:130
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.
#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
Expression object for the transposition of a sparse vector.The SVecTransposer class is a wrapper obje...
Definition: Forward.h:166
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:76
Header file for the GetMemberType type trait.
ResultType_t< VT > TransposeType
Transpose type for expression template evaluations.
Definition: SVecTransExpr.h:131
#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:781
ConstIterator begin() const
Returns an iterator to the first non-zero element of the sparse vector.
Definition: SVecTransExpr.h:192
Header file for the exception macros of the math module.
Operand operand() const noexcept
Returns the sparse vector operand.
Definition: SVecTransExpr.h:268
Constraint on the data type.
Constraint on the data type.
Header file for the EnableIf class template.
BLAZE_CREATE_GET_TYPE_MEMBER_TYPE_TRAIT(GetConstIterator, ConstIterator, INVALID_TYPE)
Definition of the GetConstIterator type trait.
ConstIterator find(size_t index) const
Searches for a specific vector element.
Definition: SVecTransExpr.h:233
Header file for the VecTransExpr base class.
typename T::TransposeType TransposeType_t
Alias declaration for nested TransposeType type definitions.The TransposeType_t alias declaration pro...
Definition: Aliases.h:470
Header file for run time assertion macros.
SVecTransExpr(const VT &sv) noexcept
Constructor for the SVecTransExpr class.
Definition: SVecTransExpr.h:155
ElementType_t< VT > ElementType
Resulting element type.
Definition: SVecTransExpr.h:132
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.The CompositeType_t alias declaration pro...
Definition: Aliases.h:90
Utility type for generic codes.
auto smpAddAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP addition assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:131
ReturnType_t< VT > ReturnType
Return type for expression template evaluations.
Definition: SVecTransExpr.h:133
#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
Header file for all forward declarations for expression class templates.
size_t nonZeros() const
Returns the number of non-zero elements in the sparse vector.
Definition: SVecTransExpr.h:222
auto smpAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:100
If_t< IsExpression_v< VT >, const VT, const VT & > Operand
Composite data type of the sparse vector expression.
Definition: SVecTransExpr.h:142
#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
If_t< useAssign, const ResultType, const SVecTransExpr & > CompositeType
Data type for composite expression templates.
Definition: SVecTransExpr.h:136
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:765
Header file for the sparse vector transposer.
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: SVecTransExpr.h:212
auto smpSubAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP subtraction assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:162
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:146
Header file for the IntegralConstant class template.
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: SVecTransExpr.h:147
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: SVecTransExpr.h:179
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SVecTransExpr.h:292
static constexpr bool useAssign
Compilation switch for the serial evaluation strategy of the transposition expression.
Definition: SVecTransExpr.h:104
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression,...
Definition: Assert.h:101
auto smpMultAssign(Vector< VT1, TF1 > &lhs, const Vector< VT2, TF2 > &rhs) -> EnableIf_t< IsDenseVector_v< VT1 > >
Default implementation of the SMP multiplication assignment of a vector to a dense vector.
Definition: DenseVector.h:191
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:202
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SVecTransExpr.h:280