All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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>
52 #include <blaze/math/Intrinsics.h>
64 #include <blaze/util/Assert.h>
67 #include <blaze/util/SelectType.h>
68 #include <blaze/util/Types.h>
71 #include <blaze/util/Unused.h>
72 
73 
74 namespace blaze {
75 
76 //=================================================================================================
77 //
78 // CLASS SVECTDVECMULTEXPR
79 //
80 //=================================================================================================
81 
82 //*************************************************************************************************
89 template< typename VT1 // Type of the left-hand side sparse vector
90  , typename VT2 > // Type of the right-hand side dense vector
91 class SVecTDVecMultExpr : public SparseMatrix< SVecTDVecMultExpr<VT1,VT2>, true >
92  , private VecTVecMultExpr
93  , private Computation
94 {
95  private:
96  //**Type definitions****************************************************************************
97  typedef typename VT1::ResultType RT1;
98  typedef typename VT2::ResultType RT2;
99  typedef typename VT1::ReturnType RN1;
100  typedef typename VT2::ReturnType RN2;
101  typedef typename VT1::CompositeType CT1;
102  typedef typename VT2::CompositeType CT2;
103  typedef typename VT1::ElementType ET1;
104  typedef typename VT2::ElementType ET2;
105  //**********************************************************************************************
106 
107  //**Return type evaluation**********************************************************************
109 
114  enum { returnExpr = !IsTemporary<RN1>::value && !IsTemporary<RN2>::value };
115 
118  //**********************************************************************************************
119 
120  //**Evaluation strategy*************************************************************************
122 
128  enum { useAssign = ( IsComputation<VT1>::value || !IsNumeric<ET1>::value ||
130 
132  template< typename MT >
134  struct UseAssign {
135  enum { value = useAssign };
136  };
138  //**********************************************************************************************
139 
140  //**********************************************************************************************
142 
145  template< typename T1, typename T2, typename T3 >
146  struct UseVectorizedKernel {
147  enum { value = T1::vectorizable && T3::vectorizable &&
151  };
153  //**********************************************************************************************
154 
155  //**********************************************************************************************
157 
160  template< typename T1, typename T2, typename T3 >
161  struct UseDefaultKernel {
162  enum { value = !UseVectorizedKernel<T1,T2,T3>::value };
163  };
165  //**********************************************************************************************
166 
167  public:
168  //**Type definitions****************************************************************************
174 
177 
180 
182  typedef typename SelectType< IsExpression<VT1>::value, const VT1, const VT1& >::Type LeftOperand;
183 
185  typedef typename SelectType< IsExpression<VT2>::value, const VT2, const VT2& >::Type RightOperand;
186 
188  typedef typename SelectType< IsComputation<VT1>::value, const RT1, CT1 >::Type LT;
189 
191  typedef typename SelectType< IsComputation<VT2>::value, const RT2, CT2 >::Type RT;
192  //**********************************************************************************************
193 
194  //**Compilation flags***************************************************************************
196  enum { smpAssignable = 0 };
197  //**********************************************************************************************
198 
199  //**ConstIterator class definition**************************************************************
203  {
204  public:
205  //**Type definitions*************************************************************************
208 
211 
213  typedef ET2 RightElement;
214 
215  typedef std::forward_iterator_tag IteratorCategory;
216  typedef Element ValueType;
220 
221  // STL iterator requirements
227  //*******************************************************************************************
228 
229  //**Constructor******************************************************************************
233  : it_( it ) // Iterator over the elements of the left-hand side sparse vector expression
234  , v_ ( v ) // Element of the right-hand side dense vector expression.
235  {}
236  //*******************************************************************************************
237 
238  //**Prefix increment operator****************************************************************
244  ++it_;
245  return *this;
246  }
247  //*******************************************************************************************
248 
249  //**Element access operator******************************************************************
254  inline const Element operator*() const {
255  return Element( it_->value() * v_, it_->index() );
256  }
257  //*******************************************************************************************
258 
259  //**Element access operator******************************************************************
264  inline const ConstIterator* operator->() const {
265  return this;
266  }
267  //*******************************************************************************************
268 
269  //**Value function***************************************************************************
274  inline ReturnType value() const {
275  return it_->value() * v_;
276  }
277  //*******************************************************************************************
278 
279  //**Index function***************************************************************************
284  inline size_t index() const {
285  return it_->index();
286  }
287  //*******************************************************************************************
288 
289  //**Equality operator************************************************************************
295  inline bool operator==( const ConstIterator& rhs ) const {
296  return it_ == rhs.it_;
297  }
298  //*******************************************************************************************
299 
300  //**Inequality operator**********************************************************************
306  inline bool operator!=( const ConstIterator& rhs ) const {
307  return it_ != rhs.it_;
308  }
309  //*******************************************************************************************
310 
311  //**Subtraction operator*********************************************************************
317  inline DifferenceType operator-( const ConstIterator& rhs ) const {
318  return it_ - rhs.it_;
319  }
320  //*******************************************************************************************
321 
322  private:
323  //**Member variables*************************************************************************
326  //*******************************************************************************************
327  };
328  //**********************************************************************************************
329 
330  //**Constructor*********************************************************************************
336  explicit inline SVecTDVecMultExpr( const VT1& lhs, const VT2& rhs )
337  : lhs_( lhs ) // Left-hand side sparse vector of the multiplication expression
338  , rhs_( rhs ) // Right-hand side dense vector of the multiplication expression
339  {}
340  //**********************************************************************************************
341 
342  //**Access operator*****************************************************************************
349  inline ReturnType operator()( size_t i, size_t j ) const {
350  BLAZE_INTERNAL_ASSERT( i < lhs_.size(), "Invalid row access index" );
351  BLAZE_INTERNAL_ASSERT( j < rhs_.size(), "Invalid column access index" );
352 
353  return lhs_[i] * rhs_[j];
354  }
355  //**********************************************************************************************
356 
357  //**Begin function******************************************************************************
363  inline ConstIterator begin( size_t i ) const {
364  return ConstIterator( lhs_.begin(), rhs_[i] );
365  }
366  //**********************************************************************************************
367 
368  //**End function********************************************************************************
374  inline ConstIterator end( size_t i ) const {
375  return ConstIterator( lhs_.end(), rhs_[i] );
376  }
377  //**********************************************************************************************
378 
379  //**Rows function*******************************************************************************
384  inline size_t rows() const {
385  return lhs_.size();
386  }
387  //**********************************************************************************************
388 
389  //**Columns function****************************************************************************
394  inline size_t columns() const {
395  return rhs_.size();
396  }
397  //**********************************************************************************************
398 
399  //**NonZeros function***************************************************************************
404  inline size_t nonZeros() const {
405  return lhs_.nonZeros() * rhs_.size();
406  }
407  //**********************************************************************************************
408 
409  //**NonZeros function***************************************************************************
415  inline size_t nonZeros( size_t i ) const {
416  UNUSED_PARAMETER( i );
417  return lhs_.nonZeros();
418  }
419  //**********************************************************************************************
420 
421  //**Left operand access*************************************************************************
426  inline LeftOperand leftOperand() const {
427  return lhs_;
428  }
429  //**********************************************************************************************
430 
431  //**Right operand access************************************************************************
436  inline RightOperand rightOperand() const {
437  return rhs_;
438  }
439  //**********************************************************************************************
440 
441  //**********************************************************************************************
447  template< typename T >
448  inline bool canAlias( const T* alias ) const {
449  return ( lhs_.canAlias( alias ) || rhs_.canAlias( alias ) );
450  }
451  //**********************************************************************************************
452 
453  //**********************************************************************************************
459  template< typename T >
460  inline bool isAliased( const T* alias ) const {
461  return ( lhs_.isAliased( alias ) || rhs_.isAliased( alias ) );
462  }
463  //**********************************************************************************************
464 
465  private:
466  //**Member variables****************************************************************************
467  LeftOperand lhs_;
468  RightOperand rhs_;
469  //**********************************************************************************************
470 
471  //**Assignment to row-major dense matrices******************************************************
483  template< typename MT > // Type of the target dense matrix
484  friend inline void assign( DenseMatrix<MT,false>& lhs, const SVecTDVecMultExpr& rhs )
485  {
487 
488  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
489  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
490 
491  LT x( rhs.lhs_ ); // Evaluation of the left-hand side sparse vector operand
492  RT y( rhs.rhs_ ); // Evaluation of the right-hand side dense vector operand
493 
494  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
495  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
496  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
497  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
498 
499  SVecTDVecMultExpr::selectAssignKernel( ~lhs, x, y );
500  }
502  //**********************************************************************************************
503 
504  //**Default assignment to row-major dense matrices**********************************************
518  template< typename MT // Type of the left-hand side target matrix
519  , typename VT3 // Type of the left-hand side vector operand
520  , typename VT4 > // Type of the right-hand side vector operand
521  static inline typename EnableIf< UseDefaultKernel<MT,VT3,VT4> >::Type
522  selectAssignKernel( DenseMatrix<MT,false>& A, const VT3& x, const VT4& y )
523  {
525 
526  const ConstIterator end( x.end() );
527 
528  for( ConstIterator element=x.begin(); element!=end; ++element ) {
529  if( !isDefault( element->value() ) ) {
530  for( size_t j=0UL; j<y.size(); ++j ) {
531  (~A)(element->index(),j) = element->value() * y[j];
532  }
533  }
534  }
535  }
537  //**********************************************************************************************
538 
539  //**Vectorized assignment to row-major dense matrices*******************************************
553  template< typename MT // Type of the left-hand side target matrix
554  , typename VT3 // Type of the left-hand side vector operand
555  , typename VT4 > // Type of the right-hand side vector operand
556  static inline typename EnableIf< UseVectorizedKernel<MT,VT3,VT4> >::Type
557  selectAssignKernel( DenseMatrix<MT,false>& A, const VT3& x, const VT4& y )
558  {
560 
561  typedef IntrinsicTrait<ElementType> IT;
562  typedef typename IT::Type IntrinsicType;
563 
564  const ConstIterator begin( x.begin() );
565  const ConstIterator end ( x.end() );
566 
567  for( ConstIterator element=begin; element!=end; ++element )
568  {
569  const IntrinsicType x1( set( element->value() ) );
570 
571  for( size_t j=0UL; j<(~A).columns(); j+=IT::size ) {
572  (~A).store( element->index(), j, x1 * y.load(j) );
573  }
574  }
575  }
577  //**********************************************************************************************
578 
579  //**Assignment to column-major dense matrices***************************************************
595  template< typename MT > // Type of the target dense matrix
596  friend inline typename EnableIf< UseAssign<MT> >::Type
597  assign( DenseMatrix<MT,true>& lhs, const SVecTDVecMultExpr& rhs )
598  {
600 
601  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
602  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
603 
605 
606  LT x( rhs.lhs_ ); // Evaluation of the left-hand side sparse vector operand
607  RT y( rhs.rhs_ ); // Evaluation of the right-hand side dense vector operand
608 
609  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
610  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
611  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
612  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
613 
614  const ConstIterator end( x.end() );
615 
616  for( size_t i=0UL; i<y.size(); ++i ) {
617  if( !isDefault( y[i] ) ) {
618  for( ConstIterator element=x.begin(); element!=end; ++element ) {
619  (~lhs)(element->index(),i) = element->value() * y[i];
620  }
621  }
622  }
623  }
625  //**********************************************************************************************
626 
627  //**Assignment to row-major sparse matrices*****************************************************
639  template< typename MT > // Type of the target sparse matrix
640  friend inline void assign( SparseMatrix<MT,false>& lhs, const SVecTDVecMultExpr& rhs )
641  {
643 
644  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
645  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
646 
648 
649  LT x( rhs.lhs_ ); // Evaluation of the left-hand side sparse vector operand
650  RT y( rhs.rhs_ ); // Evaluation of the right-hand side dense vector operand
651 
652  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
653  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
654  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
655  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
656 
657  const ConstIterator end( x.end() );
658 
659  for( ConstIterator element=x.begin(); element!=end; ++element ) {
660  if( !isDefault( element->value() ) ) {
661  (~lhs).reserve( element->index(), y.size() );
662  for( size_t i=0UL; i<y.size(); ++i ) {
663  (~lhs).append( element->index(), i, element->value() * y[i] );
664  }
665  }
666  }
667  }
669  //**********************************************************************************************
670 
671  //**Assignment to column-major sparse matrices**************************************************
687  template< typename MT > // Type of the target sparse matrix
688  friend inline typename EnableIf< UseAssign<MT> >::Type
689  assign( SparseMatrix<MT,true>& lhs, const SVecTDVecMultExpr& rhs )
690  {
692 
693  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
694  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
695 
697 
698  LT x( rhs.lhs_ ); // Evaluation of the left-hand side sparse vector operand
699  RT y( rhs.rhs_ ); // Evaluation of the right-hand side dense vector operand
700 
701  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
702  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
703  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
704  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
705 
706  const ConstIterator end( x.end() );
707 
708  for( size_t i=0UL; i<y.size(); ++i ) {
709  if( !isDefault( y[i] ) ) {
710  (~lhs).reserve( i, x.nonZeros() );
711  for( ConstIterator element=x.begin(); element!=end; ++element ) {
712  (~lhs).append( element->index(), i, element->value() * y[i] );
713  }
714  }
715  }
716  }
718  //**********************************************************************************************
719 
720  //**Addition assignment to row-major dense matrices*********************************************
733  template< typename MT > // Type of the target dense matrix
734  friend inline void addAssign( DenseMatrix<MT,false>& lhs, const SVecTDVecMultExpr& rhs )
735  {
737 
738  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
739  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
740 
741  LT x( rhs.lhs_ ); // Evaluation of the left-hand side sparse vector operand
742  RT y( rhs.rhs_ ); // Evaluation of the right-hand side dense vector operand
743 
744  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
745  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
746  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
747  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
748 
749  SVecTDVecMultExpr::selectAddAssignKernel( ~lhs, x, y );
750  }
752  //**********************************************************************************************
753 
754  //**Default addition assignment to row-major dense matrices*************************************
768  template< typename MT // Type of the left-hand side target matrix
769  , typename VT3 // Type of the left-hand side vector operand
770  , typename VT4 > // Type of the right-hand side vector operand
771  static inline typename EnableIf< UseDefaultKernel<MT,VT3,VT4> >::Type
772  selectAddAssignKernel( DenseMatrix<MT,false>& A, const VT3& x, const VT4& y )
773  {
775 
776  const ConstIterator end( x.end() );
777 
778  for( ConstIterator element=x.begin(); element!=end; ++element ) {
779  if( !isDefault( element->value() ) ) {
780  for( size_t i=0UL; i<y.size(); ++i ) {
781  (~A)(element->index(),i) += element->value() * y[i];
782  }
783  }
784  }
785  }
787  //**********************************************************************************************
788 
789  //**Vectorized addition assignment to row-major dense matrices**********************************
803  template< typename MT // Type of the left-hand side target matrix
804  , typename VT3 // Type of the left-hand side vector operand
805  , typename VT4 > // Type of the right-hand side vector operand
806  static inline typename EnableIf< UseVectorizedKernel<MT,VT3,VT4> >::Type
807  selectAddAssignKernel( DenseMatrix<MT,false>& A, const VT3& x, const VT4& y )
808  {
810 
811  typedef IntrinsicTrait<ElementType> IT;
812  typedef typename IT::Type IntrinsicType;
813 
814  const ConstIterator begin( x.begin() );
815  const ConstIterator end ( x.end() );
816 
817  for( ConstIterator element=begin; element!=end; ++element )
818  {
819  const IntrinsicType x1( set( element->value() ) );
820 
821  for( size_t j=0UL; j<(~A).columns(); j+=IT::size ) {
822  (~A).store( element->index(), j, (~A).load(element->index(),j) + x1 * y.load(j) );
823  }
824  }
825  }
827  //**********************************************************************************************
828 
829  //**Addition assignment to column-major dense matrices******************************************
845  template< typename MT > // Type of the target dense matrix
846  friend inline typename EnableIf< UseAssign<MT> >::Type
847  addAssign( DenseMatrix<MT,true>& lhs, const SVecTDVecMultExpr& rhs )
848  {
850 
851  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
852  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
853 
855 
856  LT x( rhs.lhs_ ); // Evaluation of the left-hand side sparse vector operand
857  RT y( rhs.rhs_ ); // Evaluation of the right-hand side dense vector operand
858 
859  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
860  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
861  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
862  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
863 
864  const ConstIterator end( x.end() );
865 
866  for( size_t i=0UL; i<y.size(); ++i ) {
867  if( !isDefault( y[i] ) ) {
868  for( ConstIterator element=x.begin(); element!=end; ++element ) {
869  (~lhs)(element->index(),i) += element->value() * y[i];
870  }
871  }
872  }
873  }
875  //**********************************************************************************************
876 
877  //**Addition assignment to sparse matrices******************************************************
878  // No special implementation for the addition assignment to sparse matrices.
879  //**********************************************************************************************
880 
881  //**Subtraction assignment to row-major dense matrices******************************************
894  template< typename MT > // Type of the target dense matrix
895  friend inline void subAssign( DenseMatrix<MT,false>& lhs, const SVecTDVecMultExpr& rhs )
896  {
898 
899  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
900  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
901 
902  LT x( rhs.lhs_ ); // Evaluation of the left-hand side sparse vector operand
903  RT y( rhs.rhs_ ); // Evaluation of the right-hand side dense vector operand
904 
905  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
906  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
907  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
908  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
909 
910  SVecTDVecMultExpr::selectSubAssignKernel( ~lhs, x, y );
911  }
913  //**********************************************************************************************
914 
915  //**Default subtraction assignment to row-major dense matrices**********************************
929  template< typename MT // Type of the left-hand side target matrix
930  , typename VT3 // Type of the left-hand side vector operand
931  , typename VT4 > // Type of the right-hand side vector operand
932  static inline typename EnableIf< UseDefaultKernel<MT,VT3,VT4> >::Type
933  selectSubAssignKernel( DenseMatrix<MT,false>& A, const VT3& x, const VT4& y )
934  {
936 
937  const ConstIterator end( x.end() );
938 
939  for( ConstIterator element=x.begin(); element!=end; ++element ) {
940  if( !isDefault( element->value() ) ) {
941  for( size_t i=0UL; i<y.size(); ++i ) {
942  (~A)(element->index(),i) -= element->value() * y[i];
943  }
944  }
945  }
946  }
948  //**********************************************************************************************
949 
950  //**Vectorized subtraction assignment to row-major dense matrices*******************************
964  template< typename MT // Type of the left-hand side target matrix
965  , typename VT3 // Type of the left-hand side vector operand
966  , typename VT4 > // Type of the right-hand side vector operand
967  static inline typename EnableIf< UseVectorizedKernel<MT,VT3,VT4> >::Type
968  selectSubAssignKernel( DenseMatrix<MT,false>& A, const VT3& x, const VT4& y )
969  {
971 
972  typedef IntrinsicTrait<ElementType> IT;
973  typedef typename IT::Type IntrinsicType;
974 
975  const ConstIterator begin( x.begin() );
976  const ConstIterator end ( x.end() );
977 
978  for( ConstIterator element=begin; element!=end; ++element )
979  {
980  const IntrinsicType x1( set( element->value() ) );
981 
982  for( size_t j=0UL; j<(~A).columns(); j+=IT::size ) {
983  (~A).store( element->index(), j, (~A).load(element->index(),j) - x1 * y.load(j) );
984  }
985  }
986  }
988  //**********************************************************************************************
989 
990  //**Subtraction assignment to column-major dense matrices***************************************
1006  template< typename MT > // Type of the target dense matrix
1007  friend inline typename EnableIf< UseAssign<MT> >::Type
1008  subAssign( DenseMatrix<MT,true>& lhs, const SVecTDVecMultExpr& rhs )
1009  {
1011 
1012  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
1013  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
1014 
1016 
1017  LT x( rhs.lhs_ ); // Evaluation of the left-hand side sparse vector operand
1018  RT y( rhs.rhs_ ); // Evaluation of the right-hand side dense vector operand
1019 
1020  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
1021  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
1022  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
1023  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
1024 
1025  const ConstIterator end( x.end() );
1026 
1027  for( size_t i=0UL; i<y.size(); ++i ) {
1028  if( !isDefault( y[i] ) ) {
1029  for( ConstIterator element=x.begin(); element!=end; ++element ) {
1030  (~lhs)(element->index(),i) -= element->value() * y[i];
1031  }
1032  }
1033  }
1034  }
1036  //**********************************************************************************************
1037 
1038  //**Subtraction assignment to sparse matrices***************************************************
1039  // No special implementation for the subtraction assignment to sparse matrices.
1040  //**********************************************************************************************
1041 
1042  //**Multiplication assignment to dense matrices*************************************************
1043  // No special implementation for the multiplication assignment to dense matrices.
1044  //**********************************************************************************************
1045 
1046  //**Multiplication assignment to sparse matrices************************************************
1047  // No special implementation for the multiplication assignment to sparse matrices.
1048  //**********************************************************************************************
1049 
1050  //**Compile time checks*************************************************************************
1057  //**********************************************************************************************
1058 };
1059 //*************************************************************************************************
1060 
1061 
1062 
1063 
1064 //=================================================================================================
1065 //
1066 // GLOBAL BINARY ARITHMETIC OPERATORS
1067 //
1068 //=================================================================================================
1069 
1070 //*************************************************************************************************
1099 template< typename T1 // Type of the left-hand side sparse vector
1100  , typename T2 > // Type of the right-hand side dense vector
1101 inline const SVecTDVecMultExpr<T1,T2>
1103 {
1105 
1106  return SVecTDVecMultExpr<T1,T2>( ~lhs, ~rhs );
1107 }
1108 //*************************************************************************************************
1109 
1110 
1111 
1112 
1113 //=================================================================================================
1114 //
1115 // EXPRESSION TRAIT SPECIALIZATIONS
1116 //
1117 //=================================================================================================
1118 
1119 //*************************************************************************************************
1121 template< typename VT1, typename VT2, bool AF >
1122 struct SubmatrixExprTrait< SVecTDVecMultExpr<VT1,VT2>, AF >
1123 {
1124  public:
1125  //**********************************************************************************************
1126  typedef typename MultExprTrait< typename SubvectorExprTrait<const VT1,AF>::Type
1127  , typename SubvectorExprTrait<const VT2,AF>::Type >::Type Type;
1128  //**********************************************************************************************
1129 };
1131 //*************************************************************************************************
1132 
1133 
1134 //*************************************************************************************************
1136 template< typename VT1, typename VT2 >
1137 struct RowExprTrait< SVecTDVecMultExpr<VT1,VT2> >
1138 {
1139  public:
1140  //**********************************************************************************************
1141  typedef typename MultExprTrait< typename VT1::ReturnType, VT2 >::Type Type;
1142  //**********************************************************************************************
1143 };
1145 //*************************************************************************************************
1146 
1147 
1148 //*************************************************************************************************
1150 template< typename VT1, typename VT2 >
1151 struct ColumnExprTrait< SVecTDVecMultExpr<VT1,VT2> >
1152 {
1153  public:
1154  //**********************************************************************************************
1155  typedef typename MultExprTrait< VT1, typename VT2::ReturnType >::Type Type;
1156  //**********************************************************************************************
1157 };
1159 //*************************************************************************************************
1160 
1161 } // namespace blaze
1162 
1163 #endif
std::forward_iterator_tag IteratorCategory
The iterator category.
Definition: SVecTDVecMultExpr.h:215
Pointer difference type of the Blaze library.
ValueType value_type
Type of the underlying pointers.
Definition: SVecTDVecMultExpr.h:223
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
EnableIf< IsIntegral< T >, Load< T, sizeof(T)> >::Type::Type load(const T *address)
Loads a vector of integral values.
Definition: Load.h:222
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:4075
ResultType::OppositeType OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: SVecTDVecMultExpr.h:171
Iterator over the elements of the sparse vector-dense vector outer product expression.
Definition: SVecTDVecMultExpr.h:202
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: SVecTDVecMultExpr.h:448
RightOperand rightOperand() const
Returns the right-hand side dense vector operand.
Definition: SVecTDVecMultExpr.h:436
#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
bool isDefault(const DynamicMatrix< Type, SO > &m)
Returns whether the given dense matrix is in default state.
Definition: DynamicMatrix.h:4622
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:197
SelectType< IsExpression< VT2 >::value, const VT2, const VT2 & >::Type RightOperand
Composite type of the right-hand side dense vector expression.
Definition: SVecTDVecMultExpr.h:185
Header file for the ColumnExprTrait class template.
ConstIterator begin(size_t i) const
Returns an iterator to the first non-zero element of column i.
Definition: SVecTDVecMultExpr.h:363
Expression object for sparse vector-dense vector outer products.The SVecTDVecMultExpr class represent...
Definition: Forward.h:117
VT1::ResultType RT1
Result type of the left-hand side sparse vector expression.
Definition: SVecTDVecMultExpr.h:97
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2384
size_t index() const
Access to the current index of the sparse element.
Definition: SVecTDVecMultExpr.h:284
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:249
void UNUSED_PARAMETER(const T1 &)
Suppression of unused parameter warnings.
Definition: Unused.h:84
SelectType< IsComputation< VT1 >::value, const RT1, CT1 >::Type LT
Type for the assignment of the left-hand side dense vector operand.
Definition: SVecTDVecMultExpr.h:188
ConstIterator end(size_t i) const
Returns an iterator just past the last non-zero element of column i.
Definition: SVecTDVecMultExpr.h:374
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
ConstIterator(IteratorType it, RightElement v)
Constructor for the ConstIterator class.
Definition: SVecTDVecMultExpr.h:232
const Element operator*() const
Direct access to the sparse matrix element at the current iterator position.
Definition: SVecTDVecMultExpr.h:254
RightOperand rhs_
Right-hand side dense vector of the multiplication expression.
Definition: SVecTDVecMultExpr.h:468
Base class for dense matrices.The DenseMatrix class is a base class for all dense matrix classes...
Definition: DenseMatrix.h:70
Constraint on the data type.
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: SVecTDVecMultExpr.h:219
DifferenceType difference_type
Difference between two iterators.
Definition: SVecTDVecMultExpr.h:226
Header file for the SparseMatrix base class.
Constraint on the data type.
Header file for the MultExprTrait class template.
IteratorType it_
Iterator over the elements of the left-hand side sparse vector expression.
Definition: SVecTDVecMultExpr.h:324
SVecTDVecMultExpr(const VT1 &lhs, const VT2 &rhs)
Constructor for the SVecTDVecMultExpr class.
Definition: SVecTDVecMultExpr.h:336
Header file for the ValueIndexPair class.
SelectType< IsComputation< VT2 >::value, const RT2, CT2 >::Type RT
Type for the assignment of the right-hand side dense vector operand.
Definition: SVecTDVecMultExpr.h:191
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.
RemoveReference< LeftOperand >::Type::ConstIterator IteratorType
Iterator type of the sparse vector expression.
Definition: SVecTDVecMultExpr.h:210
size_t columns() const
Returns the current number of columns of the matrix.
Definition: SVecTDVecMultExpr.h:394
VT2::CompositeType CT2
Composite type of the right-hand side dense vector expression.
Definition: SVecTDVecMultExpr.h:102
bool operator!=(const ConstIterator &rhs) const
Inequality comparison between two ConstIterator objects.
Definition: SVecTDVecMultExpr.h:306
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2388
MultExprTrait< RN1, RN2 >::Type ExprReturnType
Expression return type for the subscript operator.
Definition: SVecTDVecMultExpr.h:117
Element ValueType
Type of the underlying pointers.
Definition: SVecTDVecMultExpr.h:216
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:179
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
ET2 RightElement
Element type of the dense vector expression.
Definition: SVecTDVecMultExpr.h:213
Constraint on the data type.
VT2::ResultType RT2
Result type of the right-hand side dense vector expression.
Definition: SVecTDVecMultExpr.h:98
size_t rows() const
Returns the current number of rows of the matrix.
Definition: SVecTDVecMultExpr.h:384
RightElement v_
Element of the right-hand side dense vector expression.
Definition: SVecTDVecMultExpr.h:325
Constraint on the data type.
SelectType< useAssign, const ResultType, const SVecTDVecMultExpr & >::Type CompositeType
Data type for composite expression templates.
Definition: SVecTDVecMultExpr.h:179
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2382
SVecTDVecMultExpr< VT1, VT2 > This
Type of this SVecTDVecMultExpr instance.
Definition: SVecTDVecMultExpr.h:169
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 sparse vector expression.
Definition: SVecTDVecMultExpr.h:101
ReferenceType reference
Reference return type.
Definition: SVecTDVecMultExpr.h:225
bool operator==(const ConstIterator &rhs) const
Equality comparison between two ConstIterator objects.
Definition: SVecTDVecMultExpr.h:295
Header file for the IsNumeric type trait.
VT2::ReturnType RN2
Return type of the right-hand side dense vector expression.
Definition: SVecTDVecMultExpr.h:100
const SelectType< returnExpr, ExprReturnType, ElementType >::Type ReturnType
Return type for expression template evaluations.
Definition: SVecTDVecMultExpr.h:176
Header file for the SubmatrixExprTrait class template.
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2383
Removal of reference modifiers.The RemoveCV type trait removes any reference modifiers from the given...
Definition: RemoveReference.h:69
IteratorCategory iterator_category
The iterator category.
Definition: SVecTDVecMultExpr.h:222
Intrinsic characteristics of data types.The IntrinsicTrait class template provides the intrinsic char...
Definition: IntrinsicTrait.h:748
Header file for run time assertion macros.
Base template for the MultTrait class.
Definition: MultTrait.h:141
ReturnType value() const
Access to the current value of the sparse element.
Definition: SVecTDVecMultExpr.h:274
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:209
LeftOperand leftOperand() const
Returns the left-hand side sparse vector operand.
Definition: SVecTDVecMultExpr.h:426
Substitution Failure Is Not An Error (SFINAE) class.The EnableIf class template is an auxiliary tool ...
Definition: EnableIf.h:184
VT2::ElementType ET2
Element type of the right-hand side dense vector expression.
Definition: SVecTDVecMultExpr.h:104
ResultType::ElementType ElementType
Resulting element type.
Definition: SVecTDVecMultExpr.h:173
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: SVecTDVecMultExpr.h:460
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:239
Header file for the isDefault shim.
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: SVecTDVecMultExpr.h:172
ValueType * PointerType
Pointer return type.
Definition: SVecTDVecMultExpr.h:217
VT1::ElementType ET1
Element type of the left-hand side sparse vector expression.
Definition: SVecTDVecMultExpr.h:103
ValueIndexPair< ElementType > Element
Element type of the sparse matrix expression.
Definition: SVecTDVecMultExpr.h:207
Header file for the RemoveReference type trait.
LeftOperand lhs_
Left-hand side sparse vector of the multiplication expression.
Definition: SVecTDVecMultExpr.h:467
Header file for all intrinsic functionality.
PointerType pointer
Pointer return type.
Definition: SVecTDVecMultExpr.h:224
DifferenceType operator-(const ConstIterator &rhs) const
Calculating the number of elements between two expression iterators.
Definition: SVecTDVecMultExpr.h:317
#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
Index-value-pair for sparse vectors and matrices.The ValueIndexPair class represents a single index-v...
Definition: ValueIndexPair.h:69
Header file for the IsComputation type trait class.
const ConstIterator * operator->() const
Direct access to the sparse matrix element at the current iterator position.
Definition: SVecTDVecMultExpr.h:264
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:105
#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:2379
Header file for basic type definitions.
ConstIterator & operator++()
Pre-increment operator.
Definition: SVecTDVecMultExpr.h:243
#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.
ValueType & ReferenceType
Reference return type.
Definition: SVecTDVecMultExpr.h:218
MultTrait< RT1, RT2 >::Type ResultType
Result type for expression template evaluations.
Definition: SVecTDVecMultExpr.h:170
VT1::ReturnType RN1
Return type of the left-hand side sparse vector expression.
Definition: SVecTDVecMultExpr.h:99
size_t nonZeros(size_t i) const
Returns the number of non-zero elements in the specified column.
Definition: SVecTDVecMultExpr.h:415
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: SVecTDVecMultExpr.h:349
Evaluation of the resulting expression type of a multiplication.Via this type trait it is possible to...
Definition: MultExprTrait.h:137
SelectType< IsExpression< VT1 >::value, const VT1, const VT1 & >::Type LeftOperand
Composite type of the left-hand side sparse vector expression.
Definition: SVecTDVecMultExpr.h:182
#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
EnableIf< IsIntegral< T >, Set< T, sizeof(T)> >::Type::Type set(T value)
Sets all values in the vector to the given integral value.
Definition: Set.h:209
void store(float *address, const sse_float_t &value)
Aligned store of a vector of &#39;float&#39; values.
Definition: Store.h:242
Header file for the IsExpression type trait class.
size_t nonZeros() const
Returns the number of non-zero elements in the sparse matrix.
Definition: SVecTDVecMultExpr.h:404
Header file for the FunctionTrace class.