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>
59 #include <blaze/util/FalseType.h>
62 #include <blaze/util/InvalidType.h>
63 #include <blaze/util/mpl/If.h>
64 #include <blaze/util/TrueType.h>
65 #include <blaze/util/Types.h>
67 
68 
69 namespace blaze {
70 
71 //=================================================================================================
72 //
73 // CLASS SVECTRANSEXPR
74 //
75 //=================================================================================================
76 
77 //*************************************************************************************************
84 template< typename VT // Type of the sparse vector
85  , bool TF > // Transpose flag
86 class SVecTransExpr
87  : public VecTransExpr< SparseVector< SVecTransExpr<VT,TF>, TF > >
88  , private If< IsComputation_v<VT>, Computation, Transformation >::Type
89 {
90  private:
91  //**Type definitions****************************************************************************
93 
95  BLAZE_CREATE_GET_TYPE_MEMBER_TYPE_TRAIT( GetConstIterator, ConstIterator, INVALID_TYPE );
96  //**********************************************************************************************
97 
98  //**Serial evaluation strategy******************************************************************
100 
106  static constexpr bool useAssign = RequiresEvaluation_v<VT>;
107 
109  template< typename VT2 >
111  static constexpr bool UseAssign_v = useAssign;
113  //**********************************************************************************************
114 
115  //**Parallel evaluation strategy****************************************************************
117 
123  template< typename VT2 >
124  static constexpr bool UseSMPAssign_v = ( VT2::smpAssignable && useAssign );
126  //**********************************************************************************************
127 
128  public:
129  //**Type definitions****************************************************************************
136 
139 
141  using ConstIterator = GetConstIterator_t<VT>;
142 
144  using Operand = If_t< IsExpression_v<VT>, const VT, const VT& >;
145  //**********************************************************************************************
146 
147  //**Compilation flags***************************************************************************
149  static constexpr bool smpAssignable = VT::smpAssignable;
150  //**********************************************************************************************
151 
152  //**Constructor*********************************************************************************
157  explicit inline SVecTransExpr( const VT& sv ) noexcept
158  : sv_( sv ) // Sparse vector of the transposition expression
159  {}
160  //**********************************************************************************************
161 
162  //**Subscript operator**************************************************************************
168  inline ReturnType operator[]( size_t index ) const {
169  BLAZE_INTERNAL_ASSERT( index < sv_.size(), "Invalid vector access index" );
170  return sv_[index];
171  }
172  //**********************************************************************************************
173 
174  //**At function*********************************************************************************
181  inline ReturnType at( size_t index ) const {
182  if( index >= sv_.size() ) {
183  BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
184  }
185  return (*this)[index];
186  }
187  //**********************************************************************************************
188 
189  //**Begin function******************************************************************************
194  inline ConstIterator begin() const {
195  return ConstIterator( sv_.begin() );
196  }
197  //**********************************************************************************************
198 
199  //**End function********************************************************************************
204  inline ConstIterator end() const {
205  return ConstIterator( sv_.end() );
206  }
207  //**********************************************************************************************
208 
209  //**Size function*******************************************************************************
214  inline size_t size() const noexcept {
215  return sv_.size();
216  }
217  //**********************************************************************************************
218 
219  //**NonZeros function***************************************************************************
224  inline size_t nonZeros() const {
225  return sv_.nonZeros();
226  }
227  //**********************************************************************************************
228 
229  //**Find function*******************************************************************************
235  inline ConstIterator find( size_t index ) const {
237  return ConstIterator( sv_.find( index ) );
238  }
239  //**********************************************************************************************
240 
241  //**LowerBound function*************************************************************************
247  inline ConstIterator lowerBound( size_t index ) const {
249  return ConstIterator( sv_.lowerBound( index ) );
250  }
251  //**********************************************************************************************
252 
253  //**UpperBound function*************************************************************************
259  inline ConstIterator upperBound( size_t index ) const {
261  return ConstIterator( sv_.upperBound( index ) );
262  }
263  //**********************************************************************************************
264 
265  //**Operand access******************************************************************************
270  inline Operand operand() const noexcept {
271  return sv_;
272  }
273  //**********************************************************************************************
274 
275  //**********************************************************************************************
281  template< typename T >
282  inline bool canAlias( const T* alias ) const noexcept {
283  return sv_.canAlias( alias );
284  }
285  //**********************************************************************************************
286 
287  //**********************************************************************************************
293  template< typename T >
294  inline bool isAliased( const T* alias ) const noexcept {
295  return sv_.isAliased( alias );
296  }
297  //**********************************************************************************************
298 
299  //**********************************************************************************************
304  inline bool canSMPAssign() const noexcept {
305  return sv_.canSMPAssign();
306  }
307  //**********************************************************************************************
308 
309  private:
310  //**Member variables****************************************************************************
312  //**********************************************************************************************
313 
314  //**Assignment to dense vectors*****************************************************************
328  template< typename VT2 > // Type of the target dense vector
329  friend inline auto assign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
331  {
333 
334  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
335 
336  DVecTransposer<VT2,!TF> tmp( ~lhs );
337  assign( tmp, rhs.sv_ );
338  }
340  //**********************************************************************************************
341 
342  //**Assignment to sparse vectors****************************************************************
356  template< typename VT2 > // Type of the target sparse vector
357  friend inline auto assign( SparseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
359  {
361 
362  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
363 
364  SVecTransposer<VT2,!TF> tmp( ~lhs );
365  assign( tmp, rhs.sv_ );
366  }
368  //**********************************************************************************************
369 
370  //**Addition assignment to dense vectors********************************************************
384  template< typename VT2 > // Type of the target dense vector
385  friend inline auto addAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
386  -> EnableIf_t< UseAssign_v<VT2> >
387  {
389 
390  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
391 
392  DVecTransposer<VT2,!TF> tmp( ~lhs );
393  addAssign( tmp, rhs.sv_ );
394  }
396  //**********************************************************************************************
397 
398  //**Addition assignment to sparse vectors*******************************************************
399  // No special implementation for the addition assignment to sparse vectors.
400  //**********************************************************************************************
401 
402  //**Subtraction assignment to dense vectors*****************************************************
416  template< typename VT2 > // Type of the target dense vector
417  friend inline auto subAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
418  -> EnableIf_t< UseAssign_v<VT2> >
419  {
421 
422  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
423 
424  DVecTransposer<VT2,!TF> tmp( ~lhs );
425  subAssign( tmp, rhs.sv_ );
426  }
428  //**********************************************************************************************
429 
430  //**Subtraction assignment to sparse vectors****************************************************
431  // No special implementation for the subtraction assignment to sparse vectors.
432  //**********************************************************************************************
433 
434  //**Multiplication assignment to dense vectors**************************************************
448  template< typename VT2 > // Type of the target dense vector
449  friend inline auto multAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
450  -> EnableIf_t< UseAssign_v<VT2> >
451  {
453 
454  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
455 
456  DVecTransposer<VT2,!TF> tmp( ~lhs );
457  multAssign( tmp, rhs.sv_ );
458  }
460  //**********************************************************************************************
461 
462  //**Multiplication assignment to sparse vectors*************************************************
463  // No special implementation for the multiplication assignment to sparse vectors.
464  //**********************************************************************************************
465 
466  //**SMP assignment to dense vectors*************************************************************
480  template< typename VT2 > // Type of the target dense vector
481  friend inline auto smpAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
482  -> EnableIf_t< UseSMPAssign_v<VT2> >
483  {
485 
486  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
487 
488  DVecTransposer<VT2,!TF> tmp( ~lhs );
489  smpAssign( tmp, rhs.sv_ );
490  }
492  //**********************************************************************************************
493 
494  //**SMP assignment to sparse vectors************************************************************
508  template< typename VT2 > // Type of the target sparse vector
509  friend inline auto smpAssign( SparseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
510  -> EnableIf_t< UseSMPAssign_v<VT2> >
511  {
513 
514  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
515 
516  SVecTransposer<VT2,!TF> tmp( ~lhs );
517  smpAssign( tmp, rhs.sv_ );
518  }
520  //**********************************************************************************************
521 
522  //**SMP addition assignment to dense vectors****************************************************
536  template< typename VT2 > // Type of the target dense vector
537  friend inline auto smpAddAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
538  -> EnableIf_t< UseSMPAssign_v<VT2> >
539  {
541 
542  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
543 
544  DVecTransposer<VT2,!TF> tmp( ~lhs );
545  smpAddAssign( tmp, rhs.sv_ );
546  }
548  //**********************************************************************************************
549 
550  //**SMP addition assignment to sparse vectors***************************************************
551  // No special implementation for the SMP addition assignment to sparse vectors.
552  //**********************************************************************************************
553 
554  //**SMP subtraction assignment to dense vectors*************************************************
568  template< typename VT2 > // Type of the target dense vector
569  friend inline auto smpSubAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
570  -> EnableIf_t< UseSMPAssign_v<VT2> >
571  {
573 
574  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
575 
576  DVecTransposer<VT2,!TF> tmp( ~lhs );
577  smpSubAssign( tmp, rhs.sv_ );
578  }
580  //**********************************************************************************************
581 
582  //**SMP subtraction assignment to sparse vectors************************************************
583  // No special implementation for the SMP subtraction assignment to sparse vectors.
584  //**********************************************************************************************
585 
586  //**SMP multiplication assignment to dense vectors**********************************************
601  template< typename VT2 > // Type of the target dense vector
602  friend inline auto smpMultAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
603  -> EnableIf_t< UseSMPAssign_v<VT2> >
604  {
606 
607  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
608 
609  DVecTransposer<VT2,!TF> tmp( ~lhs );
610  smpMultAssign( tmp, rhs.sv_ );
611  }
613  //**********************************************************************************************
614 
615  //**SMP multiplication assignment to sparse vectors*********************************************
616  // No special implementation for the SMP multiplication assignment to sparse vectors.
617  //**********************************************************************************************
618 
619  //**Compile time checks*************************************************************************
623  //**********************************************************************************************
624 };
625 //*************************************************************************************************
626 
627 
628 
629 
630 //=================================================================================================
631 //
632 // GLOBAL OPERATORS
633 //
634 //=================================================================================================
635 
636 //*************************************************************************************************
655 template< typename VT // Type of the sparse vector
656  , bool TF > // Transpose flag
657 inline decltype(auto) trans( const SparseVector<VT,TF>& sv )
658 {
660 
661  using ReturnType = const SVecTransExpr<VT,!TF>;
662  return ReturnType( ~sv );
663 }
664 //*************************************************************************************************
665 
666 
667 //*************************************************************************************************
675 template< typename VT // Type of the sparse vector
676  , bool TF > // Transpose flag
677 inline decltype(auto) transTo_backend( const SparseVector<VT,TF>& sv, FalseType )
678 {
679  return trans( ~sv );
680 }
682 //*************************************************************************************************
683 
684 
685 //*************************************************************************************************
693 template< typename VT // Type of the sparse vector
694  , bool TF > // Transpose flag
695 inline const VT& transTo_backend( const SparseVector<VT,TF>& sv, TrueType )
696 {
697  return ~sv;
698 }
700 //*************************************************************************************************
701 
702 
703 //*************************************************************************************************
715 template< bool TTF // Target transpose flag
716  , typename VT // Type of the sparse vector
717  , bool TF > // Current transpose flag of the sparse vector
718 inline decltype(auto) transTo( const SparseVector<VT,TF>& sv )
719 {
720  return transTo_backend( ~sv, BoolConstant<TTF == TF>() );
721 }
722 //*************************************************************************************************
723 
724 
725 
726 
727 //=================================================================================================
728 //
729 // GLOBAL RESTRUCTURING FUNCTIONS
730 //
731 //=================================================================================================
732 
733 //*************************************************************************************************
753 template< typename VT // Type of the sparse vector
754  , bool TF > // Transpose flag
755 inline decltype(auto) trans( const SVecTransExpr<VT,TF>& sv )
756 {
758 
759  return sv.operand();
760 }
762 //*************************************************************************************************
763 
764 
765 //*************************************************************************************************
777 template< typename VT // Type of the left-hand side sparse vector
778  , typename ST // Type of the right-hand side scalar value
779  , bool TF > // Transpose flag
780 inline decltype(auto) trans( const SVecScalarMultExpr<VT,ST,TF>& sv )
781 {
783 
784  return trans( sv.leftOperand() ) * sv.rightOperand();
785 }
787 //*************************************************************************************************
788 
789 } // namespace blaze
790 
791 #endif
BoolConstant< false > FalseType
Type/value traits base class.The FalseType class is used as base class for type traits and value trai...
Definition: FalseType.h:61
ConstIterator lowerBound(size_t index) const
Returns an iterator to the first index not less then the given index.
Definition: SVecTransExpr.h:247
Header file for auxiliary alias declarations.
Operand sv_
Sparse vector of the transposition expression.
Definition: SVecTransExpr.h:311
Header file for basic type definitions.
Header file for the SparseVector base class.
typename If< Condition, T1, T2 >::Type If_t
Auxiliary alias declaration for the If class template.The If_t alias declaration provides a convenien...
Definition: If.h:109
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: SVecTransExpr.h:304
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:141
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:168
Generic wrapper for a compile time constant integral value.The IntegralConstant class template repres...
Definition: IntegralConstant.h:71
static constexpr bool smpAssignable
Compilation flag for SMP assignments.
Definition: CompressedMatrix.h:3113
Expression object for sparse vector transpositions.The SVecTransExpr class represents the compile tim...
Definition: Forward.h:155
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: TrueType.h:61
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:259
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:77
CompositeType_t< VT > CT
Composite type of the sparse vector expression.
Definition: SVecTransExpr.h:92
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:132
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:156
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:133
#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:783
ConstIterator begin() const
Returns an iterator to the first non-zero element of the sparse vector.
Definition: SVecTransExpr.h:194
Header file for the exception macros of the math module.
Operand operand() const noexcept
Returns the sparse vector operand.
Definition: SVecTransExpr.h:270
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.
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:235
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:157
ElementType_t< VT > ElementType
Resulting element type.
Definition: SVecTransExpr.h:134
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:135
#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
size_t nonZeros() const
Returns the number of non-zero elements in the sparse vector.
Definition: SVecTransExpr.h:224
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:144
#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
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:3081
If_t< useAssign, const ResultType, const SVecTransExpr &> CompositeType
Data type for composite expression templates.
Definition: SVecTransExpr.h:138
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:214
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:138
Header file for the IntegralConstant class template.
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: SVecTransExpr.h:149
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: SVecTransExpr.h:181
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SVecTransExpr.h:294
static constexpr bool useAssign
Compilation switch for the serial evaluation strategy of the transposition expression.
Definition: SVecTransExpr.h:106
#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
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 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:204
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SVecTransExpr.h:282