All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DVecTSVecMultExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_DVECTSVECMULTEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_DVECTSVECMULTEXPR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <iterator>
52 #include <blaze/math/Intrinsics.h>
65 #include <blaze/util/Assert.h>
67 #include <blaze/util/EnableIf.h>
69 #include <blaze/util/SelectType.h>
70 #include <blaze/util/Types.h>
73 #include <blaze/util/Unused.h>
74 
75 
76 namespace blaze {
77 
78 //=================================================================================================
79 //
80 // CLASS DVECTSVECMULTEXPR
81 //
82 //=================================================================================================
83 
84 //*************************************************************************************************
91 template< typename VT1 // Type of the left-hand side dense vector
92  , typename VT2 > // Type of the right-hand side sparse vector
93 class DVecTSVecMultExpr : public SparseMatrix< DVecTSVecMultExpr<VT1,VT2>, false >
94  , private VecTVecMultExpr
95  , private Computation
96 {
97  private:
98  //**Type definitions****************************************************************************
99  typedef typename VT1::ResultType RT1;
100  typedef typename VT2::ResultType RT2;
101  typedef typename VT1::ReturnType RN1;
102  typedef typename VT2::ReturnType RN2;
103  typedef typename VT1::CompositeType CT1;
104  typedef typename VT2::CompositeType CT2;
105  typedef typename VT1::ElementType ET1;
106  typedef typename VT2::ElementType ET2;
107  //**********************************************************************************************
108 
109  //**Return type evaluation**********************************************************************
111 
116  enum { returnExpr = !IsTemporary<RN1>::value && !IsTemporary<RN2>::value };
117 
120  //**********************************************************************************************
121 
122  //**Evaluation strategy*************************************************************************
124 
131  enum { useAssign = ( IsComputation<VT1>::value || !IsNumeric<ET1>::value ||
133 
135  template< typename MT >
137  struct UseAssign {
138  enum { value = useAssign };
139  };
141  //**********************************************************************************************
142 
143  //**********************************************************************************************
145 
148  template< typename T1, typename T2, typename T3 >
149  struct UseVectorizedKernel {
150  enum { value = T1::vectorizable && T2::vectorizable &&
154  };
156  //**********************************************************************************************
157 
158  //**********************************************************************************************
160 
163  template< typename T1, typename T2, typename T3 >
164  struct UseDefaultKernel {
165  enum { value = !UseVectorizedKernel<T1,T2,T3>::value };
166  };
168  //**********************************************************************************************
169 
170  public:
171  //**Type definitions****************************************************************************
177 
180 
183 
185  typedef typename SelectType< IsExpression<VT1>::value, const VT1, const VT1& >::Type LeftOperand;
186 
188  typedef typename SelectType< IsExpression<VT2>::value, const VT2, const VT2& >::Type RightOperand;
189 
191  typedef typename SelectType< IsComputation<VT1>::value, const RT1, CT1 >::Type LT;
192 
194  typedef typename SelectType< IsComputation<VT2>::value, const RT2, CT2 >::Type RT;
195  //**********************************************************************************************
196 
197  //**Compilation flags***************************************************************************
199  enum { smpAssignable = 0 };
200  //**********************************************************************************************
201 
202  //**ConstIterator class definition**************************************************************
206  {
207  public:
208  //**Type definitions*************************************************************************
211 
213  typedef ET1 LeftElement;
214 
217 
218  typedef std::forward_iterator_tag IteratorCategory;
219  typedef Element ValueType;
223 
224  // STL iterator requirements
230  //*******************************************************************************************
231 
232  //**Constructor******************************************************************************
236  : v_ ( v ) // Element of the left-hand side dense vector expression.
237  , it_( it ) // Iterator over the elements of the right-hand side sparse vector expression
238  {}
239  //*******************************************************************************************
240 
241  //**Prefix increment operator****************************************************************
247  ++it_;
248  return *this;
249  }
250  //*******************************************************************************************
251 
252  //**Element access operator******************************************************************
257  inline const Element operator*() const {
258  return Element( v_ * it_->value(), it_->index() );
259  }
260  //*******************************************************************************************
261 
262  //**Element access operator******************************************************************
267  inline const ConstIterator* operator->() const {
268  return this;
269  }
270  //*******************************************************************************************
271 
272  //**Value function***************************************************************************
277  inline ReturnType value() const {
278  return v_ * it_->value();
279  }
280  //*******************************************************************************************
281 
282  //**Index function***************************************************************************
287  inline size_t index() const {
288  return it_->index();
289  }
290  //*******************************************************************************************
291 
292  //**Equality operator************************************************************************
298  inline bool operator==( const ConstIterator& rhs ) const {
299  return it_ == rhs.it_;
300  }
301  //*******************************************************************************************
302 
303  //**Inequality operator**********************************************************************
309  inline bool operator!=( const ConstIterator& rhs ) const {
310  return it_ != rhs.it_;
311  }
312  //*******************************************************************************************
313 
314  //**Subtraction operator*********************************************************************
320  inline DifferenceType operator-( const ConstIterator& rhs ) const {
321  return it_ - rhs.it_;
322  }
323  //*******************************************************************************************
324 
325  private:
326  //**Member variables*************************************************************************
329  //*******************************************************************************************
330  };
331  //**********************************************************************************************
332 
333  //**Constructor*********************************************************************************
339  explicit inline DVecTSVecMultExpr( const VT1& lhs, const VT2& rhs )
340  : lhs_( lhs ) // Left-hand side dense vector of the multiplication expression
341  , rhs_( rhs ) // Right-hand side sparse vector of the multiplication expression
342  {}
343  //**********************************************************************************************
344 
345  //**Access operator*****************************************************************************
352  inline ReturnType operator()( size_t i, size_t j ) const {
353  BLAZE_INTERNAL_ASSERT( i < lhs_.size(), "Invalid row access index" );
354  BLAZE_INTERNAL_ASSERT( j < rhs_.size(), "Invalid column access index" );
355 
356  return lhs_[i] * rhs_[j];
357  }
358  //**********************************************************************************************
359 
360  //**Begin function******************************************************************************
366  inline ConstIterator begin( size_t i ) const {
367  return ConstIterator( lhs_[i], rhs_.begin() );
368  }
369  //**********************************************************************************************
370 
371  //**End function********************************************************************************
377  inline ConstIterator end( size_t i ) const {
378  return ConstIterator( lhs_[i], rhs_.end() );
379  }
380  //**********************************************************************************************
381 
382  //**Rows function*******************************************************************************
387  inline size_t rows() const {
388  return lhs_.size();
389  }
390  //**********************************************************************************************
391 
392  //**Columns function****************************************************************************
397  inline size_t columns() const {
398  return rhs_.size();
399  }
400  //**********************************************************************************************
401 
402  //**NonZeros function***************************************************************************
407  inline size_t nonZeros() const {
408  return lhs_.size() * rhs_.nonZeros();
409  }
410  //**********************************************************************************************
411 
412  //**NonZeros function***************************************************************************
418  inline size_t nonZeros( size_t i ) const {
419  UNUSED_PARAMETER( i );
420  return rhs_.nonZeros();
421  }
422  //**********************************************************************************************
423 
424  //**Left operand access*************************************************************************
429  inline LeftOperand leftOperand() const {
430  return lhs_;
431  }
432  //**********************************************************************************************
433 
434  //**Right operand access************************************************************************
439  inline RightOperand rightOperand() const {
440  return rhs_;
441  }
442  //**********************************************************************************************
443 
444  //**********************************************************************************************
450  template< typename T >
451  inline bool canAlias( const T* alias ) const {
452  return ( lhs_.canAlias( alias ) || rhs_.canAlias( alias ) );
453  }
454  //**********************************************************************************************
455 
456  //**********************************************************************************************
462  template< typename T >
463  inline bool isAliased( const T* alias ) const {
464  return ( lhs_.isAliased( alias ) || rhs_.isAliased( alias ) );
465  }
466  //**********************************************************************************************
467 
468  private:
469  //**Member variables****************************************************************************
470  LeftOperand lhs_;
471  RightOperand rhs_;
472  //**********************************************************************************************
473 
474  //**Assignment to row-major dense matrices******************************************************
489  template< typename MT > // Type of the target dense matrix
490  friend inline typename EnableIf< UseAssign<MT> >::Type
492  {
494 
495  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
496  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
497 
499 
500  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
501  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse vector operand
502 
503  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
504  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
505  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
506  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
507 
508  const ConstIterator begin( y.begin() );
509  const ConstIterator end ( y.end() );
510 
511  for( size_t i=0UL; i<(~lhs).rows(); ++i ) {
512  for( ConstIterator element=begin; element!=end; ++element ) {
513  (~lhs)(i,element->index()) = x[i] * element->value();
514  }
515  }
516  }
518  //**********************************************************************************************
519 
520  //**Assignment to column-major dense matrices***************************************************
533  template< typename MT > // Type of the target dense matrix
534  friend inline void assign( DenseMatrix<MT,true>& lhs, const DVecTSVecMultExpr& rhs )
535  {
537 
538  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
539  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
540 
541  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
542  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse vector operand
543 
544  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
545  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
546  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
547  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
548 
549  DVecTSVecMultExpr::selectAssignKernel( ~lhs, x, y );
550  }
552  //**********************************************************************************************
553 
554  //**Default assignment to column-major dense matrices*******************************************
568  template< typename MT // Type of the left-hand side target matrix
569  , typename VT3 // Type of the left-hand side vector operand
570  , typename VT4 > // Type of the right-hand side vector operand
571  static inline typename EnableIf< UseDefaultKernel<MT,VT3,VT4> >::Type
572  selectAssignKernel( DenseMatrix<MT,true>& A, const VT3& x, const VT4& y )
573  {
575 
576  const ConstIterator begin( y.begin() );
577  const ConstIterator end ( y.end() );
578 
579  for( ConstIterator element=begin; element!=end; ++element ) {
580  for( size_t i=0UL; i<(~A).rows(); ++i ) {
581  (~A)(i,element->index()) = x[i] * element->value();
582  }
583  }
584  }
586  //**********************************************************************************************
587 
588  //**Vectorized assignment to column-major dense matrices****************************************
602  template< typename MT // Type of the left-hand side target matrix
603  , typename VT3 // Type of the left-hand side vector operand
604  , typename VT4 > // Type of the right-hand side vector operand
605  static inline typename EnableIf< UseVectorizedKernel<MT,VT3,VT4> >::Type
606  selectAssignKernel( DenseMatrix<MT,true>& A, const VT3& x, const VT4& y )
607  {
609 
610  typedef IntrinsicTrait<ElementType> IT;
611  typedef typename IT::Type IntrinsicType;
612 
613  const ConstIterator begin( y.begin() );
614  const ConstIterator end ( y.end() );
615 
616  for( ConstIterator element=begin; element!=end; ++element )
617  {
618  const IntrinsicType y1( set( element->value() ) );
619 
620  for( size_t i=0UL; i<(~A).rows(); i+=IT::size ) {
621  (~A).store( i, element->index(), x.load(i) * y1 );
622  }
623  }
624  }
626  //**********************************************************************************************
627 
628  //**Assignment to row-major sparse matrices*****************************************************
643  template< typename MT > // Type of the target sparse matrix
644  friend inline typename EnableIf< UseAssign<MT> >::Type
645  assign( SparseMatrix<MT,false>& lhs, const DVecTSVecMultExpr& rhs )
646  {
648 
649  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
650  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
651 
653 
654  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
655  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse vector operand
656 
657  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
658  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
659  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
660  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
661 
662  const ConstIterator begin( y.begin() );
663  const ConstIterator end ( y.end() );
664 
665  for( size_t i=0UL; i<x.size(); ++i ) {
666  if( !isDefault( x[i] ) ) {
667  (~lhs).reserve( i, y.nonZeros() );
668  for( ConstIterator element=begin; element!=end; ++element ) {
669  (~lhs).append( i, element->index(), x[i] * element->value() );
670  }
671  }
672  }
673  }
675  //**********************************************************************************************
676 
677  //**Assignment to column-major sparse matrices*****************************************************
690  template< typename MT > // Type of the target sparse matrix
691  friend inline void assign( SparseMatrix<MT,true>& lhs, const DVecTSVecMultExpr& rhs )
692  {
694 
695  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
696  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
697 
699 
700  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
701  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse vector operand
702 
703  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
704  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
705  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
706  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
707 
708  const ConstIterator begin( y.begin() );
709  const ConstIterator end ( y.end() );
710 
711  for( ConstIterator element=begin; element!=end; ++element ) {
712  if( !isDefault( element->value() ) ) {
713  (~lhs).reserve( element->index(), x.size() );
714  for( size_t i=0UL; i<(~lhs).rows(); ++i ) {
715  (~lhs).append( i, element->index(), x[i] * element->value() );
716  }
717  }
718  }
719  }
721  //**********************************************************************************************
722 
723  //**Addition assignment to row-major dense matrices*********************************************
739  template< typename MT > // Type of the target dense matrix
740  friend inline typename EnableIf< UseAssign<MT> >::Type
741  addAssign( DenseMatrix<MT,false>& lhs, const DVecTSVecMultExpr& rhs )
742  {
744 
745  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
746  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
747 
749 
750  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
751  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse vector operand
752 
753  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
754  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
755  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
756  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
757 
758  const ConstIterator begin( y.begin() );
759  const ConstIterator end ( y.end() );
760 
761  for( size_t i=0UL; i<(~lhs).rows(); ++i ) {
762  for( ConstIterator element=begin; element!=end; ++element ) {
763  (~lhs)(i,element->index()) += x[i] * element->value();
764  }
765  }
766  }
768  //**********************************************************************************************
769 
770  //**Addition assignment to column-major dense matrices******************************************
783  template< typename MT > // Type of the target dense matrix
784  friend inline void addAssign( DenseMatrix<MT,true>& lhs, const DVecTSVecMultExpr& rhs )
785  {
787 
788  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
789  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
790 
791  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
792  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse vector operand
793 
794  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
795  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
796  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
797  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
798 
799  DVecTSVecMultExpr::selectAddAssignKernel( ~lhs, x, y );
800  }
802  //**********************************************************************************************
803 
804  //**Default addition assignment to column dense matrices****************************************
818  template< typename MT // Type of the left-hand side target matrix
819  , typename VT3 // Type of the left-hand side vector operand
820  , typename VT4 > // Type of the right-hand side vector operand
821  static inline typename EnableIf< UseDefaultKernel<MT,VT3,VT4> >::Type
822  selectAddAssignKernel( DenseMatrix<MT,true>& A, const VT3& x, const VT4& y )
823  {
825 
826  const ConstIterator begin( y.begin() );
827  const ConstIterator end ( y.end() );
828 
829  for( ConstIterator element=begin; element!=end; ++element ) {
830  for( size_t i=0UL; i<(~A).rows(); ++i ) {
831  (~A)(i,element->index()) += x[i] * element->value();
832  }
833  }
834  }
836  //**********************************************************************************************
837 
838  //**Vectorized addition assignment to column-major dense matrices*******************************
852  template< typename MT // Type of the left-hand side target matrix
853  , typename VT3 // Type of the left-hand side vector operand
854  , typename VT4 > // Type of the right-hand side vector operand
855  static inline typename EnableIf< UseVectorizedKernel<MT,VT3,VT4> >::Type
856  selectAddAssignKernel( DenseMatrix<MT,true>& A, const VT3& x, const VT4& y )
857  {
859 
860  typedef IntrinsicTrait<ElementType> IT;
861  typedef typename IT::Type IntrinsicType;
862 
863  const ConstIterator begin( y.begin() );
864  const ConstIterator end ( y.end() );
865 
866  for( ConstIterator element=begin; element!=end; ++element )
867  {
868  const IntrinsicType y1( set( element->value() ) );
869 
870  for( size_t i=0UL; i<(~A).rows(); i+=IT::size ) {
871  (~A).store( i, element->index(), (~A).load(i,element->index()) + x.load(i) * y1 );
872  }
873  }
874  }
876  //**********************************************************************************************
877 
878  //**Addition assignment to sparse matrices******************************************************
879  // No special implementation for the addition assignment to sparse matrices.
880  //**********************************************************************************************
881 
882  //**Subtraction assignment to row-major dense matrices******************************************
898  template< typename MT > // Type of the target dense matrix
899  friend inline typename EnableIf< UseAssign<MT> >::Type
900  subAssign( DenseMatrix<MT,false>& lhs, const DVecTSVecMultExpr& rhs )
901  {
903 
904  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
905  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
906 
908 
909  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
910  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse vector operand
911 
912  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
913  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
914  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
915  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
916 
917  const ConstIterator begin( y.begin() );
918  const ConstIterator end ( y.end() );
919 
920  for( size_t i=0UL; i<(~lhs).rows(); ++i ) {
921  for( ConstIterator element=begin; element!=end; ++element ) {
922  (~lhs)(i,element->index()) -= x[i] * element->value();
923  }
924  }
925  }
927  //**********************************************************************************************
928 
929  //**Subtraction assignment to column-major dense matrices***************************************
942  template< typename MT > // Type of the target dense matrix
943  friend inline void subAssign( DenseMatrix<MT,true>& lhs, const DVecTSVecMultExpr& rhs )
944  {
946 
947  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
948  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
949 
950  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
951  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side sparse vector operand
952 
953  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
954  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
955  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
956  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
957 
958  DVecTSVecMultExpr::selectSubAssignKernel( ~lhs, x, y );
959  }
961  //**********************************************************************************************
962 
963  //**Default subtraction assignment to column dense matrices*************************************
977  template< typename MT // Type of the left-hand side target matrix
978  , typename VT3 // Type of the left-hand side vector operand
979  , typename VT4 > // Type of the right-hand side vector operand
980  static inline typename EnableIf< UseDefaultKernel<MT,VT3,VT4> >::Type
981  selectSubAssignKernel( DenseMatrix<MT,true>& A, const VT3& x, const VT4& y )
982  {
984 
985  const ConstIterator begin( y.begin() );
986  const ConstIterator end ( y.end() );
987 
988  for( ConstIterator element=begin; element!=end; ++element ) {
989  for( size_t i=0UL; i<(~A).rows(); ++i ) {
990  (~A)(i,element->index()) -= x[i] * element->value();
991  }
992  }
993  }
995  //**********************************************************************************************
996 
997  //**Vectorized subtraction assignment to column-major dense matrices****************************
1011  template< typename MT // Type of the left-hand side target matrix
1012  , typename VT3 // Type of the left-hand side vector operand
1013  , typename VT4 > // Type of the right-hand side vector operand
1014  static inline typename EnableIf< UseVectorizedKernel<MT,VT3,VT4> >::Type
1015  selectSubAssignKernel( DenseMatrix<MT,true>& A, const VT3& x, const VT4& y )
1016  {
1018 
1019  typedef IntrinsicTrait<ElementType> IT;
1020  typedef typename IT::Type IntrinsicType;
1021 
1022  const ConstIterator begin( y.begin() );
1023  const ConstIterator end ( y.end() );
1024 
1025  for( ConstIterator element=begin; element!=end; ++element )
1026  {
1027  const IntrinsicType y1( set( element->value() ) );
1028 
1029  for( size_t i=0UL; i<(~A).rows(); i+=IT::size ) {
1030  (~A).store( i, element->index(), (~A).load(i,element->index()) - x.load(i) * y1 );
1031  }
1032  }
1033  }
1035  //**********************************************************************************************
1036 
1037  //**Subtraction assignment to sparse matrices***************************************************
1038  // No special implementation for the subtraction assignment to sparse matrices.
1039  //**********************************************************************************************
1040 
1041  //**Multiplication assignment to dense matrices*************************************************
1042  // No special implementation for the multiplication assignment to dense matrices.
1043  //**********************************************************************************************
1044 
1045  //**Multiplication assignment to sparse matrices************************************************
1046  // No special implementation for the multiplication assignment to sparse matrices.
1047  //**********************************************************************************************
1048 
1049  //**Compile time checks*************************************************************************
1056  //**********************************************************************************************
1057 };
1058 //*************************************************************************************************
1059 
1060 
1061 
1062 
1063 //=================================================================================================
1064 //
1065 // GLOBAL BINARY ARITHMETIC OPERATORS
1066 //
1067 //=================================================================================================
1068 
1069 //*************************************************************************************************
1098 template< typename T1 // Type of the left-hand side dense vector
1099  , typename T2 > // Type of the right-hand side sparse vector
1100 inline const DVecTSVecMultExpr<T1,T2>
1102 {
1104 
1105  return DVecTSVecMultExpr<T1,T2>( ~lhs, ~rhs );
1106 }
1107 //*************************************************************************************************
1108 
1109 
1110 
1111 
1112 //=================================================================================================
1113 //
1114 // EXPRESSION TRAIT SPECIALIZATIONS
1115 //
1116 //=================================================================================================
1117 
1118 //*************************************************************************************************
1120 template< typename VT1, typename VT2, bool AF >
1121 struct SubmatrixExprTrait< DVecTSVecMultExpr<VT1,VT2>, AF >
1122 {
1123  public:
1124  //**********************************************************************************************
1125  typedef typename MultExprTrait< typename SubvectorExprTrait<const VT1,AF>::Type
1126  , typename SubvectorExprTrait<const VT2,AF>::Type >::Type Type;
1127  //**********************************************************************************************
1128 };
1130 //*************************************************************************************************
1131 
1132 
1133 //*************************************************************************************************
1135 template< typename VT1, typename VT2 >
1136 struct RowExprTrait< DVecTSVecMultExpr<VT1,VT2> >
1137 {
1138  public:
1139  //**********************************************************************************************
1140  typedef typename MultExprTrait< typename VT1::ReturnType, VT2 >::Type Type;
1141  //**********************************************************************************************
1142 };
1144 //*************************************************************************************************
1145 
1146 
1147 //*************************************************************************************************
1149 template< typename VT1, typename VT2 >
1150 struct ColumnExprTrait< DVecTSVecMultExpr<VT1,VT2> >
1151 {
1152  public:
1153  //**********************************************************************************************
1154  typedef typename MultExprTrait< VT1, typename VT2::ReturnType >::Type Type;
1155  //**********************************************************************************************
1156 };
1158 //*************************************************************************************************
1159 
1160 } // namespace blaze
1161 
1162 #endif
ValueType * PointerType
Pointer return type.
Definition: DVecTSVecMultExpr.h:220
Pointer difference type of the Blaze library.
VT1::ReturnType RN1
Return type of the left-hand side dense vector expression.
Definition: DVecTSVecMultExpr.h:101
Compile time check whether the given type is a computational expression template.This type trait clas...
Definition: IsComputation.h:89
Compile time check for numeric types.This type trait tests whether or not the given template paramete...
Definition: IsNumeric.h:98
PointerType pointer
Pointer return type.
Definition: DVecTSVecMultExpr.h:227
EnableIf< IsIntegral< T > >::Type store(T *address, const typename Store< T, sizeof(T)>::Type &value)
Aligned store of a vector of integral values.
Definition: Store.h:223
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
VT2::ElementType ET2
Element type of the right-hand side sparse vector expression.
Definition: DVecTSVecMultExpr.h:106
ValueType & ReferenceType
Reference return type.
Definition: DVecTSVecMultExpr.h:221
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:4329
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: DVecTSVecMultExpr.h:463
SelectType< IsComputation< VT1 >::value, const RT1, CT1 >::Type LT
Type for the assignment of the left-hand side dense vector operand.
Definition: DVecTSVecMultExpr.h:191
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: DVecTSVecMultExpr.h:222
size_t rows() const
Returns the current number of rows of the matrix.
Definition: DVecTSVecMultExpr.h:387
#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:4642
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:199
Header file for the ColumnExprTrait class template.
bool operator!=(const ConstIterator &rhs) const
Inequality comparison between two ConstIterator objects.
Definition: DVecTSVecMultExpr.h:309
const ConstIterator * operator->() const
Direct access to the sparse matrix element at the current iterator position.
Definition: DVecTSVecMultExpr.h:267
VT1::ElementType ET1
Element type of the left-hand side dense vector expression.
Definition: DVecTSVecMultExpr.h:105
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2408
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:251
IteratorType it_
Iterator over the elements of the right-hand side sparse vector expression.
Definition: DVecTSVecMultExpr.h:328
void UNUSED_PARAMETER(const T1 &)
Suppression of unused parameter warnings.
Definition: Unused.h:84
size_t index() const
Access to the current index of the sparse element.
Definition: DVecTSVecMultExpr.h:287
std::forward_iterator_tag IteratorCategory
The iterator category.
Definition: DVecTSVecMultExpr.h:218
const DMatSerialExpr< MT, SO > serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:690
Header file for the Computation base class.
Type relationship analysis.This class tests if the two data types A and B are equal. For this type comparison, the cv-qualifiers of both data types are ignored. If A and B are the same data type (ignoring the cv-qualifiers), then the value member enumeration is set to 1, the nested type definition Type is TrueType, and the class derives from TrueType. Otherwise value is set to 0, Type is FalseType, and the class derives from FalseType.
Definition: IsSame.h:158
SelectType< IsExpression< VT2 >::value, const VT2, const VT2 & >::Type RightOperand
Composite type of the right-hand side sparse vector expression.
Definition: DVecTSVecMultExpr.h:188
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: DVecTSVecMultExpr.h:352
Element ValueType
Type of the underlying pointers.
Definition: DVecTSVecMultExpr.h:219
const Element operator*() const
Direct access to the sparse matrix element at the current iterator position.
Definition: DVecTSVecMultExpr.h:257
DVecTSVecMultExpr(const VT1 &lhs, const VT2 &rhs)
Constructor for the DVecTSVecMultExpr class.
Definition: DVecTSVecMultExpr.h:339
Base class for dense matrices.The DenseMatrix class is a base class for all dense matrix classes...
Definition: DenseMatrix.h:70
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes...
Definition: Forward.h:107
Constraint on the data type.
MultExprTrait< RN1, RN2 >::Type ExprReturnType
Expression return type for the subscript operator.
Definition: DVecTSVecMultExpr.h:119
Header file for the SparseMatrix base class.
Constraint on the data type.
Header file for the MultExprTrait class template.
ValueType value_type
Type of the underlying pointers.
Definition: DVecTSVecMultExpr.h:226
ConstIterator begin(size_t i) const
Returns an iterator to the first non-zero element of row i.
Definition: DVecTSVecMultExpr.h:366
Header file for the ValueIndexPair class.
Compile time type selection.The SelectType class template selects one of the two given types T1 and T...
Definition: SelectType.h:59
Header file for the IsTemporary type trait class.
Header file for the multiplication trait.
ConstIterator & operator++()
Pre-increment operator.
Definition: DVecTSVecMultExpr.h:246
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2412
LeftOperand lhs_
Left-hand side dense vector of the multiplication expression.
Definition: DVecTSVecMultExpr.h:470
ResultType::ElementType ElementType
Resulting element type.
Definition: DVecTSVecMultExpr.h:176
Expression object for dense vector-sparse vector outer products.The DVecTSVecMultExpr class represent...
Definition: DVecTSVecMultExpr.h:93
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: DVecTSVecMultExpr.h:451
ConstIterator(LeftElement v, IteratorType it)
Constructor for the ConstIterator class.
Definition: DVecTSVecMultExpr.h:235
bool operator==(const ConstIterator &rhs) const
Equality comparison between two ConstIterator objects.
Definition: DVecTSVecMultExpr.h:298
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:271
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
IteratorCategory iterator_category
The iterator category.
Definition: DVecTSVecMultExpr.h:225
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a sparse, N-dimensional vector type...
Definition: SparseVector.h:79
Constraint on the data type.
Constraint on the data type.
DifferenceType difference_type
Difference between two iterators.
Definition: DVecTSVecMultExpr.h:229
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2406
Header file for the SelectType class template.
Header file for the RowExprTrait class template.
Header file for all forward declarations for expression class templates.
Constraint on the data type.
Header file for the VecTVecMultExpr base class.
VT1::CompositeType CT1
Composite type of the left-hand side dense vector expression.
Definition: DVecTSVecMultExpr.h:103
Header file for the EnableIf class template.
Header file for the serial shim.
RightOperand rightOperand() const
Returns the right-hand side sparse vector operand.
Definition: DVecTSVecMultExpr.h:439
Header file for the IsNumeric type trait.
LeftOperand leftOperand() const
Returns the left-hand side dense vector operand.
Definition: DVecTSVecMultExpr.h:429
ConstIterator end(size_t i) const
Returns an iterator just past the last non-zero element of row i.
Definition: DVecTSVecMultExpr.h:377
Iterator over the elements of the dense vector-sparse vector outer product expression.
Definition: DVecTSVecMultExpr.h:205
Header file for the SubmatrixExprTrait class template.
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2407
Removal of reference modifiers.The RemoveCV type trait removes any reference modifiers from the given...
Definition: RemoveReference.h:69
VT1::ResultType RT1
Result type of the left-hand side dense vector expression.
Definition: DVecTSVecMultExpr.h:99
Intrinsic characteristics of data types.The IntrinsicTrait class template provides the intrinsic char...
Definition: IntrinsicTrait.h:748
size_t columns() const
Returns the current number of columns of the matrix.
Definition: DVecTSVecMultExpr.h:397
Header file for run time assertion macros.
Base template for the MultTrait class.
Definition: MultTrait.h:141
RightOperand rhs_
Right-hand side sparse vector of the multiplication expression.
Definition: DVecTSVecMultExpr.h:471
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:301
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: DVecTSVecMultExpr.h:175
Substitution Failure Is Not An Error (SFINAE) class.The EnableIf class template is an auxiliary tool ...
Definition: EnableIf.h:184
DVecTSVecMultExpr< VT1, VT2 > This
Type of this DVecTSVecMultExpr instance.
Definition: DVecTSVecMultExpr.h:172
ValueIndexPair< ElementType > Element
Element type of the sparse matrix expression.
Definition: DVecTSVecMultExpr.h:210
size_t nonZeros(size_t i) const
Returns the number of non-zero elements in the specified row.
Definition: DVecTSVecMultExpr.h:418
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:331
Header file for the isDefault shim.
ReferenceType reference
Reference return type.
Definition: DVecTSVecMultExpr.h:228
ReturnType value() const
Access to the current value of the sparse element.
Definition: DVecTSVecMultExpr.h:277
Header file for the RemoveReference type trait.
ResultType::OppositeType OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: DVecTSVecMultExpr.h:174
Base class for all outer product expression templates.The VecTVecMultExpr class serves as a tag for a...
Definition: VecTVecMultExpr.h:66
ET1 LeftElement
Element type of the dense vector expression.
Definition: DVecTSVecMultExpr.h:213
Header file for all intrinsic functionality.
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a dense, N-dimensional vector type...
Definition: DenseVector.h:79
VT2::ReturnType RN2
Return type of the right-hand side sparse vector expression.
Definition: DVecTSVecMultExpr.h:102
Index-value-pair for sparse vectors and matrices.The ValueIndexPair class represents a single index-v...
Definition: ValueIndexPair.h:69
MultTrait< RT1, RT2 >::Type ResultType
Result type for expression template evaluations.
Definition: DVecTSVecMultExpr.h:173
Header file for the IsComputation type trait class.
const SelectType< returnExpr, ExprReturnType, ElementType >::Type ReturnType
Return type for expression template evaluations.
Definition: DVecTSVecMultExpr.h:179
Base class for all compute expression templates.The Computation class serves as a tag for all computa...
Definition: Computation.h:59
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:108
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:157
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2403
LeftElement v_
Element of the left-hand side dense vector expression.
Definition: DVecTSVecMultExpr.h:327
DifferenceType operator-(const ConstIterator &rhs) const
Calculating the number of elements between two expression iterators.
Definition: DVecTSVecMultExpr.h:320
SelectType< useAssign, const ResultType, const DVecTSVecMultExpr & >::Type CompositeType
Data type for composite expression templates.
Definition: DVecTSVecMultExpr.h:182
Header file for basic type definitions.
#define BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a row dense or sparse vector type (i...
Definition: TransposeFlag.h:81
RemoveReference< RightOperand >::Type::ConstIterator IteratorType
Iterator type of the sparse vector expression.
Definition: DVecTSVecMultExpr.h:216
Header file for the SubvectorExprTrait class template.
VT2::CompositeType CT2
Composite type of the right-hand side sparse vector expression.
Definition: DVecTSVecMultExpr.h:104
size_t nonZeros() const
Returns the number of non-zero elements in the sparse matrix.
Definition: DVecTSVecMultExpr.h:407
SelectType< IsExpression< VT1 >::value, const VT1, const VT1 & >::Type LeftOperand
Composite type of the left-hand side dense vector expression.
Definition: DVecTSVecMultExpr.h:185
VT2::ResultType RT2
Result type of the right-hand side sparse vector expression.
Definition: DVecTSVecMultExpr.h:100
Evaluation of the resulting expression type of a multiplication.Via this type trait it is possible to...
Definition: MultExprTrait.h:137
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_INTERNAL_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERTION flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:101
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
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.
SelectType< IsComputation< VT2 >::value, const RT2, CT2 >::Type RT
Type for the assignment of the right-hand side dense vector operand.
Definition: DVecTSVecMultExpr.h:194