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/InvalidType.h>
71 #include <blaze/util/mpl/And.h>
72 #include <blaze/util/mpl/If.h>
73 #include <blaze/util/mpl/Or.h>
74 #include <blaze/util/Types.h>
77 
78 
79 namespace blaze {
80 
81 //=================================================================================================
82 //
83 // CLASS SVECSCALARMULTEXPR
84 //
85 //=================================================================================================
86 
87 //*************************************************************************************************
94 template< typename VT // Type of the left-hand side sparse vector
95  , typename ST // Type of the right-hand side scalar value
96  , bool TF > // Transpose flag
97 class SVecScalarMultExpr
98  : public VecScalarMultExpr< SparseVector< SVecScalarMultExpr<VT,ST,TF>, TF > >
99  , private Computation
100 {
101  private:
102  //**Type definitions****************************************************************************
103  using RT = ResultType_<VT>;
104  using RN = ReturnType_<VT>;
106  //**********************************************************************************************
107 
108  //**Return type evaluation**********************************************************************
110 
115  enum : bool { returnExpr = !IsTemporary<RN>::value };
116 
119  //**********************************************************************************************
120 
121  //**Serial evaluation strategy******************************************************************
123 
129  enum : bool { useAssign = RequiresEvaluation<VT>::value };
130 
132  template< typename VT2 >
134  struct UseAssign {
135  enum : bool { value = useAssign };
136  };
138  //**********************************************************************************************
139 
140  //**Parallel evaluation strategy****************************************************************
142 
148  template< typename VT2 >
149  struct UseSMPAssign {
150  enum : bool { value = ( !VT2::smpAssignable || !VT::smpAssignable ) && useAssign };
151  };
153  //**********************************************************************************************
154 
155  public:
156  //**Type definitions****************************************************************************
161 
164 
167 
169  using LeftOperand = If_< IsExpression<VT>, const VT, const VT& >;
170 
172  using RightOperand = ST;
173  //**********************************************************************************************
174 
175  //**Compilation flags***************************************************************************
177  enum : bool { smpAssignable = false };
178  //**********************************************************************************************
179 
180  //**ConstIterator class definition**************************************************************
184  {
185  public:
186  //**Type definitions*************************************************************************
189 
192 
193  using IteratorCategory = std::forward_iterator_tag;
194  using ValueType = Element;
198 
199  // STL iterator requirements
205  //*******************************************************************************************
206 
207  //**Constructor******************************************************************************
210  inline ConstIterator( IteratorType vector, RightOperand scalar )
211  : vector_( vector ) // Iterator over the elements of the left-hand side sparse vector expression
212  , scalar_( scalar ) // Right-hand side scalar of the multiplication expression
213  {}
214  //*******************************************************************************************
215 
216  //**Prefix increment operator****************************************************************
222  ++vector_;
223  return *this;
224  }
225  //*******************************************************************************************
226 
227  //**Element access operator******************************************************************
232  inline const Element operator*() const {
233  return Element( vector_->value() * scalar_, vector_->index() );
234  }
235  //*******************************************************************************************
236 
237  //**Element access operator******************************************************************
242  inline const ConstIterator* operator->() const {
243  return this;
244  }
245  //*******************************************************************************************
246 
247  //**Value function***************************************************************************
252  inline ReturnType value() const {
253  return vector_->value() * scalar_;
254  }
255  //*******************************************************************************************
256 
257  //**Index function***************************************************************************
262  inline size_t index() const {
263  return vector_->index();
264  }
265  //*******************************************************************************************
266 
267  //**Equality operator************************************************************************
273  inline bool operator==( const ConstIterator& rhs ) const {
274  return vector_ == rhs.vector_;
275  }
276  //*******************************************************************************************
277 
278  //**Inequality operator**********************************************************************
284  inline bool operator!=( const ConstIterator& rhs ) const {
285  return vector_ != rhs.vector_;
286  }
287  //*******************************************************************************************
288 
289  //**Subtraction operator*********************************************************************
295  inline DifferenceType operator-( const ConstIterator& rhs ) const {
296  return vector_ - rhs.vector_;
297  }
298  //*******************************************************************************************
299 
300  private:
301  //**Member variables*************************************************************************
304  //*******************************************************************************************
305  };
306  //**********************************************************************************************
307 
308  //**Constructor*********************************************************************************
314  explicit inline SVecScalarMultExpr( const VT& vector, ST scalar ) noexcept
315  : vector_( vector ) // Left-hand side sparse vector of the multiplication expression
316  , scalar_( scalar ) // Right-hand side scalar of the multiplication expression
317  {}
318  //**********************************************************************************************
319 
320  //**Subscript operator**************************************************************************
326  inline ReturnType operator[]( size_t index ) const {
327  BLAZE_INTERNAL_ASSERT( index < vector_.size(), "Invalid vector access index" );
328  return vector_[index] * scalar_;
329  }
330  //**********************************************************************************************
331 
332  //**At function*********************************************************************************
339  inline ReturnType at( size_t index ) const {
340  if( index >= vector_.size() ) {
341  BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
342  }
343  return (*this)[index];
344  }
345  //**********************************************************************************************
346 
347  //**Begin function******************************************************************************
352  inline ConstIterator begin() const {
353  return ConstIterator( vector_.begin(), scalar_ );
354  }
355  //**********************************************************************************************
356 
357  //**End function********************************************************************************
362  inline ConstIterator end() const {
363  return ConstIterator( vector_.end(), scalar_ );
364  }
365  //**********************************************************************************************
366 
367  //**Size function*******************************************************************************
372  inline size_t size() const noexcept {
373  return vector_.size();
374  }
375  //**********************************************************************************************
376 
377  //**NonZeros function***************************************************************************
382  inline size_t nonZeros() const {
383  return vector_.nonZeros();
384  }
385  //**********************************************************************************************
386 
387  //**Find function*******************************************************************************
393  inline ConstIterator find( size_t index ) const {
395  return ConstIterator( vector_.find( index ), scalar_ );
396  }
397  //**********************************************************************************************
398 
399  //**LowerBound function*************************************************************************
405  inline ConstIterator lowerBound( size_t index ) const {
407  return ConstIterator( vector_.lowerBound( index ), scalar_ );
408  }
409  //**********************************************************************************************
410 
411  //**UpperBound function*************************************************************************
417  inline ConstIterator upperBound( size_t index ) const {
419  return ConstIterator( vector_.upperBound( index ), scalar_ );
420  }
421  //**********************************************************************************************
422 
423  //**Left operand access*************************************************************************
428  inline LeftOperand leftOperand() const noexcept {
429  return vector_;
430  }
431  //**********************************************************************************************
432 
433  //**Right operand access************************************************************************
438  inline RightOperand rightOperand() const noexcept {
439  return scalar_;
440  }
441  //**********************************************************************************************
442 
443  //**********************************************************************************************
449  template< typename T >
450  inline bool canAlias( const T* alias ) const noexcept {
451  return vector_.canAlias( alias );
452  }
453  //**********************************************************************************************
454 
455  //**********************************************************************************************
461  template< typename T >
462  inline bool isAliased( const T* alias ) const noexcept {
463  return vector_.isAliased( alias );
464  }
465  //**********************************************************************************************
466 
467  private:
468  //**Member variables****************************************************************************
471  //**********************************************************************************************
472 
473  //**Assignment to dense vectors*****************************************************************
487  template< typename VT2 > // Type of the target dense vector
488  friend inline EnableIf_< UseAssign<VT2> >
489  assign( DenseVector<VT2,TF>& lhs, const SVecScalarMultExpr& rhs )
490  {
492 
493  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
494 
495  assign( ~lhs, rhs.vector_ );
496  (~lhs) *= rhs.scalar_;
497  }
499  //**********************************************************************************************
500 
501  //**Assignment to sparse vectors****************************************************************
515  template< typename VT2 > // Type of the target sparse vector
516  friend inline EnableIf_< UseAssign<VT2> >
517  assign( SparseVector<VT2,TF>& lhs, const SVecScalarMultExpr& rhs )
518  {
520 
521  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
522 
523  assign( ~lhs, rhs.vector_ );
524  (~lhs) *= rhs.scalar_;
525  }
527  //**********************************************************************************************
528 
529  //**Addition assignment to dense vectors********************************************************
543  template< typename VT2 > // Type of the target dense vector
544  friend inline EnableIf_< UseAssign<VT2> >
545  addAssign( DenseVector<VT2,TF>& lhs, const SVecScalarMultExpr& rhs )
546  {
548 
552 
553  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
554 
555  const ResultType tmp( serial( rhs ) );
556  addAssign( ~lhs, tmp );
557  }
559  //**********************************************************************************************
560 
561  //**Addition assignment to sparse vectors*******************************************************
562  // No special implementation for the addition assignment to sparse vectors.
563  //**********************************************************************************************
564 
565  //**Subtraction assignment to dense vectors*****************************************************
579  template< typename VT2 > // Type of the target dense vector
580  friend inline EnableIf_< UseAssign<VT2> >
581  subAssign( DenseVector<VT2,TF>& lhs, const SVecScalarMultExpr& rhs )
582  {
584 
588 
589  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
590 
591  const ResultType tmp( serial( rhs ) );
592  subAssign( ~lhs, tmp );
593  }
595  //**********************************************************************************************
596 
597  //**Subtraction assignment to sparse vectors****************************************************
598  // No special implementation for the subtraction assignment to sparse vectors.
599  //**********************************************************************************************
600 
601  //**Multiplication assignment to dense vectors**************************************************
615  template< typename VT2 > // Type of the target dense vector
616  friend inline EnableIf_< UseAssign<VT2> >
617  multAssign( DenseVector<VT2,TF>& lhs, const SVecScalarMultExpr& rhs )
618  {
620 
624 
625  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
626 
627  const ResultType tmp( serial( rhs ) );
628  multAssign( ~lhs, tmp );
629  }
631  //**********************************************************************************************
632 
633  //**Multiplication assignment to sparse vectors*************************************************
634  // No special implementation for the multiplication assignment to sparse vectors.
635  //**********************************************************************************************
636 
637  //**SMP assignment to dense vectors*************************************************************
638  // No special implementation for the SMP assignment to dense vectors.
639  //**********************************************************************************************
640 
641  //**SMP assignment to sparse vectors************************************************************
642  // No special implementation for the SMP assignment to sparse vectors.
643  //**********************************************************************************************
644 
645  //**SMP addition assignment to dense vectors****************************************************
659  template< typename VT2 > // Type of the target dense vector
660  friend inline EnableIf_< UseSMPAssign<VT2> >
661  smpAddAssign( DenseVector<VT2,TF>& lhs, const SVecScalarMultExpr& rhs )
662  {
664 
668 
669  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
670 
671  const ResultType tmp( rhs );
672  smpAddAssign( ~lhs, tmp );
673  }
675  //**********************************************************************************************
676 
677  //**SMP addition assignment to sparse vectors***************************************************
678  // No special implementation for the SMP addition assignment to sparse vectors.
679  //**********************************************************************************************
680 
681  //**SMP subtraction assignment to dense vectors*************************************************
695  template< typename VT2 > // Type of the target dense vector
696  friend inline EnableIf_< UseSMPAssign<VT2> >
697  smpSubAssign( DenseVector<VT2,TF>& lhs, const SVecScalarMultExpr& rhs )
698  {
700 
704 
705  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
706 
707  const ResultType tmp( rhs );
708  smpSubAssign( ~lhs, tmp );
709  }
711  //**********************************************************************************************
712 
713  //**SMP subtraction assignment to sparse vectors************************************************
714  // No special implementation for the SMP subtraction assignment to sparse vectors.
715  //**********************************************************************************************
716 
717  //**SMP multiplication assignment to dense vectors**********************************************
731  template< typename VT2 > // Type of the target dense vector
732  friend inline EnableIf_< UseSMPAssign<VT2> >
733  smpMultAssign( DenseVector<VT2,TF>& lhs, const SVecScalarMultExpr& rhs )
734  {
736 
740 
741  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
742 
743  const ResultType tmp( rhs );
744  smpMultAssign( ~lhs, tmp );
745  }
747  //**********************************************************************************************
748 
749  //**SMP multiplication assignment to sparse vectors*********************************************
750  // No special implementation for the SMP multiplication assignment to sparse vectors.
751  //**********************************************************************************************
752 
753  //**Compile time checks*************************************************************************
760  //**********************************************************************************************
761 };
762 //*************************************************************************************************
763 
764 
765 
766 
767 //=================================================================================================
768 //
769 // GLOBAL UNARY ARITHMETIC OPERATORS
770 //
771 //=================================================================================================
772 
773 //*************************************************************************************************
790 template< typename VT // Type of the sparse vector
791  , bool TF > // Transpose flag
792 inline decltype(auto) operator-( const SparseVector<VT,TF>& sv )
793 {
795 
796  using ScalarType = UnderlyingBuiltin_<VT>;
798  return ReturnType( ~sv, ScalarType(-1) );
799 }
800 //*************************************************************************************************
801 
802 
803 
804 
805 //=================================================================================================
806 //
807 // GLOBAL BINARY ARITHMETIC OPERATORS
808 //
809 //=================================================================================================
810 
811 //*************************************************************************************************
832 template< typename VT // Type of the left-hand side sparse vector
833  , typename ST // Type of the right-hand side scalar
834  , bool TF // Transpose flag
835  , typename = EnableIf_< IsNumeric<ST> > >
836 inline decltype(auto) operator*( const SparseVector<VT,TF>& vec, ST scalar )
837 {
839 
840  using ScalarType = MultTrait_< UnderlyingBuiltin_<VT>, ST >;
842  return ReturnType( ~vec, scalar );
843 }
844 //*************************************************************************************************
845 
846 
847 //*************************************************************************************************
868 template< typename ST // Type of the left-hand side scalar
869  , typename VT // Type of the right-hand side sparse vector
870  , bool TF // Transpose flag
871  , typename = EnableIf_< IsNumeric<ST> > >
872 inline decltype(auto) operator*( ST scalar, const SparseVector<VT,TF>& vec )
873 {
875 
876  using ScalarType = MultTrait_< ST, UnderlyingBuiltin_<VT> >;
878  return ReturnType( ~vec, scalar );
879 }
880 //*************************************************************************************************
881 
882 
883 
884 
885 //=================================================================================================
886 //
887 // GLOBAL FUNCTIONS
888 //
889 //=================================================================================================
890 
891 //*************************************************************************************************
909 template< typename VT // Type of the sparse vector
910  , bool TF > // Transpose flag
911 inline decltype(auto) normalize( const SparseVector<VT,TF>& vec )
912 {
914 
916 
917  const ElementType len ( length( ~vec ) );
918  const ElementType ilen( ( len != ElementType(0) )?( ElementType(1) / len ):( 0 ) );
919 
921  return ReturnType( ~vec, ilen );
922 }
923 //*************************************************************************************************
924 
925 
926 
927 
928 //=================================================================================================
929 //
930 // GLOBAL RESTRUCTURING UNARY ARITHMETIC OPERATORS
931 //
932 //=================================================================================================
933 
934 //*************************************************************************************************
946 template< typename VT // Type of the sparse vector
947  , typename ST // Type of the scalar
948  , bool TF > // Transpose flag
949 inline decltype(auto) operator-( const SVecScalarMultExpr<VT,ST,TF>& sv )
950 {
952 
954  return ReturnType( sv.leftOperand(), -sv.rightOperand() );
955 }
957 //*************************************************************************************************
958 
959 
960 
961 
962 //=================================================================================================
963 //
964 // GLOBAL RESTRUCTURING BINARY ARITHMETIC OPERATORS
965 //
966 //=================================================================================================
967 
968 //*************************************************************************************************
981 template< typename VT // Type of the sparse vector of the left-hand side expression
982  , typename ST1 // Type of the scalar of the left-hand side expression
983  , bool TF // Transpose flag of the sparse vector
984  , typename ST2 // Type of the right-hand side scalar
985  , typename = EnableIf_< IsNumeric<ST2> > >
986 inline decltype(auto) operator*( const SVecScalarMultExpr<VT,ST1,TF>& vec, ST2 scalar )
987 {
989 
990  return vec.leftOperand() * ( vec.rightOperand() * scalar );
991 }
993 //*************************************************************************************************
994 
995 
996 //*************************************************************************************************
1009 template< typename ST1 // Type of the left-hand side scalar
1010  , typename VT // Type of the sparse vector of the right-hand side expression
1011  , typename ST2 // Type of the scalar of the right-hand side expression
1012  , bool TF // Transpose flag of the sparse vector
1013  , typename = EnableIf_< IsNumeric<ST1> > >
1014 inline decltype(auto) operator*( ST1 scalar, const SVecScalarMultExpr<VT,ST2,TF>& vec )
1015 {
1017 
1018  return vec.leftOperand() * ( scalar * vec.rightOperand() );
1019 }
1021 //*************************************************************************************************
1022 
1023 
1024 //*************************************************************************************************
1037 template< typename VT // Type of the dense vector of the left-hand side expression
1038  , typename ST1 // Type of the scalar of the left-hand side expression
1039  , bool TF // Transpose flag of the dense vector
1040  , typename ST2 // Type of the right-hand side scalar
1042 inline decltype(auto) operator/( const SVecScalarMultExpr<VT,ST1,TF>& vec, ST2 scalar )
1043 {
1045 
1046  return vec.leftOperand() * ( vec.rightOperand() / scalar );
1047 }
1049 //*************************************************************************************************
1050 
1051 
1052 //*************************************************************************************************
1066 template< typename VT1 // Type of the sparse vector of the left-hand side expression
1067  , typename ST // Type of the scalar of the left-hand side expression
1068  , bool TF // Transpose flag of the dense vectors
1069  , typename VT2 > // Type of the right-hand side dense vector
1070 inline decltype(auto)
1072 {
1074 
1075  return ( lhs.leftOperand() * (~rhs) ) * lhs.rightOperand();
1076 }
1078 //*************************************************************************************************
1079 
1080 
1081 //*************************************************************************************************
1095 template< typename VT1 // Type of the left-hand side dense vector
1096  , bool TF // Transpose flag of the dense vectors
1097  , typename VT2 // Type of the sparse vector of the right-hand side expression
1098  , typename ST > // Type of the scalar of the right-hand side expression
1099 inline decltype(auto)
1101 {
1103 
1104  return ( (~lhs) * rhs.leftOperand() ) * rhs.rightOperand();
1105 }
1107 //*************************************************************************************************
1108 
1109 
1110 //*************************************************************************************************
1124 template< typename VT1 // Type of the sparse vector of the left-hand side expression
1125  , typename ST // Type of the scalar of the left-hand side expression
1126  , typename VT2 > // Type of the right-hand side dense vector
1127 inline decltype(auto)
1129 {
1131 
1132  return ( lhs.leftOperand() * (~rhs) ) * lhs.rightOperand();
1133 }
1135 //*************************************************************************************************
1136 
1137 
1138 //*************************************************************************************************
1152 template< typename VT1 // Type of the left-hand side dense vector
1153  , typename VT2 // Type of the sparse vector of the right-hand side expression
1154  , typename ST > // Type of the scalar of the right-hand side expression
1155 inline decltype(auto)
1157 {
1159 
1160  return ( (~lhs) * rhs.leftOperand() ) * rhs.rightOperand();
1161 }
1163 //*************************************************************************************************
1164 
1165 
1166 //*************************************************************************************************
1180 template< typename VT1 // Type of the sparse vector of the left-hand side expression
1181  , typename ST // Type of the scalar of the left-hand side expression
1182  , bool TF // Transpose flag of the vectors
1183  , typename VT2 > // Type of the right-hand side sparse vector
1184 inline decltype(auto)
1186 {
1188 
1189  return ( lhs.leftOperand() * (~rhs) ) * lhs.rightOperand();
1190 }
1192 //*************************************************************************************************
1193 
1194 
1195 //*************************************************************************************************
1209 template< typename VT1 // Type of the left-hand side sparse vector
1210  , bool TF // Transpose flag of the vectors
1211  , typename VT2 // Type of the sparse vector of the right-hand side expression
1212  , typename ST > // Type of the scalar of the right-hand side expression
1213 inline decltype(auto)
1215 {
1217 
1218  return ( (~lhs) * rhs.leftOperand() ) * rhs.rightOperand();
1219 }
1221 //*************************************************************************************************
1222 
1223 
1224 //*************************************************************************************************
1238 template< typename VT1 // Type of the sparse vector of the left-hand side expression
1239  , typename ST1 // Type of the scalar of the left-hand side expression
1240  , bool TF // Transpose flag of the sparse vectors
1241  , typename VT2 // Type of the sparse vector of the right-hand side expression
1242  , typename ST2 > // Type of the scalar of the right-hand side expression
1243 inline decltype(auto)
1245 {
1247 
1248  return ( lhs.leftOperand() * rhs.leftOperand() ) * ( lhs.rightOperand() * rhs.rightOperand() );
1249 }
1251 //*************************************************************************************************
1252 
1253 
1254 //*************************************************************************************************
1268 template< typename VT1 // Type of the sparse vector of the left-hand side expression
1269  , typename ST // Type of the scalar of the left-hand side expression
1270  , typename VT2 > // Type of the right-hand side sparse vector
1271 inline decltype(auto)
1273 {
1275 
1276  return ( lhs.leftOperand() * (~rhs) ) * lhs.rightOperand();
1277 }
1279 //*************************************************************************************************
1280 
1281 
1282 //*************************************************************************************************
1296 template< typename VT1 // Type of the left-hand side sparse vector
1297  , typename VT2 // Type of the sparse vector of the right-hand side expression
1298  , typename ST > // Type of the scalar of the right-hand side expression
1299 inline decltype(auto)
1301 {
1303 
1304  return ( (~lhs) * rhs.leftOperand() ) * rhs.rightOperand();
1305 }
1307 //*************************************************************************************************
1308 
1309 
1310 //*************************************************************************************************
1324 template< typename VT1 // Type of the sparse vector of the left-hand side expression
1325  , typename ST1 // Type of the scalar of the left-hand side expression
1326  , typename VT2 // Type of the sparse vector of the right-hand side expression
1327  , typename ST2 > // Type of the scalar of the right-hand side expression
1328 inline decltype(auto)
1330 {
1332 
1333  return ( lhs.leftOperand() * rhs.leftOperand() ) * ( lhs.rightOperand() * rhs.rightOperand() );
1334 }
1336 //*************************************************************************************************
1337 
1338 
1339 //*************************************************************************************************
1353 template< typename MT // Type of the left-hand side dense matrix
1354  , bool SO // Storage order of the left-hand side dense matrix
1355  , typename VT // Type of the sparse vector of the right-hand side expression
1356  , typename ST > // Type of the scalar of the right-hand side expression
1357 inline decltype(auto)
1359 {
1361 
1362  return ( (~mat) * vec.leftOperand() ) * vec.rightOperand();
1363 }
1365 //*************************************************************************************************
1366 
1367 
1368 //*************************************************************************************************
1382 template< typename VT // Type of the sparse vector of the left-hand side expression
1383  , typename ST // Type of the scalar of the left-hand side expression
1384  , typename MT // Type of the right-hand side dense matrix
1385  , bool SO > // Storage order of the right-hand side dense matrix
1386 inline decltype(auto)
1388 {
1390 
1391  return ( vec.leftOperand() * (~mat) ) * vec.rightOperand();
1392 }
1394 //*************************************************************************************************
1395 
1396 
1397 //*************************************************************************************************
1411 template< typename MT // Type of the left-hand side sparse matrix
1412  , bool SO // Storage order of the left-hand side sparse matrix
1413  , typename VT // Type of the sparse vector of the right-hand side expression
1414  , typename ST > // Type of the scalar of the right-hand side expression
1415 inline decltype(auto)
1417 {
1419 
1420  return ( (~mat) * vec.leftOperand() ) * vec.rightOperand();
1421 }
1423 //*************************************************************************************************
1424 
1425 
1426 //*************************************************************************************************
1440 template< typename VT // Type of the sparse vector of the left-hand side expression
1441  , typename ST // Type of the scalar of the left-hand side expression
1442  , typename MT // Type of the right-hand side sparse matrix
1443  , bool SO > // Storage order of the right-hand side sparse matrix
1444 inline decltype(auto)
1446 {
1448 
1449  return ( vec.leftOperand() * (~mat) ) * vec.rightOperand();
1450 }
1452 //*************************************************************************************************
1453 
1454 
1455 
1456 
1457 //=================================================================================================
1458 //
1459 // SIZE SPECIALIZATIONS
1460 //
1461 //=================================================================================================
1462 
1463 //*************************************************************************************************
1465 template< typename VT, typename ST, bool TF >
1466 struct Size< SVecScalarMultExpr<VT,ST,TF> >
1467  : public Size<VT>
1468 {};
1470 //*************************************************************************************************
1471 
1472 } // namespace blaze
1473 
1474 #endif
RightOperand rightOperand() const noexcept
Returns the right-hand side scalar operand.
Definition: SVecScalarMultExpr.h:438
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:382
bool operator==(const ConstIterator &rhs) const
Equality comparison between two ConstIterator objects.
Definition: SVecScalarMultExpr.h:273
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:70
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:284
ResultType_< VT > RT
Result type of the sparse vector expression.
Definition: SVecScalarMultExpr.h:103
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:1073
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:200
DifferenceType operator-(const ConstIterator &rhs) const
Calculating the number of elements between two expression iterators.
Definition: SVecScalarMultExpr.h:295
ConstIterator begin() const
Returns an iterator to the first non-zero element of the sparse vector.
Definition: SVecScalarMultExpr.h:352
MultExprTrait_< RN, ST > ExprReturnType
Expression return type for the subscript operator.
Definition: SVecScalarMultExpr.h:118
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:183
typename MultTrait< T1, T2 >::Type MultTrait_
Auxiliary alias declaration for the MultTrait class template.The MultTrait_ alias declaration provide...
Definition: MultTrait.h:250
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:731
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:193
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:221
Base class for dense matrices.The DenseMatrix class is a base class for all dense matrix classes...
Definition: DenseMatrix.h:78
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:576
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:232
RightOperand scalar_
Right-hand side scalar of the multiplication expression.
Definition: SVecScalarMultExpr.h:470
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:72
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:57
Header file for the If class template.
RightOperand scalar_
Right-hand side scalar of the multiplication expression.
Definition: SVecScalarMultExpr.h:303
Header file for the UnderlyingBuiltin type trait.
Type ElementType
Type of the compressed matrix elements.
Definition: CompressedMatrix.h:3081
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:104
decltype(auto) normalize(const DenseVector< VT, TF > &vec)
Normalization of the dense vector ( ).
Definition: DVecScalarMultExpr.h:1156
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SVecScalarMultExpr.h:462
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:3087
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:70
const IfTrue_< returnExpr, ExprReturnType, ElementType > ReturnType
Return type for expression template evaluations.
Definition: SVecScalarMultExpr.h:163
#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:326
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:242
ConstIterator_< RemoveReference_< LeftOperand > > IteratorType
Iterator type of the sparse vector expression.
Definition: SVecScalarMultExpr.h:191
Header file for the EnableIf class template.
Header file for the IsNumeric type trait.
Header file for run time assertion macros.
Utility type for generic codes.
TransposeType_< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: SVecScalarMultExpr.h:159
IteratorType vector_
Iterator over the elements of the left-hand side sparse vector expression.
Definition: SVecScalarMultExpr.h:302
ConstIterator lowerBound(size_t index) const
Returns an iterator to the first index not less then the given index.
Definition: SVecScalarMultExpr.h:405
ConstIterator end() const
Returns an iterator just past the last non-zero element of the sparse vector.
Definition: SVecScalarMultExpr.h:362
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SVecScalarMultExpr.h:450
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:158
Constraint on the data type.
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: SVecScalarMultExpr.h:372
#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:166
Compile time check for data types.This type trait tests whether or not the given template parameter i...
Definition: IsInvertible.h:83
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:819
#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:393
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:3082
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:169
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 or evaluation.The Or alias declaration performs at compile time a logical or (&#39;&&&#3...
Definition: Or.h:76
Compile time evaluation of the size of a vector.The Size type trait evaluates the size of the given v...
Definition: Size.h:74
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:262
SVecScalarMultExpr(const VT &vector, ST scalar) noexcept
Constructor for the SVecScalarMultExpr class.
Definition: SVecScalarMultExpr.h:314
ConstIterator upperBound(size_t index) const
Returns an iterator to the first index greater then the given index.
Definition: SVecScalarMultExpr.h:417
CompositeType_< VT > CT
Composite type of the sparse vector expression.
Definition: SVecScalarMultExpr.h:105
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:469
ElementType_< ResultType > ElementType
Resulting element type.
Definition: SVecScalarMultExpr.h:160
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: SVecScalarMultExpr.h:339
ReturnType value() const
Access to the current value of the sparse element.
Definition: SVecScalarMultExpr.h:252
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:428
ST RightOperand
Composite type of the right-hand side scalar value.
Definition: SVecScalarMultExpr.h:172
#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:210