SMatSVecMultExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_SMATSVECMULTEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_SMATSVECMULTEXPR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <stdexcept>
56 #include <blaze/math/shims/Reset.h>
69 #include <blaze/util/Assert.h>
71 #include <blaze/util/DisableIf.h>
72 #include <blaze/util/EnableIf.h>
74 #include <blaze/util/mpl/Or.h>
75 #include <blaze/util/SelectType.h>
76 #include <blaze/util/Types.h>
78 
79 
80 namespace blaze {
81 
82 //=================================================================================================
83 //
84 // CLASS SMATDVECMULTEXPR
85 //
86 //=================================================================================================
87 
88 //*************************************************************************************************
95 template< typename MT // Type of the left-hand side sparse matrix
96  , typename VT > // Type of the right-hand side sparse vector
97 class SMatSVecMultExpr : public SparseVector< SMatSVecMultExpr<MT,VT>, false >
98  , private MatVecMultExpr
99  , private Computation
100 {
101  private:
102  //**Type definitions****************************************************************************
103  typedef typename MT::ResultType MRT;
104  typedef typename VT::ResultType VRT;
105  typedef typename MT::CompositeType MCT;
106  typedef typename VT::CompositeType VCT;
107  //**********************************************************************************************
108 
109  //**********************************************************************************************
111  enum { evaluateMatrix = RequiresEvaluation<MT>::value };
112  //**********************************************************************************************
113 
114  //**********************************************************************************************
116  enum { evaluateVector = RequiresEvaluation<VT>::value || IsComputation<VT>::value };
117  //**********************************************************************************************
118 
119  //**********************************************************************************************
121 
125  template< typename T1 >
126  struct UseSMPAssign {
127  enum { value = ( evaluateMatrix || evaluateVector ) };
128  };
130  //**********************************************************************************************
131 
132  public:
133  //**Type definitions****************************************************************************
138  typedef const ElementType ReturnType;
139 
141  typedef const ResultType CompositeType;
142 
144  typedef typename SelectType< IsExpression<MT>::value, const MT, const MT& >::Type LeftOperand;
145 
147  typedef typename SelectType< IsExpression<VT>::value, const VT, const VT& >::Type RightOperand;
148 
151 
154  //**********************************************************************************************
155 
156  //**Compilation flags***************************************************************************
158  enum { smpAssignable = !evaluateMatrix && MT::smpAssignable &&
159  !evaluateVector && VT::smpAssignable };
160  //**********************************************************************************************
161 
162  //**Constructor*********************************************************************************
168  explicit inline SMatSVecMultExpr( const MT& mat, const VT& vec )
169  : mat_( mat ) // Left-hand side sparse matrix of the multiplication expression
170  , vec_( vec ) // Right-hand side sparse vector of the multiplication expression
171  {
172  BLAZE_INTERNAL_ASSERT( mat_.columns() == vec_.size(), "Invalid matrix and vector sizes" );
173  }
174  //**********************************************************************************************
175 
176  //**Subscript operator**************************************************************************
182  inline ReturnType operator[]( size_t index ) const {
183  BLAZE_INTERNAL_ASSERT( index < mat_.rows(), "Invalid vector access index" );
184 
185  typedef typename RemoveReference<MCT>::Type::ConstIterator MatrixIterator;
186  typedef typename RemoveReference<VCT>::Type::ConstIterator VectorIterator;
187 
188  ElementType res = ElementType();
189 
190  // Early exit
191  if( vec_.size() == 0UL )
192  return res;
193 
194  // Fast computation in case both the left-hand side matrix operand and the right-hand
195  // side vector operand directly provide iterators
197  {
198  MCT A( mat_ ); // Evaluation of the left-hand side sparse matrix operand
199  VCT x( vec_ ); // Evaluation of the right-hand side sparse vector operand
200 
201  MatrixIterator melem( A.begin(index) );
202  const MatrixIterator mend( A.end(index) );
203  if( melem == mend ) {
204  return res;
205  }
206 
207  VectorIterator velem( x.begin() );
208  const VectorIterator vend( x.end() );
209  if( velem == vend ) {
210  return res;
211  }
212 
213  while( true ) {
214  if( melem->index() < velem->index() ) {
215  ++melem;
216  if( melem == mend ) break;
217  }
218  else if( velem->index() < melem->index() ) {
219  ++velem;
220  if( velem == vend ) break;
221  }
222  else {
223  res = melem->value() * velem->value();
224  ++melem;
225  ++velem;
226  break;
227  }
228  }
229 
230  if( melem != mend && velem != vend )
231  {
232  while( true ) {
233  if( melem->index() < velem->index() ) {
234  ++melem;
235  if( melem == mend ) break;
236  }
237  else if( velem->index() < melem->index() ) {
238  ++velem;
239  if( velem == vend ) break;
240  }
241  else {
242  res += melem->value() * velem->value();
243  ++melem;
244  if( melem == mend ) break;
245  ++velem;
246  if( velem == vend ) break;
247  }
248  }
249  }
250  }
251 
252  // Optimized computation in case the left-hand side matrix operand directly provides iterators
254  {
255  MCT A( mat_ ); // Evaluation of the left-hand side sparse matrix operand
256 
257  MatrixIterator melem( A.begin(index) );
258  const MatrixIterator mend( A.end(index) );
259 
260  if( melem == mend )
261  return res;
262 
263  res = melem->value() * vec_[melem->index()];
264  ++melem;
265  for( ; melem!=mend; ++melem ) {
266  res += melem->value() * vec_[melem->index()];
267  }
268  }
269 
270  // Optimized computation in case the right-hand side vector operand directly provides iterators
272  {
273  VCT x( vec_ ); // Evaluation of the right-hand side sparse vector operand
274 
275  VectorIterator velem( x.begin() );
276  const VectorIterator vend( x.end() );
277 
278  if( velem == vend )
279  return res;
280 
281  res = mat_(index,velem->index()) * velem->value();
282  ++velem;
283  for( ; velem!=vend; ++velem ) {
284  res += mat_(index,velem->index()) * velem->value();
285  }
286  }
287 
288  // Default computation in case both operands don't provide iterators
289  else {
290  res = mat_(index,0UL) * vec_[0UL];
291  for( size_t j=1UL; j<vec_.size(); ++j ) {
292  res += mat_(index,j) * vec_[j];
293  }
294  }
295 
296  return res;
297  }
298  //**********************************************************************************************
299 
300  //**Size function*******************************************************************************
305  inline size_t size() const {
306  return mat_.rows();
307  }
308  //**********************************************************************************************
309 
310  //**NonZeros function***************************************************************************
315  inline size_t nonZeros() const {
316  return mat_.rows();
317  }
318  //**********************************************************************************************
319 
320  //**Left operand access*************************************************************************
325  inline LeftOperand leftOperand() const {
326  return mat_;
327  }
328  //**********************************************************************************************
329 
330  //**Right operand access************************************************************************
335  inline RightOperand rightOperand() const {
336  return vec_;
337  }
338  //**********************************************************************************************
339 
340  //**********************************************************************************************
346  template< typename T >
347  inline bool canAlias( const T* alias ) const {
348  return ( mat_.isAliased( alias ) || vec_.isAliased( alias ) );
349  }
350  //**********************************************************************************************
351 
352  //**********************************************************************************************
358  template< typename T >
359  inline bool isAliased( const T* alias ) const {
360  return ( mat_.isAliased( alias ) || vec_.isAliased( alias ) );
361  }
362  //**********************************************************************************************
363 
364  //**********************************************************************************************
369  inline bool canSMPAssign() const {
370  return ( size() > SMP_SMATSVECMULT_THRESHOLD );
371  }
372  //**********************************************************************************************
373 
374  private:
375  //**Member variables****************************************************************************
376  LeftOperand mat_;
377  RightOperand vec_;
378  //**********************************************************************************************
379 
380  //**Assignment to dense vectors*****************************************************************
392  template< typename VT1 > // Type of the target dense vector
393  friend inline void assign( DenseVector<VT1,false>& lhs, const SMatSVecMultExpr& rhs )
394  {
396 
397  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
398 
399  // Resetting the left-hand side target dense vector
400  reset( ~lhs );
401 
402  // Evaluation of the right-hand side sparse vector operand
403  RT x( serial( rhs.vec_ ) );
404  if( x.nonZeros() == 0UL ) return;
405 
406  // Evaluation of the left-hand side sparse matrix operand
407  LT A( serial( rhs.mat_ ) );
408 
409  // Checking the evaluated operators
410  BLAZE_INTERNAL_ASSERT( A.rows() == rhs.mat_.rows() , "Invalid number of rows" );
411  BLAZE_INTERNAL_ASSERT( A.columns() == rhs.mat_.columns(), "Invalid number of columns" );
412  BLAZE_INTERNAL_ASSERT( x.size() == rhs.vec_.size() , "Invalid vector size" );
413  BLAZE_INTERNAL_ASSERT( A.rows() == (~lhs).size() , "Invalid vector size" );
414 
415  // Performing the sparse matrix-sparse vector multiplication
416  SMatSVecMultExpr::selectAssignKernel( ~lhs, A, x );
417  }
419  //**********************************************************************************************
420 
421  //**Default assignment to dense vectors*********************************************************
435  template< typename VT1 // Type of the left-hand side target vector
436  , typename MT1 // Type of the left-hand side matrix operand
437  , typename VT2 > // Type of the right-hand side vector operand
438  static inline void selectAssignKernel( VT1& y, const MT1& A, const VT2& x )
439  {
440  typedef typename RemoveReference<LT>::Type::ConstIterator MatrixIterator;
441  typedef typename RemoveReference<RT>::Type::ConstIterator VectorIterator;
442 
443  const VectorIterator vend( x.end() );
444 
445  for( size_t i=0UL; i<y.size(); ++i )
446  {
447  const MatrixIterator mend ( A.end(i) );
448  MatrixIterator melem( A.begin(i) );
449 
450  if( melem == mend ) continue;
451 
452  VectorIterator velem( x.begin() );
453 
454  while( true ) {
455  if( melem->index() < velem->index() ) {
456  ++melem;
457  if( melem == mend ) break;
458  }
459  else if( velem->index() < melem->index() ) {
460  ++velem;
461  if( velem == vend ) break;
462  }
463  else {
464  y[i] = melem->value() * velem->value();
465  ++melem;
466  ++velem;
467  break;
468  }
469  }
470 
471  if( melem != mend && velem != vend )
472  {
473  while( true ) {
474  if( melem->index() < velem->index() ) {
475  ++melem;
476  if( melem == mend ) break;
477  }
478  else if( velem->index() < melem->index() ) {
479  ++velem;
480  if( velem == vend ) break;
481  }
482  else {
483  y[i] += melem->value() * velem->value();
484  ++melem;
485  if( melem == mend ) break;
486  ++velem;
487  if( velem == vend ) break;
488  }
489  }
490  }
491  }
492  }
494  //**********************************************************************************************
495 
496  //**Assignment to sparse vectors****************************************************************
508  template< typename VT1 > // Type of the target sparse vector
509  friend inline void assign( SparseVector<VT1,false>& lhs, const SMatSVecMultExpr& rhs )
510  {
512 
513  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
514 
515  typedef typename RemoveReference<LT>::Type::ConstIterator MatrixIterator;
516  typedef typename RemoveReference<RT>::Type::ConstIterator VectorIterator;
517 
518  RT x( rhs.vec_ ); // Evaluation of the right-hand side sparse vector operand
519  if( x.nonZeros() == 0UL ) return;
520 
521  LT A( rhs.mat_ ); // Evaluation of the left-hand side sparse matrix operand
522 
523  BLAZE_INTERNAL_ASSERT( A.rows() == rhs.mat_.rows() , "Invalid number of rows" );
524  BLAZE_INTERNAL_ASSERT( A.columns() == rhs.mat_.columns(), "Invalid number of columns" );
525  BLAZE_INTERNAL_ASSERT( x.size() == rhs.vec_.size() , "Invalid vector size" );
526  BLAZE_INTERNAL_ASSERT( A.rows() == (~lhs).size() , "Invalid vector size" );
527 
528  ElementType accu;
529  const VectorIterator vend( x.end() );
530 
531  for( size_t i=0UL; i<(~lhs).size(); ++i )
532  {
533  const MatrixIterator mend ( A.end(i) );
534  MatrixIterator melem( A.begin(i) );
535 
536  if( melem == mend ) continue;
537 
538  VectorIterator velem( x.begin() );
539 
540  reset( accu );
541 
542  while( true ) {
543  if( melem->index() < velem->index() ) {
544  ++melem;
545  if( melem == mend ) break;
546  }
547  else if( velem->index() < melem->index() ) {
548  ++velem;
549  if( velem == vend ) break;
550  }
551  else {
552  accu = melem->value() * velem->value();
553  ++melem;
554  ++velem;
555  break;
556  }
557  }
558 
559  if( melem != mend && velem != vend )
560  {
561  while( true ) {
562  if( melem->index() < velem->index() ) {
563  ++melem;
564  if( melem == mend ) break;
565  }
566  else if( velem->index() < melem->index() ) {
567  ++velem;
568  if( velem == vend ) break;
569  }
570  else {
571  accu += melem->value() * velem->value();
572  ++melem;
573  if( melem == mend ) break;
574  ++velem;
575  if( velem == vend ) break;
576  }
577  }
578  }
579 
580  if( !isDefault( accu ) )
581  (~lhs).insert( i, accu );
582  }
583  }
585  //**********************************************************************************************
586 
587  //**Addition assignment to dense vectors********************************************************
599  template< typename VT1 > // Type of the target dense vector
600  friend inline void addAssign( DenseVector<VT1,false>& lhs, const SMatSVecMultExpr& rhs )
601  {
603 
604  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
605 
606  // Evaluation of the right-hand side sparse vector operand
607  RT x( serial( rhs.vec_ ) );
608  if( x.nonZeros() == 0UL ) return;
609 
610  // Evaluation of the left-hand side sparse matrix operand
611  LT A( serial( rhs.mat_ ) );
612 
613  // Checking the evaluated operators
614  BLAZE_INTERNAL_ASSERT( A.rows() == rhs.mat_.rows() , "Invalid number of rows" );
615  BLAZE_INTERNAL_ASSERT( A.columns() == rhs.mat_.columns(), "Invalid number of columns" );
616  BLAZE_INTERNAL_ASSERT( x.size() == rhs.vec_.size() , "Invalid vector size" );
617  BLAZE_INTERNAL_ASSERT( A.rows() == (~lhs).size() , "Invalid vector size" );
618 
619  // Performing the sparse matrix-sparse vector multiplication
620  SMatSVecMultExpr::selectAddAssignKernel( ~lhs, A, x );
621  }
623  //**********************************************************************************************
624 
625  //**Default addition assignment to dense vectors************************************************
639  template< typename VT1 // Type of the left-hand side target vector
640  , typename MT1 // Type of the left-hand side matrix operand
641  , typename VT2 > // Type of the right-hand side vector operand
642  static inline void selectAddAssignKernel( VT1& y, const MT1& A, const VT2& x )
643  {
644  typedef typename RemoveReference<LT>::Type::ConstIterator MatrixIterator;
645  typedef typename RemoveReference<RT>::Type::ConstIterator VectorIterator;
646 
647  const VectorIterator vend( x.end() );
648 
649  for( size_t i=0UL; i<y.size(); ++i )
650  {
651  const MatrixIterator mend ( A.end(i) );
652  MatrixIterator melem( A.begin(i) );
653 
654  if( melem == mend ) continue;
655 
656  VectorIterator velem( x.begin() );
657 
658  while( true ) {
659  if( melem->index() < velem->index() ) {
660  ++melem;
661  if( melem == mend ) break;
662  }
663  else if( velem->index() < melem->index() ) {
664  ++velem;
665  if( velem == vend ) break;
666  }
667  else {
668  y[i] += melem->value() * velem->value();
669  ++melem;
670  if( melem == mend ) break;
671  ++velem;
672  if( velem == vend ) break;
673  }
674  }
675  }
676  }
678  //**********************************************************************************************
679 
680  //**Addition assignment to sparse vectors*******************************************************
681  // No special implementation for the addition assignment to sparse vectors.
682  //**********************************************************************************************
683 
684  //**Subtraction assignment to dense vectors*****************************************************
696  template< typename VT1 > // Type of the target dense vector
697  friend inline void subAssign( DenseVector<VT1,false>& lhs, const SMatSVecMultExpr& rhs )
698  {
700 
701  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
702 
703  typedef typename RemoveReference<LT>::Type::ConstIterator MatrixIterator;
704  typedef typename RemoveReference<RT>::Type::ConstIterator VectorIterator;
705 
706  // Evaluation of the right-hand side sparse vector operand
707  RT x( serial( rhs.vec_ ) );
708  if( x.nonZeros() == 0UL ) return;
709 
710  // Evaluation of the left-hand side sparse matrix operand
711  LT A( serial( rhs.mat_ ) );
712 
713  // Checking the evaluated operators
714  BLAZE_INTERNAL_ASSERT( A.rows() == rhs.mat_.rows() , "Invalid number of rows" );
715  BLAZE_INTERNAL_ASSERT( A.columns() == rhs.mat_.columns(), "Invalid number of columns" );
716  BLAZE_INTERNAL_ASSERT( x.size() == rhs.vec_.size() , "Invalid vector size" );
717  BLAZE_INTERNAL_ASSERT( A.rows() == (~lhs).size() , "Invalid vector size" );
718 
719  // Performing the sparse matrix-sparse vector multiplication
720  SMatSVecMultExpr::selectSubAssignKernel( ~lhs, A, x );
721  }
723  //**********************************************************************************************
724 
725  //**Default subtraction assignment to dense vectors*********************************************
739  template< typename VT1 // Type of the left-hand side target vector
740  , typename MT1 // Type of the left-hand side matrix operand
741  , typename VT2 > // Type of the right-hand side vector operand
742  static inline void selectSubAssignKernel( VT1& y, const MT1& A, const VT2& x )
743  {
744  typedef typename RemoveReference<LT>::Type::ConstIterator MatrixIterator;
745  typedef typename RemoveReference<RT>::Type::ConstIterator VectorIterator;
746 
747  const VectorIterator vend( x.end() );
748 
749  for( size_t i=0UL; i<y.size(); ++i )
750  {
751  const MatrixIterator mend ( A.end(i) );
752  MatrixIterator melem( A.begin(i) );
753 
754  if( melem == mend ) continue;
755 
756  VectorIterator velem( x.begin() );
757 
758  while( true ) {
759  if( melem->index() < velem->index() ) {
760  ++melem;
761  if( melem == mend ) break;
762  }
763  else if( velem->index() < melem->index() ) {
764  ++velem;
765  if( velem == vend ) break;
766  }
767  else {
768  y[i] -= melem->value() * velem->value();
769  ++melem;
770  if( melem == mend ) break;
771  ++velem;
772  if( velem == vend ) break;
773  }
774  }
775  }
776  }
778  //**********************************************************************************************
779 
780  //**Subtraction assignment to sparse vectors****************************************************
781  // No special implementation for the subtraction assignment to sparse vectors.
782  //**********************************************************************************************
783 
784  //**Multiplication assignment to dense vectors**************************************************
796  template< typename VT1 > // Type of the target dense vector
797  friend inline void multAssign( DenseVector<VT1,false>& lhs, const SMatSVecMultExpr& rhs )
798  {
800 
804 
805  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
806 
807  const ResultType tmp( serial( rhs ) );
808  multAssign( ~lhs, tmp );
809  }
811  //**********************************************************************************************
812 
813  //**Multiplication assignment to sparse vectors*************************************************
814  // No special implementation for the multiplication assignment to sparse vectors.
815  //**********************************************************************************************
816 
817  //**SMP assignment to dense vectors*************************************************************
831  template< typename VT1 > // Type of the target dense vector
832  friend inline typename EnableIf< UseSMPAssign<VT1> >::Type
833  smpAssign( DenseVector<VT1,false>& lhs, const SMatSVecMultExpr& rhs )
834  {
836 
837  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
838 
839  // Resetting the left-hand side target dense vector
840  reset( ~lhs );
841 
842  // Evaluation of the right-hand side sparse vector operand
843  RT x( rhs.vec_ );
844  if( x.nonZeros() == 0UL ) return;
845 
846  // Evaluation of the left-hand side sparse matrix operand
847  LT A( rhs.mat_ );
848 
849  // Checking the evaluated operators
850  BLAZE_INTERNAL_ASSERT( A.rows() == rhs.mat_.rows() , "Invalid number of rows" );
851  BLAZE_INTERNAL_ASSERT( A.columns() == rhs.mat_.columns(), "Invalid number of columns" );
852  BLAZE_INTERNAL_ASSERT( x.size() == rhs.vec_.size() , "Invalid vector size" );
853  BLAZE_INTERNAL_ASSERT( A.rows() == (~lhs).size() , "Invalid vector size" );
854 
855  // Performing the sparse matrix-sparse vector multiplication
856  smpAssign( ~lhs, A * x );
857  }
859  //**********************************************************************************************
860 
861  //**SMP assignment to sparse vectors************************************************************
862  // No special implementation for the SMP assignment to sparse vectors.
863  //**********************************************************************************************
864 
865  //**SMP addition assignment to dense vectors****************************************************
880  template< typename VT1 > // Type of the target dense vector
881  friend inline typename EnableIf< UseSMPAssign<VT1> >::Type
882  smpAddAssign( DenseVector<VT1,false>& lhs, const SMatSVecMultExpr& rhs )
883  {
885 
886  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
887 
888  // Evaluation of the right-hand side sparse vector operand
889  RT x( rhs.vec_ );
890  if( x.nonZeros() == 0UL ) return;
891 
892  // Evaluation of the left-hand side sparse matrix operand
893  LT A( rhs.mat_ );
894 
895  // Checking the evaluated operators
896  BLAZE_INTERNAL_ASSERT( A.rows() == rhs.mat_.rows() , "Invalid number of rows" );
897  BLAZE_INTERNAL_ASSERT( A.columns() == rhs.mat_.columns(), "Invalid number of columns" );
898  BLAZE_INTERNAL_ASSERT( x.size() == rhs.vec_.size() , "Invalid vector size" );
899  BLAZE_INTERNAL_ASSERT( A.rows() == (~lhs).size() , "Invalid vector size" );
900 
901  // Performing the sparse matrix-sparse vector multiplication
902  smpAddAssign( ~lhs, A * x );
903  }
905  //**********************************************************************************************
906 
907  //**SMP addition assignment to sparse vectors***************************************************
908  // No special implementation for the SMP addition assignment to sparse vectors.
909  //**********************************************************************************************
910 
911  //**SMP subtraction assignment to dense vectors*************************************************
926  template< typename VT1 > // Type of the target dense vector
927  friend inline typename EnableIf< UseSMPAssign<VT1> >::Type
928  smpSubAssign( DenseVector<VT1,false>& lhs, const SMatSVecMultExpr& rhs )
929  {
931 
932  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
933 
934  typedef typename RemoveReference<LT>::Type::ConstIterator MatrixIterator;
935  typedef typename RemoveReference<RT>::Type::ConstIterator VectorIterator;
936 
937  // Evaluation of the right-hand side sparse vector operand
938  RT x( rhs.vec_ );
939  if( x.nonZeros() == 0UL ) return;
940 
941  // Evaluation of the left-hand side sparse matrix operand
942  LT A( rhs.mat_ );
943 
944  // Checking the evaluated operators
945  BLAZE_INTERNAL_ASSERT( A.rows() == rhs.mat_.rows() , "Invalid number of rows" );
946  BLAZE_INTERNAL_ASSERT( A.columns() == rhs.mat_.columns(), "Invalid number of columns" );
947  BLAZE_INTERNAL_ASSERT( x.size() == rhs.vec_.size() , "Invalid vector size" );
948  BLAZE_INTERNAL_ASSERT( A.rows() == (~lhs).size() , "Invalid vector size" );
949 
950  // Performing the sparse matrix-sparse vector multiplication
951  smpSubAssign( ~lhs, A * x );
952  }
954  //**********************************************************************************************
955 
956  //**SMP subtraction assignment to sparse vectors************************************************
957  // No special implementation for the SMP subtraction assignment to sparse vectors.
958  //**********************************************************************************************
959 
960  //**SMP multiplication assignment to dense vectors**********************************************
975  template< typename VT1 > // Type of the target dense vector
976  friend inline typename EnableIf< UseSMPAssign<VT1> >::Type
977  smpMultAssign( DenseVector<VT1,false>& lhs, const SMatSVecMultExpr& rhs )
978  {
980 
984 
985  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
986 
987  const ResultType tmp( rhs );
988  smpMultAssign( ~lhs, tmp );
989  }
991  //**********************************************************************************************
992 
993  //**SMP multiplication assignment to sparse vectors*********************************************
994  // No special implementation for the SMP multiplication assignment to sparse vectors.
995  //**********************************************************************************************
996 
997  //**Compile time checks*************************************************************************
1006  //**********************************************************************************************
1007 };
1008 //*************************************************************************************************
1009 
1010 
1011 
1012 
1013 //=================================================================================================
1014 //
1015 // GLOBAL BINARY ARITHMETIC OPERATORS
1016 //
1017 //=================================================================================================
1018 
1019 //*************************************************************************************************
1050 template< typename T1 // Type of the left-hand side sparse matrix
1051  , typename T2 > // Type of the right-hand side sparse vector
1052 inline const typename DisableIf< Or< IsSymmetric<T1>, IsMatMatMultExpr<T1> >
1053  , SMatSVecMultExpr<T1,T2> >::Type
1055 {
1057 
1058  if( (~mat).columns() != (~vec).size() )
1059  throw std::invalid_argument( "Matrix and vector sizes do not match" );
1060 
1061  return SMatSVecMultExpr<T1,T2>( ~mat, ~vec );
1062 }
1063 //*************************************************************************************************
1064 
1065 
1066 
1067 
1068 //=================================================================================================
1069 //
1070 // GLOBAL RESTRUCTURING BINARY ARITHMETIC OPERATORS
1071 //
1072 //=================================================================================================
1073 
1074 //*************************************************************************************************
1089 template< typename T1 // Type of the left-hand side sparse matrix
1090  , typename T2 > // Type of the right-hand side sparse vector
1091 inline const typename EnableIf< IsSymmetric<T1>, typename MultExprTrait<T1,T2>::Type >::Type
1092  operator*( const SparseMatrix<T1,false>& mat, const SparseVector<T2,false>& vec )
1093 {
1095 
1097 
1098  if( (~mat).columns() != (~vec).size() )
1099  throw std::invalid_argument( "Matrix and vector sizes do not match" );
1100 
1101  return trans( ~mat ) * (~vec);
1102 }
1104 //*************************************************************************************************
1105 
1106 
1107 //*************************************************************************************************
1121 template< typename T1 // Type of the left-hand side sparse matrix
1122  , bool SO // Storage order of the left-hand side sparse matrix
1123  , typename T2 > // Type of the right-hand side sparse vector
1124 inline const typename EnableIf< IsMatMatMultExpr<T1>, typename MultExprTrait<T1,T2>::Type >::Type
1125  operator*( const SparseMatrix<T1,SO>& mat, const SparseVector<T2,false>& vec )
1126 {
1128 
1130 
1131  return (~mat).leftOperand() * ( (~mat).rightOperand() * vec );
1132 }
1134 //*************************************************************************************************
1135 
1136 
1137 
1138 
1139 //=================================================================================================
1140 //
1141 // SIZE SPECIALIZATIONS
1142 //
1143 //=================================================================================================
1144 
1145 //*************************************************************************************************
1147 template< typename MT, typename VT >
1148 struct Size< SMatSVecMultExpr<MT,VT> >
1149  : public Rows<MT>
1150 {};
1152 //*************************************************************************************************
1153 
1154 
1155 
1156 
1157 //=================================================================================================
1158 //
1159 // EXPRESSION TRAIT SPECIALIZATIONS
1160 //
1161 //=================================================================================================
1162 
1163 //*************************************************************************************************
1165 template< typename MT, typename VT, bool AF >
1166 struct SubvectorExprTrait< SMatSVecMultExpr<MT,VT>, AF >
1167 {
1168  public:
1169  //**********************************************************************************************
1170  typedef typename MultExprTrait< typename SubmatrixExprTrait<const MT,AF>::Type
1171  , typename SubvectorExprTrait<const VT,AF>::Type >::Type Type;
1172  //**********************************************************************************************
1173 };
1175 //*************************************************************************************************
1176 
1177 } // namespace blaze
1178 
1179 #endif
SelectType< IsExpression< VT >::value, const VT, const VT & >::Type RightOperand
Composite type of the right-hand side sparse vector expression.
Definition: SMatSVecMultExpr.h:147
const size_t SMP_SMATSVECMULT_THRESHOLD
SMP row-major sparse matrix/sparse vector multiplication threshold.This threshold specifies when a ro...
Definition: Thresholds.h:598
Compile time check whether the given type is a computational expression template.This type trait clas...
Definition: IsComputation.h:89
LeftOperand mat_
Left-hand side sparse matrix of the multiplication expression.
Definition: SMatSVecMultExpr.h:376
BLAZE_ALWAYS_INLINE void multAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the multiplication assignment of a matrix to a matrix.
Definition: Matrix.h:879
Header file for the Rows type trait.
const DMatDMatMultExpr< T1, T2 > operator*(const DenseMatrix< T1, false > &lhs, const DenseMatrix< T2, false > &rhs)
Multiplication operator for the multiplication of two row-major dense matrices ( ).
Definition: DMatDMatMultExpr.h:8247
Header file for basic type definitions.
Header file for the SparseVector base class.
VT::CompositeType VCT
Composite type of the right-hand side sparse vector expression.
Definition: SMatSVecMultExpr.h:106
ResultType::ElementType ElementType
Resulting element type.
Definition: SMatSVecMultExpr.h:137
#define BLAZE_CONSTRAINT_MUST_BE_COLUMN_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a column dense or sparse vector type...
Definition: TransposeFlag.h:159
const ElementType ReturnType
Return type for expression template evaluations.
Definition: SMatSVecMultExpr.h:138
VT::ResultType VRT
Result type of the right-hand side sparse vector expression.
Definition: SMatSVecMultExpr.h:104
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:209
MultTrait< MRT, VRT >::Type ResultType
Result type for expression template evaluations.
Definition: SMatSVecMultExpr.h:135
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:821
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2507
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:261
const DMatSerialExpr< MT, SO > serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:699
Header file for the Computation base class.
Header file for the RequiresEvaluation type trait.
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: SMatSVecMultExpr.h:347
SelectType< evaluateVector, const VRT, VCT >::Type RT
Type for the assignment of the right-hand side sparse vector operand.
Definition: SMatSVecMultExpr.h:153
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes...
Definition: Forward.h:107
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:861
size_t size() const
Returns the current size/dimension of the vector.
Definition: SMatSVecMultExpr.h:305
Constraint on the data type.
Constraint on the data type.
size_t nonZeros() const
Returns an estimation for the number of non-zero elements in the sparse vector.
Definition: SMatSVecMultExpr.h:315
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:90
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:263
SelectType< evaluateMatrix, const MRT, MCT >::Type LT
Type for the assignment of the left-hand side sparse matrix operand.
Definition: SMatSVecMultExpr.h:150
Compile time type selection.The SelectType class template selects one of the two given types T1 and T...
Definition: SelectType.h:59
Header file for the DisableIf class template.
Header file for the multiplication trait.
Header file for the IsSymmetric type trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Expression object for sparse matrix-sparse vector multiplications.The SMatSVecMultExpr class represen...
Definition: Forward.h:99
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2511
Header file for the Or class template.
Header file for the IsMatMatMultExpr type trait class.
BLAZE_ALWAYS_INLINE void assign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the assignment of a matrix to a matrix.
Definition: Matrix.h:635
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_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:79
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: SMatSVecMultExpr.h:182
Constraint on the data type.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_MATMATMULTEXPR_TYPE(T)
Constraint on the data type.In case the given data type T is a matrix/matrix multiplication expressio...
Definition: MatMatMultExpr.h:126
#define BLAZE_CONSTRAINT_MUST_BE_REFERENCE_TYPE(T)
Constraint on the data type.In case the given data type T is not a reference type, a compilation error is created.
Definition: Reference.h:78
RightOperand rightOperand() const
Returns the right-hand side sparse vector operand.
Definition: SMatSVecMultExpr.h:335
#define BLAZE_CONSTRAINT_MUST_FORM_VALID_MATVECMULTEXPR(T1, T2)
Constraint on the data type.In case the given data types T1 and T2 do not form a valid matrix/vector ...
Definition: MatVecMultExpr.h:166
Constraints on the storage order of matrix types.
Header file for the SelectType class template.
Header file for all forward declarations for expression class templates.
Constraint on the data type.
SMatSVecMultExpr< MT, VT > This
Type of this SMatSVecMultExpr instance.
Definition: SMatSVecMultExpr.h:134
SMatSVecMultExpr(const MT &mat, const VT &vec)
Constructor for the SMatSVecMultExpr class.
Definition: SMatSVecMultExpr.h:168
Header file for the EnableIf class template.
MT::CompositeType MCT
Composite type of the left-hand side sparse matrix expression.
Definition: SMatSVecMultExpr.h:105
Header file for the serial shim.
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: SMatSVecMultExpr.h:136
EnableIf< IsDenseMatrix< MT1 > >::Type 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:160
RightOperand vec_
Right-hand side sparse vector of the multiplication expression.
Definition: SMatSVecMultExpr.h:377
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a symmetric matrix type, a compilation error is created.
Definition: Symmetric.h:116
#define BLAZE_CONSTRAINT_MUST_BE_ROW_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a row-major dense or sparse matrix t...
Definition: StorageOrder.h:81
Removal of reference modifiers.The RemoveCV type trait removes any reference modifiers from the given...
Definition: RemoveReference.h:69
Header file for run time assertion macros.
EnableIf< IsDenseMatrix< MT1 > >::Type smpAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:98
Base template for the MultTrait class.
Definition: MultTrait.h:150
BLAZE_ALWAYS_INLINE void addAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the addition assignment of a matrix to a matrix.
Definition: Matrix.h:742
bool canSMPAssign() const
Returns whether the expression can be used in SMP assignments.
Definition: SMatSVecMultExpr.h:369
Header file for the reset shim.
Header file for the isDefault shim.
Constraint on the data type.
const ResultType CompositeType
Data type for composite expression templates.
Definition: SMatSVecMultExpr.h:141
Header file for the RemoveReference type trait.
LeftOperand leftOperand() const
Returns the left-hand side sparse matrix operand.
Definition: SMatSVecMultExpr.h:325
const DMatTransExpr< MT,!SO > trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:937
Header file for the IsComputation type trait class.
EnableIf< IsDenseMatrix< MT1 > >::Type 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:129
MT::ResultType MRT
Result type of the left-hand side sparse matrix expression.
Definition: SMatSVecMultExpr.h:103
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:108
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:157
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2502
BLAZE_ALWAYS_INLINE size_t columns(const Matrix< MT, SO > &matrix)
Returns the current number of columns of the matrix.
Definition: Matrix.h:332
Header file for the SubvectorExprTrait class template.
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: SMatSVecMultExpr.h:359
Constraint on the data type.
Header file for the MatVecMultExpr base class.
Constraint on the data type.
EnableIf< IsDenseVector< VT1 > >::Type 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:189
Header file for the Size type trait.
Header file for the thresholds for matrix/vector and matrix/matrix multiplications.
#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
#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:79
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.
BLAZE_ALWAYS_INLINE void subAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the subtraction assignment of a matrix to matrix.
Definition: Matrix.h:849
SelectType< IsExpression< MT >::value, const MT, const MT & >::Type LeftOperand
Composite type of the left-hand side sparse matrix expression.
Definition: SMatSVecMultExpr.h:144