All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DVecTSVecMultExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_DVECTSVECMULTEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_DVECTSVECMULTEXPR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <iterator>
55 #include <blaze/math/Intrinsics.h>
71 #include <blaze/util/Assert.h>
73 #include <blaze/util/EnableIf.h>
75 #include <blaze/util/SelectType.h>
76 #include <blaze/util/Types.h>
79 #include <blaze/util/Unused.h>
80 
81 
82 namespace blaze {
83 
84 //=================================================================================================
85 //
86 // CLASS DVECTSVECMULTEXPR
87 //
88 //=================================================================================================
89 
90 //*************************************************************************************************
97 template< typename VT1 // Type of the left-hand side dense vector
98  , typename VT2 > // Type of the right-hand side sparse vector
99 class DVecTSVecMultExpr : public SparseMatrix< DVecTSVecMultExpr<VT1,VT2>, false >
100  , private VecTVecMultExpr
101  , private Computation
102 {
103  private:
104  //**Type definitions****************************************************************************
105  typedef typename VT1::ResultType RT1;
106  typedef typename VT2::ResultType RT2;
107  typedef typename VT1::ReturnType RN1;
108  typedef typename VT2::ReturnType RN2;
109  typedef typename VT1::CompositeType CT1;
110  typedef typename VT2::CompositeType CT2;
111  typedef typename VT1::ElementType ET1;
112  typedef typename VT2::ElementType ET2;
113  //**********************************************************************************************
114 
115  //**Return type evaluation**********************************************************************
117 
122  enum { returnExpr = !IsTemporary<RN1>::value && !IsTemporary<RN2>::value };
123 
126  //**********************************************************************************************
127 
128  //**Evaluation strategy*************************************************************************
130 
137  enum { useAssign = ( IsComputation<VT1>::value || !IsNumeric<ET1>::value ||
139 
141  template< typename MT >
143  struct UseAssign {
144  enum { value = useAssign };
145  };
147  //**********************************************************************************************
148 
149  //**********************************************************************************************
151 
154  template< typename T1, typename T2, typename T3 >
155  struct UseVectorizedKernel {
156  enum { value = T1::vectorizable && T2::vectorizable &&
160  };
162  //**********************************************************************************************
163 
164  //**********************************************************************************************
166 
169  template< typename T1, typename T2, typename T3 >
170  struct UseDefaultKernel {
171  enum { value = !UseVectorizedKernel<T1,T2,T3>::value };
172  };
174  //**********************************************************************************************
175 
176  public:
177  //**Type definitions****************************************************************************
183 
186 
189 
191  typedef typename SelectType< IsExpression<VT1>::value, const VT1, const VT1& >::Type LeftOperand;
192 
194  typedef typename SelectType< IsExpression<VT2>::value, const VT2, const VT2& >::Type RightOperand;
195 
197  typedef typename SelectType< IsComputation<VT1>::value, const RT1, CT1 >::Type LT;
198 
200  typedef typename SelectType< IsComputation<VT2>::value, const RT2, CT2 >::Type RT;
201  //**********************************************************************************************
202 
203  //**Compilation flags***************************************************************************
205  enum { smpAssignable = 0 };
206  //**********************************************************************************************
207 
208  //**ConstIterator class definition**************************************************************
212  {
213  public:
214  //**Type definitions*************************************************************************
217 
219  typedef ET1 LeftElement;
220 
223 
224  typedef std::forward_iterator_tag IteratorCategory;
225  typedef Element ValueType;
229 
230  // STL iterator requirements
236  //*******************************************************************************************
237 
238  //**Constructor******************************************************************************
242  : v_ ( v ) // Element of the left-hand side dense vector expression.
243  , it_( it ) // Iterator over the elements of the right-hand side sparse vector expression
244  {}
245  //*******************************************************************************************
246 
247  //**Prefix increment operator****************************************************************
253  ++it_;
254  return *this;
255  }
256  //*******************************************************************************************
257 
258  //**Element access operator******************************************************************
263  inline const Element operator*() const {
264  return Element( v_ * it_->value(), it_->index() );
265  }
266  //*******************************************************************************************
267 
268  //**Element access operator******************************************************************
273  inline const ConstIterator* operator->() const {
274  return this;
275  }
276  //*******************************************************************************************
277 
278  //**Value function***************************************************************************
283  inline ReturnType value() const {
284  return v_ * it_->value();
285  }
286  //*******************************************************************************************
287 
288  //**Index function***************************************************************************
293  inline size_t index() const {
294  return it_->index();
295  }
296  //*******************************************************************************************
297 
298  //**Equality operator************************************************************************
304  inline bool operator==( const ConstIterator& rhs ) const {
305  return it_ == rhs.it_;
306  }
307  //*******************************************************************************************
308 
309  //**Inequality operator**********************************************************************
315  inline bool operator!=( const ConstIterator& rhs ) const {
316  return it_ != rhs.it_;
317  }
318  //*******************************************************************************************
319 
320  //**Subtraction operator*********************************************************************
326  inline DifferenceType operator-( const ConstIterator& rhs ) const {
327  return it_ - rhs.it_;
328  }
329  //*******************************************************************************************
330 
331  private:
332  //**Member variables*************************************************************************
335  //*******************************************************************************************
336  };
337  //**********************************************************************************************
338 
339  //**Constructor*********************************************************************************
345  explicit inline DVecTSVecMultExpr( const VT1& lhs, const VT2& rhs )
346  : lhs_( lhs ) // Left-hand side dense vector of the multiplication expression
347  , rhs_( rhs ) // Right-hand side sparse vector of the multiplication expression
348  {}
349  //**********************************************************************************************
350 
351  //**Access operator*****************************************************************************
358  inline ReturnType operator()( size_t i, size_t j ) const {
359  BLAZE_INTERNAL_ASSERT( i < lhs_.size(), "Invalid row access index" );
360  BLAZE_INTERNAL_ASSERT( j < rhs_.size(), "Invalid column access index" );
361 
362  return lhs_[i] * rhs_[j];
363  }
364  //**********************************************************************************************
365 
366  //**Begin function******************************************************************************
372  inline ConstIterator begin( size_t i ) const {
373  return ConstIterator( lhs_[i], rhs_.begin() );
374  }
375  //**********************************************************************************************
376 
377  //**End function********************************************************************************
383  inline ConstIterator end( size_t i ) const {
384  return ConstIterator( lhs_[i], rhs_.end() );
385  }
386  //**********************************************************************************************
387 
388  //**Rows function*******************************************************************************
393  inline size_t rows() const {
394  return lhs_.size();
395  }
396  //**********************************************************************************************
397 
398  //**Columns function****************************************************************************
403  inline size_t columns() const {
404  return rhs_.size();
405  }
406  //**********************************************************************************************
407 
408  //**NonZeros function***************************************************************************
413  inline size_t nonZeros() const {
414  return lhs_.size() * rhs_.nonZeros();
415  }
416  //**********************************************************************************************
417 
418  //**NonZeros function***************************************************************************
424  inline size_t nonZeros( size_t i ) const {
425  UNUSED_PARAMETER( i );
426  return rhs_.nonZeros();
427  }
428  //**********************************************************************************************
429 
430  //**Find function*******************************************************************************
437  inline ConstIterator find( size_t i, size_t j ) const {
439  return ConstIterator( lhs_[i], rhs_.find( j ) );
440  }
441  //**********************************************************************************************
442 
443  //**LowerBound function*************************************************************************
450  inline ConstIterator lowerBound( size_t i, size_t j ) const {
452  return ConstIterator( lhs_[i], rhs_.lowerBound( j ) );
453  }
454  //**********************************************************************************************
455 
456  //**UpperBound function*************************************************************************
463  inline ConstIterator upperBound( size_t i, size_t j ) const {
465  return ConstIterator( lhs_[i], rhs_.upperBound( j ) );
466  }
467  //**********************************************************************************************
468 
469  //**Left operand access*************************************************************************
474  inline LeftOperand leftOperand() const {
475  return lhs_;
476  }
477  //**********************************************************************************************
478 
479  //**Right operand access************************************************************************
484  inline RightOperand rightOperand() const {
485  return rhs_;
486  }
487  //**********************************************************************************************
488 
489  //**********************************************************************************************
495  template< typename T >
496  inline bool canAlias( const T* alias ) const {
497  return ( lhs_.canAlias( alias ) || rhs_.canAlias( alias ) );
498  }
499  //**********************************************************************************************
500 
501  //**********************************************************************************************
507  template< typename T >
508  inline bool isAliased( const T* alias ) const {
509  return ( lhs_.isAliased( alias ) || rhs_.isAliased( alias ) );
510  }
511  //**********************************************************************************************
512 
513  private:
514  //**Member variables****************************************************************************
515  LeftOperand lhs_;
516  RightOperand rhs_;
517  //**********************************************************************************************
518 
519  //**Assignment to row-major dense matrices******************************************************
534  template< typename MT > // Type of the target dense matrix
535  friend inline typename EnableIf< UseAssign<MT> >::Type
537  {
539 
540  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
541  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
542 
544 
545  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
546  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse vector operand
547 
548  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
549  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
550  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
551  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
552 
553  const ConstIterator begin( y.begin() );
554  const ConstIterator end ( y.end() );
555 
556  for( size_t i=0UL; i<(~lhs).rows(); ++i ) {
557  for( ConstIterator element=begin; element!=end; ++element ) {
558  (~lhs)(i,element->index()) = x[i] * element->value();
559  }
560  }
561  }
563  //**********************************************************************************************
564 
565  //**Assignment to column-major dense matrices***************************************************
578  template< typename MT > // Type of the target dense matrix
579  friend inline void assign( DenseMatrix<MT,true>& lhs, const DVecTSVecMultExpr& rhs )
580  {
582 
584 
585  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
586  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
587 
588  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
589  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse vector operand
590 
591  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
592  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
593  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
594  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
595 
596  DVecTSVecMultExpr::selectAssignKernel( ~lhs, x, y );
597  }
599  //**********************************************************************************************
600 
601  //**Default assignment to column-major dense matrices*******************************************
615  template< typename MT // Type of the left-hand side target matrix
616  , typename VT3 // Type of the left-hand side vector operand
617  , typename VT4 > // Type of the right-hand side vector operand
618  static inline typename EnableIf< UseDefaultKernel<MT,VT3,VT4> >::Type
619  selectAssignKernel( DenseMatrix<MT,true>& A, const VT3& x, const VT4& y )
620  {
622 
623  const ConstIterator begin( y.begin() );
624  const ConstIterator end ( y.end() );
625 
626  for( ConstIterator element=begin; element!=end; ++element ) {
627  for( size_t i=0UL; i<(~A).rows(); ++i ) {
628  (~A)(i,element->index()) = x[i] * element->value();
629  }
630  }
631  }
633  //**********************************************************************************************
634 
635  //**Vectorized assignment to column-major dense matrices****************************************
649  template< typename MT // Type of the left-hand side target matrix
650  , typename VT3 // Type of the left-hand side vector operand
651  , typename VT4 > // Type of the right-hand side vector operand
652  static inline typename EnableIf< UseVectorizedKernel<MT,VT3,VT4> >::Type
653  selectAssignKernel( DenseMatrix<MT,true>& A, const VT3& x, const VT4& y )
654  {
656 
657  typedef IntrinsicTrait<ElementType> IT;
658  typedef typename IT::Type IntrinsicType;
659 
660  const ConstIterator begin( y.begin() );
661  const ConstIterator end ( y.end() );
662 
663  for( ConstIterator element=begin; element!=end; ++element )
664  {
665  const IntrinsicType y1( set( element->value() ) );
666 
667  for( size_t i=0UL; i<(~A).rows(); i+=IT::size ) {
668  (~A).store( i, element->index(), x.load(i) * y1 );
669  }
670  }
671  }
673  //**********************************************************************************************
674 
675  //**Assignment to row-major sparse matrices*****************************************************
690  template< typename MT > // Type of the target sparse matrix
691  friend inline typename EnableIf< UseAssign<MT> >::Type
692  assign( SparseMatrix<MT,false>& lhs, const DVecTSVecMultExpr& rhs )
693  {
695 
696  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
697  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
698 
700 
701  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
702  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse vector operand
703 
704  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
705  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
706  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
707  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
708 
709  const ConstIterator begin( y.begin() );
710  const ConstIterator end ( y.end() );
711 
712  for( size_t i=0UL; i<x.size(); ++i ) {
713  if( !isDefault( x[i] ) ) {
714  (~lhs).reserve( i, y.nonZeros() );
715  for( ConstIterator element=begin; element!=end; ++element ) {
716  (~lhs).append( i, element->index(), x[i] * element->value() );
717  }
718  }
719  }
720  }
722  //**********************************************************************************************
723 
724  //**Assignment to column-major sparse matrices*****************************************************
737  template< typename MT > // Type of the target sparse matrix
738  friend inline void assign( SparseMatrix<MT,true>& lhs, const DVecTSVecMultExpr& rhs )
739  {
741 
743 
744  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
745  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
746 
748 
749  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
750  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse vector operand
751 
752  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
753  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
754  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
755  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
756 
757  const ConstIterator begin( y.begin() );
758  const ConstIterator end ( y.end() );
759 
760  for( ConstIterator element=begin; element!=end; ++element ) {
761  if( !isDefault( element->value() ) ) {
762  (~lhs).reserve( element->index(), x.size() );
763  for( size_t i=0UL; i<(~lhs).rows(); ++i ) {
764  (~lhs).append( i, element->index(), x[i] * element->value() );
765  }
766  }
767  }
768  }
770  //**********************************************************************************************
771 
772  //**Addition assignment to row-major dense matrices*********************************************
788  template< typename MT > // Type of the target dense matrix
789  friend inline typename EnableIf< UseAssign<MT> >::Type
790  addAssign( DenseMatrix<MT,false>& lhs, const DVecTSVecMultExpr& rhs )
791  {
793 
794  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
795  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
796 
798 
799  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
800  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse vector operand
801 
802  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
803  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
804  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
805  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
806 
807  const ConstIterator begin( y.begin() );
808  const ConstIterator end ( y.end() );
809 
810  for( size_t i=0UL; i<(~lhs).rows(); ++i ) {
811  for( ConstIterator element=begin; element!=end; ++element ) {
812  (~lhs)(i,element->index()) += x[i] * element->value();
813  }
814  }
815  }
817  //**********************************************************************************************
818 
819  //**Addition assignment to column-major dense matrices******************************************
832  template< typename MT > // Type of the target dense matrix
833  friend inline void addAssign( DenseMatrix<MT,true>& lhs, const DVecTSVecMultExpr& rhs )
834  {
836 
838 
839  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
840  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
841 
842  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
843  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse vector operand
844 
845  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
846  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
847  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
848  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
849 
850  DVecTSVecMultExpr::selectAddAssignKernel( ~lhs, x, y );
851  }
853  //**********************************************************************************************
854 
855  //**Default addition assignment to column dense matrices****************************************
869  template< typename MT // Type of the left-hand side target matrix
870  , typename VT3 // Type of the left-hand side vector operand
871  , typename VT4 > // Type of the right-hand side vector operand
872  static inline typename EnableIf< UseDefaultKernel<MT,VT3,VT4> >::Type
873  selectAddAssignKernel( DenseMatrix<MT,true>& A, const VT3& x, const VT4& y )
874  {
876 
877  const ConstIterator begin( y.begin() );
878  const ConstIterator end ( y.end() );
879 
880  for( ConstIterator element=begin; element!=end; ++element ) {
881  for( size_t i=0UL; i<(~A).rows(); ++i ) {
882  (~A)(i,element->index()) += x[i] * element->value();
883  }
884  }
885  }
887  //**********************************************************************************************
888 
889  //**Vectorized addition assignment to column-major dense matrices*******************************
903  template< typename MT // Type of the left-hand side target matrix
904  , typename VT3 // Type of the left-hand side vector operand
905  , typename VT4 > // Type of the right-hand side vector operand
906  static inline typename EnableIf< UseVectorizedKernel<MT,VT3,VT4> >::Type
907  selectAddAssignKernel( DenseMatrix<MT,true>& A, const VT3& x, const VT4& y )
908  {
910 
911  typedef IntrinsicTrait<ElementType> IT;
912  typedef typename IT::Type IntrinsicType;
913 
914  const ConstIterator begin( y.begin() );
915  const ConstIterator end ( y.end() );
916 
917  for( ConstIterator element=begin; element!=end; ++element )
918  {
919  const IntrinsicType y1( set( element->value() ) );
920 
921  for( size_t i=0UL; i<(~A).rows(); i+=IT::size ) {
922  (~A).store( i, element->index(), (~A).load(i,element->index()) + x.load(i) * y1 );
923  }
924  }
925  }
927  //**********************************************************************************************
928 
929  //**Addition assignment to sparse matrices******************************************************
930  // No special implementation for the addition assignment to sparse matrices.
931  //**********************************************************************************************
932 
933  //**Subtraction assignment to row-major dense matrices******************************************
949  template< typename MT > // Type of the target dense matrix
950  friend inline typename EnableIf< UseAssign<MT> >::Type
951  subAssign( DenseMatrix<MT,false>& lhs, const DVecTSVecMultExpr& rhs )
952  {
954 
955  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
956  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
957 
959 
960  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
961  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse vector operand
962 
963  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
964  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
965  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
966  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
967 
968  const ConstIterator begin( y.begin() );
969  const ConstIterator end ( y.end() );
970 
971  for( size_t i=0UL; i<(~lhs).rows(); ++i ) {
972  for( ConstIterator element=begin; element!=end; ++element ) {
973  (~lhs)(i,element->index()) -= x[i] * element->value();
974  }
975  }
976  }
978  //**********************************************************************************************
979 
980  //**Subtraction assignment to column-major dense matrices***************************************
993  template< typename MT > // Type of the target dense matrix
994  friend inline void subAssign( DenseMatrix<MT,true>& lhs, const DVecTSVecMultExpr& rhs )
995  {
997 
999 
1000  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
1001  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
1002 
1003  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
1004  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse vector operand
1005 
1006  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
1007  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
1008  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
1009  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
1010 
1011  DVecTSVecMultExpr::selectSubAssignKernel( ~lhs, x, y );
1012  }
1014  //**********************************************************************************************
1015 
1016  //**Default subtraction assignment to column dense matrices*************************************
1030  template< typename MT // Type of the left-hand side target matrix
1031  , typename VT3 // Type of the left-hand side vector operand
1032  , typename VT4 > // Type of the right-hand side vector operand
1033  static inline typename EnableIf< UseDefaultKernel<MT,VT3,VT4> >::Type
1034  selectSubAssignKernel( DenseMatrix<MT,true>& A, const VT3& x, const VT4& y )
1035  {
1037 
1038  const ConstIterator begin( y.begin() );
1039  const ConstIterator end ( y.end() );
1040 
1041  for( ConstIterator element=begin; element!=end; ++element ) {
1042  for( size_t i=0UL; i<(~A).rows(); ++i ) {
1043  (~A)(i,element->index()) -= x[i] * element->value();
1044  }
1045  }
1046  }
1048  //**********************************************************************************************
1049 
1050  //**Vectorized subtraction assignment to column-major dense matrices****************************
1064  template< typename MT // Type of the left-hand side target matrix
1065  , typename VT3 // Type of the left-hand side vector operand
1066  , typename VT4 > // Type of the right-hand side vector operand
1067  static inline typename EnableIf< UseVectorizedKernel<MT,VT3,VT4> >::Type
1068  selectSubAssignKernel( DenseMatrix<MT,true>& A, const VT3& x, const VT4& y )
1069  {
1071 
1072  typedef IntrinsicTrait<ElementType> IT;
1073  typedef typename IT::Type IntrinsicType;
1074 
1075  const ConstIterator begin( y.begin() );
1076  const ConstIterator end ( y.end() );
1077 
1078  for( ConstIterator element=begin; element!=end; ++element )
1079  {
1080  const IntrinsicType y1( set( element->value() ) );
1081 
1082  for( size_t i=0UL; i<(~A).rows(); i+=IT::size ) {
1083  (~A).store( i, element->index(), (~A).load(i,element->index()) - x.load(i) * y1 );
1084  }
1085  }
1086  }
1088  //**********************************************************************************************
1089 
1090  //**Subtraction assignment to sparse matrices***************************************************
1091  // No special implementation for the subtraction assignment to sparse matrices.
1092  //**********************************************************************************************
1093 
1094  //**Multiplication assignment to dense matrices*************************************************
1095  // No special implementation for the multiplication assignment to dense matrices.
1096  //**********************************************************************************************
1097 
1098  //**Multiplication assignment to sparse matrices************************************************
1099  // No special implementation for the multiplication assignment to sparse matrices.
1100  //**********************************************************************************************
1101 
1102  //**Compile time checks*************************************************************************
1110  //**********************************************************************************************
1111 };
1112 //*************************************************************************************************
1113 
1114 
1115 
1116 
1117 //=================================================================================================
1118 //
1119 // GLOBAL BINARY ARITHMETIC OPERATORS
1120 //
1121 //=================================================================================================
1122 
1123 //*************************************************************************************************
1152 template< typename T1 // Type of the left-hand side dense vector
1153  , typename T2 > // Type of the right-hand side sparse vector
1154 inline const DVecTSVecMultExpr<T1,T2>
1156 {
1158 
1159  return DVecTSVecMultExpr<T1,T2>( ~lhs, ~rhs );
1160 }
1161 //*************************************************************************************************
1162 
1163 
1164 
1165 
1166 //=================================================================================================
1167 //
1168 // ROWS SPECIALIZATIONS
1169 //
1170 //=================================================================================================
1171 
1172 //*************************************************************************************************
1174 template< typename VT1, typename VT2 >
1175 struct Rows< DVecTSVecMultExpr<VT1,VT2> > : public Size<VT1>
1176 {};
1178 //*************************************************************************************************
1179 
1180 
1181 
1182 
1183 //=================================================================================================
1184 //
1185 // COLUMNS SPECIALIZATIONS
1186 //
1187 //=================================================================================================
1188 
1189 //*************************************************************************************************
1191 template< typename VT1, typename VT2 >
1192 struct Columns< DVecTSVecMultExpr<VT1,VT2> > : public Size<VT2>
1193 {};
1195 //*************************************************************************************************
1196 
1197 
1198 
1199 
1200 //=================================================================================================
1201 //
1202 // EXPRESSION TRAIT SPECIALIZATIONS
1203 //
1204 //=================================================================================================
1205 
1206 //*************************************************************************************************
1208 template< typename VT1, typename VT2, bool AF >
1209 struct SubmatrixExprTrait< DVecTSVecMultExpr<VT1,VT2>, AF >
1210 {
1211  public:
1212  //**********************************************************************************************
1213  typedef typename MultExprTrait< typename SubvectorExprTrait<const VT1,AF>::Type
1214  , typename SubvectorExprTrait<const VT2,AF>::Type >::Type Type;
1215  //**********************************************************************************************
1216 };
1218 //*************************************************************************************************
1219 
1220 
1221 //*************************************************************************************************
1223 template< typename VT1, typename VT2 >
1224 struct RowExprTrait< DVecTSVecMultExpr<VT1,VT2> >
1225 {
1226  public:
1227  //**********************************************************************************************
1228  typedef typename MultExprTrait< typename VT1::ReturnType, VT2 >::Type Type;
1229  //**********************************************************************************************
1230 };
1232 //*************************************************************************************************
1233 
1234 
1235 //*************************************************************************************************
1237 template< typename VT1, typename VT2 >
1238 struct ColumnExprTrait< DVecTSVecMultExpr<VT1,VT2> >
1239 {
1240  public:
1241  //**********************************************************************************************
1242  typedef typename MultExprTrait< VT1, typename VT2::ReturnType >::Type Type;
1243  //**********************************************************************************************
1244 };
1246 //*************************************************************************************************
1247 
1248 } // namespace blaze
1249 
1250 #endif
ValueType * PointerType
Pointer return type.
Definition: DVecTSVecMultExpr.h:226
Pointer difference type of the Blaze library.
VT1::ReturnType RN1
Return type of the left-hand side dense vector expression.
Definition: DVecTSVecMultExpr.h:107
Compile time check whether the given type is a computational expression template.This type trait clas...
Definition: IsComputation.h:89
Compile time check for numeric types.This type trait tests whether or not the given template paramete...
Definition: IsNumeric.h:98
PointerType pointer
Pointer return type.
Definition: DVecTSVecMultExpr.h:233
Compile time check whether the given type is a temporary vector or matrix type.This type trait class ...
Definition: IsTemporary.h:87
VT2::ElementType ET2
Element type of the right-hand side sparse vector expression.
Definition: DVecTSVecMultExpr.h:112
Header file for the Rows type trait.
ValueType & ReferenceType
Reference return type.
Definition: DVecTSVecMultExpr.h:227
Header file for the UNUSED_PARAMETER function template.
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:4838
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: DVecTSVecMultExpr.h:508
SelectType< IsComputation< VT1 >::value, const RT1, CT1 >::Type LT
Type for the assignment of the left-hand side dense vector operand.
Definition: DVecTSVecMultExpr.h:197
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector)
Returns the current size/dimension of the vector.
Definition: Vector.h:258
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: DVecTSVecMultExpr.h:228
size_t rows() const
Returns the current number of rows of the matrix.
Definition: DVecTSVecMultExpr.h:393
#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
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:205
ConstIterator lowerBound(size_t i, size_t j) const
Returns an iterator to the first index not less then the given index.
Definition: DVecTSVecMultExpr.h:450
Header file for the ColumnExprTrait class template.
bool operator!=(const ConstIterator &rhs) const
Inequality comparison between two ConstIterator objects.
Definition: DVecTSVecMultExpr.h:315
const ConstIterator * operator->() const
Direct access to the sparse matrix element at the current iterator position.
Definition: DVecTSVecMultExpr.h:273
VT1::ElementType ET1
Element type of the left-hand side dense vector expression.
Definition: DVecTSVecMultExpr.h:111
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2478
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:257
IteratorType it_
Iterator over the elements of the right-hand side sparse vector expression.
Definition: DVecTSVecMultExpr.h:334
BLAZE_ALWAYS_INLINE EnableIf< IsIntegral< T >, Load< T, sizeof(T)> >::Type::Type load(const T *address)
Loads a vector of integral values.
Definition: Load.h:224
void UNUSED_PARAMETER(const T1 &)
Suppression of unused parameter warnings.
Definition: Unused.h:81
size_t index() const
Access to the current index of the sparse element.
Definition: DVecTSVecMultExpr.h:293
std::forward_iterator_tag IteratorCategory
The iterator category.
Definition: DVecTSVecMultExpr.h:224
const DMatSerialExpr< MT, SO > serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:695
Header file for the Computation base class.
Type relationship analysis.This class tests if the two data types A and B are equal. For this type comparison, the cv-qualifiers of both data types are ignored. If A and B are the same data type (ignoring the cv-qualifiers), then the value member enumeration is set to 1, the nested type definition Type is TrueType, and the class derives from TrueType. Otherwise value is set to 0, Type is FalseType, and the class derives from FalseType.
Definition: IsSame.h:158
SelectType< IsExpression< VT2 >::value, const VT2, const VT2 & >::Type RightOperand
Composite type of the right-hand side sparse vector expression.
Definition: DVecTSVecMultExpr.h:194
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: DVecTSVecMultExpr.h:358
Element ValueType
Type of the underlying pointers.
Definition: DVecTSVecMultExpr.h:225
const Element operator*() const
Direct access to the sparse matrix element at the current iterator position.
Definition: DVecTSVecMultExpr.h:263
DVecTSVecMultExpr(const VT1 &lhs, const VT2 &rhs)
Constructor for the DVecTSVecMultExpr class.
Definition: DVecTSVecMultExpr.h:345
Base class for dense matrices.The DenseMatrix class is a base class for all dense matrix classes...
Definition: DenseMatrix.h:70
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes...
Definition: Forward.h:107
Constraint on the data type.
MultExprTrait< RN1, RN2 >::Type ExprReturnType
Expression return type for the subscript operator.
Definition: DVecTSVecMultExpr.h:125
Header file for the SparseMatrix base class.
Constraint on the data type.
Header file for the MultExprTrait class template.
ValueType value_type
Type of the underlying pointers.
Definition: DVecTSVecMultExpr.h:232
ConstIterator begin(size_t i) const
Returns an iterator to the first non-zero element of row i.
Definition: DVecTSVecMultExpr.h:372
Header file for the ValueIndexPair class.
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 IsTemporary type trait class.
Header file for the multiplication trait.
ConstIterator & operator++()
Pre-increment operator.
Definition: DVecTSVecMultExpr.h:252
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2482
#define BLAZE_CONSTRAINT_MUST_FORM_VALID_VECTVECMULTEXPR(T1, T2)
Constraint on the data type.In case the given data types T1 and T2 do not form a valid vector/vector ...
Definition: VecTVecMultExpr.h:161
LeftOperand lhs_
Left-hand side dense vector of the multiplication expression.
Definition: DVecTSVecMultExpr.h:515
ResultType::ElementType ElementType
Resulting element type.
Definition: DVecTSVecMultExpr.h:182
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
Header file for the Columns type trait.
Expression object for dense vector-sparse vector outer products.The DVecTSVecMultExpr class represent...
Definition: DVecTSVecMultExpr.h:99
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: DVecTSVecMultExpr.h:496
ConstIterator(LeftElement v, IteratorType it)
Constructor for the ConstIterator class.
Definition: DVecTSVecMultExpr.h:241
bool operator==(const ConstIterator &rhs) const
Equality comparison between two ConstIterator objects.
Definition: DVecTSVecMultExpr.h:304
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
IteratorCategory iterator_category
The iterator category.
Definition: DVecTSVecMultExpr.h:231
#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
Constraint on the data type.
Constraint on the data type.
DifferenceType difference_type
Difference between two iterators.
Definition: DVecTSVecMultExpr.h:235
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2476
Constraint on the data type.
Header file for the SelectType class template.
Header file for the RowExprTrait class template.
Header file for all forward declarations for expression class templates.
Constraint on the data type.
Header file for the VecTVecMultExpr base class.
VT1::CompositeType CT1
Composite type of the left-hand side dense vector expression.
Definition: DVecTSVecMultExpr.h:109
Header file for the EnableIf class template.
Header file for the serial shim.
ConstIterator find(size_t i, size_t j) const
Searches for a specific matrix element.
Definition: DVecTSVecMultExpr.h:437
RightOperand rightOperand() const
Returns the right-hand side sparse vector operand.
Definition: DVecTSVecMultExpr.h:484
Header file for the IsNumeric type trait.
LeftOperand leftOperand() const
Returns the left-hand side dense vector operand.
Definition: DVecTSVecMultExpr.h:474
ConstIterator end(size_t i) const
Returns an iterator just past the last non-zero element of row i.
Definition: DVecTSVecMultExpr.h:383
Iterator over the elements of the dense vector-sparse vector outer product expression.
Definition: DVecTSVecMultExpr.h:211
BLAZE_ALWAYS_INLINE EnableIf< IsIntegral< T >, Set< T, sizeof(T)> >::Type::Type set(T value)
Sets all values in the vector to the given integral value.
Definition: Set.h:211
#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
Header file for the SubmatrixExprTrait class template.
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2477
Removal of reference modifiers.The RemoveCV type trait removes any reference modifiers from the given...
Definition: RemoveReference.h:69
VT1::ResultType RT1
Result type of the left-hand side dense vector expression.
Definition: DVecTSVecMultExpr.h:105
Intrinsic characteristics of data types.The IntrinsicTrait class template provides the intrinsic char...
Definition: IntrinsicTrait.h:749
size_t columns() const
Returns the current number of columns of the matrix.
Definition: DVecTSVecMultExpr.h:403
Header file for run time assertion macros.
Base template for the MultTrait class.
Definition: MultTrait.h:142
RightOperand rhs_
Right-hand side sparse vector of the multiplication expression.
Definition: DVecTSVecMultExpr.h:516
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
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: DVecTSVecMultExpr.h:181
Substitution Failure Is Not An Error (SFINAE) class.The EnableIf class template is an auxiliary tool ...
Definition: EnableIf.h:184
DVecTSVecMultExpr< VT1, VT2 > This
Type of this DVecTSVecMultExpr instance.
Definition: DVecTSVecMultExpr.h:178
ValueIndexPair< ElementType > Element
Element type of the sparse matrix expression.
Definition: DVecTSVecMultExpr.h:216
size_t nonZeros(size_t i) const
Returns the number of non-zero elements in the specified row.
Definition: DVecTSVecMultExpr.h:424
Header file for the isDefault shim.
ReferenceType reference
Reference return type.
Definition: DVecTSVecMultExpr.h:234
BLAZE_ALWAYS_INLINE bool isDefault(const NonNumericProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: NonNumericProxy.h:874
Constraint on the data type.
ReturnType value() const
Access to the current value of the sparse element.
Definition: DVecTSVecMultExpr.h:283
#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:118
Constraint on the data type.
Header file for the RemoveReference type trait.
ResultType::OppositeType OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: DVecTSVecMultExpr.h:180
Base class for all outer product expression templates.The VecTVecMultExpr class serves as a tag for a...
Definition: VecTVecMultExpr.h:66
ET1 LeftElement
Element type of the dense vector expression.
Definition: DVecTSVecMultExpr.h:219
Header file for all intrinsic functionality.
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a dense, N-dimensional vector type...
Definition: DenseVector.h:79
VT2::ReturnType RN2
Return type of the right-hand side sparse vector expression.
Definition: DVecTSVecMultExpr.h:108
Index-value-pair for sparse vectors and matrices.The ValueIndexPair class represents a single index-v...
Definition: ValueIndexPair.h:70
MultTrait< RT1, RT2 >::Type ResultType
Result type for expression template evaluations.
Definition: DVecTSVecMultExpr.h:179
Header file for the IsComputation type trait class.
const SelectType< returnExpr, ExprReturnType, ElementType >::Type ReturnType
Return type for expression template evaluations.
Definition: DVecTSVecMultExpr.h:185
Base class for all compute expression templates.The Computation class serves as a tag for all computa...
Definition: Computation.h:59
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:2473
LeftElement v_
Element of the left-hand side dense vector expression.
Definition: DVecTSVecMultExpr.h:333
DifferenceType operator-(const ConstIterator &rhs) const
Calculating the number of elements between two expression iterators.
Definition: DVecTSVecMultExpr.h:326
SelectType< useAssign, const ResultType, const DVecTSVecMultExpr & >::Type CompositeType
Data type for composite expression templates.
Definition: DVecTSVecMultExpr.h:188
Header file for basic type definitions.
#define BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a row dense or sparse vector type (i...
Definition: TransposeFlag.h:81
RemoveReference< RightOperand >::Type::ConstIterator IteratorType
Iterator type of the sparse vector expression.
Definition: DVecTSVecMultExpr.h:222
Header file for the SubvectorExprTrait class template.
VT2::CompositeType CT2
Composite type of the right-hand side sparse vector expression.
Definition: DVecTSVecMultExpr.h:110
size_t nonZeros() const
Returns the number of non-zero elements in the sparse matrix.
Definition: DVecTSVecMultExpr.h:413
SelectType< IsExpression< VT1 >::value, const VT1, const VT1 & >::Type LeftOperand
Composite type of the left-hand side dense vector expression.
Definition: DVecTSVecMultExpr.h:191
BLAZE_ALWAYS_INLINE EnableIf< IsIntegral< T > >::Type store(T *address, const typename Store< T, sizeof(T)>::Type &value)
Aligned store of a vector of integral values.
Definition: Store.h:225
VT2::ResultType RT2
Result type of the right-hand side sparse vector expression.
Definition: DVecTSVecMultExpr.h:106
Header file for the Size type trait.
Evaluation of the resulting expression type of a multiplication.Via this type trait it is possible to...
Definition: MultExprTrait.h:137
#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
ConstIterator upperBound(size_t i, size_t j) const
Returns an iterator to the first index greater then the given index.
Definition: DVecTSVecMultExpr.h:463
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< IsComputation< VT2 >::value, const RT2, CT2 >::Type RT
Type for the assignment of the right-hand side dense vector operand.
Definition: DVecTSVecMultExpr.h:200