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>
65 #include <blaze/util/Assert.h>
68 #include <blaze/util/SelectType.h>
69 #include <blaze/util/Types.h>
72 #include <blaze/util/Unused.h>
73 
74 
75 namespace blaze {
76 
77 //=================================================================================================
78 //
79 // CLASS SVECTDVECMULTEXPR
80 //
81 //=================================================================================================
82 
83 //*************************************************************************************************
90 template< typename VT1 // Type of the left-hand side sparse vector
91  , typename VT2 > // Type of the right-hand side dense vector
92 class SVecTDVecMultExpr : public SparseMatrix< SVecTDVecMultExpr<VT1,VT2>, true >
93  , private VecTVecMultExpr
94  , private Computation
95 {
96  private:
97  //**Type definitions****************************************************************************
98  typedef typename VT1::ResultType RT1;
99  typedef typename VT2::ResultType RT2;
100  typedef typename VT1::ReturnType RN1;
101  typedef typename VT2::ReturnType RN2;
102  typedef typename VT1::CompositeType CT1;
103  typedef typename VT2::CompositeType CT2;
104  typedef typename VT1::ElementType ET1;
105  typedef typename VT2::ElementType ET2;
106  //**********************************************************************************************
107 
108  //**Return type evaluation**********************************************************************
110 
115  enum { returnExpr = !IsTemporary<RN1>::value && !IsTemporary<RN2>::value };
116 
119  //**********************************************************************************************
120 
121  //**Evaluation strategy*************************************************************************
123 
129  enum { useAssign = ( IsComputation<VT1>::value || !IsNumeric<ET1>::value ||
131 
133  template< typename MT >
135  struct UseAssign {
136  enum { value = useAssign };
137  };
139  //**********************************************************************************************
140 
141  //**********************************************************************************************
143 
146  template< typename T1, typename T2, typename T3 >
147  struct UseVectorizedKernel {
148  enum { value = T1::vectorizable && T3::vectorizable &&
152  };
154  //**********************************************************************************************
155 
156  //**********************************************************************************************
158 
161  template< typename T1, typename T2, typename T3 >
162  struct UseDefaultKernel {
163  enum { value = !UseVectorizedKernel<T1,T2,T3>::value };
164  };
166  //**********************************************************************************************
167 
168  public:
169  //**Type definitions****************************************************************************
175 
178 
181 
183  typedef typename SelectType< IsExpression<VT1>::value, const VT1, const VT1& >::Type LeftOperand;
184 
186  typedef typename SelectType< IsExpression<VT2>::value, const VT2, const VT2& >::Type RightOperand;
187 
189  typedef typename SelectType< IsComputation<VT1>::value, const RT1, CT1 >::Type LT;
190 
192  typedef typename SelectType< IsComputation<VT2>::value, const RT2, CT2 >::Type RT;
193  //**********************************************************************************************
194 
195  //**Compilation flags***************************************************************************
197  enum { smpAssignable = 0 };
198  //**********************************************************************************************
199 
200  //**ConstIterator class definition**************************************************************
204  {
205  public:
206  //**Type definitions*************************************************************************
209 
212 
214  typedef ET2 RightElement;
215 
216  typedef std::forward_iterator_tag IteratorCategory;
217  typedef Element ValueType;
221 
222  // STL iterator requirements
228  //*******************************************************************************************
229 
230  //**Constructor******************************************************************************
234  : it_( it ) // Iterator over the elements of the left-hand side sparse vector expression
235  , v_ ( v ) // Element of the right-hand side dense vector expression.
236  {}
237  //*******************************************************************************************
238 
239  //**Prefix increment operator****************************************************************
245  ++it_;
246  return *this;
247  }
248  //*******************************************************************************************
249 
250  //**Element access operator******************************************************************
255  inline const Element operator*() const {
256  return Element( it_->value() * v_, it_->index() );
257  }
258  //*******************************************************************************************
259 
260  //**Element access operator******************************************************************
265  inline const ConstIterator* operator->() const {
266  return this;
267  }
268  //*******************************************************************************************
269 
270  //**Value function***************************************************************************
275  inline ReturnType value() const {
276  return it_->value() * v_;
277  }
278  //*******************************************************************************************
279 
280  //**Index function***************************************************************************
285  inline size_t index() const {
286  return it_->index();
287  }
288  //*******************************************************************************************
289 
290  //**Equality operator************************************************************************
296  inline bool operator==( const ConstIterator& rhs ) const {
297  return it_ == rhs.it_;
298  }
299  //*******************************************************************************************
300 
301  //**Inequality operator**********************************************************************
307  inline bool operator!=( const ConstIterator& rhs ) const {
308  return it_ != rhs.it_;
309  }
310  //*******************************************************************************************
311 
312  //**Subtraction operator*********************************************************************
318  inline DifferenceType operator-( const ConstIterator& rhs ) const {
319  return it_ - rhs.it_;
320  }
321  //*******************************************************************************************
322 
323  private:
324  //**Member variables*************************************************************************
327  //*******************************************************************************************
328  };
329  //**********************************************************************************************
330 
331  //**Constructor*********************************************************************************
337  explicit inline SVecTDVecMultExpr( const VT1& lhs, const VT2& rhs )
338  : lhs_( lhs ) // Left-hand side sparse vector of the multiplication expression
339  , rhs_( rhs ) // Right-hand side dense vector of the multiplication expression
340  {}
341  //**********************************************************************************************
342 
343  //**Access operator*****************************************************************************
350  inline ReturnType operator()( size_t i, size_t j ) const {
351  BLAZE_INTERNAL_ASSERT( i < lhs_.size(), "Invalid row access index" );
352  BLAZE_INTERNAL_ASSERT( j < rhs_.size(), "Invalid column access index" );
353 
354  return lhs_[i] * rhs_[j];
355  }
356  //**********************************************************************************************
357 
358  //**Begin function******************************************************************************
364  inline ConstIterator begin( size_t i ) const {
365  return ConstIterator( lhs_.begin(), rhs_[i] );
366  }
367  //**********************************************************************************************
368 
369  //**End function********************************************************************************
375  inline ConstIterator end( size_t i ) const {
376  return ConstIterator( lhs_.end(), rhs_[i] );
377  }
378  //**********************************************************************************************
379 
380  //**Rows function*******************************************************************************
385  inline size_t rows() const {
386  return lhs_.size();
387  }
388  //**********************************************************************************************
389 
390  //**Columns function****************************************************************************
395  inline size_t columns() const {
396  return rhs_.size();
397  }
398  //**********************************************************************************************
399 
400  //**NonZeros function***************************************************************************
405  inline size_t nonZeros() const {
406  return lhs_.nonZeros() * rhs_.size();
407  }
408  //**********************************************************************************************
409 
410  //**NonZeros function***************************************************************************
416  inline size_t nonZeros( size_t i ) const {
417  UNUSED_PARAMETER( i );
418  return lhs_.nonZeros();
419  }
420  //**********************************************************************************************
421 
422  //**Left operand access*************************************************************************
427  inline LeftOperand leftOperand() const {
428  return lhs_;
429  }
430  //**********************************************************************************************
431 
432  //**Right operand access************************************************************************
437  inline RightOperand rightOperand() const {
438  return rhs_;
439  }
440  //**********************************************************************************************
441 
442  //**********************************************************************************************
448  template< typename T >
449  inline bool canAlias( const T* alias ) const {
450  return ( lhs_.canAlias( alias ) || rhs_.canAlias( alias ) );
451  }
452  //**********************************************************************************************
453 
454  //**********************************************************************************************
460  template< typename T >
461  inline bool isAliased( const T* alias ) const {
462  return ( lhs_.isAliased( alias ) || rhs_.isAliased( alias ) );
463  }
464  //**********************************************************************************************
465 
466  private:
467  //**Member variables****************************************************************************
468  LeftOperand lhs_;
469  RightOperand rhs_;
470  //**********************************************************************************************
471 
472  //**Assignment to row-major dense matrices******************************************************
484  template< typename MT > // Type of the target dense matrix
485  friend inline void assign( DenseMatrix<MT,false>& lhs, const SVecTDVecMultExpr& rhs )
486  {
488 
489  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
490  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
491 
492  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse vector operand
493  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense vector operand
494 
495  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
496  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
497  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
498  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
499 
500  SVecTDVecMultExpr::selectAssignKernel( ~lhs, x, y );
501  }
503  //**********************************************************************************************
504 
505  //**Default assignment to row-major dense matrices**********************************************
519  template< typename MT // Type of the left-hand side target matrix
520  , typename VT3 // Type of the left-hand side vector operand
521  , typename VT4 > // Type of the right-hand side vector operand
522  static inline typename EnableIf< UseDefaultKernel<MT,VT3,VT4> >::Type
523  selectAssignKernel( DenseMatrix<MT,false>& A, const VT3& x, const VT4& y )
524  {
526 
527  const ConstIterator end( x.end() );
528 
529  for( ConstIterator element=x.begin(); element!=end; ++element ) {
530  if( !isDefault( element->value() ) ) {
531  for( size_t j=0UL; j<y.size(); ++j ) {
532  (~A)(element->index(),j) = element->value() * y[j];
533  }
534  }
535  }
536  }
538  //**********************************************************************************************
539 
540  //**Vectorized assignment to row-major dense matrices*******************************************
554  template< typename MT // Type of the left-hand side target matrix
555  , typename VT3 // Type of the left-hand side vector operand
556  , typename VT4 > // Type of the right-hand side vector operand
557  static inline typename EnableIf< UseVectorizedKernel<MT,VT3,VT4> >::Type
558  selectAssignKernel( DenseMatrix<MT,false>& A, const VT3& x, const VT4& y )
559  {
561 
562  typedef IntrinsicTrait<ElementType> IT;
563  typedef typename IT::Type IntrinsicType;
564 
565  const ConstIterator begin( x.begin() );
566  const ConstIterator end ( x.end() );
567 
568  for( ConstIterator element=begin; element!=end; ++element )
569  {
570  const IntrinsicType x1( set( element->value() ) );
571 
572  for( size_t j=0UL; j<(~A).columns(); j+=IT::size ) {
573  (~A).store( element->index(), j, x1 * y.load(j) );
574  }
575  }
576  }
578  //**********************************************************************************************
579 
580  //**Assignment to column-major dense matrices***************************************************
596  template< typename MT > // Type of the target dense matrix
597  friend inline typename EnableIf< UseAssign<MT> >::Type
598  assign( DenseMatrix<MT,true>& lhs, const SVecTDVecMultExpr& rhs )
599  {
601 
602  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
603  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
604 
606 
607  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse vector operand
608  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense vector operand
609 
610  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
611  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
612  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
613  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
614 
615  const ConstIterator end( x.end() );
616 
617  for( size_t i=0UL; i<y.size(); ++i ) {
618  if( !isDefault( y[i] ) ) {
619  for( ConstIterator element=x.begin(); element!=end; ++element ) {
620  (~lhs)(element->index(),i) = element->value() * y[i];
621  }
622  }
623  }
624  }
626  //**********************************************************************************************
627 
628  //**Assignment to row-major sparse matrices*****************************************************
640  template< typename MT > // Type of the target sparse matrix
641  friend inline void assign( SparseMatrix<MT,false>& lhs, const SVecTDVecMultExpr& rhs )
642  {
644 
645  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
646  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
647 
649 
650  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse vector operand
651  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense vector operand
652 
653  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
654  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
655  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
656  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
657 
658  const ConstIterator end( x.end() );
659 
660  for( ConstIterator element=x.begin(); element!=end; ++element ) {
661  if( !isDefault( element->value() ) ) {
662  (~lhs).reserve( element->index(), y.size() );
663  for( size_t i=0UL; i<y.size(); ++i ) {
664  (~lhs).append( element->index(), i, element->value() * y[i] );
665  }
666  }
667  }
668  }
670  //**********************************************************************************************
671 
672  //**Assignment to column-major sparse matrices**************************************************
688  template< typename MT > // Type of the target sparse matrix
689  friend inline typename EnableIf< UseAssign<MT> >::Type
690  assign( SparseMatrix<MT,true>& lhs, const SVecTDVecMultExpr& rhs )
691  {
693 
694  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
695  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
696 
698 
699  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse vector operand
700  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense vector operand
701 
702  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
703  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
704  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
705  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
706 
707  const ConstIterator end( x.end() );
708 
709  for( size_t i=0UL; i<y.size(); ++i ) {
710  if( !isDefault( y[i] ) ) {
711  (~lhs).reserve( i, x.nonZeros() );
712  for( ConstIterator element=x.begin(); element!=end; ++element ) {
713  (~lhs).append( element->index(), i, element->value() * y[i] );
714  }
715  }
716  }
717  }
719  //**********************************************************************************************
720 
721  //**Addition assignment to row-major dense matrices*********************************************
734  template< typename MT > // Type of the target dense matrix
735  friend inline void addAssign( DenseMatrix<MT,false>& lhs, const SVecTDVecMultExpr& rhs )
736  {
738 
739  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
740  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
741 
742  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse vector operand
743  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense vector operand
744 
745  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
746  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
747  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
748  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
749 
750  SVecTDVecMultExpr::selectAddAssignKernel( ~lhs, x, y );
751  }
753  //**********************************************************************************************
754 
755  //**Default addition assignment to row-major dense matrices*************************************
769  template< typename MT // Type of the left-hand side target matrix
770  , typename VT3 // Type of the left-hand side vector operand
771  , typename VT4 > // Type of the right-hand side vector operand
772  static inline typename EnableIf< UseDefaultKernel<MT,VT3,VT4> >::Type
773  selectAddAssignKernel( DenseMatrix<MT,false>& A, const VT3& x, const VT4& y )
774  {
776 
777  const ConstIterator end( x.end() );
778 
779  for( ConstIterator element=x.begin(); element!=end; ++element ) {
780  if( !isDefault( element->value() ) ) {
781  for( size_t i=0UL; i<y.size(); ++i ) {
782  (~A)(element->index(),i) += element->value() * y[i];
783  }
784  }
785  }
786  }
788  //**********************************************************************************************
789 
790  //**Vectorized addition assignment to row-major dense matrices**********************************
804  template< typename MT // Type of the left-hand side target matrix
805  , typename VT3 // Type of the left-hand side vector operand
806  , typename VT4 > // Type of the right-hand side vector operand
807  static inline typename EnableIf< UseVectorizedKernel<MT,VT3,VT4> >::Type
808  selectAddAssignKernel( DenseMatrix<MT,false>& A, const VT3& x, const VT4& y )
809  {
811 
812  typedef IntrinsicTrait<ElementType> IT;
813  typedef typename IT::Type IntrinsicType;
814 
815  const ConstIterator begin( x.begin() );
816  const ConstIterator end ( x.end() );
817 
818  for( ConstIterator element=begin; element!=end; ++element )
819  {
820  const IntrinsicType x1( set( element->value() ) );
821 
822  for( size_t j=0UL; j<(~A).columns(); j+=IT::size ) {
823  (~A).store( element->index(), j, (~A).load(element->index(),j) + x1 * y.load(j) );
824  }
825  }
826  }
828  //**********************************************************************************************
829 
830  //**Addition assignment to column-major dense matrices******************************************
846  template< typename MT > // Type of the target dense matrix
847  friend inline typename EnableIf< UseAssign<MT> >::Type
848  addAssign( DenseMatrix<MT,true>& lhs, const SVecTDVecMultExpr& rhs )
849  {
851 
852  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
853  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
854 
856 
857  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse vector operand
858  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense vector operand
859 
860  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
861  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
862  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
863  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
864 
865  const ConstIterator end( x.end() );
866 
867  for( size_t i=0UL; i<y.size(); ++i ) {
868  if( !isDefault( y[i] ) ) {
869  for( ConstIterator element=x.begin(); element!=end; ++element ) {
870  (~lhs)(element->index(),i) += element->value() * y[i];
871  }
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******************************************
895  template< typename MT > // Type of the target dense matrix
896  friend inline void subAssign( DenseMatrix<MT,false>& lhs, const SVecTDVecMultExpr& rhs )
897  {
899 
900  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
901  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
902 
903  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse vector operand
904  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense vector operand
905 
906  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
907  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
908  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
909  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
910 
911  SVecTDVecMultExpr::selectSubAssignKernel( ~lhs, x, y );
912  }
914  //**********************************************************************************************
915 
916  //**Default subtraction assignment to row-major dense matrices**********************************
930  template< typename MT // Type of the left-hand side target matrix
931  , typename VT3 // Type of the left-hand side vector operand
932  , typename VT4 > // Type of the right-hand side vector operand
933  static inline typename EnableIf< UseDefaultKernel<MT,VT3,VT4> >::Type
934  selectSubAssignKernel( DenseMatrix<MT,false>& A, const VT3& x, const VT4& y )
935  {
937 
938  const ConstIterator end( x.end() );
939 
940  for( ConstIterator element=x.begin(); element!=end; ++element ) {
941  if( !isDefault( element->value() ) ) {
942  for( size_t i=0UL; i<y.size(); ++i ) {
943  (~A)(element->index(),i) -= element->value() * y[i];
944  }
945  }
946  }
947  }
949  //**********************************************************************************************
950 
951  //**Vectorized subtraction assignment to row-major dense matrices*******************************
965  template< typename MT // Type of the left-hand side target matrix
966  , typename VT3 // Type of the left-hand side vector operand
967  , typename VT4 > // Type of the right-hand side vector operand
968  static inline typename EnableIf< UseVectorizedKernel<MT,VT3,VT4> >::Type
969  selectSubAssignKernel( DenseMatrix<MT,false>& A, const VT3& x, const VT4& y )
970  {
972 
973  typedef IntrinsicTrait<ElementType> IT;
974  typedef typename IT::Type IntrinsicType;
975 
976  const ConstIterator begin( x.begin() );
977  const ConstIterator end ( x.end() );
978 
979  for( ConstIterator element=begin; element!=end; ++element )
980  {
981  const IntrinsicType x1( set( element->value() ) );
982 
983  for( size_t j=0UL; j<(~A).columns(); j+=IT::size ) {
984  (~A).store( element->index(), j, (~A).load(element->index(),j) - x1 * y.load(j) );
985  }
986  }
987  }
989  //**********************************************************************************************
990 
991  //**Subtraction assignment to column-major dense matrices***************************************
1007  template< typename MT > // Type of the target dense matrix
1008  friend inline typename EnableIf< UseAssign<MT> >::Type
1009  subAssign( DenseMatrix<MT,true>& lhs, const SVecTDVecMultExpr& rhs )
1010  {
1012 
1013  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
1014  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
1015 
1017 
1018  LT x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side sparse vector operand
1019  RT y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense vector operand
1020 
1021  BLAZE_INTERNAL_ASSERT( x.size() == rhs.lhs_.size() , "Invalid vector size" );
1022  BLAZE_INTERNAL_ASSERT( y.size() == rhs.rhs_.size() , "Invalid vector size" );
1023  BLAZE_INTERNAL_ASSERT( x.size() == (~lhs).rows() , "Invalid vector size" );
1024  BLAZE_INTERNAL_ASSERT( y.size() == (~lhs).columns(), "Invalid vector size" );
1025 
1026  const ConstIterator end( x.end() );
1027 
1028  for( size_t i=0UL; i<y.size(); ++i ) {
1029  if( !isDefault( y[i] ) ) {
1030  for( ConstIterator element=x.begin(); element!=end; ++element ) {
1031  (~lhs)(element->index(),i) -= element->value() * y[i];
1032  }
1033  }
1034  }
1035  }
1037  //**********************************************************************************************
1038 
1039  //**Subtraction assignment to sparse matrices***************************************************
1040  // No special implementation for the subtraction assignment to sparse matrices.
1041  //**********************************************************************************************
1042 
1043  //**Multiplication assignment to dense matrices*************************************************
1044  // No special implementation for the multiplication assignment to dense matrices.
1045  //**********************************************************************************************
1046 
1047  //**Multiplication assignment to sparse matrices************************************************
1048  // No special implementation for the multiplication assignment to sparse matrices.
1049  //**********************************************************************************************
1050 
1051  //**Compile time checks*************************************************************************
1058  //**********************************************************************************************
1059 };
1060 //*************************************************************************************************
1061 
1062 
1063 
1064 
1065 //=================================================================================================
1066 //
1067 // GLOBAL BINARY ARITHMETIC OPERATORS
1068 //
1069 //=================================================================================================
1070 
1071 //*************************************************************************************************
1100 template< typename T1 // Type of the left-hand side sparse vector
1101  , typename T2 > // Type of the right-hand side dense vector
1102 inline const SVecTDVecMultExpr<T1,T2>
1104 {
1106 
1107  return SVecTDVecMultExpr<T1,T2>( ~lhs, ~rhs );
1108 }
1109 //*************************************************************************************************
1110 
1111 
1112 
1113 
1114 //=================================================================================================
1115 //
1116 // EXPRESSION TRAIT SPECIALIZATIONS
1117 //
1118 //=================================================================================================
1119 
1120 //*************************************************************************************************
1122 template< typename VT1, typename VT2, bool AF >
1123 struct SubmatrixExprTrait< SVecTDVecMultExpr<VT1,VT2>, AF >
1124 {
1125  public:
1126  //**********************************************************************************************
1127  typedef typename MultExprTrait< typename SubvectorExprTrait<const VT1,AF>::Type
1128  , typename SubvectorExprTrait<const VT2,AF>::Type >::Type Type;
1129  //**********************************************************************************************
1130 };
1132 //*************************************************************************************************
1133 
1134 
1135 //*************************************************************************************************
1137 template< typename VT1, typename VT2 >
1138 struct RowExprTrait< SVecTDVecMultExpr<VT1,VT2> >
1139 {
1140  public:
1141  //**********************************************************************************************
1142  typedef typename MultExprTrait< typename VT1::ReturnType, VT2 >::Type Type;
1143  //**********************************************************************************************
1144 };
1146 //*************************************************************************************************
1147 
1148 
1149 //*************************************************************************************************
1151 template< typename VT1, typename VT2 >
1152 struct ColumnExprTrait< SVecTDVecMultExpr<VT1,VT2> >
1153 {
1154  public:
1155  //**********************************************************************************************
1156  typedef typename MultExprTrait< VT1, typename VT2::ReturnType >::Type Type;
1157  //**********************************************************************************************
1158 };
1160 //*************************************************************************************************
1161 
1162 } // namespace blaze
1163 
1164 #endif
std::forward_iterator_tag IteratorCategory
The iterator category.
Definition: SVecTDVecMultExpr.h:216
Pointer difference type of the Blaze library.
ValueType value_type
Type of the underlying pointers.
Definition: SVecTDVecMultExpr.h:224
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
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
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
ResultType::OppositeType OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: SVecTDVecMultExpr.h:172
Iterator over the elements of the sparse vector-dense vector outer product expression.
Definition: SVecTDVecMultExpr.h:203
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: SVecTDVecMultExpr.h:449
RightOperand rightOperand() const
Returns the right-hand side dense vector operand.
Definition: SVecTDVecMultExpr.h:437
#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
SelectType< IsExpression< VT2 >::value, const VT2, const VT2 & >::Type RightOperand
Composite type of the right-hand side dense vector expression.
Definition: SVecTDVecMultExpr.h:186
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:364
Expression object for sparse vector-dense vector outer products.The SVecTDVecMultExpr class represent...
Definition: Forward.h:121
VT1::ResultType RT1
Result type of the left-hand side sparse vector expression.
Definition: SVecTDVecMultExpr.h:98
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2408
size_t index() const
Access to the current index of the sparse element.
Definition: SVecTDVecMultExpr.h:285
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:251
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:189
ConstIterator end(size_t i) const
Returns an iterator just past the last non-zero element of column i.
Definition: SVecTDVecMultExpr.h:375
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
ConstIterator(IteratorType it, RightElement v)
Constructor for the ConstIterator class.
Definition: SVecTDVecMultExpr.h:233
const Element operator*() const
Direct access to the sparse matrix element at the current iterator position.
Definition: SVecTDVecMultExpr.h:255
RightOperand rhs_
Right-hand side dense vector of the multiplication expression.
Definition: SVecTDVecMultExpr.h:469
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:220
DifferenceType difference_type
Difference between two iterators.
Definition: SVecTDVecMultExpr.h:227
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:325
SVecTDVecMultExpr(const VT1 &lhs, const VT2 &rhs)
Constructor for the SVecTDVecMultExpr class.
Definition: SVecTDVecMultExpr.h:337
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:192
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:211
size_t columns() const
Returns the current number of columns of the matrix.
Definition: SVecTDVecMultExpr.h:395
VT2::CompositeType CT2
Composite type of the right-hand side dense vector expression.
Definition: SVecTDVecMultExpr.h:103
bool operator!=(const ConstIterator &rhs) const
Inequality comparison between two ConstIterator objects.
Definition: SVecTDVecMultExpr.h:307
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2412
MultExprTrait< RN1, RN2 >::Type ExprReturnType
Expression return type for the subscript operator.
Definition: SVecTDVecMultExpr.h:118
Element ValueType
Type of the underlying pointers.
Definition: SVecTDVecMultExpr.h:217
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
#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:214
Constraint on the data type.
VT2::ResultType RT2
Result type of the right-hand side dense vector expression.
Definition: SVecTDVecMultExpr.h:99
size_t rows() const
Returns the current number of rows of the matrix.
Definition: SVecTDVecMultExpr.h:385
RightElement v_
Element of the right-hand side dense vector expression.
Definition: SVecTDVecMultExpr.h:326
Constraint on the data type.
SelectType< useAssign, const ResultType, const SVecTDVecMultExpr & >::Type CompositeType
Data type for composite expression templates.
Definition: SVecTDVecMultExpr.h:180
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2406
SVecTDVecMultExpr< VT1, VT2 > This
Type of this SVecTDVecMultExpr instance.
Definition: SVecTDVecMultExpr.h:170
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:102
Header file for the serial shim.
ReferenceType reference
Reference return type.
Definition: SVecTDVecMultExpr.h:226
bool operator==(const ConstIterator &rhs) const
Equality comparison between two ConstIterator objects.
Definition: SVecTDVecMultExpr.h:296
Header file for the IsNumeric type trait.
VT2::ReturnType RN2
Return type of the right-hand side dense vector expression.
Definition: SVecTDVecMultExpr.h:101
const SelectType< returnExpr, ExprReturnType, ElementType >::Type ReturnType
Return type for expression template evaluations.
Definition: SVecTDVecMultExpr.h:177
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
IteratorCategory iterator_category
The iterator category.
Definition: SVecTDVecMultExpr.h:223
Intrinsic characteristics of data types.The IntrinsicTrait class template provides the intrinsic char...
Definition: IntrinsicTrait.h:748
Header file for run time assertion macros.
Base template for the MultTrait class.
Definition: MultTrait.h:141
ReturnType value() const
Access to the current value of the sparse element.
Definition: SVecTDVecMultExpr.h:275
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
LeftOperand leftOperand() const
Returns the left-hand side sparse vector operand.
Definition: SVecTDVecMultExpr.h:427
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:105
ResultType::ElementType ElementType
Resulting element type.
Definition: SVecTDVecMultExpr.h:174
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: SVecTDVecMultExpr.h:461
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.
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: SVecTDVecMultExpr.h:173
ValueType * PointerType
Pointer return type.
Definition: SVecTDVecMultExpr.h:218
VT1::ElementType ET1
Element type of the left-hand side sparse vector expression.
Definition: SVecTDVecMultExpr.h:104
ValueIndexPair< ElementType > Element
Element type of the sparse matrix expression.
Definition: SVecTDVecMultExpr.h:208
Header file for the RemoveReference type trait.
LeftOperand lhs_
Left-hand side sparse vector of the multiplication expression.
Definition: SVecTDVecMultExpr.h:468
Header file for all intrinsic functionality.
PointerType pointer
Pointer return type.
Definition: SVecTDVecMultExpr.h:225
DifferenceType operator-(const ConstIterator &rhs) const
Calculating the number of elements between two expression iterators.
Definition: SVecTDVecMultExpr.h:318
#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:265
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
Header file for basic type definitions.
ConstIterator & operator++()
Pre-increment operator.
Definition: SVecTDVecMultExpr.h:244
#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:219
MultTrait< RT1, RT2 >::Type ResultType
Result type for expression template evaluations.
Definition: SVecTDVecMultExpr.h:171
VT1::ReturnType RN1
Return type of the left-hand side sparse vector expression.
Definition: SVecTDVecMultExpr.h:100
size_t nonZeros(size_t i) const
Returns the number of non-zero elements in the specified column.
Definition: SVecTDVecMultExpr.h:416
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: SVecTDVecMultExpr.h:350
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:183
#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.
size_t nonZeros() const
Returns the number of non-zero elements in the sparse matrix.
Definition: SVecTDVecMultExpr.h:405
Header file for the FunctionTrace class.