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  //**ConstIterator class definition**************************************************************
198  {
199  public:
200  //**Type definitions*************************************************************************
203 
206 
208  typedef ET2 RightElement;
209 
210  typedef std::forward_iterator_tag IteratorCategory;
211  typedef Element ValueType;
215 
216  // STL iterator requirements
222  //*******************************************************************************************
223 
224  //**Constructor******************************************************************************
228  : it_( it ) // Iterator over the elements of the left-hand side sparse vector expression
229  , v_ ( v ) // Element of the right-hand side dense vector expression.
230  {}
231  //*******************************************************************************************
232 
233  //**Prefix increment operator****************************************************************
239  ++it_;
240  return *this;
241  }
242  //*******************************************************************************************
243 
244  //**Element access operator******************************************************************
249  inline const Element operator*() const {
250  return Element( it_->value() * v_, it_->index() );
251  }
252  //*******************************************************************************************
253 
254  //**Element access operator******************************************************************
259  inline const ConstIterator* operator->() const {
260  return this;
261  }
262  //*******************************************************************************************
263 
264  //**Value function***************************************************************************
269  inline ReturnType value() const {
270  return it_->value() * v_;
271  }
272  //*******************************************************************************************
273 
274  //**Index function***************************************************************************
279  inline size_t index() const {
280  return it_->index();
281  }
282  //*******************************************************************************************
283 
284  //**Equality operator************************************************************************
290  inline bool operator==( const ConstIterator& rhs ) const {
291  return it_ == rhs.it_;
292  }
293  //*******************************************************************************************
294 
295  //**Inequality operator**********************************************************************
301  inline bool operator!=( const ConstIterator& rhs ) const {
302  return it_ != rhs.it_;
303  }
304  //*******************************************************************************************
305 
306  //**Subtraction operator*********************************************************************
312  inline DifferenceType operator-( const ConstIterator& rhs ) const {
313  return it_ - rhs.it_;
314  }
315  //*******************************************************************************************
316 
317  private:
318  //**Member variables*************************************************************************
321  //*******************************************************************************************
322  };
323  //**********************************************************************************************
324 
325  //**Constructor*********************************************************************************
331  explicit inline SVecTDVecMultExpr( const VT1& lhs, const VT2& rhs )
332  : lhs_( lhs ) // Left-hand side sparse vector of the multiplication expression
333  , rhs_( rhs ) // Right-hand side dense vector of the multiplication expression
334  {}
335  //**********************************************************************************************
336 
337  //**Access operator*****************************************************************************
344  inline ReturnType operator()( size_t i, size_t j ) const {
345  BLAZE_INTERNAL_ASSERT( i < lhs_.size(), "Invalid row access index" );
346  BLAZE_INTERNAL_ASSERT( j < rhs_.size(), "Invalid column access index" );
347 
348  return lhs_[i] * rhs_[j];
349  }
350  //**********************************************************************************************
351 
352  //**Begin function******************************************************************************
358  inline ConstIterator begin( size_t i ) const {
359  return ConstIterator( lhs_.begin(), rhs_[i] );
360  }
361  //**********************************************************************************************
362 
363  //**End function********************************************************************************
369  inline ConstIterator end( size_t i ) const {
370  return ConstIterator( lhs_.end(), rhs_[i] );
371  }
372  //**********************************************************************************************
373 
374  //**Rows function*******************************************************************************
379  inline size_t rows() const {
380  return lhs_.size();
381  }
382  //**********************************************************************************************
383 
384  //**Columns function****************************************************************************
389  inline size_t columns() const {
390  return rhs_.size();
391  }
392  //**********************************************************************************************
393 
394  //**NonZeros function***************************************************************************
399  inline size_t nonZeros() const {
400  return lhs_.nonZeros() * rhs_.size();
401  }
402  //**********************************************************************************************
403 
404  //**NonZeros function***************************************************************************
410  inline size_t nonZeros( size_t i ) const {
411  UNUSED_PARAMETER( i );
412  return lhs_.nonZeros();
413  }
414  //**********************************************************************************************
415 
416  //**Left operand access*************************************************************************
421  inline LeftOperand leftOperand() const {
422  return lhs_;
423  }
424  //**********************************************************************************************
425 
426  //**Right operand access************************************************************************
431  inline RightOperand rightOperand() const {
432  return rhs_;
433  }
434  //**********************************************************************************************
435 
436  //**********************************************************************************************
442  template< typename T >
443  inline bool canAlias( const T* alias ) const {
444  return ( lhs_.canAlias( alias ) || rhs_.canAlias( alias ) );
445  }
446  //**********************************************************************************************
447 
448  //**********************************************************************************************
454  template< typename T >
455  inline bool isAliased( const T* alias ) const {
456  return ( lhs_.isAliased( alias ) || rhs_.isAliased( alias ) );
457  }
458  //**********************************************************************************************
459 
460  private:
461  //**Member variables****************************************************************************
462  LeftOperand lhs_;
463  RightOperand rhs_;
464  //**********************************************************************************************
465 
466  //**Assignment to row-major dense matrices******************************************************
478  template< typename MT > // Type of the target dense matrix
479  friend inline void assign( DenseMatrix<MT,false>& lhs, const SVecTDVecMultExpr& rhs )
480  {
482 
483  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
484  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
485 
486  LT x( rhs.lhs_ ); // Evaluation of the left-hand side sparse vector operand
487  RT y( rhs.rhs_ ); // Evaluation of the right-hand side dense vector operand
488 
489  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
490  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
491  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
492  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
493 
494  SVecTDVecMultExpr::selectAssignKernel( ~lhs, x, y );
495  }
497  //**********************************************************************************************
498 
499  //**Default assignment to row-major dense matrices**********************************************
513  template< typename MT // Type of the left-hand side target matrix
514  , typename VT3 // Type of the left-hand side vector operand
515  , typename VT4 > // Type of the right-hand side vector operand
516  static inline typename EnableIf< UseDefaultKernel<MT,VT3,VT4> >::Type
517  selectAssignKernel( DenseMatrix<MT,false>& A, const VT3& x, const VT4& y )
518  {
520 
521  const ConstIterator end( x.end() );
522 
523  for( ConstIterator element=x.begin(); element!=end; ++element ) {
524  if( !isDefault( element->value() ) ) {
525  for( size_t j=0UL; j<y.size(); ++j ) {
526  (~A)(element->index(),j) = element->value() * y[j];
527  }
528  }
529  }
530  }
532  //**********************************************************************************************
533 
534  //**Vectorized assignment to row-major dense matrices*******************************************
548  template< typename MT // Type of the left-hand side target matrix
549  , typename VT3 // Type of the left-hand side vector operand
550  , typename VT4 > // Type of the right-hand side vector operand
551  static inline typename EnableIf< UseVectorizedKernel<MT,VT3,VT4> >::Type
552  selectAssignKernel( DenseMatrix<MT,false>& A, const VT3& x, const VT4& y )
553  {
555 
556  typedef IntrinsicTrait<ElementType> IT;
557  typedef typename IT::Type IntrinsicType;
558 
559  const ConstIterator begin( x.begin() );
560  const ConstIterator end ( x.end() );
561 
562  for( ConstIterator element=begin; element!=end; ++element )
563  {
564  const IntrinsicType x1( set( element->value() ) );
565 
566  for( size_t j=0UL; j<(~A).columns(); j+=IT::size ) {
567  (~A).store( element->index(), j, x1 * y.load(j) );
568  }
569  }
570  }
572  //**********************************************************************************************
573 
574  //**Assignment to column-major dense matrices***************************************************
590  template< typename MT > // Type of the target dense matrix
591  friend inline typename EnableIf< UseAssign<MT> >::Type
592  assign( DenseMatrix<MT,true>& lhs, const SVecTDVecMultExpr& rhs )
593  {
595 
596  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
597  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
598 
600 
601  LT x( rhs.lhs_ ); // Evaluation of the left-hand side sparse vector operand
602  RT y( rhs.rhs_ ); // Evaluation of the right-hand side dense vector operand
603 
604  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
605  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
606  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
607  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
608 
609  const ConstIterator end( x.end() );
610 
611  for( size_t i=0UL; i<y.size(); ++i ) {
612  if( !isDefault( y[i] ) ) {
613  for( ConstIterator element=x.begin(); element!=end; ++element ) {
614  (~lhs)(element->index(),i) = element->value() * y[i];
615  }
616  }
617  }
618  }
620  //**********************************************************************************************
621 
622  //**Assignment to row-major sparse matrices*****************************************************
634  template< typename MT > // Type of the target sparse matrix
635  friend inline void assign( SparseMatrix<MT,false>& lhs, const SVecTDVecMultExpr& rhs )
636  {
638 
639  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
640  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
641 
643 
644  LT x( rhs.lhs_ ); // Evaluation of the left-hand side sparse vector operand
645  RT y( rhs.rhs_ ); // Evaluation of the right-hand side dense vector operand
646 
647  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
648  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
649  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
650  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
651 
652  const ConstIterator end( x.end() );
653 
654  for( ConstIterator element=x.begin(); element!=end; ++element ) {
655  if( !isDefault( element->value() ) ) {
656  (~lhs).reserve( element->index(), y.size() );
657  for( size_t i=0UL; i<y.size(); ++i ) {
658  (~lhs).append( element->index(), i, element->value() * y[i] );
659  }
660  }
661  }
662  }
664  //**********************************************************************************************
665 
666  //**Assignment to column-major sparse matrices**************************************************
682  template< typename MT > // Type of the target sparse matrix
683  friend inline typename EnableIf< UseAssign<MT> >::Type
684  assign( SparseMatrix<MT,true>& lhs, const SVecTDVecMultExpr& rhs )
685  {
687 
688  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
689  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
690 
692 
693  LT x( rhs.lhs_ ); // Evaluation of the left-hand side sparse vector operand
694  RT y( rhs.rhs_ ); // Evaluation of the right-hand side dense vector operand
695 
696  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
697  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
698  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
699  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
700 
701  const ConstIterator end( x.end() );
702 
703  for( size_t i=0UL; i<y.size(); ++i ) {
704  if( !isDefault( y[i] ) ) {
705  (~lhs).reserve( i, x.nonZeros() );
706  for( ConstIterator element=x.begin(); element!=end; ++element ) {
707  (~lhs).append( element->index(), i, element->value() * y[i] );
708  }
709  }
710  }
711  }
713  //**********************************************************************************************
714 
715  //**Addition assignment to row-major dense matrices*********************************************
728  template< typename MT > // Type of the target dense matrix
729  friend inline void addAssign( DenseMatrix<MT,false>& lhs, const SVecTDVecMultExpr& rhs )
730  {
732 
733  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
734  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
735 
736  LT x( rhs.lhs_ ); // Evaluation of the left-hand side sparse vector operand
737  RT y( rhs.rhs_ ); // Evaluation of the right-hand side dense vector operand
738 
739  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
740  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
741  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
742  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
743 
744  SVecTDVecMultExpr::selectAddAssignKernel( ~lhs, x, y );
745  }
747  //**********************************************************************************************
748 
749  //**Default addition assignment to row-major dense matrices*************************************
763  template< typename MT // Type of the left-hand side target matrix
764  , typename VT3 // Type of the left-hand side vector operand
765  , typename VT4 > // Type of the right-hand side vector operand
766  static inline typename EnableIf< UseDefaultKernel<MT,VT3,VT4> >::Type
767  selectAddAssignKernel( DenseMatrix<MT,false>& A, const VT3& x, const VT4& y )
768  {
770 
771  const ConstIterator end( x.end() );
772 
773  for( ConstIterator element=x.begin(); element!=end; ++element ) {
774  if( !isDefault( element->value() ) ) {
775  for( size_t i=0UL; i<y.size(); ++i ) {
776  (~A)(element->index(),i) += element->value() * y[i];
777  }
778  }
779  }
780  }
782  //**********************************************************************************************
783 
784  //**Vectorized addition assignment to row-major dense matrices**********************************
798  template< typename MT // Type of the left-hand side target matrix
799  , typename VT3 // Type of the left-hand side vector operand
800  , typename VT4 > // Type of the right-hand side vector operand
801  static inline typename EnableIf< UseVectorizedKernel<MT,VT3,VT4> >::Type
802  selectAddAssignKernel( DenseMatrix<MT,false>& A, const VT3& x, const VT4& y )
803  {
805 
806  typedef IntrinsicTrait<ElementType> IT;
807  typedef typename IT::Type IntrinsicType;
808 
809  const ConstIterator begin( x.begin() );
810  const ConstIterator end ( x.end() );
811 
812  for( ConstIterator element=begin; element!=end; ++element )
813  {
814  const IntrinsicType x1( set( element->value() ) );
815 
816  for( size_t j=0UL; j<(~A).columns(); j+=IT::size ) {
817  (~A).store( element->index(), j, (~A).load(element->index(),j) + x1 * y.load(j) );
818  }
819  }
820  }
822  //**********************************************************************************************
823 
824  //**Addition assignment to column-major dense matrices******************************************
840  template< typename MT > // Type of the target dense matrix
841  friend inline typename EnableIf< UseAssign<MT> >::Type
842  addAssign( DenseMatrix<MT,true>& lhs, const SVecTDVecMultExpr& rhs )
843  {
845 
846  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
847  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
848 
850 
851  LT x( rhs.lhs_ ); // Evaluation of the left-hand side sparse vector operand
852  RT y( rhs.rhs_ ); // Evaluation of the right-hand side dense vector operand
853 
854  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
855  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
856  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
857  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
858 
859  const ConstIterator end( x.end() );
860 
861  for( size_t i=0UL; i<y.size(); ++i ) {
862  if( !isDefault( y[i] ) ) {
863  for( ConstIterator element=x.begin(); element!=end; ++element ) {
864  (~lhs)(element->index(),i) += element->value() * y[i];
865  }
866  }
867  }
868  }
870  //**********************************************************************************************
871 
872  //**Addition assignment to sparse matrices******************************************************
873  // No special implementation for the addition assignment to sparse matrices.
874  //**********************************************************************************************
875 
876  //**Subtraction assignment to row-major dense matrices******************************************
889  template< typename MT > // Type of the target dense matrix
890  friend inline void subAssign( DenseMatrix<MT,false>& lhs, const SVecTDVecMultExpr& rhs )
891  {
893 
894  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
895  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
896 
897  LT x( rhs.lhs_ ); // Evaluation of the left-hand side sparse vector operand
898  RT y( rhs.rhs_ ); // Evaluation of the right-hand side dense vector operand
899 
900  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
901  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
902  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
903  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
904 
905  SVecTDVecMultExpr::selectSubAssignKernel( ~lhs, x, y );
906  }
908  //**********************************************************************************************
909 
910  //**Default subtraction assignment to row-major dense matrices**********************************
924  template< typename MT // Type of the left-hand side target matrix
925  , typename VT3 // Type of the left-hand side vector operand
926  , typename VT4 > // Type of the right-hand side vector operand
927  static inline typename EnableIf< UseDefaultKernel<MT,VT3,VT4> >::Type
928  selectSubAssignKernel( DenseMatrix<MT,false>& A, const VT3& x, const VT4& y )
929  {
931 
932  const ConstIterator end( x.end() );
933 
934  for( ConstIterator element=x.begin(); element!=end; ++element ) {
935  if( !isDefault( element->value() ) ) {
936  for( size_t i=0UL; i<y.size(); ++i ) {
937  (~A)(element->index(),i) -= element->value() * y[i];
938  }
939  }
940  }
941  }
943  //**********************************************************************************************
944 
945  //**Vectorized subtraction assignment to row-major dense matrices*******************************
959  template< typename MT // Type of the left-hand side target matrix
960  , typename VT3 // Type of the left-hand side vector operand
961  , typename VT4 > // Type of the right-hand side vector operand
962  static inline typename EnableIf< UseVectorizedKernel<MT,VT3,VT4> >::Type
963  selectSubAssignKernel( DenseMatrix<MT,false>& A, const VT3& x, const VT4& y )
964  {
966 
967  typedef IntrinsicTrait<ElementType> IT;
968  typedef typename IT::Type IntrinsicType;
969 
970  const ConstIterator begin( x.begin() );
971  const ConstIterator end ( x.end() );
972 
973  for( ConstIterator element=begin; element!=end; ++element )
974  {
975  const IntrinsicType x1( set( element->value() ) );
976 
977  for( size_t j=0UL; j<(~A).columns(); j+=IT::size ) {
978  (~A).store( element->index(), j, (~A).load(element->index(),j) - x1 * y.load(j) );
979  }
980  }
981  }
983  //**********************************************************************************************
984 
985  //**Subtraction assignment to column-major dense matrices***************************************
1001  template< typename MT > // Type of the target dense matrix
1002  friend inline typename EnableIf< UseAssign<MT> >::Type
1003  subAssign( DenseMatrix<MT,true>& lhs, const SVecTDVecMultExpr& rhs )
1004  {
1006 
1007  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
1008  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
1009 
1011 
1012  LT x( rhs.lhs_ ); // Evaluation of the left-hand side sparse vector operand
1013  RT y( rhs.rhs_ ); // Evaluation of the right-hand side dense vector operand
1014 
1015  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
1016  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
1017  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
1018  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
1019 
1020  const ConstIterator end( x.end() );
1021 
1022  for( size_t i=0UL; i<y.size(); ++i ) {
1023  if( !isDefault( y[i] ) ) {
1024  for( ConstIterator element=x.begin(); element!=end; ++element ) {
1025  (~lhs)(element->index(),i) -= element->value() * y[i];
1026  }
1027  }
1028  }
1029  }
1031  //**********************************************************************************************
1032 
1033  //**Subtraction assignment to sparse matrices***************************************************
1034  // No special implementation for the subtraction assignment to sparse matrices.
1035  //**********************************************************************************************
1036 
1037  //**Multiplication assignment to dense matrices*************************************************
1038  // No special implementation for the multiplication assignment to dense matrices.
1039  //**********************************************************************************************
1040 
1041  //**Multiplication assignment to sparse matrices************************************************
1042  // No special implementation for the multiplication assignment to sparse matrices.
1043  //**********************************************************************************************
1044 
1045  //**Compile time checks*************************************************************************
1052  //**********************************************************************************************
1053 };
1054 //*************************************************************************************************
1055 
1056 
1057 
1058 
1059 //=================================================================================================
1060 //
1061 // GLOBAL BINARY ARITHMETIC OPERATORS
1062 //
1063 //=================================================================================================
1064 
1065 //*************************************************************************************************
1094 template< typename T1 // Type of the left-hand side sparse vector
1095  , typename T2 > // Type of the right-hand side dense vector
1096 inline const SVecTDVecMultExpr<T1,T2>
1098 {
1100 
1101  return SVecTDVecMultExpr<T1,T2>( ~lhs, ~rhs );
1102 }
1103 //*************************************************************************************************
1104 
1105 
1106 
1107 
1108 //=================================================================================================
1109 //
1110 // EXPRESSION TRAIT SPECIALIZATIONS
1111 //
1112 //=================================================================================================
1113 
1114 //*************************************************************************************************
1116 template< typename VT1, typename VT2 >
1117 struct SubmatrixExprTrait< SVecTDVecMultExpr<VT1,VT2> >
1118 {
1119  public:
1120  //**********************************************************************************************
1121  typedef typename MultExprTrait< typename SubvectorExprTrait<const VT1>::Type
1122  , typename SubvectorExprTrait<const VT2>::Type >::Type Type;
1123  //**********************************************************************************************
1124 };
1126 //*************************************************************************************************
1127 
1128 
1129 //*************************************************************************************************
1131 template< typename VT1, typename VT2 >
1132 struct RowExprTrait< SVecTDVecMultExpr<VT1,VT2> >
1133 {
1134  public:
1135  //**********************************************************************************************
1136  typedef typename MultExprTrait< typename VT1::ReturnType, VT2 >::Type Type;
1137  //**********************************************************************************************
1138 };
1140 //*************************************************************************************************
1141 
1142 
1143 //*************************************************************************************************
1145 template< typename VT1, typename VT2 >
1146 struct ColumnExprTrait< SVecTDVecMultExpr<VT1,VT2> >
1147 {
1148  public:
1149  //**********************************************************************************************
1150  typedef typename MultExprTrait< VT1, typename VT2::ReturnType >::Type Type;
1151  //**********************************************************************************************
1152 };
1154 //*************************************************************************************************
1155 
1156 } // namespace blaze
1157 
1158 #endif
std::forward_iterator_tag IteratorCategory
The iterator category.
Definition: SVecTDVecMultExpr.h:210
Pointer difference type of the Blaze library.
ValueType value_type
Type of the underlying pointers.
Definition: SVecTDVecMultExpr.h:218
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:3703
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:197
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: SVecTDVecMultExpr.h:443
RightOperand rightOperand() const
Returns the right-hand side dense vector operand.
Definition: SVecTDVecMultExpr.h:431
#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:4555
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:196
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:358
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:2375
size_t index() const
Access to the current index of the sparse element.
Definition: SVecTDVecMultExpr.h:279
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:248
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:369
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:227
const Element operator*() const
Direct access to the sparse matrix element at the current iterator position.
Definition: SVecTDVecMultExpr.h:249
RightOperand rhs_
Right-hand side dense vector of the multiplication expression.
Definition: SVecTDVecMultExpr.h:463
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:214
DifferenceType difference_type
Difference between two iterators.
Definition: SVecTDVecMultExpr.h:221
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:319
SVecTDVecMultExpr(const VT1 &lhs, const VT2 &rhs)
Constructor for the SVecTDVecMultExpr class.
Definition: SVecTDVecMultExpr.h:331
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:205
size_t columns() const
Returns the current number of columns of the matrix.
Definition: SVecTDVecMultExpr.h:389
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:301
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2379
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:211
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:208
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:379
RightElement v_
Element of the right-hand side dense vector expression.
Definition: SVecTDVecMultExpr.h:320
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:2373
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:220
bool operator==(const ConstIterator &rhs) const
Equality comparison between two ConstIterator objects.
Definition: SVecTDVecMultExpr.h:290
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:2374
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:217
Intrinsic characteristics of data types.The IntrinsicTrait class template provides the intrinsic char...
Definition: IntrinsicTrait.h:648
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:269
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:421
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:455
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:212
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:202
Header file for the RemoveReference type trait.
LeftOperand lhs_
Left-hand side sparse vector of the multiplication expression.
Definition: SVecTDVecMultExpr.h:462
Header file for all intrinsic functionality.
PointerType pointer
Pointer return type.
Definition: SVecTDVecMultExpr.h:219
DifferenceType operator-(const ConstIterator &rhs) const
Calculating the number of elements between two expression iterators.
Definition: SVecTDVecMultExpr.h:312
#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:259
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:2370
Header file for basic type definitions.
ConstIterator & operator++()
Pre-increment operator.
Definition: SVecTDVecMultExpr.h:238
#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:213
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:410
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: SVecTDVecMultExpr.h:344
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:399
Header file for the FunctionTrace class.