SVecTDVecMultExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_SVECTDVECMULTEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_SVECTDVECMULTEXPR_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 SVECTDVECMULTEXPR
87 //
88 //=================================================================================================
89 
90 //*************************************************************************************************
97 template< typename VT1 // Type of the left-hand side sparse vector
98  , typename VT2 > // Type of the right-hand side dense vector
99 class SVecTDVecMultExpr : public SparseMatrix< SVecTDVecMultExpr<VT1,VT2>, true >
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 
136  enum { useAssign = ( IsComputation<VT1>::value || !IsNumeric<ET1>::value ||
138 
140  template< typename MT >
142  struct UseAssign {
143  enum { value = useAssign };
144  };
146  //**********************************************************************************************
147 
148  //**********************************************************************************************
150 
153  template< typename T1, typename T2, typename T3 >
154  struct UseVectorizedKernel {
155  enum { value = T1::vectorizable && T3::vectorizable &&
159  };
161  //**********************************************************************************************
162 
163  //**********************************************************************************************
165 
168  template< typename T1, typename T2, typename T3 >
169  struct UseDefaultKernel {
170  enum { value = !UseVectorizedKernel<T1,T2,T3>::value };
171  };
173  //**********************************************************************************************
174 
175  public:
176  //**Type definitions****************************************************************************
182 
185 
188 
190  typedef typename SelectType< IsExpression<VT1>::value, const VT1, const VT1& >::Type LeftOperand;
191 
193  typedef typename SelectType< IsExpression<VT2>::value, const VT2, const VT2& >::Type RightOperand;
194 
196  typedef typename SelectType< IsComputation<VT1>::value, const RT1, CT1 >::Type LT;
197 
199  typedef typename SelectType< IsComputation<VT2>::value, const RT2, CT2 >::Type RT;
200  //**********************************************************************************************
201 
202  //**Compilation flags***************************************************************************
204  enum { smpAssignable = 0 };
205  //**********************************************************************************************
206 
207  //**ConstIterator class definition**************************************************************
211  {
212  public:
213  //**Type definitions*************************************************************************
216 
219 
221  typedef ET2 RightElement;
222 
223  typedef std::forward_iterator_tag IteratorCategory;
224  typedef Element ValueType;
225  typedef ValueType* PointerType;
226  typedef ValueType& ReferenceType;
228 
229  // STL iterator requirements
230  typedef IteratorCategory iterator_category;
231  typedef ValueType value_type;
232  typedef PointerType pointer;
233  typedef ReferenceType reference;
234  typedef DifferenceType difference_type;
235  //*******************************************************************************************
236 
237  //**Constructor******************************************************************************
240  inline ConstIterator( IteratorType it, RightElement v )
241  : it_( it ) // Iterator over the elements of the left-hand side sparse vector expression
242  , v_ ( v ) // Element of the right-hand side dense vector expression.
243  {}
244  //*******************************************************************************************
245 
246  //**Prefix increment operator****************************************************************
252  ++it_;
253  return *this;
254  }
255  //*******************************************************************************************
256 
257  //**Element access operator******************************************************************
262  inline const Element operator*() const {
263  return Element( it_->value() * v_, it_->index() );
264  }
265  //*******************************************************************************************
266 
267  //**Element access operator******************************************************************
272  inline const ConstIterator* operator->() const {
273  return this;
274  }
275  //*******************************************************************************************
276 
277  //**Value function***************************************************************************
282  inline ReturnType value() const {
283  return it_->value() * v_;
284  }
285  //*******************************************************************************************
286 
287  //**Index function***************************************************************************
292  inline size_t index() const {
293  return it_->index();
294  }
295  //*******************************************************************************************
296 
297  //**Equality operator************************************************************************
303  inline bool operator==( const ConstIterator& rhs ) const {
304  return it_ == rhs.it_;
305  }
306  //*******************************************************************************************
307 
308  //**Inequality operator**********************************************************************
314  inline bool operator!=( const ConstIterator& rhs ) const {
315  return it_ != rhs.it_;
316  }
317  //*******************************************************************************************
318 
319  //**Subtraction operator*********************************************************************
325  inline DifferenceType operator-( const ConstIterator& rhs ) const {
326  return it_ - rhs.it_;
327  }
328  //*******************************************************************************************
329 
330  private:
331  //**Member variables*************************************************************************
332  IteratorType it_;
333  RightElement v_;
334  //*******************************************************************************************
335  };
336  //**********************************************************************************************
337 
338  //**Constructor*********************************************************************************
344  explicit inline SVecTDVecMultExpr( const VT1& lhs, const VT2& rhs )
345  : lhs_( lhs ) // Left-hand side sparse vector of the multiplication expression
346  , rhs_( rhs ) // Right-hand side dense vector of the multiplication expression
347  {}
348  //**********************************************************************************************
349 
350  //**Access operator*****************************************************************************
357  inline ReturnType operator()( size_t i, size_t j ) const {
358  BLAZE_INTERNAL_ASSERT( i < lhs_.size(), "Invalid row access index" );
359  BLAZE_INTERNAL_ASSERT( j < rhs_.size(), "Invalid column access index" );
360 
361  return lhs_[i] * rhs_[j];
362  }
363  //**********************************************************************************************
364 
365  //**Begin function******************************************************************************
371  inline ConstIterator begin( size_t i ) const {
372  return ConstIterator( lhs_.begin(), rhs_[i] );
373  }
374  //**********************************************************************************************
375 
376  //**End function********************************************************************************
382  inline ConstIterator end( size_t i ) const {
383  return ConstIterator( lhs_.end(), rhs_[i] );
384  }
385  //**********************************************************************************************
386 
387  //**Rows function*******************************************************************************
392  inline size_t rows() const {
393  return lhs_.size();
394  }
395  //**********************************************************************************************
396 
397  //**Columns function****************************************************************************
402  inline size_t columns() const {
403  return rhs_.size();
404  }
405  //**********************************************************************************************
406 
407  //**NonZeros function***************************************************************************
412  inline size_t nonZeros() const {
413  return lhs_.nonZeros() * rhs_.size();
414  }
415  //**********************************************************************************************
416 
417  //**NonZeros function***************************************************************************
423  inline size_t nonZeros( size_t i ) const {
424  UNUSED_PARAMETER( i );
425  return lhs_.nonZeros();
426  }
427  //**********************************************************************************************
428 
429  //**Find function*******************************************************************************
436  inline ConstIterator find( size_t i, size_t j ) const {
438  return ConstIterator( lhs_.find( i ), rhs_[j] );
439  }
440  //**********************************************************************************************
441 
442  //**LowerBound function*************************************************************************
449  inline ConstIterator lowerBound( size_t i, size_t j ) const {
451  return ConstIterator( lhs_.lowerBound( i ), rhs_[j] );
452  }
453  //**********************************************************************************************
454 
455  //**UpperBound function*************************************************************************
462  inline ConstIterator upperBound( size_t i, size_t j ) const {
464  return ConstIterator( lhs_.upperBound( i ), rhs_[j] );
465  }
466  //**********************************************************************************************
467 
468  //**Left operand access*************************************************************************
473  inline LeftOperand leftOperand() const {
474  return lhs_;
475  }
476  //**********************************************************************************************
477 
478  //**Right operand access************************************************************************
483  inline RightOperand rightOperand() const {
484  return rhs_;
485  }
486  //**********************************************************************************************
487 
488  //**********************************************************************************************
494  template< typename T >
495  inline bool canAlias( const T* alias ) const {
496  return ( lhs_.canAlias( alias ) || rhs_.canAlias( alias ) );
497  }
498  //**********************************************************************************************
499 
500  //**********************************************************************************************
506  template< typename T >
507  inline bool isAliased( const T* alias ) const {
508  return ( lhs_.isAliased( alias ) || rhs_.isAliased( alias ) );
509  }
510  //**********************************************************************************************
511 
512  private:
513  //**Member variables****************************************************************************
514  LeftOperand lhs_;
515  RightOperand rhs_;
516  //**********************************************************************************************
517 
518  //**Assignment to row-major dense matrices******************************************************
530  template< typename MT > // Type of the target dense matrix
531  friend inline void assign( DenseMatrix<MT,false>& lhs, const SVecTDVecMultExpr& rhs )
532  {
534 
536 
537  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
538  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
539 
540  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse vector operand
541  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense vector operand
542 
543  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
544  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
545  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
546  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
547 
548  SVecTDVecMultExpr::selectAssignKernel( ~lhs, x, y );
549  }
551  //**********************************************************************************************
552 
553  //**Default assignment to row-major dense matrices**********************************************
567  template< typename MT // Type of the left-hand side target matrix
568  , typename VT3 // Type of the left-hand side vector operand
569  , typename VT4 > // Type of the right-hand side vector operand
570  static inline typename EnableIf< UseDefaultKernel<MT,VT3,VT4> >::Type
571  selectAssignKernel( DenseMatrix<MT,false>& A, const VT3& x, const VT4& y )
572  {
574 
575  const ConstIterator end( x.end() );
576 
577  for( ConstIterator element=x.begin(); element!=end; ++element ) {
578  if( !isDefault( element->value() ) ) {
579  for( size_t j=0UL; j<y.size(); ++j ) {
580  (~A)(element->index(),j) = element->value() * y[j];
581  }
582  }
583  }
584  }
586  //**********************************************************************************************
587 
588  //**Vectorized assignment to row-major dense matrices*******************************************
602  template< typename MT // Type of the left-hand side target matrix
603  , typename VT3 // Type of the left-hand side vector operand
604  , typename VT4 > // Type of the right-hand side vector operand
605  static inline typename EnableIf< UseVectorizedKernel<MT,VT3,VT4> >::Type
606  selectAssignKernel( DenseMatrix<MT,false>& A, const VT3& x, const VT4& y )
607  {
609 
610  typedef IntrinsicTrait<ElementType> IT;
611  typedef typename IT::Type IntrinsicType;
612 
613  const ConstIterator begin( x.begin() );
614  const ConstIterator end ( x.end() );
615 
616  for( ConstIterator element=begin; element!=end; ++element )
617  {
618  const IntrinsicType x1( set( element->value() ) );
619 
620  for( size_t j=0UL; j<(~A).columns(); j+=IT::size ) {
621  (~A).store( element->index(), j, x1 * y.load(j) );
622  }
623  }
624  }
626  //**********************************************************************************************
627 
628  //**Assignment to column-major dense matrices***************************************************
644  template< typename MT > // Type of the target dense matrix
645  friend inline typename EnableIf< UseAssign<MT> >::Type
646  assign( DenseMatrix<MT,true>& lhs, const SVecTDVecMultExpr& rhs )
647  {
649 
650  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
651  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
652 
654 
655  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse vector operand
656  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense vector operand
657 
658  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
659  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
660  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
661  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
662 
663  const ConstIterator end( x.end() );
664 
665  for( size_t i=0UL; i<y.size(); ++i ) {
666  if( !isDefault( y[i] ) ) {
667  for( ConstIterator element=x.begin(); element!=end; ++element ) {
668  (~lhs)(element->index(),i) = element->value() * y[i];
669  }
670  }
671  }
672  }
674  //**********************************************************************************************
675 
676  //**Assignment to row-major sparse matrices*****************************************************
688  template< typename MT > // Type of the target sparse matrix
689  friend inline void assign( SparseMatrix<MT,false>& lhs, const SVecTDVecMultExpr& rhs )
690  {
692 
694 
695  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
696  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns() , "Invalid number of columns" );
697 
699 
700  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse vector operand
701  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense vector operand
702 
703  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
704  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
705  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
706  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
707 
708  const ConstIterator begin( x.begin() );
709  const ConstIterator end ( x.end() );
710 
711  if( begin == end )
712  return;
713 
714  (~lhs).reserve( begin->index(), rhs.nonZeros() );
715 
716  size_t index( 0UL );
717 
718  for( ConstIterator element=begin; element!=end; ++element ) {
719  if( !isDefault( element->value() ) ) {
720  for( ; index < element->index(); ++index ) {
721  (~lhs).finalize( index );
722  }
723  for( size_t i=0UL; i<y.size(); ++i ) {
724  (~lhs).append( element->index(), i, element->value() * y[i] );
725  }
726  (~lhs).finalize( index++ );
727  }
728  }
729 
730  for( ; index < x.size(); ++index ) {
731  (~lhs).finalize( index );
732  }
733  }
735  //**********************************************************************************************
736 
737  //**Assignment to column-major sparse matrices**************************************************
753  template< typename MT > // Type of the target sparse matrix
754  friend inline typename EnableIf< UseAssign<MT> >::Type
755  assign( SparseMatrix<MT,true>& lhs, const SVecTDVecMultExpr& rhs )
756  {
758 
759  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
760  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns() , "Invalid number of columns" );
761  BLAZE_INTERNAL_ASSERT( (~lhs).capacity() >= rhs.nonZeros(), "Insufficient capacity" );
762 
764 
765  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse vector operand
766  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense vector operand
767 
768  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
769  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
770  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
771  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
772 
773  const ConstIterator begin( x.begin() );
774  const ConstIterator end ( x.end() );
775 
776  if( begin == end )
777  return;
778 
779  for( size_t i=0UL; i<y.size(); ++i ) {
780  if( !isDefault( y[i] ) ) {
781  for( ConstIterator element=begin; element!=end; ++element ) {
782  (~lhs).append( element->index(), i, element->value() * y[i] );
783  }
784  }
785  (~lhs).finalize( i );
786  }
787  }
789  //**********************************************************************************************
790 
791  //**Addition assignment to row-major dense matrices*********************************************
804  template< typename MT > // Type of the target dense matrix
805  friend inline void addAssign( DenseMatrix<MT,false>& lhs, const SVecTDVecMultExpr& rhs )
806  {
808 
810 
811  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
812  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
813 
814  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse vector operand
815  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense vector operand
816 
817  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
818  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
819  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
820  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
821 
822  SVecTDVecMultExpr::selectAddAssignKernel( ~lhs, x, y );
823  }
825  //**********************************************************************************************
826 
827  //**Default addition assignment to row-major dense matrices*************************************
841  template< typename MT // Type of the left-hand side target matrix
842  , typename VT3 // Type of the left-hand side vector operand
843  , typename VT4 > // Type of the right-hand side vector operand
844  static inline typename EnableIf< UseDefaultKernel<MT,VT3,VT4> >::Type
845  selectAddAssignKernel( DenseMatrix<MT,false>& A, const VT3& x, const VT4& y )
846  {
848 
849  const ConstIterator end( x.end() );
850 
851  for( ConstIterator element=x.begin(); element!=end; ++element ) {
852  if( !isDefault( element->value() ) ) {
853  for( size_t i=0UL; i<y.size(); ++i ) {
854  (~A)(element->index(),i) += element->value() * y[i];
855  }
856  }
857  }
858  }
860  //**********************************************************************************************
861 
862  //**Vectorized addition assignment to row-major dense matrices**********************************
876  template< typename MT // Type of the left-hand side target matrix
877  , typename VT3 // Type of the left-hand side vector operand
878  , typename VT4 > // Type of the right-hand side vector operand
879  static inline typename EnableIf< UseVectorizedKernel<MT,VT3,VT4> >::Type
880  selectAddAssignKernel( DenseMatrix<MT,false>& A, const VT3& x, const VT4& y )
881  {
883 
884  typedef IntrinsicTrait<ElementType> IT;
885  typedef typename IT::Type IntrinsicType;
886 
887  const ConstIterator begin( x.begin() );
888  const ConstIterator end ( x.end() );
889 
890  for( ConstIterator element=begin; element!=end; ++element )
891  {
892  const IntrinsicType x1( set( element->value() ) );
893 
894  for( size_t j=0UL; j<(~A).columns(); j+=IT::size ) {
895  (~A).store( element->index(), j, (~A).load(element->index(),j) + x1 * y.load(j) );
896  }
897  }
898  }
900  //**********************************************************************************************
901 
902  //**Addition assignment to column-major dense matrices******************************************
918  template< typename MT > // Type of the target dense matrix
919  friend inline typename EnableIf< UseAssign<MT> >::Type
920  addAssign( DenseMatrix<MT,true>& lhs, const SVecTDVecMultExpr& rhs )
921  {
923 
924  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
925  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
926 
928 
929  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse vector operand
930  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense vector operand
931 
932  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
933  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
934  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
935  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
936 
937  const ConstIterator end( x.end() );
938 
939  for( size_t i=0UL; i<y.size(); ++i ) {
940  if( !isDefault( y[i] ) ) {
941  for( ConstIterator element=x.begin(); element!=end; ++element ) {
942  (~lhs)(element->index(),i) += element->value() * y[i];
943  }
944  }
945  }
946  }
948  //**********************************************************************************************
949 
950  //**Addition assignment to sparse matrices******************************************************
951  // No special implementation for the addition assignment to sparse matrices.
952  //**********************************************************************************************
953 
954  //**Subtraction assignment to row-major dense matrices******************************************
967  template< typename MT > // Type of the target dense matrix
968  friend inline void subAssign( DenseMatrix<MT,false>& lhs, const SVecTDVecMultExpr& rhs )
969  {
971 
973 
974  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
975  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
976 
977  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse vector operand
978  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense vector operand
979 
980  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
981  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
982  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
983  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
984 
985  SVecTDVecMultExpr::selectSubAssignKernel( ~lhs, x, y );
986  }
988  //**********************************************************************************************
989 
990  //**Default subtraction assignment to row-major dense matrices**********************************
1004  template< typename MT // Type of the left-hand side target matrix
1005  , typename VT3 // Type of the left-hand side vector operand
1006  , typename VT4 > // Type of the right-hand side vector operand
1007  static inline typename EnableIf< UseDefaultKernel<MT,VT3,VT4> >::Type
1008  selectSubAssignKernel( DenseMatrix<MT,false>& A, const VT3& x, const VT4& y )
1009  {
1011 
1012  const ConstIterator end( x.end() );
1013 
1014  for( ConstIterator element=x.begin(); element!=end; ++element ) {
1015  if( !isDefault( element->value() ) ) {
1016  for( size_t i=0UL; i<y.size(); ++i ) {
1017  (~A)(element->index(),i) -= element->value() * y[i];
1018  }
1019  }
1020  }
1021  }
1023  //**********************************************************************************************
1024 
1025  //**Vectorized subtraction assignment to row-major dense matrices*******************************
1039  template< typename MT // Type of the left-hand side target matrix
1040  , typename VT3 // Type of the left-hand side vector operand
1041  , typename VT4 > // Type of the right-hand side vector operand
1042  static inline typename EnableIf< UseVectorizedKernel<MT,VT3,VT4> >::Type
1043  selectSubAssignKernel( DenseMatrix<MT,false>& A, const VT3& x, const VT4& y )
1044  {
1046 
1047  typedef IntrinsicTrait<ElementType> IT;
1048  typedef typename IT::Type IntrinsicType;
1049 
1050  const ConstIterator begin( x.begin() );
1051  const ConstIterator end ( x.end() );
1052 
1053  for( ConstIterator element=begin; element!=end; ++element )
1054  {
1055  const IntrinsicType x1( set( element->value() ) );
1056 
1057  for( size_t j=0UL; j<(~A).columns(); j+=IT::size ) {
1058  (~A).store( element->index(), j, (~A).load(element->index(),j) - x1 * y.load(j) );
1059  }
1060  }
1061  }
1063  //**********************************************************************************************
1064 
1065  //**Subtraction assignment to column-major dense matrices***************************************
1081  template< typename MT > // Type of the target dense matrix
1082  friend inline typename EnableIf< UseAssign<MT> >::Type
1083  subAssign( DenseMatrix<MT,true>& lhs, const SVecTDVecMultExpr& rhs )
1084  {
1086 
1087  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
1088  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
1089 
1091 
1092  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse vector operand
1093  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense vector operand
1094 
1095  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
1096  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
1097  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
1098  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
1099 
1100  const ConstIterator end( x.end() );
1101 
1102  for( size_t i=0UL; i<y.size(); ++i ) {
1103  if( !isDefault( y[i] ) ) {
1104  for( ConstIterator element=x.begin(); element!=end; ++element ) {
1105  (~lhs)(element->index(),i) -= element->value() * y[i];
1106  }
1107  }
1108  }
1109  }
1111  //**********************************************************************************************
1112 
1113  //**Subtraction assignment to sparse matrices***************************************************
1114  // No special implementation for the subtraction assignment to sparse matrices.
1115  //**********************************************************************************************
1116 
1117  //**Multiplication assignment to dense matrices*************************************************
1118  // No special implementation for the multiplication assignment to dense matrices.
1119  //**********************************************************************************************
1120 
1121  //**Multiplication assignment to sparse matrices************************************************
1122  // No special implementation for the multiplication assignment to sparse matrices.
1123  //**********************************************************************************************
1124 
1125  //**Compile time checks*************************************************************************
1133  //**********************************************************************************************
1134 };
1135 //*************************************************************************************************
1136 
1137 
1138 
1139 
1140 //=================================================================================================
1141 //
1142 // GLOBAL BINARY ARITHMETIC OPERATORS
1143 //
1144 //=================================================================================================
1145 
1146 //*************************************************************************************************
1175 template< typename T1 // Type of the left-hand side sparse vector
1176  , typename T2 > // Type of the right-hand side dense vector
1177 inline const SVecTDVecMultExpr<T1,T2>
1179 {
1181 
1182  return SVecTDVecMultExpr<T1,T2>( ~lhs, ~rhs );
1183 }
1184 //*************************************************************************************************
1185 
1186 
1187 
1188 
1189 //=================================================================================================
1190 //
1191 // ROWS SPECIALIZATIONS
1192 //
1193 //=================================================================================================
1194 
1195 //*************************************************************************************************
1197 template< typename VT1, typename VT2 >
1198 struct Rows< SVecTDVecMultExpr<VT1,VT2> > : public Size<VT1>
1199 {};
1201 //*************************************************************************************************
1202 
1203 
1204 
1205 
1206 //=================================================================================================
1207 //
1208 // COLUMNS SPECIALIZATIONS
1209 //
1210 //=================================================================================================
1211 
1212 //*************************************************************************************************
1214 template< typename VT1, typename VT2 >
1215 struct Columns< SVecTDVecMultExpr<VT1,VT2> > : public Size<VT2>
1216 {};
1218 //*************************************************************************************************
1219 
1220 
1221 
1222 
1223 //=================================================================================================
1224 //
1225 // EXPRESSION TRAIT SPECIALIZATIONS
1226 //
1227 //=================================================================================================
1228 
1229 //*************************************************************************************************
1231 template< typename VT1, typename VT2, bool AF >
1232 struct SubmatrixExprTrait< SVecTDVecMultExpr<VT1,VT2>, AF >
1233 {
1234  public:
1235  //**********************************************************************************************
1236  typedef typename MultExprTrait< typename SubvectorExprTrait<const VT1,AF>::Type
1237  , typename SubvectorExprTrait<const VT2,AF>::Type >::Type Type;
1238  //**********************************************************************************************
1239 };
1241 //*************************************************************************************************
1242 
1243 
1244 //*************************************************************************************************
1246 template< typename VT1, typename VT2 >
1247 struct RowExprTrait< SVecTDVecMultExpr<VT1,VT2> >
1248 {
1249  public:
1250  //**********************************************************************************************
1251  typedef typename MultExprTrait< typename VT1::ReturnType, VT2 >::Type Type;
1252  //**********************************************************************************************
1253 };
1255 //*************************************************************************************************
1256 
1257 
1258 //*************************************************************************************************
1260 template< typename VT1, typename VT2 >
1261 struct ColumnExprTrait< SVecTDVecMultExpr<VT1,VT2> >
1262 {
1263  public:
1264  //**********************************************************************************************
1265  typedef typename MultExprTrait< VT1, typename VT2::ReturnType >::Type Type;
1266  //**********************************************************************************************
1267 };
1269 //*************************************************************************************************
1270 
1271 } // namespace blaze
1272 
1273 #endif
Pointer difference type of the Blaze library.
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
Compile time check whether the given type is a temporary vector or matrix type.This type trait class ...
Definition: IsTemporary.h:87
Header file for the Rows type trait.
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
Iterator over the elements of the sparse vector-dense vector outer product expression.
Definition: SVecTDVecMultExpr.h:210
Header file for basic type definitions.
std::forward_iterator_tag IteratorCategory
The iterator category.
Definition: SVecTDVecMultExpr.h:223
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector)
Returns the current size/dimension of the vector.
Definition: Vector.h:264
#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
size_t nonZeros(size_t i) const
Returns the number of non-zero elements in the specified column.
Definition: SVecTDVecMultExpr.h:423
LeftOperand leftOperand() const
Returns the left-hand side sparse vector operand.
Definition: SVecTDVecMultExpr.h:473
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:209
Header file for the ColumnExprTrait class template.
DifferenceType difference_type
Difference between two iterators.
Definition: SVecTDVecMultExpr.h:234
size_t columns() const
Returns the current number of columns of the matrix.
Definition: SVecTDVecMultExpr.h:402
ValueType * PointerType
Pointer return type.
Definition: SVecTDVecMultExpr.h:225
Expression object for sparse vector-dense vector outer products.The SVecTDVecMultExpr class represent...
Definition: Forward.h:121
size_t nonZeros() const
Returns the number of non-zero elements in the sparse matrix.
Definition: SVecTDVecMultExpr.h:412
MultTrait< RT1, RT2 >::Type ResultType
Result type for expression template evaluations.
Definition: SVecTDVecMultExpr.h:178
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
void UNUSED_PARAMETER(const T1 &)
Suppression of unused parameter warnings.
Definition: Unused.h:81
ConstIterator begin(size_t i) const
Returns an iterator to the first non-zero element of column i.
Definition: SVecTDVecMultExpr.h:371
ResultType::ElementType ElementType
Resulting element type.
Definition: SVecTDVecMultExpr.h:181
VT2::ReturnType RN2
Return type of the right-hand side dense vector expression.
Definition: SVecTDVecMultExpr.h:108
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
ConstIterator end(size_t i) const
Returns an iterator just past the last non-zero element of column i.
Definition: SVecTDVecMultExpr.h:382
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
ValueIndexPair< ElementType > Element
Element type of the sparse matrix expression.
Definition: SVecTDVecMultExpr.h:215
SVecTDVecMultExpr< VT1, VT2 > This
Type of this SVecTDVecMultExpr instance.
Definition: SVecTDVecMultExpr.h:177
RemoveReference< LeftOperand >::Type::ConstIterator IteratorType
Iterator type of the sparse vector expression.
Definition: SVecTDVecMultExpr.h:218
RightElement v_
Element of the right-hand side dense vector expression.
Definition: SVecTDVecMultExpr.h:333
const SelectType< returnExpr, ExprReturnType, ElementType >::Type ReturnType
Return type for expression template evaluations.
Definition: SVecTDVecMultExpr.h:184
Base class for dense matrices.The DenseMatrix class is a base class for all dense matrix classes...
Definition: DenseMatrix.h:70
ValueType value_type
Type of the underlying pointers.
Definition: SVecTDVecMultExpr.h:231
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:861
Constraint on the data type.
Header file for the SparseMatrix base class.
Constraint on the data type.
Header file for the MultExprTrait class template.
const ConstIterator * operator->() const
Direct access to the sparse matrix element at the current iterator position.
Definition: SVecTDVecMultExpr.h:272
IteratorType it_
Iterator over the elements of the left-hand side sparse vector expression.
Definition: SVecTDVecMultExpr.h:332
VT2::ResultType RT2
Result type of the right-hand side dense vector expression.
Definition: SVecTDVecMultExpr.h:106
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
ReferenceType reference
Reference return type.
Definition: SVecTDVecMultExpr.h:233
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
bool operator!=(const ConstIterator &rhs) const
Inequality comparison between two ConstIterator objects.
Definition: SVecTDVecMultExpr.h:314
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: SVecTDVecMultExpr.h:180
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
size_t rows() const
Returns the current number of rows of the matrix.
Definition: SVecTDVecMultExpr.h:392
MultExprTrait< RN1, RN2 >::Type ExprReturnType
Expression return type for the subscript operator.
Definition: SVecTDVecMultExpr.h:125
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
bool operator==(const ConstIterator &rhs) const
Equality comparison between two ConstIterator objects.
Definition: SVecTDVecMultExpr.h:303
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.
ConstIterator find(size_t i, size_t j) const
Searches for a specific matrix element.
Definition: SVecTDVecMultExpr.h:436
SVecTDVecMultExpr(const VT1 &lhs, const VT2 &rhs)
Constructor for the SVecTDVecMultExpr class.
Definition: SVecTDVecMultExpr.h:344
DifferenceType operator-(const ConstIterator &rhs) const
Calculating the number of elements between two expression iterators.
Definition: SVecTDVecMultExpr.h:325
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a sparse, N-dimensional vector type...
Definition: SparseVector.h:79
ReturnType value() const
Access to the current value of the sparse element.
Definition: SVecTDVecMultExpr.h:282
Constraint on the data type.
Constraint on the data type.
LeftOperand lhs_
Left-hand side sparse vector of the multiplication expression.
Definition: SVecTDVecMultExpr.h:514
SelectType< IsComputation< VT2 >::value, const RT2, CT2 >::Type RT
Type for the assignment of the right-hand side dense vector operand.
Definition: SVecTDVecMultExpr.h:199
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.
RightOperand rhs_
Right-hand side dense vector of the multiplication expression.
Definition: SVecTDVecMultExpr.h:515
Header file for the EnableIf class template.
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: SVecTDVecMultExpr.h:495
Header file for the serial shim.
Element ValueType
Type of the underlying pointers.
Definition: SVecTDVecMultExpr.h:224
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
Header file for the IsNumeric type trait.
ConstIterator lowerBound(size_t i, size_t j) const
Returns an iterator to the first index not less then the given index.
Definition: SVecTDVecMultExpr.h:449
#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.
VT1::ResultType RT1
Result type of the left-hand side sparse vector expression.
Definition: SVecTDVecMultExpr.h:105
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
Intrinsic characteristics of data types.The IntrinsicTrait class template provides the intrinsic char...
Definition: IntrinsicTrait.h:749
Header file for run time assertion macros.
SelectType< useAssign, const ResultType, const SVecTDVecMultExpr & >::Type CompositeType
Data type for composite expression templates.
Definition: SVecTDVecMultExpr.h:187
Base template for the MultTrait class.
Definition: MultTrait.h:150
ConstIterator & operator++()
Pre-increment operator.
Definition: SVecTDVecMultExpr.h:251
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
VT1::ReturnType RN1
Return type of the left-hand side sparse vector expression.
Definition: SVecTDVecMultExpr.h:107
VT1::CompositeType CT1
Composite type of the left-hand side sparse vector expression.
Definition: SVecTDVecMultExpr.h:109
VT2::CompositeType CT2
Composite type of the right-hand side dense vector expression.
Definition: SVecTDVecMultExpr.h:110
Substitution Failure Is Not An Error (SFINAE) class.The EnableIf class template is an auxiliary tool ...
Definition: EnableIf.h:184
SelectType< IsExpression< VT1 >::value, const VT1, const VT1 & >::Type LeftOperand
Composite type of the left-hand side sparse vector expression.
Definition: SVecTDVecMultExpr.h:190
const Element operator*() const
Direct access to the sparse matrix element at the current iterator position.
Definition: SVecTDVecMultExpr.h:262
Header file for the isDefault shim.
Constraint on the data type.
ET2 RightElement
Element type of the dense vector expression.
Definition: SVecTDVecMultExpr.h:221
#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
ConstIterator upperBound(size_t i, size_t j) const
Returns an iterator to the first index greater then the given index.
Definition: SVecTDVecMultExpr.h:462
Constraint on the data type.
ConstIterator(IteratorType it, RightElement v)
Constructor for the ConstIterator class.
Definition: SVecTDVecMultExpr.h:240
Header file for the RemoveReference type trait.
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
ValueType & ReferenceType
Reference return type.
Definition: SVecTDVecMultExpr.h:226
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
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: SVecTDVecMultExpr.h:357
RightOperand rightOperand() const
Returns the right-hand side dense vector operand.
Definition: SVecTDVecMultExpr.h:483
Index-value-pair for sparse vectors and matrices.The ValueIndexPair class represents a single index-v...
Definition: ValueIndexPair.h:70
IteratorCategory iterator_category
The iterator category.
Definition: SVecTDVecMultExpr.h:230
Header file for the IsComputation type trait class.
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
SelectType< IsExpression< VT2 >::value, const VT2, const VT2 & >::Type RightOperand
Composite type of the right-hand side dense vector expression.
Definition: SVecTDVecMultExpr.h:193
#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
Header file for the SubvectorExprTrait class template.
SelectType< IsComputation< VT1 >::value, const RT1, CT1 >::Type LT
Type for the assignment of the left-hand side dense vector operand.
Definition: SVecTDVecMultExpr.h:196
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: SVecTDVecMultExpr.h:507
size_t index() const
Access to the current index of the sparse element.
Definition: SVecTDVecMultExpr.h:292
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
VT1::ElementType ET1
Element type of the left-hand side sparse vector expression.
Definition: SVecTDVecMultExpr.h:111
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: SVecTDVecMultExpr.h:227
PointerType pointer
Pointer return type.
Definition: SVecTDVecMultExpr.h:232
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
ResultType::OppositeType OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: SVecTDVecMultExpr.h:179
VT2::ElementType ET2
Element type of the right-hand side dense vector expression.
Definition: SVecTDVecMultExpr.h:112