SVecScalarMultExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_SVECSCALARMULTEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_SVECSCALARMULTEXPR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <iterator>
44 #include <utility>
45 #include <blaze/math/Aliases.h>
50 #include <blaze/math/Exception.h>
65 #include <blaze/util/Assert.h>
69 #include <blaze/util/DisableIf.h>
70 #include <blaze/util/EnableIf.h>
72 #include <blaze/util/mpl/If.h>
73 #include <blaze/util/Types.h>
76 
77 
78 namespace blaze {
79 
80 //=================================================================================================
81 //
82 // CLASS SVECSCALARMULTEXPR
83 //
84 //=================================================================================================
85 
86 //*************************************************************************************************
93 template< typename VT // Type of the left-hand side sparse vector
94  , typename ST // Type of the right-hand side scalar value
95  , bool TF > // Transpose flag
96 class SVecScalarMultExpr
97  : public VecScalarMultExpr< SparseVector< SVecScalarMultExpr<VT,ST,TF>, TF > >
98  , private Computation
99 {
100  private:
101  //**Type definitions****************************************************************************
105  //**********************************************************************************************
106 
107  //**Return type evaluation**********************************************************************
109 
114  static constexpr bool returnExpr = !IsTemporary_v<RN>;
115 
117  using ExprReturnType = decltype( std::declval<RN>() * std::declval<ST>() );
118  //**********************************************************************************************
119 
120  //**Serial evaluation strategy******************************************************************
122 
128  static constexpr bool useAssign = RequiresEvaluation_v<VT>;
129 
131  template< typename VT2 >
133  static constexpr bool UseAssign_v = useAssign;
135  //**********************************************************************************************
136 
137  //**Parallel evaluation strategy****************************************************************
139 
145  template< typename VT2 >
146  static constexpr bool UseSMPAssign_v =
149  //**********************************************************************************************
150 
151  public:
152  //**Type definitions****************************************************************************
158 
161 
164 
166  using LeftOperand = If_t< IsExpression_v<VT>, const VT, const VT& >;
167 
169  using RightOperand = ST;
170  //**********************************************************************************************
171 
172  //**Compilation flags***************************************************************************
174  static constexpr bool smpAssignable = false;
175  //**********************************************************************************************
176 
177  //**ConstIterator class definition**************************************************************
181  {
182  public:
183  //**Type definitions*************************************************************************
186 
189 
190  using IteratorCategory = std::forward_iterator_tag;
191  using ValueType = Element;
195 
196  // STL iterator requirements
202  //*******************************************************************************************
203 
204  //**Constructor******************************************************************************
207  inline ConstIterator( IteratorType vector, RightOperand scalar )
208  : vector_( vector ) // Iterator over the elements of the left-hand side sparse vector expression
209  , scalar_( scalar ) // Right-hand side scalar of the multiplication expression
210  {}
211  //*******************************************************************************************
212 
213  //**Prefix increment operator****************************************************************
219  ++vector_;
220  return *this;
221  }
222  //*******************************************************************************************
223 
224  //**Element access operator******************************************************************
229  inline const Element operator*() const {
230  return Element( vector_->value() * scalar_, vector_->index() );
231  }
232  //*******************************************************************************************
233 
234  //**Element access operator******************************************************************
239  inline const ConstIterator* operator->() const {
240  return this;
241  }
242  //*******************************************************************************************
243 
244  //**Value function***************************************************************************
249  inline ReturnType value() const {
250  return vector_->value() * scalar_;
251  }
252  //*******************************************************************************************
253 
254  //**Index function***************************************************************************
259  inline size_t index() const {
260  return vector_->index();
261  }
262  //*******************************************************************************************
263 
264  //**Equality operator************************************************************************
270  inline bool operator==( const ConstIterator& rhs ) const {
271  return vector_ == rhs.vector_;
272  }
273  //*******************************************************************************************
274 
275  //**Inequality operator**********************************************************************
281  inline bool operator!=( const ConstIterator& rhs ) const {
282  return vector_ != rhs.vector_;
283  }
284  //*******************************************************************************************
285 
286  //**Subtraction operator*********************************************************************
292  inline DifferenceType operator-( const ConstIterator& rhs ) const {
293  return vector_ - rhs.vector_;
294  }
295  //*******************************************************************************************
296 
297  private:
298  //**Member variables*************************************************************************
301  //*******************************************************************************************
302  };
303  //**********************************************************************************************
304 
305  //**Constructor*********************************************************************************
311  explicit inline SVecScalarMultExpr( const VT& vector, ST scalar ) noexcept
312  : vector_( vector ) // Left-hand side sparse vector of the multiplication expression
313  , scalar_( scalar ) // Right-hand side scalar of the multiplication expression
314  {}
315  //**********************************************************************************************
316 
317  //**Subscript operator**************************************************************************
323  inline ReturnType operator[]( size_t index ) const {
324  BLAZE_INTERNAL_ASSERT( index < vector_.size(), "Invalid vector access index" );
325  return vector_[index] * scalar_;
326  }
327  //**********************************************************************************************
328 
329  //**At function*********************************************************************************
336  inline ReturnType at( size_t index ) const {
337  if( index >= vector_.size() ) {
338  BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
339  }
340  return (*this)[index];
341  }
342  //**********************************************************************************************
343 
344  //**Begin function******************************************************************************
349  inline ConstIterator begin() const {
350  return ConstIterator( vector_.begin(), scalar_ );
351  }
352  //**********************************************************************************************
353 
354  //**End function********************************************************************************
359  inline ConstIterator end() const {
360  return ConstIterator( vector_.end(), scalar_ );
361  }
362  //**********************************************************************************************
363 
364  //**Size function*******************************************************************************
369  inline size_t size() const noexcept {
370  return vector_.size();
371  }
372  //**********************************************************************************************
373 
374  //**NonZeros function***************************************************************************
379  inline size_t nonZeros() const {
380  return vector_.nonZeros();
381  }
382  //**********************************************************************************************
383 
384  //**Find function*******************************************************************************
390  inline ConstIterator find( size_t index ) const {
392  return ConstIterator( vector_.find( index ), scalar_ );
393  }
394  //**********************************************************************************************
395 
396  //**LowerBound function*************************************************************************
402  inline ConstIterator lowerBound( size_t index ) const {
404  return ConstIterator( vector_.lowerBound( index ), scalar_ );
405  }
406  //**********************************************************************************************
407 
408  //**UpperBound function*************************************************************************
414  inline ConstIterator upperBound( size_t index ) const {
416  return ConstIterator( vector_.upperBound( index ), scalar_ );
417  }
418  //**********************************************************************************************
419 
420  //**Left operand access*************************************************************************
425  inline LeftOperand leftOperand() const noexcept {
426  return vector_;
427  }
428  //**********************************************************************************************
429 
430  //**Right operand access************************************************************************
435  inline RightOperand rightOperand() const noexcept {
436  return scalar_;
437  }
438  //**********************************************************************************************
439 
440  //**********************************************************************************************
446  template< typename T >
447  inline bool canAlias( const T* alias ) const noexcept {
448  return vector_.canAlias( alias );
449  }
450  //**********************************************************************************************
451 
452  //**********************************************************************************************
458  template< typename T >
459  inline bool isAliased( const T* alias ) const noexcept {
460  return vector_.isAliased( alias );
461  }
462  //**********************************************************************************************
463 
464  private:
465  //**Member variables****************************************************************************
468  //**********************************************************************************************
469 
470  //**Assignment to dense vectors*****************************************************************
484  template< typename VT2 > // Type of the target dense vector
485  friend inline auto assign( DenseVector<VT2,TF>& lhs, const SVecScalarMultExpr& rhs )
487  {
489 
490  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
491 
492  assign( ~lhs, rhs.vector_ );
493  (~lhs) *= rhs.scalar_;
494  }
496  //**********************************************************************************************
497 
498  //**Assignment to sparse vectors****************************************************************
512  template< typename VT2 > // Type of the target sparse vector
513  friend inline auto assign( SparseVector<VT2,TF>& lhs, const SVecScalarMultExpr& rhs )
515  {
517 
518  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
519 
520  assign( ~lhs, rhs.vector_ );
521  (~lhs) *= rhs.scalar_;
522  }
524  //**********************************************************************************************
525 
526  //**Addition assignment to dense vectors********************************************************
540  template< typename VT2 > // Type of the target dense vector
541  friend inline auto addAssign( DenseVector<VT2,TF>& lhs, const SVecScalarMultExpr& rhs )
542  -> EnableIf_t< UseAssign_v<VT2> >
543  {
545 
549 
550  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
551 
552  const ResultType tmp( serial( rhs ) );
553  addAssign( ~lhs, tmp );
554  }
556  //**********************************************************************************************
557 
558  //**Addition assignment to sparse vectors*******************************************************
559  // No special implementation for the addition assignment to sparse vectors.
560  //**********************************************************************************************
561 
562  //**Subtraction assignment to dense vectors*****************************************************
576  template< typename VT2 > // Type of the target dense vector
577  friend inline auto subAssign( DenseVector<VT2,TF>& lhs, const SVecScalarMultExpr& rhs )
578  -> EnableIf_t< UseAssign_v<VT2> >
579  {
581 
585 
586  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
587 
588  const ResultType tmp( serial( rhs ) );
589  subAssign( ~lhs, tmp );
590  }
592  //**********************************************************************************************
593 
594  //**Subtraction assignment to sparse vectors****************************************************
595  // No special implementation for the subtraction assignment to sparse vectors.
596  //**********************************************************************************************
597 
598  //**Multiplication assignment to dense vectors**************************************************
612  template< typename VT2 > // Type of the target dense vector
613  friend inline auto multAssign( DenseVector<VT2,TF>& lhs, const SVecScalarMultExpr& rhs )
614  -> EnableIf_t< UseAssign_v<VT2> >
615  {
617 
621 
622  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
623 
624  const ResultType tmp( serial( rhs ) );
625  multAssign( ~lhs, tmp );
626  }
628  //**********************************************************************************************
629 
630  //**Multiplication assignment to sparse vectors*************************************************
631  // No special implementation for the multiplication assignment to sparse vectors.
632  //**********************************************************************************************
633 
634  //**SMP assignment to dense vectors*************************************************************
635  // No special implementation for the SMP assignment to dense vectors.
636  //**********************************************************************************************
637 
638  //**SMP assignment to sparse vectors************************************************************
639  // No special implementation for the SMP assignment to sparse vectors.
640  //**********************************************************************************************
641 
642  //**SMP addition assignment to dense vectors****************************************************
656  template< typename VT2 > // Type of the target dense vector
657  friend inline auto smpAddAssign( DenseVector<VT2,TF>& lhs, const SVecScalarMultExpr& rhs )
658  -> EnableIf_t< UseSMPAssign_v<VT2> >
659  {
661 
665 
666  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
667 
668  const ResultType tmp( rhs );
669  smpAddAssign( ~lhs, tmp );
670  }
672  //**********************************************************************************************
673 
674  //**SMP addition assignment to sparse vectors***************************************************
675  // No special implementation for the SMP addition assignment to sparse vectors.
676  //**********************************************************************************************
677 
678  //**SMP subtraction assignment to dense vectors*************************************************
692  template< typename VT2 > // Type of the target dense vector
693  friend inline auto smpSubAssign( DenseVector<VT2,TF>& lhs, const SVecScalarMultExpr& rhs )
694  -> EnableIf_t< UseSMPAssign_v<VT2> >
695  {
697 
701 
702  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
703 
704  const ResultType tmp( rhs );
705  smpSubAssign( ~lhs, tmp );
706  }
708  //**********************************************************************************************
709 
710  //**SMP subtraction assignment to sparse vectors************************************************
711  // No special implementation for the SMP subtraction assignment to sparse vectors.
712  //**********************************************************************************************
713 
714  //**SMP multiplication assignment to dense vectors**********************************************
728  template< typename VT2 > // Type of the target dense vector
729  friend inline auto smpMultAssign( DenseVector<VT2,TF>& lhs, const SVecScalarMultExpr& rhs )
730  -> EnableIf_t< UseSMPAssign_v<VT2> >
731  {
733 
737 
738  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
739 
740  const ResultType tmp( rhs );
741  smpMultAssign( ~lhs, tmp );
742  }
744  //**********************************************************************************************
745 
746  //**SMP multiplication assignment to sparse vectors*********************************************
747  // No special implementation for the SMP multiplication assignment to sparse vectors.
748  //**********************************************************************************************
749 
750  //**Compile time checks*************************************************************************
758  //**********************************************************************************************
759 };
760 //*************************************************************************************************
761 
762 
763 
764 
765 //=================================================================================================
766 //
767 // GLOBAL UNARY ARITHMETIC OPERATORS
768 //
769 //=================================================================================================
770 
771 //*************************************************************************************************
788 template< typename VT // Type of the sparse vector
789  , bool TF > // Transpose flag
790 inline decltype(auto) operator-( const SparseVector<VT,TF>& sv )
791 {
793 
794  using ScalarType = UnderlyingBuiltin_t<VT>;
796  return ReturnType( ~sv, ScalarType(-1) );
797 }
798 //*************************************************************************************************
799 
800 
801 
802 
803 //=================================================================================================
804 //
805 // GLOBAL BINARY ARITHMETIC OPERATORS
806 //
807 //=================================================================================================
808 
809 //*************************************************************************************************
822 template< typename VT // Type of the left-hand side sparse vector
823  , bool TF // Transpose flag of the left-hand side sparse vector
824  , typename ST // Type of the right-hand side scalar
825  , DisableIf_t< IsZero_v<VT> >* = nullptr >
826 inline const SVecScalarMultExpr< VT, MultTrait_t< UnderlyingBuiltin_t<VT>, ST >, TF >
827  svecscalarmult( const SparseVector<VT,TF>& vec, ST scalar )
828 {
830 
831  using ScalarType = MultTrait_t< UnderlyingBuiltin_t<VT>, ST >;
832  using ReturnType = const SVecScalarMultExpr<VT,ScalarType,TF>;
833  return ReturnType( ~vec, scalar );
834 }
836 //*************************************************************************************************
837 
838 
839 //*************************************************************************************************
852 template< typename VT // Type of the left-hand side sparse vector
853  , bool TF // Transpose flag of the left-hand side sparse vector
854  , typename ST // Type of the right-hand side scalar
855  , EnableIf_t< IsZero_v<VT> >* = nullptr >
856 inline decltype(auto)
857  svecscalarmult( const SparseVector<VT,TF>& vec, ST scalar )
858 {
860 
861  UNUSED_PARAMETER( scalar );
862 
863  using ReturnType = const MultTrait_t< ResultType_t<VT>, ST >;
864 
867 
868  return ReturnType( (~vec).size() );
869 }
871 //*************************************************************************************************
872 
873 
874 //*************************************************************************************************
895 template< typename VT // Type of the left-hand side sparse vector
896  , typename ST // Type of the right-hand side scalar
897  , bool TF // Transpose flag
898  , EnableIf_t< IsNumeric_v<ST> >* = nullptr >
899 inline decltype(auto) operator*( const SparseVector<VT,TF>& vec, ST scalar )
900 {
902 
903  return svecscalarmult( ~vec, scalar );
904 }
905 //*************************************************************************************************
906 
907 
908 //*************************************************************************************************
929 template< typename ST // Type of the left-hand side scalar
930  , typename VT // Type of the right-hand side sparse vector
931  , bool TF // Transpose flag
932  , EnableIf_t< IsNumeric_v<ST> >* = nullptr >
933 inline decltype(auto) operator*( ST scalar, const SparseVector<VT,TF>& vec )
934 {
936 
937  return svecscalarmult( ~vec, scalar );
938 }
939 //*************************************************************************************************
940 
941 
942 
943 
944 //=================================================================================================
945 //
946 // GLOBAL FUNCTIONS
947 //
948 //=================================================================================================
949 
950 //*************************************************************************************************
968 template< typename VT // Type of the sparse vector
969  , bool TF > // Transpose flag
970 inline decltype(auto) normalize( const SparseVector<VT,TF>& vec )
971 {
973 
975 
976  const ElementType len ( length( ~vec ) );
977  const ElementType ilen( ( len != ElementType(0) )?( ElementType(1) / len ):( 0 ) );
978 
980  return ReturnType( ~vec, ilen );
981 }
982 //*************************************************************************************************
983 
984 
985 
986 
987 //=================================================================================================
988 //
989 // GLOBAL RESTRUCTURING UNARY ARITHMETIC OPERATORS
990 //
991 //=================================================================================================
992 
993 //*************************************************************************************************
1005 template< typename VT // Type of the sparse vector
1006  , typename ST // Type of the scalar
1007  , bool TF > // Transpose flag
1008 inline decltype(auto) operator-( const SVecScalarMultExpr<VT,ST,TF>& sv )
1009 {
1011 
1012  using ReturnType = const SVecScalarMultExpr<VT,ST,TF>;
1013  return ReturnType( sv.leftOperand(), -sv.rightOperand() );
1014 }
1016 //*************************************************************************************************
1017 
1018 
1019 
1020 
1021 //=================================================================================================
1022 //
1023 // GLOBAL RESTRUCTURING BINARY ARITHMETIC OPERATORS
1024 //
1025 //=================================================================================================
1026 
1027 //*************************************************************************************************
1040 template< typename VT // Type of the sparse vector of the left-hand side expression
1041  , typename ST1 // Type of the scalar of the left-hand side expression
1042  , bool TF // Transpose flag of the sparse vector
1043  , typename ST2 // Type of the right-hand side scalar
1044  , EnableIf_t< IsNumeric_v<ST2> >* = nullptr >
1045 inline decltype(auto) operator*( const SVecScalarMultExpr<VT,ST1,TF>& vec, ST2 scalar )
1046 {
1048 
1049  return vec.leftOperand() * ( vec.rightOperand() * scalar );
1050 }
1052 //*************************************************************************************************
1053 
1054 
1055 //*************************************************************************************************
1068 template< typename ST1 // Type of the left-hand side scalar
1069  , typename VT // Type of the sparse vector of the right-hand side expression
1070  , typename ST2 // Type of the scalar of the right-hand side expression
1071  , bool TF // Transpose flag of the sparse vector
1072  , EnableIf_t< IsNumeric_v<ST1> >* = nullptr >
1073 inline decltype(auto) operator*( ST1 scalar, const SVecScalarMultExpr<VT,ST2,TF>& vec )
1074 {
1076 
1077  return vec.leftOperand() * ( scalar * vec.rightOperand() );
1078 }
1080 //*************************************************************************************************
1081 
1082 
1083 //*************************************************************************************************
1096 template< typename VT // Type of the dense vector of the left-hand side expression
1097  , typename ST1 // Type of the scalar of the left-hand side expression
1098  , bool TF // Transpose flag of the dense vector
1099  , typename ST2 // Type of the right-hand side scalar
1100  , EnableIf_t< IsNumeric_v<ST2> && ( IsInvertible_v<ST1> || IsInvertible_v<ST2> ) >* = nullptr >
1101 inline decltype(auto) operator/( const SVecScalarMultExpr<VT,ST1,TF>& vec, ST2 scalar )
1102 {
1104 
1105  return vec.leftOperand() * ( vec.rightOperand() / scalar );
1106 }
1108 //*************************************************************************************************
1109 
1110 
1111 //*************************************************************************************************
1125 template< typename VT1 // Type of the sparse vector of the left-hand side expression
1126  , typename ST // Type of the scalar of the left-hand side expression
1127  , bool TF // Transpose flag of the dense vectors
1128  , typename VT2 > // Type of the right-hand side dense vector
1129 inline decltype(auto)
1130  operator*( const SVecScalarMultExpr<VT1,ST,TF>& lhs, const DenseVector<VT2,TF>& rhs )
1131 {
1133 
1134  return ( lhs.leftOperand() * (~rhs) ) * lhs.rightOperand();
1135 }
1137 //*************************************************************************************************
1138 
1139 
1140 //*************************************************************************************************
1154 template< typename VT1 // Type of the left-hand side dense vector
1155  , bool TF // Transpose flag of the dense vectors
1156  , typename VT2 // Type of the sparse vector of the right-hand side expression
1157  , typename ST > // Type of the scalar of the right-hand side expression
1158 inline decltype(auto)
1159  operator*( const DenseVector<VT1,TF>& lhs, const SVecScalarMultExpr<VT2,ST,TF>& rhs )
1160 {
1162 
1163  return ( (~lhs) * rhs.leftOperand() ) * rhs.rightOperand();
1164 }
1166 //*************************************************************************************************
1167 
1168 
1169 //*************************************************************************************************
1183 template< typename VT1 // Type of the sparse vector of the left-hand side expression
1184  , typename ST // Type of the scalar of the left-hand side expression
1185  , typename VT2 > // Type of the right-hand side dense vector
1186 inline decltype(auto)
1187  operator*( const SVecScalarMultExpr<VT1,ST,false>& lhs, const DenseVector<VT2,true>& rhs )
1188 {
1190 
1191  return ( lhs.leftOperand() * (~rhs) ) * lhs.rightOperand();
1192 }
1194 //*************************************************************************************************
1195 
1196 
1197 //*************************************************************************************************
1211 template< typename VT1 // Type of the left-hand side dense vector
1212  , typename VT2 // Type of the sparse vector of the right-hand side expression
1213  , typename ST > // Type of the scalar of the right-hand side expression
1214 inline decltype(auto)
1215  operator*( const DenseVector<VT1,false>& lhs, const SVecScalarMultExpr<VT2,ST,true>& rhs )
1216 {
1218 
1219  return ( (~lhs) * rhs.leftOperand() ) * rhs.rightOperand();
1220 }
1222 //*************************************************************************************************
1223 
1224 
1225 //*************************************************************************************************
1239 template< typename VT1 // Type of the sparse vector of the left-hand side expression
1240  , typename ST // Type of the scalar of the left-hand side expression
1241  , bool TF // Transpose flag of the vectors
1242  , typename VT2 > // Type of the right-hand side sparse vector
1243 inline decltype(auto)
1244  operator*( const SVecScalarMultExpr<VT1,ST,TF>& lhs, const SparseVector<VT2,TF>& rhs )
1245 {
1247 
1248  return ( lhs.leftOperand() * (~rhs) ) * lhs.rightOperand();
1249 }
1251 //*************************************************************************************************
1252 
1253 
1254 //*************************************************************************************************
1268 template< typename VT1 // Type of the left-hand side sparse vector
1269  , bool TF // Transpose flag of the vectors
1270  , typename VT2 // Type of the sparse vector of the right-hand side expression
1271  , typename ST > // Type of the scalar of the right-hand side expression
1272 inline decltype(auto)
1273  operator*( const SparseVector<VT1,TF>& lhs, const SVecScalarMultExpr<VT2,ST,TF>& rhs )
1274 {
1276 
1277  return ( (~lhs) * rhs.leftOperand() ) * rhs.rightOperand();
1278 }
1280 //*************************************************************************************************
1281 
1282 
1283 //*************************************************************************************************
1297 template< typename VT1 // Type of the sparse vector of the left-hand side expression
1298  , typename ST1 // Type of the scalar of the left-hand side expression
1299  , bool TF // Transpose flag of the sparse vectors
1300  , typename VT2 // Type of the sparse vector of the right-hand side expression
1301  , typename ST2 > // Type of the scalar of the right-hand side expression
1302 inline decltype(auto)
1303  operator*( const SVecScalarMultExpr<VT1,ST1,TF>& lhs, const SVecScalarMultExpr<VT2,ST2,TF>& rhs )
1304 {
1306 
1307  return ( lhs.leftOperand() * rhs.leftOperand() ) * ( lhs.rightOperand() * rhs.rightOperand() );
1308 }
1310 //*************************************************************************************************
1311 
1312 
1313 //*************************************************************************************************
1327 template< typename VT1 // Type of the sparse vector of the left-hand side expression
1328  , typename ST // Type of the scalar of the left-hand side expression
1329  , typename VT2 > // Type of the right-hand side sparse vector
1330 inline decltype(auto)
1331  operator*( const SVecScalarMultExpr<VT1,ST,false>& lhs, const SparseVector<VT2,true>& rhs )
1332 {
1334 
1335  return ( lhs.leftOperand() * (~rhs) ) * lhs.rightOperand();
1336 }
1338 //*************************************************************************************************
1339 
1340 
1341 //*************************************************************************************************
1355 template< typename VT1 // Type of the left-hand side sparse vector
1356  , typename VT2 // Type of the sparse vector of the right-hand side expression
1357  , typename ST > // Type of the scalar of the right-hand side expression
1358 inline decltype(auto)
1359  operator*( const SparseVector<VT1,false>& lhs, const SVecScalarMultExpr<VT2,ST,true>& rhs )
1360 {
1362 
1363  return ( (~lhs) * rhs.leftOperand() ) * rhs.rightOperand();
1364 }
1366 //*************************************************************************************************
1367 
1368 
1369 //*************************************************************************************************
1383 template< typename VT1 // Type of the sparse vector of the left-hand side expression
1384  , typename ST1 // Type of the scalar of the left-hand side expression
1385  , typename VT2 // Type of the sparse vector of the right-hand side expression
1386  , typename ST2 > // Type of the scalar of the right-hand side expression
1387 inline decltype(auto)
1388  operator*( const SVecScalarMultExpr<VT1,ST1,false>& lhs, const SVecScalarMultExpr<VT2,ST2,true>& rhs )
1389 {
1391 
1392  return ( lhs.leftOperand() * rhs.leftOperand() ) * ( lhs.rightOperand() * rhs.rightOperand() );
1393 }
1395 //*************************************************************************************************
1396 
1397 
1398 //*************************************************************************************************
1412 template< typename MT // Type of the left-hand side dense matrix
1413  , bool SO // Storage order of the left-hand side dense matrix
1414  , typename VT // Type of the sparse vector of the right-hand side expression
1415  , typename ST > // Type of the scalar of the right-hand side expression
1416 inline decltype(auto)
1417  operator*( const DenseMatrix<MT,SO>& mat, const SVecScalarMultExpr<VT,ST,false>& vec )
1418 {
1420 
1421  return ( (~mat) * vec.leftOperand() ) * vec.rightOperand();
1422 }
1424 //*************************************************************************************************
1425 
1426 
1427 //*************************************************************************************************
1441 template< typename VT // Type of the sparse vector of the left-hand side expression
1442  , typename ST // Type of the scalar of the left-hand side expression
1443  , typename MT // Type of the right-hand side dense matrix
1444  , bool SO > // Storage order of the right-hand side dense matrix
1445 inline decltype(auto)
1446  operator*( const SVecScalarMultExpr<VT,ST,true>& vec, const DenseMatrix<MT,SO>& mat )
1447 {
1449 
1450  return ( vec.leftOperand() * (~mat) ) * vec.rightOperand();
1451 }
1453 //*************************************************************************************************
1454 
1455 
1456 //*************************************************************************************************
1470 template< typename MT // Type of the left-hand side sparse matrix
1471  , bool SO // Storage order of the left-hand side sparse matrix
1472  , typename VT // Type of the sparse vector of the right-hand side expression
1473  , typename ST > // Type of the scalar of the right-hand side expression
1474 inline decltype(auto)
1475  operator*( const SparseMatrix<MT,SO>& mat, const SVecScalarMultExpr<VT,ST,false>& vec )
1476 {
1478 
1479  return ( (~mat) * vec.leftOperand() ) * vec.rightOperand();
1480 }
1482 //*************************************************************************************************
1483 
1484 
1485 //*************************************************************************************************
1499 template< typename VT // Type of the sparse vector of the left-hand side expression
1500  , typename ST // Type of the scalar of the left-hand side expression
1501  , typename MT // Type of the right-hand side sparse matrix
1502  , bool SO > // Storage order of the right-hand side sparse matrix
1503 inline decltype(auto)
1504  operator*( const SVecScalarMultExpr<VT,ST,true>& vec, const SparseMatrix<MT,SO>& mat )
1505 {
1507 
1508  return ( vec.leftOperand() * (~mat) ) * vec.rightOperand();
1509 }
1511 //*************************************************************************************************
1512 
1513 } // namespace blaze
1514 
1515 #endif
RightOperand rightOperand() const noexcept
Returns the right-hand side scalar operand.
Definition: SVecScalarMultExpr.h:435
Pointer difference type of the Blaze library.
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: SVecScalarMultExpr.h:157
size_t nonZeros() const
Returns the number of non-zero elements in the sparse vector.
Definition: SVecScalarMultExpr.h:379
bool operator==(const ConstIterator &rhs) const
Equality comparison between two ConstIterator objects.
Definition: SVecScalarMultExpr.h:270
Header file for auxiliary alias declarations.
Data type constraint.
Constraint on the data type.
Header file for basic type definitions.
Header file for the SparseVector base class.
bool operator!=(const ConstIterator &rhs) const
Inequality comparison between two ConstIterator objects.
Definition: SVecScalarMultExpr.h:281
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
ConstIterator_t< RemoveReference_t< LeftOperand > > IteratorType
Iterator type of the sparse vector expression.
Definition: SVecScalarMultExpr.h:188
typename T::ResultType ResultType_t
Alias declaration for nested ResultType type definitions.The ResultType_t alias declaration provides ...
Definition: Aliases.h:390
Header file for the serial shim.
IteratorCategory iterator_category
The iterator category.
Definition: SVecScalarMultExpr.h:197
DifferenceType operator-(const ConstIterator &rhs) const
Calculating the number of elements between two expression iterators.
Definition: SVecScalarMultExpr.h:292
ConstIterator begin() const
Returns an iterator to the first non-zero element of the sparse vector.
Definition: SVecScalarMultExpr.h:349
static constexpr bool smpAssignable
Compilation flag for SMP assignments.
Definition: CompressedMatrix.h:3113
Constraint on the data type.
Iterator over the elements of the sparse vector/scalar multiplication expression. ...
Definition: SVecScalarMultExpr.h:180
MultTrait_t< RT, ST > ResultType
Result type for expression template evaluations.
Definition: SVecScalarMultExpr.h:155
Header file for the Computation base class.
Header file for the RequiresEvaluation type trait.
constexpr void UNUSED_PARAMETER(const Args &...)
Suppression of unused parameter warnings.
Definition: Unused.h:81
ValueType & ReferenceType
Reference return type.
Definition: SVecScalarMultExpr.h:193
typename T::ReturnType ReturnType_t
Alias declaration for nested ReturnType type definitions.The ReturnType_t alias declaration provides ...
Definition: Aliases.h:410
Header file for the VecScalarMultExpr base class.
ValueIndexPair< ElementType > Element
Element type of the sparse vector expression.
Definition: SVecScalarMultExpr.h:185
std::forward_iterator_tag IteratorCategory
The iterator category.
Definition: SVecScalarMultExpr.h:190
ConstIterator & operator++()
Pre-increment operator.
Definition: SVecScalarMultExpr.h:218
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.The ElementType_t alias declaration provide...
Definition: Aliases.h:170
ReturnType_t< VT > RN
Return type of the sparse vector expression.
Definition: SVecScalarMultExpr.h:103
auto length(const DenseVector< VT, TF > &dv) -> decltype(sqrt(sqrLength(~dv)))
Calculation of the length (magnitude) of the dense vector .
Definition: DenseVector.h:606
const Element operator*() const
Direct access to the sparse vector element at the current iterator position.
Definition: SVecScalarMultExpr.h:229
RightOperand scalar_
Right-hand side scalar of the multiplication expression.
Definition: SVecScalarMultExpr.h:467
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
Header file for the ValueIndexPair class.
Header file for the DisableIf class template.
Header file for the IsTemporary type trait class.
Header file for the multiplication trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for the If class template.
Element ValueType
Type of the underlying pointers.
Definition: SVecScalarMultExpr.h:191
#define BLAZE_CONSTRAINT_MUST_BE_ZERO_TYPE(T)
Constraint on the data type.In case the given data type T is not a zero vector or matrix type...
Definition: Zero.h:61
RightOperand scalar_
Right-hand side scalar of the multiplication expression.
Definition: SVecScalarMultExpr.h:300
Header file for the UnderlyingBuiltin type trait.
Type ElementType
Type of the compressed matrix elements.
Definition: CompressedMatrix.h:3080
#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
decltype(auto) normalize(const DenseVector< VT, TF > &vec)
Normalization of the dense vector ( ).
Definition: DVecScalarMultExpr.h:1148
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SVecScalarMultExpr.h:459
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:3086
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_SAME_TYPE(A, B)
Data type constraint.In case the two types A and B are not the same (ignoring all cv-qualifiers of bo...
Definition: SameType.h:71
#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
static constexpr bool useAssign
Compilation switch for the serial evaluation strategy of the multiplication expression.
Definition: SVecScalarMultExpr.h:128
Constraint on the data type.
const If_t< returnExpr, ExprReturnType, ElementType > ReturnType
Return type for expression template evaluations.
Definition: SVecScalarMultExpr.h:160
ResultType_t< VT > RT
Result type of the sparse vector expression.
Definition: SVecScalarMultExpr.h:102
Header file for the exception macros of the math module.
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: SVecScalarMultExpr.h:174
ValueType * PointerType
Pointer return type.
Definition: SVecScalarMultExpr.h:192
If_t< IsExpression_v< VT >, const VT, const VT &> LeftOperand
Composite type of the left-hand side sparse vector expression.
Definition: SVecScalarMultExpr.h:166
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: SVecScalarMultExpr.h:323
Constraint on the data type.
Header file for all forward declarations for expression class templates.
Constraint on the data type.
const ConstIterator * operator->() const
Direct access to the sparse vector element at the current iterator position.
Definition: SVecScalarMultExpr.h:239
typename UnderlyingBuiltin< T >::Type UnderlyingBuiltin_t
Auxiliary alias declaration for the UnderlyingBuiltin type trait.The UnderlyingBuiltin_t alias declar...
Definition: UnderlyingBuiltin.h:133
Header file for the EnableIf class template.
typename MultTrait< T1, T2 >::Type MultTrait_t
Auxiliary alias declaration for the MultTrait class template.The MultTrait_t alias declaration provid...
Definition: MultTrait.h:240
Header file for the IsNumeric type trait.
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.
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.The CompositeType_t alias declaration pro...
Definition: Aliases.h:90
If_t< useAssign, const ResultType, const SVecScalarMultExpr &> CompositeType
Data type for composite expression templates.
Definition: SVecScalarMultExpr.h:163
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
IteratorType vector_
Iterator over the elements of the left-hand side sparse vector expression.
Definition: SVecScalarMultExpr.h:299
ConstIterator lowerBound(size_t index) const
Returns an iterator to the first index not less then the given index.
Definition: SVecScalarMultExpr.h:402
ConstIterator end() const
Returns an iterator just past the last non-zero element of the sparse vector.
Definition: SVecScalarMultExpr.h:359
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SVecScalarMultExpr.h:447
Constraint on the data type.
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: SVecScalarMultExpr.h:369
#define BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE(T)
Constraint on the data type.In case the given data type T is not a numeric (integral or floating poin...
Definition: Numeric.h:61
Header file for the IsZero type trait.
#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
constexpr size_t size(const Matrix< MT, SO > &matrix) noexcept
Returns the total number of elements of the matrix.
Definition: Matrix.h:530
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:808
#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.
Header file for the IsInvertible type trait.
static constexpr bool returnExpr
Compilation switch for the selection of the subscript operator return type.
Definition: SVecScalarMultExpr.h:114
ConstIterator find(size_t index) const
Searches for a specific vector element.
Definition: SVecScalarMultExpr.h:390
typename T::ConstIterator ConstIterator_t
Alias declaration for nested ConstIterator type definitions.The ConstIterator_t alias declaration pro...
Definition: Aliases.h:110
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:3081
Index-value-pair for sparse vectors and matrices.The ValueIndexPair class represents a single index-v...
Definition: ValueIndexPair.h:73
Header file for the IsComputation type trait class.
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
Expression object for sparse vector-scalar multiplications.The SVecScalarMultExpr class represents th...
Definition: Forward.h:148
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:138
size_t index() const
Access to the current index of the sparse element.
Definition: SVecScalarMultExpr.h:259
SVecScalarMultExpr(const VT &vector, ST scalar) noexcept
Constructor for the SVecScalarMultExpr class.
Definition: SVecScalarMultExpr.h:311
ConstIterator upperBound(size_t index) const
Returns an iterator to the first index greater then the given index.
Definition: SVecScalarMultExpr.h:414
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: SVecScalarMultExpr.h:156
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: SVecScalarMultExpr.h:194
LeftOperand vector_
Left-hand side sparse vector of the multiplication expression.
Definition: SVecScalarMultExpr.h:466
CompositeType_t< VT > CT
Composite type of the sparse vector expression.
Definition: SVecScalarMultExpr.h:104
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: SVecScalarMultExpr.h:336
ReturnType value() const
Access to the current value of the sparse element.
Definition: SVecScalarMultExpr.h:249
#define BLAZE_CONSTRAINT_MUST_NOT_BE_ZERO_TYPE(T)
Constraint on the data type.In case the given data type T is a zero vector or matrix type...
Definition: Zero.h:81
#define BLAZE_CONSTRAINT_MUST_BE_VECTOR_WITH_TRANSPOSE_FLAG(T, TF)
Constraint on the data type.In case the given data type T is not a dense or sparse vector type and in...
Definition: TransposeFlag.h:63
#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
decltype(std::declval< RN >() *std::declval< ST >()) ExprReturnType
Expression return type for the subscript operator.
Definition: SVecScalarMultExpr.h:117
LeftOperand leftOperand() const noexcept
Returns the left-hand side sparse vector operand.
Definition: SVecScalarMultExpr.h:425
ST RightOperand
Composite type of the right-hand side scalar value.
Definition: SVecScalarMultExpr.h:169
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
#define BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE(T)
Constraint on the data type.In case the given data type T is not a floating point data type...
Definition: FloatingPoint.h:61
Header file for the IsExpression type trait class.
Header file for the function trace functionality.
ConstIterator(IteratorType vector, RightOperand scalar)
Constructor for the ConstIterator class.
Definition: SVecScalarMultExpr.h:207