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;
226  typedef ValueType* PointerType;
227  typedef ValueType& ReferenceType;
229 
230  // STL iterator requirements
231  typedef IteratorCategory iterator_category;
232  typedef ValueType value_type;
233  typedef PointerType pointer;
234  typedef ReferenceType reference;
235  typedef DifferenceType difference_type;
236  //*******************************************************************************************
237 
238  //**Constructor******************************************************************************
241  inline ConstIterator( LeftElement v, IteratorType it )
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*************************************************************************
333  LeftElement v_;
334  IteratorType it_;
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  BLAZE_INTERNAL_ASSERT( (~lhs).capacity() >= rhs.nonZeros(), "Insufficient capacity" );
699 
701 
702  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
703  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse vector operand
704 
705  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
706  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
707  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
708  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
709 
710  const ConstIterator begin( y.begin() );
711  const ConstIterator end ( y.end() );
712 
713  if( begin == end )
714  return;
715 
716  for( size_t i=0UL; i<x.size(); ++i ) {
717  if( !isDefault( x[i] ) ) {
718  for( ConstIterator element=begin; element!=end; ++element ) {
719  (~lhs).append( i, element->index(), x[i] * element->value() );
720  }
721  }
722  (~lhs).finalize( i );
723  }
724  }
726  //**********************************************************************************************
727 
728  //**Assignment to column-major sparse matrices*****************************************************
741  template< typename MT > // Type of the target sparse matrix
742  friend inline void assign( SparseMatrix<MT,true>& lhs, const DVecTSVecMultExpr& rhs )
743  {
745 
747 
748  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
749  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns() , "Invalid number of columns" );
750 
752 
753  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
754  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse vector operand
755 
756  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
757  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
758  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
759  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
760 
761  const ConstIterator begin( y.begin() );
762  const ConstIterator end ( y.end() );
763 
764  if( begin == end )
765  return;
766 
767  (~lhs).reserve( begin->index(), rhs.nonZeros() );
768 
769  size_t index( 0UL );
770 
771  for( ConstIterator element=begin; element!=end; ++element ) {
772  if( !isDefault( element->value() ) ) {
773  for( ; index < element->index(); ++index ) {
774  (~lhs).finalize( index );
775  }
776  for( size_t i=0UL; i<(~lhs).rows(); ++i ) {
777  (~lhs).append( i, element->index(), x[i] * element->value() );
778  }
779  (~lhs).finalize( index++ );
780  }
781  }
782 
783  for( ; index < y.size(); ++index ) {
784  (~lhs).finalize( index );
785  }
786  }
788  //**********************************************************************************************
789 
790  //**Addition assignment to row-major dense matrices*********************************************
806  template< typename MT > // Type of the target dense matrix
807  friend inline typename EnableIf< UseAssign<MT> >::Type
808  addAssign( DenseMatrix<MT,false>& lhs, const DVecTSVecMultExpr& rhs )
809  {
811 
812  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
813  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
814 
816 
817  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
818  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse vector operand
819 
820  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
821  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
822  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
823  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
824 
825  const ConstIterator begin( y.begin() );
826  const ConstIterator end ( y.end() );
827 
828  for( size_t i=0UL; i<(~lhs).rows(); ++i ) {
829  for( ConstIterator element=begin; element!=end; ++element ) {
830  (~lhs)(i,element->index()) += x[i] * element->value();
831  }
832  }
833  }
835  //**********************************************************************************************
836 
837  //**Addition assignment to column-major dense matrices******************************************
850  template< typename MT > // Type of the target dense matrix
851  friend inline void addAssign( DenseMatrix<MT,true>& lhs, const DVecTSVecMultExpr& rhs )
852  {
854 
856 
857  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
858  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
859 
860  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
861  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse vector operand
862 
863  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
864  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
865  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
866  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
867 
868  DVecTSVecMultExpr::selectAddAssignKernel( ~lhs, x, y );
869  }
871  //**********************************************************************************************
872 
873  //**Default addition assignment to column dense matrices****************************************
887  template< typename MT // Type of the left-hand side target matrix
888  , typename VT3 // Type of the left-hand side vector operand
889  , typename VT4 > // Type of the right-hand side vector operand
890  static inline typename EnableIf< UseDefaultKernel<MT,VT3,VT4> >::Type
891  selectAddAssignKernel( DenseMatrix<MT,true>& A, const VT3& x, const VT4& y )
892  {
894 
895  const ConstIterator begin( y.begin() );
896  const ConstIterator end ( y.end() );
897 
898  for( ConstIterator element=begin; element!=end; ++element ) {
899  for( size_t i=0UL; i<(~A).rows(); ++i ) {
900  (~A)(i,element->index()) += x[i] * element->value();
901  }
902  }
903  }
905  //**********************************************************************************************
906 
907  //**Vectorized addition assignment to column-major dense matrices*******************************
921  template< typename MT // Type of the left-hand side target matrix
922  , typename VT3 // Type of the left-hand side vector operand
923  , typename VT4 > // Type of the right-hand side vector operand
924  static inline typename EnableIf< UseVectorizedKernel<MT,VT3,VT4> >::Type
925  selectAddAssignKernel( DenseMatrix<MT,true>& A, const VT3& x, const VT4& y )
926  {
928 
929  typedef IntrinsicTrait<ElementType> IT;
930  typedef typename IT::Type IntrinsicType;
931 
932  const ConstIterator begin( y.begin() );
933  const ConstIterator end ( y.end() );
934 
935  for( ConstIterator element=begin; element!=end; ++element )
936  {
937  const IntrinsicType y1( set( element->value() ) );
938 
939  for( size_t i=0UL; i<(~A).rows(); i+=IT::size ) {
940  (~A).store( i, element->index(), (~A).load(i,element->index()) + x.load(i) * y1 );
941  }
942  }
943  }
945  //**********************************************************************************************
946 
947  //**Addition assignment to sparse matrices******************************************************
948  // No special implementation for the addition assignment to sparse matrices.
949  //**********************************************************************************************
950 
951  //**Subtraction assignment to row-major dense matrices******************************************
967  template< typename MT > // Type of the target dense matrix
968  friend inline typename EnableIf< UseAssign<MT> >::Type
969  subAssign( DenseMatrix<MT,false>& lhs, const DVecTSVecMultExpr& rhs )
970  {
972 
973  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
974  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
975 
977 
978  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
979  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse vector operand
980 
981  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
982  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
983  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
984  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
985 
986  const ConstIterator begin( y.begin() );
987  const ConstIterator end ( y.end() );
988 
989  for( size_t i=0UL; i<(~lhs).rows(); ++i ) {
990  for( ConstIterator element=begin; element!=end; ++element ) {
991  (~lhs)(i,element->index()) -= x[i] * element->value();
992  }
993  }
994  }
996  //**********************************************************************************************
997 
998  //**Subtraction assignment to column-major dense matrices***************************************
1011  template< typename MT > // Type of the target dense matrix
1012  friend inline void subAssign( DenseMatrix<MT,true>& lhs, const DVecTSVecMultExpr& rhs )
1013  {
1015 
1017 
1018  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
1019  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
1020 
1021  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
1022  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse vector operand
1023 
1024  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
1025  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
1026  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
1027  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
1028 
1029  DVecTSVecMultExpr::selectSubAssignKernel( ~lhs, x, y );
1030  }
1032  //**********************************************************************************************
1033 
1034  //**Default subtraction assignment to column dense matrices*************************************
1048  template< typename MT // Type of the left-hand side target matrix
1049  , typename VT3 // Type of the left-hand side vector operand
1050  , typename VT4 > // Type of the right-hand side vector operand
1051  static inline typename EnableIf< UseDefaultKernel<MT,VT3,VT4> >::Type
1052  selectSubAssignKernel( DenseMatrix<MT,true>& A, const VT3& x, const VT4& y )
1053  {
1055 
1056  const ConstIterator begin( y.begin() );
1057  const ConstIterator end ( y.end() );
1058 
1059  for( ConstIterator element=begin; element!=end; ++element ) {
1060  for( size_t i=0UL; i<(~A).rows(); ++i ) {
1061  (~A)(i,element->index()) -= x[i] * element->value();
1062  }
1063  }
1064  }
1066  //**********************************************************************************************
1067 
1068  //**Vectorized subtraction assignment to column-major dense matrices****************************
1082  template< typename MT // Type of the left-hand side target matrix
1083  , typename VT3 // Type of the left-hand side vector operand
1084  , typename VT4 > // Type of the right-hand side vector operand
1085  static inline typename EnableIf< UseVectorizedKernel<MT,VT3,VT4> >::Type
1086  selectSubAssignKernel( DenseMatrix<MT,true>& A, const VT3& x, const VT4& y )
1087  {
1089 
1090  typedef IntrinsicTrait<ElementType> IT;
1091  typedef typename IT::Type IntrinsicType;
1092 
1093  const ConstIterator begin( y.begin() );
1094  const ConstIterator end ( y.end() );
1095 
1096  for( ConstIterator element=begin; element!=end; ++element )
1097  {
1098  const IntrinsicType y1( set( element->value() ) );
1099 
1100  for( size_t i=0UL; i<(~A).rows(); i+=IT::size ) {
1101  (~A).store( i, element->index(), (~A).load(i,element->index()) - x.load(i) * y1 );
1102  }
1103  }
1104  }
1106  //**********************************************************************************************
1107 
1108  //**Subtraction assignment to sparse matrices***************************************************
1109  // No special implementation for the subtraction assignment to sparse matrices.
1110  //**********************************************************************************************
1111 
1112  //**Multiplication assignment to dense matrices*************************************************
1113  // No special implementation for the multiplication assignment to dense matrices.
1114  //**********************************************************************************************
1115 
1116  //**Multiplication assignment to sparse matrices************************************************
1117  // No special implementation for the multiplication assignment to sparse matrices.
1118  //**********************************************************************************************
1119 
1120  //**Compile time checks*************************************************************************
1128  //**********************************************************************************************
1129 };
1130 //*************************************************************************************************
1131 
1132 
1133 
1134 
1135 //=================================================================================================
1136 //
1137 // GLOBAL BINARY ARITHMETIC OPERATORS
1138 //
1139 //=================================================================================================
1140 
1141 //*************************************************************************************************
1170 template< typename T1 // Type of the left-hand side dense vector
1171  , typename T2 > // Type of the right-hand side sparse vector
1172 inline const DVecTSVecMultExpr<T1,T2>
1174 {
1176 
1177  return DVecTSVecMultExpr<T1,T2>( ~lhs, ~rhs );
1178 }
1179 //*************************************************************************************************
1180 
1181 
1182 
1183 
1184 //=================================================================================================
1185 //
1186 // ROWS SPECIALIZATIONS
1187 //
1188 //=================================================================================================
1189 
1190 //*************************************************************************************************
1192 template< typename VT1, typename VT2 >
1193 struct Rows< DVecTSVecMultExpr<VT1,VT2> > : public Size<VT1>
1194 {};
1196 //*************************************************************************************************
1197 
1198 
1199 
1200 
1201 //=================================================================================================
1202 //
1203 // COLUMNS SPECIALIZATIONS
1204 //
1205 //=================================================================================================
1206 
1207 //*************************************************************************************************
1209 template< typename VT1, typename VT2 >
1210 struct Columns< DVecTSVecMultExpr<VT1,VT2> > : public Size<VT2>
1211 {};
1213 //*************************************************************************************************
1214 
1215 
1216 
1217 
1218 //=================================================================================================
1219 //
1220 // EXPRESSION TRAIT SPECIALIZATIONS
1221 //
1222 //=================================================================================================
1223 
1224 //*************************************************************************************************
1226 template< typename VT1, typename VT2, bool AF >
1227 struct SubmatrixExprTrait< DVecTSVecMultExpr<VT1,VT2>, AF >
1228 {
1229  public:
1230  //**********************************************************************************************
1231  typedef typename MultExprTrait< typename SubvectorExprTrait<const VT1,AF>::Type
1232  , typename SubvectorExprTrait<const VT2,AF>::Type >::Type Type;
1233  //**********************************************************************************************
1234 };
1236 //*************************************************************************************************
1237 
1238 
1239 //*************************************************************************************************
1241 template< typename VT1, typename VT2 >
1242 struct RowExprTrait< DVecTSVecMultExpr<VT1,VT2> >
1243 {
1244  public:
1245  //**********************************************************************************************
1246  typedef typename MultExprTrait< typename VT1::ReturnType, VT2 >::Type Type;
1247  //**********************************************************************************************
1248 };
1250 //*************************************************************************************************
1251 
1252 
1253 //*************************************************************************************************
1255 template< typename VT1, typename VT2 >
1256 struct ColumnExprTrait< DVecTSVecMultExpr<VT1,VT2> >
1257 {
1258  public:
1259  //**********************************************************************************************
1260  typedef typename MultExprTrait< VT1, typename VT2::ReturnType >::Type Type;
1261  //**********************************************************************************************
1262 };
1264 //*************************************************************************************************
1265 
1266 } // namespace blaze
1267 
1268 #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:8247
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: DVecTSVecMultExpr.h:508
Header file for basic type definitions.
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:264
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:209
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:2507
BLAZE_ALWAYS_INLINE size_t capacity(const Matrix< MT, SO > &matrix)
Returns the maximum capacity of the matrix.
Definition: Matrix.h:348
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:261
IteratorType it_
Iterator over the elements of the right-hand side sparse vector expression.
Definition: DVecTSVecMultExpr.h:334
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:699
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
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:861
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.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
ConstIterator & operator++()
Pre-increment operator.
Definition: DVecTSVecMultExpr.h:252
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2511
#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
BLAZE_ALWAYS_INLINE EnableIf< And< IsIntegral< T >, HasSize< T, 2UL > > >::Type store(T *address, const sse_int16_t &value)
Aligned store of a vector of 2-byte integral values.
Definition: Store.h:80
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:2505
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
BLAZE_ALWAYS_INLINE EnableIf< And< IsIntegral< T >, HasSize< T, 2UL > >, sse_int16_t >::Type load(const T *address)
Loads a vector of 2-byte integral values.
Definition: Load.h:79
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
#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:2506
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:150
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
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
BLAZE_ALWAYS_INLINE EnableIf< And< IsIntegral< T >, HasSize< T, 2UL > >, sse_int16_t >::Type set(T value)
Sets all values in the vector to the given 2-byte integral value.
Definition: Set.h:73
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:2502
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
#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
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