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 <blaze/math/Aliases.h>
48 #include <blaze/math/Exception.h>
64 #include <blaze/util/Assert.h>
68 #include <blaze/util/EnableIf.h>
70 #include <blaze/util/mpl/And.h>
71 #include <blaze/util/mpl/If.h>
72 #include <blaze/util/mpl/Or.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****************************************************************************
102  using RT = ResultType_<VT>;
103  using RN = ReturnType_<VT>;
105  //**********************************************************************************************
106 
107  //**Return type evaluation**********************************************************************
109 
114  enum : bool { returnExpr = !IsTemporary<RN>::value };
115 
118  //**********************************************************************************************
119 
120  //**Serial evaluation strategy******************************************************************
122 
128  enum : bool { useAssign = RequiresEvaluation<VT>::value };
129 
131  template< typename VT2 >
133  struct UseAssign {
134  enum : bool { value = useAssign };
135  };
137  //**********************************************************************************************
138 
139  //**Parallel evaluation strategy****************************************************************
141 
147  template< typename VT2 >
148  struct UseSMPAssign {
149  enum : bool { value = ( !VT2::smpAssignable || !VT::smpAssignable ) && useAssign };
150  };
152  //**********************************************************************************************
153 
154  public:
155  //**Type definitions****************************************************************************
160 
163 
166 
168  using LeftOperand = If_< IsExpression<VT>, const VT, const VT& >;
169 
171  using RightOperand = ST;
172  //**********************************************************************************************
173 
174  //**Compilation flags***************************************************************************
176  enum : bool { smpAssignable = false };
177  //**********************************************************************************************
178 
179  //**ConstIterator class definition**************************************************************
183  {
184  public:
185  //**Type definitions*************************************************************************
188 
191 
192  using IteratorCategory = std::forward_iterator_tag;
193  using ValueType = Element;
197 
198  // STL iterator requirements
204  //*******************************************************************************************
205 
206  //**Constructor******************************************************************************
209  inline ConstIterator( IteratorType vector, RightOperand scalar )
210  : vector_( vector ) // Iterator over the elements of the left-hand side sparse vector expression
211  , scalar_( scalar ) // Right-hand side scalar of the multiplication expression
212  {}
213  //*******************************************************************************************
214 
215  //**Prefix increment operator****************************************************************
221  ++vector_;
222  return *this;
223  }
224  //*******************************************************************************************
225 
226  //**Element access operator******************************************************************
231  inline const Element operator*() const {
232  return Element( vector_->value() * scalar_, vector_->index() );
233  }
234  //*******************************************************************************************
235 
236  //**Element access operator******************************************************************
241  inline const ConstIterator* operator->() const {
242  return this;
243  }
244  //*******************************************************************************************
245 
246  //**Value function***************************************************************************
251  inline ReturnType value() const {
252  return vector_->value() * scalar_;
253  }
254  //*******************************************************************************************
255 
256  //**Index function***************************************************************************
261  inline size_t index() const {
262  return vector_->index();
263  }
264  //*******************************************************************************************
265 
266  //**Equality operator************************************************************************
272  inline bool operator==( const ConstIterator& rhs ) const {
273  return vector_ == rhs.vector_;
274  }
275  //*******************************************************************************************
276 
277  //**Inequality operator**********************************************************************
283  inline bool operator!=( const ConstIterator& rhs ) const {
284  return vector_ != rhs.vector_;
285  }
286  //*******************************************************************************************
287 
288  //**Subtraction operator*********************************************************************
294  inline DifferenceType operator-( const ConstIterator& rhs ) const {
295  return vector_ - rhs.vector_;
296  }
297  //*******************************************************************************************
298 
299  private:
300  //**Member variables*************************************************************************
303  //*******************************************************************************************
304  };
305  //**********************************************************************************************
306 
307  //**Constructor*********************************************************************************
313  explicit inline SVecScalarMultExpr( const VT& vector, ST scalar ) noexcept
314  : vector_( vector ) // Left-hand side sparse vector of the multiplication expression
315  , scalar_( scalar ) // Right-hand side scalar of the multiplication expression
316  {}
317  //**********************************************************************************************
318 
319  //**Subscript operator**************************************************************************
325  inline ReturnType operator[]( size_t index ) const {
326  BLAZE_INTERNAL_ASSERT( index < vector_.size(), "Invalid vector access index" );
327  return vector_[index] * scalar_;
328  }
329  //**********************************************************************************************
330 
331  //**At function*********************************************************************************
338  inline ReturnType at( size_t index ) const {
339  if( index >= vector_.size() ) {
340  BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
341  }
342  return (*this)[index];
343  }
344  //**********************************************************************************************
345 
346  //**Begin function******************************************************************************
351  inline ConstIterator begin() const {
352  return ConstIterator( vector_.begin(), scalar_ );
353  }
354  //**********************************************************************************************
355 
356  //**End function********************************************************************************
361  inline ConstIterator end() const {
362  return ConstIterator( vector_.end(), scalar_ );
363  }
364  //**********************************************************************************************
365 
366  //**Size function*******************************************************************************
371  inline size_t size() const noexcept {
372  return vector_.size();
373  }
374  //**********************************************************************************************
375 
376  //**NonZeros function***************************************************************************
381  inline size_t nonZeros() const {
382  return vector_.nonZeros();
383  }
384  //**********************************************************************************************
385 
386  //**Find function*******************************************************************************
392  inline ConstIterator find( size_t index ) const {
394  return ConstIterator( vector_.find( index ), scalar_ );
395  }
396  //**********************************************************************************************
397 
398  //**LowerBound function*************************************************************************
404  inline ConstIterator lowerBound( size_t index ) const {
406  return ConstIterator( vector_.lowerBound( index ), scalar_ );
407  }
408  //**********************************************************************************************
409 
410  //**UpperBound function*************************************************************************
416  inline ConstIterator upperBound( size_t index ) const {
418  return ConstIterator( vector_.upperBound( index ), scalar_ );
419  }
420  //**********************************************************************************************
421 
422  //**Left operand access*************************************************************************
427  inline LeftOperand leftOperand() const noexcept {
428  return vector_;
429  }
430  //**********************************************************************************************
431 
432  //**Right operand access************************************************************************
437  inline RightOperand rightOperand() const noexcept {
438  return scalar_;
439  }
440  //**********************************************************************************************
441 
442  //**********************************************************************************************
448  template< typename T >
449  inline bool canAlias( const T* alias ) const noexcept {
450  return vector_.canAlias( alias );
451  }
452  //**********************************************************************************************
453 
454  //**********************************************************************************************
460  template< typename T >
461  inline bool isAliased( const T* alias ) const noexcept {
462  return vector_.isAliased( alias );
463  }
464  //**********************************************************************************************
465 
466  private:
467  //**Member variables****************************************************************************
470  //**********************************************************************************************
471 
472  //**Assignment to dense vectors*****************************************************************
486  template< typename VT2 > // Type of the target dense vector
487  friend inline EnableIf_< UseAssign<VT2> >
488  assign( DenseVector<VT2,TF>& lhs, const SVecScalarMultExpr& rhs )
489  {
491 
492  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
493 
494  assign( ~lhs, rhs.vector_ );
495  (~lhs) *= rhs.scalar_;
496  }
498  //**********************************************************************************************
499 
500  //**Assignment to sparse vectors****************************************************************
514  template< typename VT2 > // Type of the target sparse vector
515  friend inline EnableIf_< UseAssign<VT2> >
516  assign( SparseVector<VT2,TF>& lhs, const SVecScalarMultExpr& rhs )
517  {
519 
520  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
521 
522  assign( ~lhs, rhs.vector_ );
523  (~lhs) *= rhs.scalar_;
524  }
526  //**********************************************************************************************
527 
528  //**Addition assignment to dense vectors********************************************************
542  template< typename VT2 > // Type of the target dense vector
543  friend inline EnableIf_< UseAssign<VT2> >
544  addAssign( DenseVector<VT2,TF>& lhs, const SVecScalarMultExpr& rhs )
545  {
547 
551 
552  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
553 
554  const ResultType tmp( serial( rhs ) );
555  addAssign( ~lhs, tmp );
556  }
558  //**********************************************************************************************
559 
560  //**Addition assignment to sparse vectors*******************************************************
561  // No special implementation for the addition assignment to sparse vectors.
562  //**********************************************************************************************
563 
564  //**Subtraction assignment to dense vectors*****************************************************
578  template< typename VT2 > // Type of the target dense vector
579  friend inline EnableIf_< UseAssign<VT2> >
580  subAssign( DenseVector<VT2,TF>& lhs, const SVecScalarMultExpr& rhs )
581  {
583 
587 
588  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
589 
590  const ResultType tmp( serial( rhs ) );
591  subAssign( ~lhs, tmp );
592  }
594  //**********************************************************************************************
595 
596  //**Subtraction assignment to sparse vectors****************************************************
597  // No special implementation for the subtraction assignment to sparse vectors.
598  //**********************************************************************************************
599 
600  //**Multiplication assignment to dense vectors**************************************************
614  template< typename VT2 > // Type of the target dense vector
615  friend inline EnableIf_< UseAssign<VT2> >
616  multAssign( DenseVector<VT2,TF>& lhs, const SVecScalarMultExpr& rhs )
617  {
619 
623 
624  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
625 
626  const ResultType tmp( serial( rhs ) );
627  multAssign( ~lhs, tmp );
628  }
630  //**********************************************************************************************
631 
632  //**Multiplication assignment to sparse vectors*************************************************
633  // No special implementation for the multiplication assignment to sparse vectors.
634  //**********************************************************************************************
635 
636  //**SMP assignment to dense vectors*************************************************************
637  // No special implementation for the SMP assignment to dense vectors.
638  //**********************************************************************************************
639 
640  //**SMP assignment to sparse vectors************************************************************
641  // No special implementation for the SMP assignment to sparse vectors.
642  //**********************************************************************************************
643 
644  //**SMP addition assignment to dense vectors****************************************************
658  template< typename VT2 > // Type of the target dense vector
659  friend inline EnableIf_< UseSMPAssign<VT2> >
660  smpAddAssign( DenseVector<VT2,TF>& lhs, const SVecScalarMultExpr& rhs )
661  {
663 
667 
668  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
669 
670  const ResultType tmp( rhs );
671  smpAddAssign( ~lhs, tmp );
672  }
674  //**********************************************************************************************
675 
676  //**SMP addition assignment to sparse vectors***************************************************
677  // No special implementation for the SMP addition assignment to sparse vectors.
678  //**********************************************************************************************
679 
680  //**SMP subtraction assignment to dense vectors*************************************************
694  template< typename VT2 > // Type of the target dense vector
695  friend inline EnableIf_< UseSMPAssign<VT2> >
696  smpSubAssign( DenseVector<VT2,TF>& lhs, const SVecScalarMultExpr& rhs )
697  {
699 
703 
704  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
705 
706  const ResultType tmp( rhs );
707  smpSubAssign( ~lhs, tmp );
708  }
710  //**********************************************************************************************
711 
712  //**SMP subtraction assignment to sparse vectors************************************************
713  // No special implementation for the SMP subtraction assignment to sparse vectors.
714  //**********************************************************************************************
715 
716  //**SMP multiplication assignment to dense vectors**********************************************
730  template< typename VT2 > // Type of the target dense vector
731  friend inline EnableIf_< UseSMPAssign<VT2> >
732  smpMultAssign( DenseVector<VT2,TF>& lhs, const SVecScalarMultExpr& rhs )
733  {
735 
739 
740  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
741 
742  const ResultType tmp( rhs );
743  smpMultAssign( ~lhs, tmp );
744  }
746  //**********************************************************************************************
747 
748  //**SMP multiplication assignment to sparse vectors*********************************************
749  // No special implementation for the SMP multiplication assignment to sparse vectors.
750  //**********************************************************************************************
751 
752  //**Compile time checks*************************************************************************
759  //**********************************************************************************************
760 };
761 //*************************************************************************************************
762 
763 
764 
765 
766 //=================================================================================================
767 //
768 // GLOBAL UNARY ARITHMETIC OPERATORS
769 //
770 //=================================================================================================
771 
772 //*************************************************************************************************
789 template< typename VT // Type of the sparse vector
790  , bool TF > // Transpose flag
791 inline decltype(auto) operator-( const SparseVector<VT,TF>& sv )
792 {
794 
795  using ScalarType = UnderlyingBuiltin_<VT>;
797  return ReturnType( ~sv, ScalarType(-1) );
798 }
799 //*************************************************************************************************
800 
801 
802 
803 
804 //=================================================================================================
805 //
806 // GLOBAL BINARY ARITHMETIC OPERATORS
807 //
808 //=================================================================================================
809 
810 //*************************************************************************************************
831 template< typename VT // Type of the left-hand side sparse vector
832  , typename ST // Type of the right-hand side scalar
833  , bool TF // Transpose flag
834  , typename = EnableIf_< IsNumeric<ST> > >
835 inline decltype(auto) operator*( const SparseVector<VT,TF>& vec, ST scalar )
836 {
838 
839  using ScalarType = MultTrait_< UnderlyingBuiltin_<VT>, ST >;
841  return ReturnType( ~vec, scalar );
842 }
843 //*************************************************************************************************
844 
845 
846 //*************************************************************************************************
867 template< typename ST // Type of the left-hand side scalar
868  , typename VT // Type of the right-hand side sparse vector
869  , bool TF // Transpose flag
870  , typename = EnableIf_< IsNumeric<ST> > >
871 inline decltype(auto) operator*( ST scalar, const SparseVector<VT,TF>& vec )
872 {
874 
875  using ScalarType = MultTrait_< ST, UnderlyingBuiltin_<VT> >;
877  return ReturnType( ~vec, scalar );
878 }
879 //*************************************************************************************************
880 
881 
882 
883 
884 //=================================================================================================
885 //
886 // GLOBAL FUNCTIONS
887 //
888 //=================================================================================================
889 
890 //*************************************************************************************************
908 template< typename VT // Type of the sparse vector
909  , bool TF > // Transpose flag
910 inline decltype(auto) normalize( const SparseVector<VT,TF>& vec )
911 {
913 
915 
916  const ElementType len ( length( ~vec ) );
917  const ElementType ilen( ( len != ElementType(0) )?( ElementType(1) / len ):( 0 ) );
918 
920  return ReturnType( ~vec, ilen );
921 }
922 //*************************************************************************************************
923 
924 
925 
926 
927 //=================================================================================================
928 //
929 // GLOBAL RESTRUCTURING UNARY ARITHMETIC OPERATORS
930 //
931 //=================================================================================================
932 
933 //*************************************************************************************************
945 template< typename VT // Type of the sparse vector
946  , typename ST // Type of the scalar
947  , bool TF > // Transpose flag
948 inline decltype(auto) operator-( const SVecScalarMultExpr<VT,ST,TF>& sv )
949 {
951 
953  return ReturnType( sv.leftOperand(), -sv.rightOperand() );
954 }
956 //*************************************************************************************************
957 
958 
959 
960 
961 //=================================================================================================
962 //
963 // GLOBAL RESTRUCTURING BINARY ARITHMETIC OPERATORS
964 //
965 //=================================================================================================
966 
967 //*************************************************************************************************
980 template< typename VT // Type of the sparse vector of the left-hand side expression
981  , typename ST1 // Type of the scalar of the left-hand side expression
982  , bool TF // Transpose flag of the sparse vector
983  , typename ST2 // Type of the right-hand side scalar
984  , typename = EnableIf_< IsNumeric<ST2> > >
985 inline decltype(auto) operator*( const SVecScalarMultExpr<VT,ST1,TF>& vec, ST2 scalar )
986 {
988 
989  return vec.leftOperand() * ( vec.rightOperand() * scalar );
990 }
992 //*************************************************************************************************
993 
994 
995 //*************************************************************************************************
1008 template< typename ST1 // Type of the left-hand side scalar
1009  , typename VT // Type of the sparse vector of the right-hand side expression
1010  , typename ST2 // Type of the scalar of the right-hand side expression
1011  , bool TF // Transpose flag of the sparse vector
1012  , typename = EnableIf_< IsNumeric<ST1> > >
1013 inline decltype(auto) operator*( ST1 scalar, const SVecScalarMultExpr<VT,ST2,TF>& vec )
1014 {
1016 
1017  return vec.leftOperand() * ( scalar * vec.rightOperand() );
1018 }
1020 //*************************************************************************************************
1021 
1022 
1023 //*************************************************************************************************
1036 template< typename VT // Type of the dense vector of the left-hand side expression
1037  , typename ST1 // Type of the scalar of the left-hand side expression
1038  , bool TF // Transpose flag of the dense vector
1039  , typename ST2 // Type of the right-hand side scalar
1041 inline decltype(auto) operator/( const SVecScalarMultExpr<VT,ST1,TF>& vec, ST2 scalar )
1042 {
1044 
1045  return vec.leftOperand() * ( vec.rightOperand() / scalar );
1046 }
1048 //*************************************************************************************************
1049 
1050 
1051 //*************************************************************************************************
1065 template< typename VT1 // Type of the sparse vector of the left-hand side expression
1066  , typename ST // Type of the scalar of the left-hand side expression
1067  , bool TF // Transpose flag of the dense vectors
1068  , typename VT2 > // Type of the right-hand side dense vector
1069 inline decltype(auto)
1071 {
1073 
1074  return ( lhs.leftOperand() * (~rhs) ) * lhs.rightOperand();
1075 }
1077 //*************************************************************************************************
1078 
1079 
1080 //*************************************************************************************************
1094 template< typename VT1 // Type of the left-hand side dense vector
1095  , bool TF // Transpose flag of the dense vectors
1096  , typename VT2 // Type of the sparse vector of the right-hand side expression
1097  , typename ST > // Type of the scalar of the right-hand side expression
1098 inline decltype(auto)
1100 {
1102 
1103  return ( (~lhs) * rhs.leftOperand() ) * rhs.rightOperand();
1104 }
1106 //*************************************************************************************************
1107 
1108 
1109 //*************************************************************************************************
1123 template< typename VT1 // Type of the sparse vector of the left-hand side expression
1124  , typename ST // Type of the scalar of the left-hand side expression
1125  , typename VT2 > // Type of the right-hand side dense vector
1126 inline decltype(auto)
1128 {
1130 
1131  return ( lhs.leftOperand() * (~rhs) ) * lhs.rightOperand();
1132 }
1134 //*************************************************************************************************
1135 
1136 
1137 //*************************************************************************************************
1151 template< typename VT1 // Type of the left-hand side dense vector
1152  , typename VT2 // Type of the sparse vector of the right-hand side expression
1153  , typename ST > // Type of the scalar of the right-hand side expression
1154 inline decltype(auto)
1156 {
1158 
1159  return ( (~lhs) * rhs.leftOperand() ) * rhs.rightOperand();
1160 }
1162 //*************************************************************************************************
1163 
1164 
1165 //*************************************************************************************************
1179 template< typename VT1 // Type of the sparse vector of the left-hand side expression
1180  , typename ST // Type of the scalar of the left-hand side expression
1181  , bool TF // Transpose flag of the vectors
1182  , typename VT2 > // Type of the right-hand side sparse vector
1183 inline decltype(auto)
1185 {
1187 
1188  return ( lhs.leftOperand() * (~rhs) ) * lhs.rightOperand();
1189 }
1191 //*************************************************************************************************
1192 
1193 
1194 //*************************************************************************************************
1208 template< typename VT1 // Type of the left-hand side sparse vector
1209  , bool TF // Transpose flag of the vectors
1210  , typename VT2 // Type of the sparse vector of the right-hand side expression
1211  , typename ST > // Type of the scalar of the right-hand side expression
1212 inline decltype(auto)
1214 {
1216 
1217  return ( (~lhs) * rhs.leftOperand() ) * rhs.rightOperand();
1218 }
1220 //*************************************************************************************************
1221 
1222 
1223 //*************************************************************************************************
1237 template< typename VT1 // Type of the sparse vector of the left-hand side expression
1238  , typename ST1 // Type of the scalar of the left-hand side expression
1239  , bool TF // Transpose flag of the sparse vectors
1240  , typename VT2 // Type of the sparse vector of the right-hand side expression
1241  , typename ST2 > // Type of the scalar of the right-hand side expression
1242 inline decltype(auto)
1244 {
1246 
1247  return ( lhs.leftOperand() * rhs.leftOperand() ) * ( lhs.rightOperand() * rhs.rightOperand() );
1248 }
1250 //*************************************************************************************************
1251 
1252 
1253 //*************************************************************************************************
1267 template< typename VT1 // Type of the sparse vector of the left-hand side expression
1268  , typename ST // Type of the scalar of the left-hand side expression
1269  , typename VT2 > // Type of the right-hand side sparse vector
1270 inline decltype(auto)
1272 {
1274 
1275  return ( lhs.leftOperand() * (~rhs) ) * lhs.rightOperand();
1276 }
1278 //*************************************************************************************************
1279 
1280 
1281 //*************************************************************************************************
1295 template< typename VT1 // Type of the left-hand side sparse vector
1296  , typename VT2 // Type of the sparse vector of the right-hand side expression
1297  , typename ST > // Type of the scalar of the right-hand side expression
1298 inline decltype(auto)
1300 {
1302 
1303  return ( (~lhs) * rhs.leftOperand() ) * rhs.rightOperand();
1304 }
1306 //*************************************************************************************************
1307 
1308 
1309 //*************************************************************************************************
1323 template< typename VT1 // Type of the sparse vector of the left-hand side expression
1324  , typename ST1 // Type of the scalar of the left-hand side expression
1325  , typename VT2 // Type of the sparse vector of the right-hand side expression
1326  , typename ST2 > // Type of the scalar of the right-hand side expression
1327 inline decltype(auto)
1329 {
1331 
1332  return ( lhs.leftOperand() * rhs.leftOperand() ) * ( lhs.rightOperand() * rhs.rightOperand() );
1333 }
1335 //*************************************************************************************************
1336 
1337 
1338 //*************************************************************************************************
1352 template< typename MT // Type of the left-hand side dense matrix
1353  , bool SO // Storage order of the left-hand side dense matrix
1354  , typename VT // Type of the sparse vector of the right-hand side expression
1355  , typename ST > // Type of the scalar of the right-hand side expression
1356 inline decltype(auto)
1358 {
1360 
1361  return ( (~mat) * vec.leftOperand() ) * vec.rightOperand();
1362 }
1364 //*************************************************************************************************
1365 
1366 
1367 //*************************************************************************************************
1381 template< typename VT // Type of the sparse vector of the left-hand side expression
1382  , typename ST // Type of the scalar of the left-hand side expression
1383  , typename MT // Type of the right-hand side dense matrix
1384  , bool SO > // Storage order of the right-hand side dense matrix
1385 inline decltype(auto)
1387 {
1389 
1390  return ( vec.leftOperand() * (~mat) ) * vec.rightOperand();
1391 }
1393 //*************************************************************************************************
1394 
1395 
1396 //*************************************************************************************************
1410 template< typename MT // Type of the left-hand side sparse matrix
1411  , bool SO // Storage order of the left-hand side sparse matrix
1412  , typename VT // Type of the sparse vector of the right-hand side expression
1413  , typename ST > // Type of the scalar of the right-hand side expression
1414 inline decltype(auto)
1416 {
1418 
1419  return ( (~mat) * vec.leftOperand() ) * vec.rightOperand();
1420 }
1422 //*************************************************************************************************
1423 
1424 
1425 //*************************************************************************************************
1439 template< typename VT // Type of the sparse vector of the left-hand side expression
1440  , typename ST // Type of the scalar of the left-hand side expression
1441  , typename MT // Type of the right-hand side sparse matrix
1442  , bool SO > // Storage order of the right-hand side sparse matrix
1443 inline decltype(auto)
1445 {
1447 
1448  return ( vec.leftOperand() * (~mat) ) * vec.rightOperand();
1449 }
1451 //*************************************************************************************************
1452 
1453 
1454 
1455 
1456 //=================================================================================================
1457 //
1458 // SIZE SPECIALIZATIONS
1459 //
1460 //=================================================================================================
1461 
1462 //*************************************************************************************************
1464 template< typename VT, typename ST, bool TF >
1465 struct Size< SVecScalarMultExpr<VT,ST,TF>, 0UL >
1466  : public Size<VT,0UL>
1467 {};
1469 //*************************************************************************************************
1470 
1471 } // namespace blaze
1472 
1473 #endif
RightOperand rightOperand() const noexcept
Returns the right-hand side scalar operand.
Definition: SVecScalarMultExpr.h:437
Pointer difference type of the Blaze library.
size_t nonZeros() const
Returns the number of non-zero elements in the sparse vector.
Definition: SVecScalarMultExpr.h:381
bool operator==(const ConstIterator &rhs) const
Equality comparison between two ConstIterator objects.
Definition: SVecScalarMultExpr.h:272
Header file for auxiliary alias declarations.
Data type constraint.
Constraint on the data type.
Compile time check whether the given type is a temporary vector or matrix type.This type trait class ...
Definition: IsTemporary.h:69
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:283
ResultType_< VT > RT
Result type of the sparse vector expression.
Definition: SVecScalarMultExpr.h:102
decltype(auto) operator/(const DenseMatrix< MT, SO > &mat, ST scalar)
Division operator for the division of a dense matrix by a scalar value ( ).
Definition: DMatScalarDivExpr.h:1070
EnableIf_< IsDenseMatrix< MT1 > > smpSubAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP subtraction assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:164
Header file for the serial shim.
IteratorCategory iterator_category
The iterator category.
Definition: SVecScalarMultExpr.h:199
DifferenceType operator-(const ConstIterator &rhs) const
Calculating the number of elements between two expression iterators.
Definition: SVecScalarMultExpr.h:294
ConstIterator begin() const
Returns an iterator to the first non-zero element of the sparse vector.
Definition: SVecScalarMultExpr.h:351
MultExprTrait_< RN, ST > ExprReturnType
Expression return type for the subscript operator.
Definition: SVecScalarMultExpr.h:117
EnableIf_< IsDenseVector< VT1 > > smpMultAssign(Vector< VT1, TF1 > &lhs, const Vector< VT2, TF2 > &rhs)
Default implementation of the SMP multiplication assignment of a vector to a dense vector...
Definition: DenseVector.h:193
Header file for the And class template.
Iterator over the elements of the sparse vector/scalar multiplication expression. ...
Definition: SVecScalarMultExpr.h:182
typename MultTrait< T1, T2 >::Type MultTrait_
Auxiliary alias declaration for the MultTrait class template.The MultTrait_ alias declaration provide...
Definition: MultTrait.h:291
Header file for the Computation base class.
const DenseIterator< Type, AF > operator-(const DenseIterator< Type, AF > &it, ptrdiff_t inc) noexcept
Subtraction between a DenseIterator and an integral value.
Definition: DenseIterator.h:733
Header file for the RequiresEvaluation type trait.
Header file for the VecScalarMultExpr base class.
typename T::ResultType ResultType_
Alias declaration for nested ResultType type definitions.The ResultType_ alias declaration provides a...
Definition: Aliases.h:343
EnableIf_< IsDenseMatrix< MT1 > > smpAddAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP addition assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:133
std::forward_iterator_tag IteratorCategory
The iterator category.
Definition: SVecScalarMultExpr.h:192
typename UnderlyingBuiltin< T >::Type UnderlyingBuiltin_
Auxiliary alias declaration for the UnderlyingBuiltin type trait.The UnderlyingBuiltin_ alias declara...
Definition: UnderlyingBuiltin.h:133
ConstIterator & operator++()
Pre-increment operator.
Definition: SVecScalarMultExpr.h:220
Base class for dense matrices.The DenseMatrix class is a base class for all dense matrix classes...
Definition: DenseMatrix.h:80
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes...
Definition: Forward.h:129
auto length(const DenseVector< VT, TF > &dv) -> decltype(sqrt(sqrLength(~dv)))
Calculation of the length (magnitude) of the dense vector .
Definition: DenseVector.h:714
typename IfTrue< Condition, T1, T2 >::Type IfTrue_
Auxiliary alias declaration for the IfTrue class template.The IfTrue_ alias declaration provides a co...
Definition: If.h:109
typename T::ReturnType ReturnType_
Alias declaration for nested ReturnType type definitions.The ReturnType_ alias declaration provides a...
Definition: Aliases.h:363
const Element operator*() const
Direct access to the sparse vector element at the current iterator position.
Definition: SVecScalarMultExpr.h:231
RightOperand scalar_
Right-hand side scalar of the multiplication expression.
Definition: SVecScalarMultExpr.h:469
typename MultExprTrait< T1, T2 >::Type MultExprTrait_
Auxiliary alias declaration for the MultExprTrait class template.The MultExprTrait_ alias declaration...
Definition: MultExprTrait.h:112
Header file for the MultExprTrait class template.
Compile time check to query the requirement to evaluate an expression.Via this type trait it is possi...
Definition: RequiresEvaluation.h:71
typename T::CompositeType CompositeType_
Alias declaration for nested CompositeType type definitions.The CompositeType_ alias declaration prov...
Definition: Aliases.h:83
Header file for the ValueIndexPair class.
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.
RightOperand scalar_
Right-hand side scalar of the multiplication expression.
Definition: SVecScalarMultExpr.h:302
Header file for the UnderlyingBuiltin type trait.
Type ElementType
Type of the compressed matrix elements.
Definition: CompressedMatrix.h:3079
Header file for the Or class template.
#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
ReturnType_< VT > RN
Return type of the sparse vector expression.
Definition: SVecScalarMultExpr.h:103
decltype(auto) normalize(const DenseVector< VT, TF > &vec)
Normalization of the dense vector ( ).
Definition: DVecScalarMultExpr.h:1154
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SVecScalarMultExpr.h:461
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:3085
typename T::ElementType ElementType_
Alias declaration for nested ElementType type definitions.The ElementType_ alias declaration provides...
Definition: Aliases.h:163
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:76
const IfTrue_< returnExpr, ExprReturnType, ElementType > ReturnType
Return type for expression template evaluations.
Definition: SVecScalarMultExpr.h:162
#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
Constraint on the data type.
Header file for the exception macros of the math module.
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: SVecScalarMultExpr.h:325
decltype(auto) operator*(const DenseMatrix< MT1, false > &lhs, const DenseMatrix< MT2, false > &rhs)
Multiplication operator for the multiplication of two row-major dense matrices ( ).
Definition: DMatDMatMultExpr.h:8893
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:241
ConstIterator_< RemoveReference_< LeftOperand > > IteratorType
Iterator type of the sparse vector expression.
Definition: SVecScalarMultExpr.h:190
Header file for the EnableIf class template.
Header file for the IsNumeric type trait.
Header file for run time assertion macros.
TransposeType_< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: SVecScalarMultExpr.h:158
IteratorType vector_
Iterator over the elements of the left-hand side sparse vector expression.
Definition: SVecScalarMultExpr.h:301
ConstIterator lowerBound(size_t index) const
Returns an iterator to the first index not less then the given index.
Definition: SVecScalarMultExpr.h:404
ConstIterator end() const
Returns an iterator just past the last non-zero element of the sparse vector.
Definition: SVecScalarMultExpr.h:361
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SVecScalarMultExpr.h:449
typename If< T1, T2, T3 >::Type If_
Auxiliary alias declaration for the If class template.The If_ alias declaration provides a convenient...
Definition: If.h:154
MultTrait_< RT, ST > ResultType
Result type for expression template evaluations.
Definition: SVecScalarMultExpr.h:157
Constraint on the data type.
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: SVecScalarMultExpr.h:371
#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
#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
IfTrue_< useAssign, const ResultType, const SVecScalarMultExpr &> CompositeType
Data type for composite expression templates.
Definition: SVecScalarMultExpr.h:165
Compile time check for data types.This type trait tests whether or not the given template parameter i...
Definition: IsInvertible.h:82
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:816
#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.
typename EnableIf< Condition, T >::Type EnableIf_
Auxiliary alias declaration for the EnableIf class template.The EnableIf_ alias declaration provides ...
Definition: EnableIf.h:224
ConstIterator find(size_t index) const
Searches for a specific vector element.
Definition: SVecScalarMultExpr.h:392
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:3080
typename T::ConstIterator ConstIterator_
Alias declaration for nested ConstIterator type definitions.The ConstIterator_ alias declaration prov...
Definition: Aliases.h:103
Index-value-pair for sparse vectors and matrices.The ValueIndexPair class represents a single index-v...
Definition: ValueIndexPair.h:73
If_< IsExpression< VT >, const VT, const VT &> LeftOperand
Composite type of the left-hand side sparse vector expression.
Definition: SVecScalarMultExpr.h:168
Header file for the IsComputation type trait class.
Expression object for sparse vector-scalar multiplications.The SVecScalarMultExpr class represents th...
Definition: Forward.h:139
Compile time logical &#39;or&#39; evaluation.The Or alias declaration performs at compile time a logical &#39;or&#39;...
Definition: Or.h:76
Compile time evaluation of the size of vectors and matrices.The Size type trait evaluates the size of...
Definition: Size.h:80
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:130
size_t index() const
Access to the current index of the sparse element.
Definition: SVecScalarMultExpr.h:261
SVecScalarMultExpr(const VT &vector, ST scalar) noexcept
Constructor for the SVecScalarMultExpr class.
Definition: SVecScalarMultExpr.h:313
ConstIterator upperBound(size_t index) const
Returns an iterator to the first index greater then the given index.
Definition: SVecScalarMultExpr.h:416
CompositeType_< VT > CT
Composite type of the sparse vector expression.
Definition: SVecScalarMultExpr.h:104
typename T::TransposeType TransposeType_
Alias declaration for nested TransposeType type definitions.The TransposeType_ alias declaration prov...
Definition: Aliases.h:423
LeftOperand vector_
Left-hand side sparse vector of the multiplication expression.
Definition: SVecScalarMultExpr.h:468
ElementType_< ResultType > ElementType
Resulting element type.
Definition: SVecScalarMultExpr.h:159
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: SVecScalarMultExpr.h:338
ReturnType value() const
Access to the current value of the sparse element.
Definition: SVecScalarMultExpr.h:251
Header file for the Size type trait.
#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
LeftOperand leftOperand() const noexcept
Returns the left-hand side sparse vector operand.
Definition: SVecScalarMultExpr.h:427
ST RightOperand
Composite type of the right-hand side scalar value.
Definition: SVecScalarMultExpr.h:171
#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:209