SMatScalarMultExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_SMATSCALARMULTEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_SMATSCALARMULTEXPR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <iterator>
44 #include <blaze/math/Aliases.h>
48 #include <blaze/math/Exception.h>
71 #include <blaze/util/Assert.h>
74 #include <blaze/util/EnableIf.h>
77 #include <blaze/util/InvalidType.h>
78 #include <blaze/util/mpl/And.h>
79 #include <blaze/util/mpl/If.h>
80 #include <blaze/util/mpl/Or.h>
81 #include <blaze/util/Types.h>
84 
85 
86 namespace blaze {
87 
88 //=================================================================================================
89 //
90 // CLASS SMATSCALARMULTEXPR
91 //
92 //=================================================================================================
93 
94 //*************************************************************************************************
101 template< typename MT // Type of the left-hand side sparse matrix
102  , typename ST // Type of the right-hand side scalar value
103  , bool SO > // Storage order
104 class SMatScalarMultExpr
105  : public MatScalarMultExpr< SparseMatrix< SMatScalarMultExpr<MT,ST,SO>, SO > >
106  , private Computation
107 {
108  private:
109  //**Type definitions****************************************************************************
110  using RT = ResultType_<MT>;
111  using RN = ReturnType_<MT>;
113  //**********************************************************************************************
114 
115  //**Return type evaluation**********************************************************************
117 
122  enum : bool { returnExpr = !IsTemporary<RN>::value };
123 
126  //**********************************************************************************************
127 
128  //**Serial evaluation strategy******************************************************************
130 
136  enum : bool { useAssign = RequiresEvaluation<MT>::value };
137 
139  template< typename MT2 >
141  struct UseAssign {
142  enum : bool { value = useAssign };
143  };
145  //**********************************************************************************************
146 
147  //**Parallel evaluation strategy****************************************************************
149 
155  template< typename MT2 >
156  struct UseSMPAssign {
157  enum : bool { value = ( !MT2::smpAssignable || !MT::smpAssignable ) && useAssign };
158  };
160  //**********************************************************************************************
161 
162  public:
163  //**Type definitions****************************************************************************
169 
172 
175 
177  using LeftOperand = If_< IsExpression<MT>, const MT, const MT& >;
178 
180  using RightOperand = ST;
181  //**********************************************************************************************
182 
183  //**ConstIterator class definition**************************************************************
187  {
188  public:
189  //**Type definitions*************************************************************************
192 
195 
196  using IteratorCategory = std::forward_iterator_tag;
197  using ValueType = Element;
201 
202  // STL iterator requirements
208  //*******************************************************************************************
209 
210  //**Constructor******************************************************************************
213  inline ConstIterator( IteratorType matrix, RightOperand scalar )
214  : matrix_( matrix ) // Iterator over the elements of the left-hand side sparse matrix expression
215  , scalar_( scalar ) // Right-hand side scalar of the multiplication expression
216  {}
217  //*******************************************************************************************
218 
219  //**Prefix increment operator****************************************************************
225  ++matrix_;
226  return *this;
227  }
228  //*******************************************************************************************
229 
230  //**Element access operator******************************************************************
235  inline const Element operator*() const {
236  return Element( matrix_->value() * scalar_, matrix_->index() );
237  }
238  //*******************************************************************************************
239 
240  //**Element access operator******************************************************************
245  inline const ConstIterator* operator->() const {
246  return this;
247  }
248  //*******************************************************************************************
249 
250  //**Value function***************************************************************************
255  inline ReturnType value() const {
256  return matrix_->value() * scalar_;
257  }
258  //*******************************************************************************************
259 
260  //**Index function***************************************************************************
265  inline size_t index() const {
266  return matrix_->index();
267  }
268  //*******************************************************************************************
269 
270  //**Equality operator************************************************************************
276  inline bool operator==( const ConstIterator& rhs ) const {
277  return matrix_ == rhs.matrix_;
278  }
279  //*******************************************************************************************
280 
281  //**Inequality operator**********************************************************************
287  inline bool operator!=( const ConstIterator& rhs ) const {
288  return matrix_ != rhs.matrix_;
289  }
290  //*******************************************************************************************
291 
292  //**Subtraction operator*********************************************************************
298  inline DifferenceType operator-( const ConstIterator& rhs ) const {
299  return matrix_ - rhs.matrix_;
300  }
301  //*******************************************************************************************
302 
303  private:
304  //**Member variables*************************************************************************
307  //*******************************************************************************************
308  };
309  //**********************************************************************************************
310 
311  //**Compilation flags***************************************************************************
313  enum : bool { smpAssignable = false };
314  //**********************************************************************************************
315 
316  //**Constructor*********************************************************************************
322  explicit inline SMatScalarMultExpr( const MT& matrix, ST scalar ) noexcept
323  : matrix_( matrix ) // Left-hand side sparse matrix of the multiplication expression
324  , scalar_( scalar ) // Right-hand side scalar of the multiplication expression
325  {}
326  //**********************************************************************************************
327 
328  //**Access operator*****************************************************************************
335  inline ReturnType operator()( size_t i, size_t j ) const {
336  BLAZE_INTERNAL_ASSERT( i < matrix_.rows() , "Invalid row access index" );
337  BLAZE_INTERNAL_ASSERT( j < matrix_.columns(), "Invalid column access index" );
338  return matrix_(i,j) * scalar_;
339  }
340  //**********************************************************************************************
341 
342  //**At function*********************************************************************************
350  inline ReturnType at( size_t i, size_t j ) const {
351  if( i >= matrix_.rows() ) {
352  BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
353  }
354  if( j >= matrix_.columns() ) {
355  BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
356  }
357  return (*this)(i,j);
358  }
359  //**********************************************************************************************
360 
361  //**Begin function******************************************************************************
367  inline ConstIterator begin( size_t i ) const {
368  return ConstIterator( matrix_.begin(i), scalar_ );
369  }
370  //**********************************************************************************************
371 
372  //**End function********************************************************************************
378  inline ConstIterator end( size_t i ) const {
379  return ConstIterator( matrix_.end(i), scalar_ );
380  }
381  //**********************************************************************************************
382 
383  //**Rows function*******************************************************************************
388  inline size_t rows() const noexcept {
389  return matrix_.rows();
390  }
391  //**********************************************************************************************
392 
393  //**Columns function****************************************************************************
398  inline size_t columns() const noexcept {
399  return matrix_.columns();
400  }
401  //**********************************************************************************************
402 
403  //**NonZeros function***************************************************************************
408  inline size_t nonZeros() const {
409  return matrix_.nonZeros();
410  }
411  //**********************************************************************************************
412 
413  //**NonZeros function***************************************************************************
419  inline size_t nonZeros( size_t i ) const {
420  return matrix_.nonZeros(i);
421  }
422  //**********************************************************************************************
423 
424  //**Find function*******************************************************************************
431  inline ConstIterator find( size_t i, size_t j ) const {
433  return ConstIterator( matrix_.find( i, j ), scalar_ );
434  }
435  //**********************************************************************************************
436 
437  //**LowerBound function*************************************************************************
444  inline ConstIterator lowerBound( size_t i, size_t j ) const {
446  return ConstIterator( matrix_.lowerBound( i, j ), scalar_ );
447  }
448  //**********************************************************************************************
449 
450  //**UpperBound function*************************************************************************
457  inline ConstIterator upperBound( size_t i, size_t j ) const {
459  return ConstIterator( matrix_.upperBound( i, j ), scalar_ );
460  }
461  //**********************************************************************************************
462 
463  //**Left operand access*************************************************************************
468  inline LeftOperand leftOperand() const noexcept {
469  return matrix_;
470  }
471  //**********************************************************************************************
472 
473  //**Right operand access************************************************************************
478  inline RightOperand rightOperand() const noexcept {
479  return scalar_;
480  }
481  //**********************************************************************************************
482 
483  //**********************************************************************************************
489  template< typename T >
490  inline bool canAlias( const T* alias ) const noexcept {
491  return matrix_.canAlias( alias );
492  }
493  //**********************************************************************************************
494 
495  //**********************************************************************************************
501  template< typename T >
502  inline bool isAliased( const T* alias ) const noexcept {
503  return matrix_.isAliased( alias );
504  }
505  //**********************************************************************************************
506 
507  private:
508  //**Member variables****************************************************************************
511  //**********************************************************************************************
512 
513  //**Assignment to dense matrices****************************************************************
527  template< typename MT2 // Type of the target dense matrix
528  , bool SO2 > // Storage order of the target dense matrix
529  friend inline EnableIf_< UseAssign<MT2> >
530  assign( DenseMatrix<MT2,SO2>& lhs, const SMatScalarMultExpr& rhs )
531  {
533 
534  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
535  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
536 
537  assign( ~lhs, rhs.matrix_ );
538  (~lhs) *= rhs.scalar_;
539  }
541  //**********************************************************************************************
542 
543  //**Assignment to sparse matrices***************************************************************
557  template< typename MT2 // Type of the target sparse matrix
558  , bool SO2 > // Storage order of the target sparse matrix
559  friend inline EnableIf_< UseAssign<MT2> >
560  assign( SparseMatrix<MT2,SO2>& lhs, const SMatScalarMultExpr& rhs )
561  {
563 
564  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
565  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
566 
567  assign( ~lhs, rhs.matrix_ );
568  (~lhs) *= rhs.scalar_;
569  }
571  //**********************************************************************************************
572 
573  //**Addition assignment to dense matrices*******************************************************
587  template< typename MT2 // Type of the target dense matrix
588  , bool SO2 > // Storage order of the target dense matrix
589  friend inline EnableIf_< UseAssign<MT2> >
590  addAssign( DenseMatrix<MT2,SO2>& lhs, const SMatScalarMultExpr& rhs )
591  {
593 
596 
597  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
598  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
599 
600  const ResultType tmp( serial( rhs ) );
601  addAssign( ~lhs, tmp );
602  }
604  //**********************************************************************************************
605 
606  //**Addition assignment to sparse matrices******************************************************
607  // No special implementation for the addition assignment to sparse matrices.
608  //**********************************************************************************************
609 
610  //**Subtraction assignment to dense matrices****************************************************
624  template< typename MT2 // Type of the target dense matrix
625  , bool SO2 > // Storage order of the target dense matrix
626  friend inline EnableIf_< UseAssign<MT2> >
627  subAssign( DenseMatrix<MT2,SO2>& lhs, const SMatScalarMultExpr& rhs )
628  {
630 
633 
634  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
635  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
636 
637  const ResultType tmp( serial( rhs ) );
638  subAssign( ~lhs, tmp );
639  }
641  //**********************************************************************************************
642 
643  //**Subtraction assignment to sparse matrices***************************************************
644  // No special implementation for the subtraction assignment to sparse matrices.
645  //**********************************************************************************************
646 
647  //**Schur product assignment to dense matrices**************************************************
661  template< typename MT2 // Type of the target dense matrix
662  , bool SO2 > // Storage order of the target dense matrix
663  friend inline EnableIf_< UseAssign<MT2> >
664  schurAssign( DenseMatrix<MT2,SO2>& lhs, const SMatScalarMultExpr& rhs )
665  {
667 
670 
671  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
672  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
673 
674  const ResultType tmp( serial( rhs ) );
675  schurAssign( ~lhs, tmp );
676  }
678  //**********************************************************************************************
679 
680  //**Schur product assignment to sparse matrices*************************************************
681  // No special implementation for the Schur product assignment to sparse matrices.
682  //**********************************************************************************************
683 
684  //**Multiplication assignment to dense matrices*************************************************
685  // No special implementation for the multiplication assignment to dense matrices.
686  //**********************************************************************************************
687 
688  //**Multiplication assignment to sparse matrices************************************************
689  // No special implementation for the multiplication assignment to sparse matrices.
690  //**********************************************************************************************
691 
692  //**SMP assignment to dense matrices************************************************************
693  // No special implementation for the SMP assignment to dense matrices.
694  //**********************************************************************************************
695 
696  //**SMP assignment to sparse matrices***********************************************************
697  // No special implementation for the SMP assignment to sparse matrices.
698  //**********************************************************************************************
699 
700  //**SMP addition assignment to dense matrices***************************************************
714  template< typename MT2 // Type of the target dense matrix
715  , bool SO2 > // Storage order of the target dense matrix
716  friend inline EnableIf_< UseSMPAssign<MT2> >
717  smpAddAssign( DenseMatrix<MT2,SO2>& lhs, const SMatScalarMultExpr& rhs )
718  {
720 
723 
724  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
725  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
726 
727  const ResultType tmp( rhs );
728  smpAddAssign( ~lhs, tmp );
729  }
731  //**********************************************************************************************
732 
733  //**SMP addition assignment to sparse matrices**************************************************
734  // No special implementation for the SMP addition assignment to sparse matrices.
735  //**********************************************************************************************
736 
737  //**SMP Schur product assignment to dense matrices**********************************************
751  template< typename MT2 // Type of the target dense matrix
752  , bool SO2 > // Storage order of the target dense matrix
753  friend inline EnableIf_< UseSMPAssign<MT2> >
754  smpSchurAssign( DenseMatrix<MT2,SO2>& lhs, const SMatScalarMultExpr& rhs )
755  {
757 
760 
761  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
762  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
763 
764  const ResultType tmp( rhs );
765  smpSchurAssign( ~lhs, tmp );
766  }
768  //**********************************************************************************************
769 
770  //**SMP Schur product assignment to sparse matrices*********************************************
771  // No special implementation for the SMP Schur product assignment to sparse matrices.
772  //**********************************************************************************************
773 
774  //**SMP subtraction assignment to dense matrices************************************************
788  template< typename MT2 // Type of the target dense matrix
789  , bool SO2 > // Storage order of the target dense matrix
790  friend inline EnableIf_< UseSMPAssign<MT2> >
791  smpSubAssign( DenseMatrix<MT2,SO2>& lhs, const SMatScalarMultExpr& rhs )
792  {
794 
797 
798  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
799  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
800 
801  const ResultType tmp( rhs );
802  smpSubAssign( ~lhs, tmp );
803  }
805  //**********************************************************************************************
806 
807  //**SMP subtraction assignment to sparse matrices***********************************************
808  // No special implementation for the SMP subtraction assignment to sparse matrices.
809  //**********************************************************************************************
810 
811  //**SMP multiplication assignment to dense matrices*********************************************
812  // No special implementation for the SMP multiplication assignment to dense matrices.
813  //**********************************************************************************************
814 
815  //**SMP multiplication assignment to sparse matrices********************************************
816  // No special implementation for the SMP multiplication assignment to sparse matrices.
817  //**********************************************************************************************
818 
819  //**Compile time checks*************************************************************************
826  //**********************************************************************************************
827 };
828 //*************************************************************************************************
829 
830 
831 
832 
833 //=================================================================================================
834 //
835 // GLOBAL UNARY ARITHMETIC OPERATORS
836 //
837 //=================================================================================================
838 
839 //*************************************************************************************************
856 template< typename MT // Data type of the sparse matrix
857  , bool SO > // Storage order
858 inline decltype(auto) operator-( const SparseMatrix<MT,SO>& sm )
859 {
861 
862  using ScalarType = UnderlyingBuiltin_<MT>;
864  return ReturnType( ~sm, ScalarType(-1) );
865 }
866 //*************************************************************************************************
867 
868 
869 
870 
871 //=================================================================================================
872 //
873 // GLOBAL BINARY ARITHMETIC OPERATORS
874 //
875 //=================================================================================================
876 
877 //*************************************************************************************************
898 template< typename MT // Type of the left-hand side sparse matrix
899  , bool SO // Storage order of the left-hand side sparse matrix
900  , typename ST // Type of the right-hand side scalar
901  , typename = EnableIf_< IsNumeric<ST> > >
902 inline decltype(auto) operator*( const SparseMatrix<MT,SO>& mat, ST scalar )
903 {
905 
906  using ScalarType = MultTrait_< UnderlyingBuiltin_<MT>, ST >;
908  return ReturnType( ~mat, scalar );
909 }
910 //*************************************************************************************************
911 
912 
913 //*************************************************************************************************
934 template< typename ST // Type of the left-hand side scalar
935  , typename MT // Type of the right-hand side sparse matrix
936  , bool SO // Storage order of the right-hand side sparse matrix
937  , typename = EnableIf_< IsNumeric<ST> > >
938 inline decltype(auto) operator*( ST scalar, const SparseMatrix<MT,SO>& mat )
939 {
941 
942  using ScalarType = MultTrait_< ST, UnderlyingBuiltin_<MT> >;
944  return ReturnType( ~mat, scalar );
945 }
946 //*************************************************************************************************
947 
948 
949 
950 
951 //=================================================================================================
952 //
953 // GLOBAL RESTRUCTURING UNARY ARITHMETIC OPERATORS
954 //
955 //=================================================================================================
956 
957 //*************************************************************************************************
969 template< typename MT // Type of the sparse matrix
970  , typename ST // Type of the scalar
971  , bool SO > // Storage order
972 inline decltype(auto) operator-( const SMatScalarMultExpr<MT,ST,SO>& sm )
973 {
975 
977  return ReturnType( sm.leftOperand(), -sm.rightOperand() );
978 }
980 //*************************************************************************************************
981 
982 
983 
984 
985 //=================================================================================================
986 //
987 // GLOBAL RESTRUCTURING BINARY ARITHMETIC OPERATORS
988 //
989 //=================================================================================================
990 
991 //*************************************************************************************************
1004 template< typename MT // Type of the sparse matrix
1005  , typename ST1 // Type of the first scalar
1006  , bool SO // Storage order of the sparse matrix
1007  , typename ST2 // Type of the second scalar
1008  , typename = EnableIf_< IsNumeric<ST2> > >
1009 inline decltype(auto) operator*( const SMatScalarMultExpr<MT,ST1,SO>& mat, ST2 scalar )
1010 {
1012 
1013  return mat.leftOperand() * ( mat.rightOperand() * scalar );
1014 }
1016 //*************************************************************************************************
1017 
1018 
1019 //*************************************************************************************************
1032 template< typename ST1 // Type of the first scalar
1033  , typename MT // Type of the sparse matrix
1034  , typename ST2 // Type of the second scalar
1035  , bool SO // Storage order of the sparse matrix
1036  , typename = EnableIf_< IsNumeric<ST1> > >
1037 inline decltype(auto) operator*( ST1 scalar, const SMatScalarMultExpr<MT,ST2,SO>& mat )
1038 {
1040 
1041  return mat.leftOperand() * ( scalar * mat.rightOperand() );
1042 }
1044 //*************************************************************************************************
1045 
1046 
1047 //*************************************************************************************************
1060 template< typename MT // Type of the sparse matrix
1061  , typename ST1 // Type of the first scalar
1062  , bool SO // Storage order of the sparse matrix
1063  , typename ST2 // Type of the second scalar
1065 inline decltype(auto) operator/( const SMatScalarMultExpr<MT,ST1,SO>& mat, ST2 scalar )
1066 {
1068 
1069  return mat.leftOperand() * ( mat.rightOperand() / scalar );
1070 }
1072 //*************************************************************************************************
1073 
1074 
1075 //*************************************************************************************************
1089 template< typename MT // Type of the sparse matrix of the left-hand side expression
1090  , typename ST // Type of the scalar of the left-hand side expression
1091  , bool SO // Storage order of the left-hand side expression
1092  , typename VT > // Type of the right-hand side dense vector
1093 inline decltype(auto)
1095 {
1097 
1098  return ( mat.leftOperand() * (~vec) ) * mat.rightOperand();
1099 }
1101 //*************************************************************************************************
1102 
1103 
1104 //*************************************************************************************************
1118 template< typename VT // Type of the left-hand side dense vector
1119  , typename MT // Type of the sparse matrix of the right-hand side expression
1120  , typename ST // Type of the scalar of the right-hand side expression
1121  , bool SO > // Storage order of the right-hand side expression
1122 inline decltype(auto)
1124 {
1126 
1127  return ( (~vec) * mat.leftOperand() ) * mat.rightOperand();
1128 }
1130 //*************************************************************************************************
1131 
1132 
1133 //*************************************************************************************************
1149 template< typename MT // Type of the sparse matrix of the left-hand side expression
1150  , typename ST1 // Type of the scalar of the left-hand side expression
1151  , bool SO // Storage order of the left-hand side expression
1152  , typename VT // Type of the dense vector of the right-hand side expression
1153  , typename ST2 > // Type of the scalar of the right-hand side expression
1154 inline decltype(auto)
1156 {
1158 
1159  return ( mat.leftOperand() * vec.leftOperand() ) * ( mat.rightOperand() * vec.rightOperand() );
1160 }
1162 //*************************************************************************************************
1163 
1164 
1165 //*************************************************************************************************
1181 template< typename VT // Type of the dense vector of the left-hand side expression
1182  , typename ST1 // Type of the scalar of the left-hand side expression
1183  , typename MT // Type of the sparse matrix of the right-hand side expression
1184  , typename ST2 // Type of the scalar of the right-hand side expression
1185  , bool SO > // Storage order of the right-hand side expression
1186 inline decltype(auto)
1188 {
1190 
1191  return ( vec.leftOperand() * mat.leftOperand() ) * ( vec.rightOperand() * mat.rightOperand() );
1192 }
1194 //*************************************************************************************************
1195 
1196 
1197 //*************************************************************************************************
1211 template< typename MT // Type of the sparse matrix of the left-hand side expression
1212  , typename ST // Type of the scalar of the left-hand side expression
1213  , bool SO // Storage order of the left-hand side expression
1214  , typename VT > // Type of the right-hand side sparse vector
1215 inline decltype(auto)
1217 {
1219 
1220  return ( mat.leftOperand() * (~vec) ) * mat.rightOperand();
1221 }
1223 //*************************************************************************************************
1224 
1225 
1226 //*************************************************************************************************
1240 template< typename VT // Type of the left-hand side sparse vector
1241  , typename MT // Type of the sparse matrix of the right-hand side expression
1242  , typename ST // Type of the scalar of the right-hand side expression
1243  , bool SO > // Storage order of the right-hand side expression
1244 inline decltype(auto)
1246 {
1248 
1249  return ( (~vec) * mat.leftOperand() ) * mat.rightOperand();
1250 }
1252 //*************************************************************************************************
1253 
1254 
1255 //*************************************************************************************************
1271 template< typename MT // Type of the sparse matrix of the left-hand side expression
1272  , typename ST1 // Type of the scalar of the left-hand side expression
1273  , bool SO // Storage order of the left-hand side expression
1274  , typename VT // Type of the sparse vector of the right-hand side expression
1275  , typename ST2 > // Type of the scalar of the right-hand side expression
1276 inline decltype(auto)
1278 {
1280 
1281  return ( mat.leftOperand() * vec.leftOperand() ) * ( mat.rightOperand() * vec.rightOperand() );
1282 }
1284 //*************************************************************************************************
1285 
1286 
1287 //*************************************************************************************************
1303 template< typename VT // Type of the sparse vector of the left-hand side expression
1304  , typename ST1 // Type of the scalar of the left-hand side expression
1305  , typename MT // Type of the sparse matrix of the right-hand side expression
1306  , typename ST2 // Type of the scalar of the right-hand side expression
1307  , bool SO > // Storage order of the right-hand side expression
1308 inline decltype(auto)
1310 {
1312 
1313  return ( vec.leftOperand() * mat.leftOperand() ) * ( vec.rightOperand() * mat.rightOperand() );
1314 }
1316 //*************************************************************************************************
1317 
1318 
1319 //*************************************************************************************************
1333 template< typename MT1 // Type of the sparse matrix of the left-hand side expression
1334  , typename ST // Type of the scalar of the left-hand side expression
1335  , bool SO1 // Storage order of the left-hand side expression
1336  , typename MT2 // Type of the right-hand side dense matrix
1337  , bool SO2 > // Storage order of the right-hand side dense matrix
1338 inline decltype(auto)
1340 {
1342 
1343  return ( lhs.leftOperand() * (~rhs) ) * lhs.rightOperand();
1344 }
1346 //*************************************************************************************************
1347 
1348 
1349 //*************************************************************************************************
1363 template< typename MT1 // Type of the left-hand side dense matrix
1364  , bool SO1 // Storage order of the left-hand side dense matrix
1365  , typename MT2 // Type of the sparse matrix of the right-hand side expression
1366  , typename ST // Type of the scalar of the right-hand side expression
1367  , bool SO2 > // Storage order of the right-hand side expression
1368 inline decltype(auto)
1370 {
1372 
1373  return ( (~lhs) * rhs.leftOperand() ) * rhs.rightOperand();
1374 }
1376 //*************************************************************************************************
1377 
1378 
1379 //*************************************************************************************************
1393 template< typename MT1 // Type of the sparse matrix of the left-hand side expression
1394  , typename ST // Type of the scalar of the left-hand side expression
1395  , bool SO1 // Storage order of the left-hand side expression
1396  , typename MT2 // Type of the right-hand side sparse matrix
1397  , bool SO2 > // Storage order of the right-hand side sparse matrix
1398 inline decltype(auto)
1400 {
1402 
1403  return ( lhs.leftOperand() * (~rhs) ) * lhs.rightOperand();
1404 }
1406 //*************************************************************************************************
1407 
1408 
1409 //*************************************************************************************************
1423 template< typename MT1 // Type of the left-hand side sparse matrix
1424  , bool SO1 // Storage order of the left-hand side sparse matrix
1425  , typename MT2 // Type of the sparse matrix of the right-hand side expression
1426  , typename ST // Type of the scalar of the right-hand side expression
1427  , bool SO2 > // Storage order of the right-hand side expression
1428 inline decltype(auto)
1430 {
1432 
1433  return ( (~lhs) * rhs.leftOperand() ) * rhs.rightOperand();
1434 }
1436 //*************************************************************************************************
1437 
1438 
1439 //*************************************************************************************************
1453 template< typename MT1 // Type of the sparse matrix of the left-hand side expression
1454  , typename ST1 // Type of the scalar of the left-hand side expression
1455  , bool SO1 // Storage order of the left-hand side expression
1456  , typename MT2 // Type of the right-hand side sparse matrix
1457  , typename ST2 // Type of the scalar of the right-hand side expression
1458  , bool SO2 > // Storage order of the right-hand side expression
1459 inline decltype(auto)
1461 {
1463 
1464  return ( lhs.leftOperand() * rhs.leftOperand() ) * ( lhs.rightOperand() * rhs.rightOperand() );
1465 }
1467 //*************************************************************************************************
1468 
1469 
1470 
1471 
1472 //=================================================================================================
1473 //
1474 // ROWS SPECIALIZATIONS
1475 //
1476 //=================================================================================================
1477 
1478 //*************************************************************************************************
1480 template< typename MT, typename ST, bool SO >
1481 struct Rows< SMatScalarMultExpr<MT,ST,SO> >
1482  : public Rows<MT>
1483 {};
1485 //*************************************************************************************************
1486 
1487 
1488 
1489 
1490 //=================================================================================================
1491 //
1492 // COLUMNS SPECIALIZATIONS
1493 //
1494 //=================================================================================================
1495 
1496 //*************************************************************************************************
1498 template< typename MT, typename ST, bool SO >
1499 struct Columns< SMatScalarMultExpr<MT,ST,SO> >
1500  : public Columns<MT>
1501 {};
1503 //*************************************************************************************************
1504 
1505 
1506 
1507 
1508 //=================================================================================================
1509 //
1510 // ISSYMMETRIC SPECIALIZATIONS
1511 //
1512 //=================================================================================================
1513 
1514 //*************************************************************************************************
1516 template< typename MT, typename ST, bool SO >
1517 struct IsSymmetric< SMatScalarMultExpr<MT,ST,SO> >
1518  : public BoolConstant< IsSymmetric<MT>::value >
1519 {};
1521 //*************************************************************************************************
1522 
1523 
1524 
1525 
1526 //=================================================================================================
1527 //
1528 // ISHERMITIAN SPECIALIZATIONS
1529 //
1530 //=================================================================================================
1531 
1532 //*************************************************************************************************
1534 template< typename MT, typename ST, bool SO >
1535 struct IsHermitian< SMatScalarMultExpr<MT,ST,SO> >
1536  : public BoolConstant< IsHermitian<MT>::value >
1537 {};
1539 //*************************************************************************************************
1540 
1541 
1542 
1543 
1544 //=================================================================================================
1545 //
1546 // ISLOWER SPECIALIZATIONS
1547 //
1548 //=================================================================================================
1549 
1550 //*************************************************************************************************
1552 template< typename MT, typename ST, bool SO >
1553 struct IsLower< SMatScalarMultExpr<MT,ST,SO> >
1554  : public BoolConstant< IsLower<MT>::value >
1555 {};
1557 //*************************************************************************************************
1558 
1559 
1560 
1561 
1562 //=================================================================================================
1563 //
1564 // ISSTRICTLYLOWER SPECIALIZATIONS
1565 //
1566 //=================================================================================================
1567 
1568 //*************************************************************************************************
1570 template< typename MT, typename ST, bool SO >
1571 struct IsStrictlyLower< SMatScalarMultExpr<MT,ST,SO> >
1572  : public BoolConstant< IsStrictlyLower<MT>::value >
1573 {};
1575 //*************************************************************************************************
1576 
1577 
1578 
1579 
1580 //=================================================================================================
1581 //
1582 // ISUPPER SPECIALIZATIONS
1583 //
1584 //=================================================================================================
1585 
1586 //*************************************************************************************************
1588 template< typename MT, typename ST, bool SO >
1589 struct IsUpper< SMatScalarMultExpr<MT,ST,SO> >
1590  : public BoolConstant< IsUpper<MT>::value >
1591 {};
1593 //*************************************************************************************************
1594 
1595 
1596 
1597 
1598 //=================================================================================================
1599 //
1600 // ISSTRICTLYUPPER SPECIALIZATIONS
1601 //
1602 //=================================================================================================
1603 
1604 //*************************************************************************************************
1606 template< typename MT, typename ST, bool SO >
1607 struct IsStrictlyUpper< SMatScalarMultExpr<MT,ST,SO> >
1608  : public BoolConstant< IsStrictlyUpper<MT>::value >
1609 {};
1611 //*************************************************************************************************
1612 
1613 } // namespace blaze
1614 
1615 #endif
RightOperand rightOperand() const noexcept
Returns the right-hand side scalar operand.
Definition: SVecScalarMultExpr.h:438
ConstIterator begin(size_t i) const
Returns an iterator to the first non-zero element of row i.
Definition: SMatScalarMultExpr.h:367
Pointer difference type of the Blaze library.
LeftOperand leftOperand() const noexcept
Returns the left-hand side dense vector operand.
Definition: DVecScalarMultExpr.h:531
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 the Rows type trait.
std::forward_iterator_tag IteratorCategory
The iterator category.
Definition: SMatScalarMultExpr.h:196
EnableIf_< IsDenseMatrix< MT1 > > smpSchurAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP Schur product assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:196
RightOperand rightOperand() const noexcept
Returns the right-hand side scalar operand.
Definition: SMatScalarMultExpr.h:478
Header file for basic type definitions.
size_t nonZeros(size_t i) const
Returns the number of non-zero elements in the specified row.
Definition: SMatScalarMultExpr.h:419
ReturnType value() const
Access to the current value of the sparse element.
Definition: SMatScalarMultExpr.h:255
RightOperand rightOperand() const noexcept
Returns the right-hand side scalar operand.
Definition: DVecScalarMultExpr.h:541
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
RightOperand scalar_
Right-hand side scalar of the multiplication expression.
Definition: SMatScalarMultExpr.h:510
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.
#define BLAZE_CONSTRAINT_MUST_BE_MATRIX_WITH_STORAGE_ORDER(T, SO)
Constraint on the data type.In case the given data type T is not a dense or sparse matrix type and in...
Definition: StorageOrder.h:63
RightOperand scalar_
Right-hand side scalar of the multiplication expression.
Definition: SMatScalarMultExpr.h:306
Generic wrapper for a compile time constant integral value.The IntegralConstant class template repres...
Definition: IntegralConstant.h:71
LeftOperand leftOperand() const noexcept
Returns the left-hand side sparse matrix operand.
Definition: SMatScalarMultExpr.h:468
TransposeType_< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: SMatScalarMultExpr.h:167
Header file for the And class template.
Compile time check for lower triangular matrices.This type trait tests whether or not the given templ...
Definition: IsLower.h:88
MultExprTrait_< RN, ST > ExprReturnType
Expression return type for the subscript operator.
Definition: SMatScalarMultExpr.h:125
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.
Compile time check for upper triangular matrices.This type trait tests whether or not the given templ...
Definition: IsUpper.h:88
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.
LeftOperand matrix_
Left-hand side sparse matrix of the multiplication expression.
Definition: SMatScalarMultExpr.h:509
ReturnType at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: SMatScalarMultExpr.h:350
DifferenceType operator-(const ConstIterator &rhs) const
Calculating the number of elements between two expression iterators.
Definition: SMatScalarMultExpr.h:298
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
typename UnderlyingBuiltin< T >::Type UnderlyingBuiltin_
Auxiliary alias declaration for the UnderlyingBuiltin type trait.The UnderlyingBuiltin_ alias declara...
Definition: UnderlyingBuiltin.h:133
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
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
Header file for the SparseMatrix base class.
Constraint on the data type.
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
ConstIterator upperBound(size_t i, size_t j) const
Returns an iterator to the first index greater then the given index.
Definition: SMatScalarMultExpr.h:457
Header file for the ValueIndexPair class.
SMatScalarMultExpr(const MT &matrix, ST scalar) noexcept
Constructor for the SMatScalarMultExpr class.
Definition: SMatScalarMultExpr.h:322
Header file for the IsTemporary type trait class.
Header file for the multiplication trait.
Header file for the IsStrictlyUpper type trait.
Header file for the IsSymmetric type trait.
IfTrue_< useAssign, const ResultType, const SMatScalarMultExpr &> CompositeType
Data type for composite expression templates.
Definition: SMatScalarMultExpr.h:174
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Header file for the If class template.
ConstIterator & operator++()
Pre-increment operator.
Definition: SMatScalarMultExpr.h:224
Header file for the UnderlyingBuiltin type trait.
Header file for the Or class template.
ST RightOperand
Composite type of the right-hand side scalar value.
Definition: SMatScalarMultExpr.h:180
#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
const ConstIterator * operator->() const
Direct access to the sparse matrix element at the current iterator position.
Definition: SMatScalarMultExpr.h:245
Header file for the Columns type trait.
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SMatScalarMultExpr.h:490
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
#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
Header file for the IsLower type trait.
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: SMatScalarMultExpr.h:398
ElementType_< ResultType > ElementType
Resulting element type.
Definition: SMatScalarMultExpr.h:168
Constraints on the storage order of matrix types.
Compile time check for symmetric matrices.This type trait tests whether or not the given template par...
Definition: IsSymmetric.h:85
Header file for the exception macros of the math module.
Compile time check for strictly upper triangular matrices.This type trait tests whether or not the gi...
Definition: IsStrictlyUpper.h:86
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
ConstIterator lowerBound(size_t i, size_t j) const
Returns an iterator to the first index not less then the given index.
Definition: SMatScalarMultExpr.h:444
Constraint on the data type.
Expression object for sparse matrix-scalar multiplications.The SMatScalarMult class represents the co...
Definition: Forward.h:114
Header file for all forward declarations for expression class templates.
MultTrait_< RT, ST > ResultType
Result type for expression template evaluations.
Definition: SMatScalarMultExpr.h:165
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SMatScalarMultExpr.h:502
Header file for the EnableIf class template.
Header file for the IsStrictlyLower type trait.
ConstIterator end(size_t i) const
Returns an iterator just past the last non-zero element of row i.
Definition: SMatScalarMultExpr.h:378
const Element operator*() const
Direct access to the sparse matrix element at the current iterator position.
Definition: SMatScalarMultExpr.h:235
Header file for the IsNumeric type trait.
Header file for the MatScalarMultExpr base class.
Header file for run time assertion macros.
Utility type for generic codes.
ConstIterator(IteratorType matrix, RightOperand scalar)
Constructor for the ConstIterator class.
Definition: SMatScalarMultExpr.h:213
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
bool operator!=(const ConstIterator &rhs) const
Inequality comparison between two ConstIterator objects.
Definition: SMatScalarMultExpr.h:287
#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
size_t nonZeros() const
Returns the number of non-zero elements in the sparse matrix.
Definition: SMatScalarMultExpr.h:408
If_< IsExpression< MT >, const MT, const MT &> LeftOperand
Composite data type of the sparse matrix expression.
Definition: SMatScalarMultExpr.h:177
Compile time check for Hermitian matrices.This type trait tests whether or not the given template par...
Definition: IsHermitian.h:85
Compile time check for data types.This type trait tests whether or not the given template parameter i...
Definition: IsInvertible.h:83
ConstIterator_< RemoveReference_< LeftOperand > > IteratorType
Iterator type of the sparse matrix expression.
Definition: SMatScalarMultExpr.h:194
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
Iterator over the elements of the sparse matrix/scalar multiplication expression. ...
Definition: SMatScalarMultExpr.h:186
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
typename T::OppositeType OppositeType_
Alias declaration for nested OppositeType type definitions.The OppositeType_ alias declaration provid...
Definition: Aliases.h:263
IteratorCategory iterator_category
The iterator category.
Definition: SMatScalarMultExpr.h:203
CompositeType_< MT > CT
Composite type of the sparse matrix expression.
Definition: SMatScalarMultExpr.h:112
Compile time check for strictly lower triangular matrices.This type trait tests whether or not the gi...
Definition: IsStrictlyLower.h:86
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
IteratorType matrix_
Iterator over the elements of the left-hand side sparse matrix expression.
Definition: SMatScalarMultExpr.h:305
Index-value-pair for sparse vectors and matrices.The ValueIndexPair class represents a single index-v...
Definition: ValueIndexPair.h:73
Header file for the IsComputation type trait class.
Expression object for dense vector-scalar multiplications.The DVecScalarMultExpr class represents the...
Definition: DVecScalarMultExpr.h:106
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
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:130
Header file for the IntegralConstant class template.
Compile time evaluation of the number of columns of a matrix.The Columns type trait evaluates the num...
Definition: Columns.h:75
Compile time evaluation of the number of rows of a matrix.The Rows type trait evaluates the number of...
Definition: Rows.h:75
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: SMatScalarMultExpr.h:388
typename T::TransposeType TransposeType_
Alias declaration for nested TransposeType type definitions.The TransposeType_ alias declaration prov...
Definition: Aliases.h:423
Header file for the IsUpper type trait.
ReturnType_< MT > RN
Return type of the sparse matrix expression.
Definition: SMatScalarMultExpr.h:111
ConstIterator find(size_t i, size_t j) const
Searches for a specific matrix element.
Definition: SMatScalarMultExpr.h:431
OppositeType_< ResultType > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: SMatScalarMultExpr.h:166
const IfTrue_< returnExpr, ExprReturnType, ElementType > ReturnType
Return type for expression template evaluations.
Definition: SMatScalarMultExpr.h:171
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: SMatScalarMultExpr.h:335
Header file for the IsHermitian type trait.
size_t index() const
Access to the current index of the sparse element.
Definition: SMatScalarMultExpr.h:265
#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
bool operator==(const ConstIterator &rhs) const
Equality comparison between two ConstIterator objects.
Definition: SMatScalarMultExpr.h:276
LeftOperand leftOperand() const noexcept
Returns the left-hand side sparse vector operand.
Definition: SVecScalarMultExpr.h:428
ResultType_< MT > RT
Result type of the sparse matrix expression.
Definition: SMatScalarMultExpr.h:110
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a sparse, N-dimensional matrix type...
Definition: SparseMatrix.h:61
Header file for the IsExpression type trait class.
Header file for the function trace functionality.