All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TSVecDMatMultExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_TSVECDMATMULTEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_TSVECDMATMULTEXPR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <stdexcept>
53 #include <blaze/math/Intrinsics.h>
54 #include <blaze/math/shims/Reset.h>
67 #include <blaze/util/Assert.h>
69 #include <blaze/util/DisableIf.h>
70 #include <blaze/util/EnableIf.h>
72 #include <blaze/util/SelectType.h>
73 #include <blaze/util/Types.h>
76 
77 
78 namespace blaze {
79 
80 //=================================================================================================
81 //
82 // CLASS TSVECDMATMULTEXPR
83 //
84 //=================================================================================================
85 
86 //*************************************************************************************************
93 template< typename VT // Type of the left-hand side sparse vector
94  , typename MT > // Type of the right-hand side dense matrix
95 class TSVecDMatMultExpr : public DenseVector< TSVecDMatMultExpr<VT,MT>, true >
96  , private TVecMatMultExpr
97  , private Computation
98 {
99  private:
100  //**Type definitions****************************************************************************
101  typedef typename VT::ResultType VRT;
102  typedef typename MT::ResultType MRT;
103  typedef typename VRT::ElementType VET;
104  typedef typename MRT::ElementType MET;
105  typedef typename VT::CompositeType VCT;
106  typedef typename MT::CompositeType MCT;
107  //**********************************************************************************************
108 
109  //**********************************************************************************************
111  enum { evaluateVector = IsComputation<VT>::value || RequiresEvaluation<VT>::value };
112  //**********************************************************************************************
113 
114  //**********************************************************************************************
116  enum { evaluateMatrix = ( IsComputation<MT>::value && IsSame<MET,VET>::value &&
118  //**********************************************************************************************
119 
120  //**********************************************************************************************
122 
125  template< typename T1, typename T2, typename T3 >
126  struct UseSMPAssignKernel {
127  enum { value = evaluateVector || evaluateMatrix };
128  };
130  //**********************************************************************************************
131 
132  //**********************************************************************************************
134 
138  template< typename T1, typename T2, typename T3 >
139  struct UseVectorizedKernel {
140  enum { value = !UseSMPAssignKernel<T1,T2,T3>::value &&
141  T1::vectorizable && T3::vectorizable &&
142  IsSame<typename T1::ElementType,typename T2::ElementType>::value &&
143  IsSame<typename T1::ElementType,typename T3::ElementType>::value &&
144  IntrinsicTrait<typename T1::ElementType>::addition &&
145  IntrinsicTrait<typename T1::ElementType>::multiplication };
146  };
148  //**********************************************************************************************
149 
150  //**********************************************************************************************
152 
156  template< typename T1, typename T2, typename T3 >
157  struct UseOptimizedKernel {
158  enum { value = !UseSMPAssignKernel<T1,T2,T3>::value &&
159  !UseVectorizedKernel<T1,T2,T3>::value &&
160  !IsResizable<typename T1::ElementType>::value &&
161  !IsResizable<VET>::value };
162  };
164  //**********************************************************************************************
165 
166  //**********************************************************************************************
168 
171  template< typename T1, typename T2, typename T3 >
172  struct UseDefaultKernel {
173  enum { value = !UseSMPAssignKernel<T1,T2,T3>::value &&
174  !UseVectorizedKernel<T1,T2,T3>::value &&
175  !UseOptimizedKernel<T1,T2,T3>::value };
176  };
178  //**********************************************************************************************
179 
180  public:
181  //**Type definitions****************************************************************************
187  typedef const ElementType ReturnType;
188  typedef const ResultType CompositeType;
189 
191  typedef typename SelectType< IsExpression<VT>::value, const VT, const VT& >::Type LeftOperand;
192 
194  typedef typename SelectType< IsExpression<MT>::value, const MT, const MT& >::Type RightOperand;
195 
198 
201  //**********************************************************************************************
202 
203  //**Compilation flags***************************************************************************
205  enum { vectorizable = MT::vectorizable &&
209 
211  enum { smpAssignable = !evaluateVector && !evaluateMatrix };
212  //**********************************************************************************************
213 
214  //**Constructor*********************************************************************************
220  explicit inline TSVecDMatMultExpr( const VT& vec, const MT& mat )
221  : vec_( vec ) // Left-hand side sparse vector of the multiplication expression
222  , mat_( mat ) // Right-hand side dense matrix of the multiplication expression
223  {
224  BLAZE_INTERNAL_ASSERT( vec_.size() == mat_.rows(), "Invalid vector and matrix sizes" );
225  }
226  //**********************************************************************************************
227 
228  //**Subscript operator**************************************************************************
234  inline ReturnType operator[]( size_t index ) const {
235  BLAZE_INTERNAL_ASSERT( index < mat_.columns(), "Invalid vector access index" );
236 
238 
239  LT x( vec_ ); // Evaluation of the left-hand side sparse vector operand
240 
241  BLAZE_INTERNAL_ASSERT( x.size() == vec_.size(), "Invalid vector size" );
242 
243  const ConstIterator end( x.end() );
244  ConstIterator element( x.begin() );
245  ElementType res;
246 
247  if( element != end ) {
248  res = element->value() * mat_( element->index(), index );
249  ++element;
250  for( ; element!=end; ++element )
251  res += element->value() * mat_( element->index(), index );
252  }
253  else {
254  reset( res );
255  }
256 
257  return res;
258  }
259  //**********************************************************************************************
260 
261  //**Size function*******************************************************************************
266  inline size_t size() const {
267  return mat_.columns();
268  }
269  //**********************************************************************************************
270 
271  //**Left operand access*************************************************************************
276  inline LeftOperand leftOperand() const {
277  return vec_;
278  }
279  //**********************************************************************************************
280 
281  //**Right operand access************************************************************************
286  inline RightOperand rightOperand() const {
287  return mat_;
288  }
289  //**********************************************************************************************
290 
291  //**********************************************************************************************
297  template< typename T >
298  inline bool canAlias( const T* alias ) const {
299  return vec_.isAliased( alias ) || mat_.isAliased( alias );
300  }
301  //**********************************************************************************************
302 
303  //**********************************************************************************************
309  template< typename T >
310  inline bool isAliased( const T* alias ) const {
311  return vec_.isAliased( alias ) || mat_.isAliased( alias );
312  }
313  //**********************************************************************************************
314 
315  //**********************************************************************************************
320  inline bool isAligned() const {
321  return mat_.isAligned();
322  }
323  //**********************************************************************************************
324 
325  //**********************************************************************************************
330  inline bool canSMPAssign() const {
331  return ( size() > SMP_TSVECDMATMULT_THRESHOLD );
332  }
333  //**********************************************************************************************
334 
335  private:
336  //**Member variables****************************************************************************
337  LeftOperand vec_;
338  RightOperand mat_;
339  //**********************************************************************************************
340 
341  //**Assignment to dense vectors*****************************************************************
354  template< typename VT2 > // Type of the target dense vector
355  friend inline void assign( DenseVector<VT2,true>& lhs, const TSVecDMatMultExpr& rhs )
356  {
358 
359  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
360 
361  // Evaluation of the left-hand side sparse vector operand
362  LT x( rhs.vec_ );
363  if( x.nonZeros() == 0UL ) {
364  reset( ~lhs );
365  return;
366  }
367 
368  // Evaluation of the right-hand side dense matrix operand
369  RT A( rhs.mat_ );
370 
371  // Checking the evaluated operands
372  BLAZE_INTERNAL_ASSERT( x.size() == rhs.vec_.size() , "Invalid vector size" );
373  BLAZE_INTERNAL_ASSERT( A.rows() == rhs.mat_.rows() , "Invalid number of rows" );
374  BLAZE_INTERNAL_ASSERT( A.columns() == rhs.mat_.columns(), "Invalid number of columns" );
375  BLAZE_INTERNAL_ASSERT( A.columns() == (~lhs).size() , "Invalid vector size" );
376 
377  // Performing the sparse vector-dense matrix multiplication
378  TSVecDMatMultExpr::selectAssignKernel( ~lhs, x, A );
379  }
381  //**********************************************************************************************
382 
383  //**Default assignment to dense vectors*********************************************************
397  template< typename VT1 // Type of the left-hand side target vector
398  , typename VT2 // Type of the left-hand side vector operand
399  , typename MT1 > // Type of the right-hand side matrix operand
400  static inline typename EnableIf< UseDefaultKernel<VT1,VT2,MT1> >::Type
401  selectAssignKernel( VT1& y, const VT2& x, const MT1& A )
402  {
404 
405  BLAZE_INTERNAL_ASSERT( x.nonZeros() != 0UL, "Invalid number of non-zero elements" );
406 
407  const size_t N( A.columns() );
408 
409  ConstIterator element( x.begin() );
410  const ConstIterator end( x.end() );
411 
412  for( size_t j=0UL; j<N; ++j ) {
413  y[j] = element->value() * A(element->index(),j);
414  }
415 
416  ++element;
417 
418  for( ; element!=end; ++element ) {
419  for( size_t j=0UL; j<N; ++j ) {
420  y[j] += element->value() * A(element->index(),j);
421  }
422  }
423  }
425  //**********************************************************************************************
426 
427  //**Optimized assignment to dense vectors*******************************************************
441  template< typename VT1 // Type of the left-hand side target vector
442  , typename VT2 // Type of the left-hand side vector operand
443  , typename MT1 > // Type of the right-hand side matrix operand
444  static inline typename EnableIf< UseOptimizedKernel<VT1,VT2,MT1> >::Type
445  selectAssignKernel( VT1& y, const VT2& x, const MT1& A )
446  {
448 
449  BLAZE_INTERNAL_ASSERT( x.nonZeros() != 0UL, "Invalid number of non-zero elements" );
450 
451  const size_t N( A.columns() );
452 
453  ConstIterator element( x.begin() );
454  const ConstIterator end( x.end() );
455 
456  const size_t iend( x.nonZeros() & size_t(-4) );
457  BLAZE_INTERNAL_ASSERT( ( x.nonZeros() - ( x.nonZeros() % 4UL ) ) == iend, "Invalid end calculation" );
458 
459  if( iend > 3UL )
460  {
461  const size_t i1( element->index() );
462  const VET v1( element->value() );
463  ++element;
464  const size_t i2( element->index() );
465  const VET v2( element->value() );
466  ++element;
467  const size_t i3( element->index() );
468  const VET v3( element->value() );
469  ++element;
470  const size_t i4( element->index() );
471  const VET v4( element->value() );
472  ++element;
473 
474  for( size_t j=0UL; j<N; ++j ) {
475  y[j] = v1 * A(i1,j) + v2 * A(i2,j) + v3 * A(i3,j) + v4 * A(i4,j);
476  }
477  }
478  else
479  {
480  const size_t i1( element->index() );
481  const VET v1( element->value() );
482  ++element;
483 
484  for( size_t j=0UL; j<N; ++j ) {
485  y[j] = v1 * A(i1,j);
486  }
487  }
488 
489  for( size_t i=(iend>3UL)?(4UL):(1UL); (i+4UL)<=iend; i+=4UL )
490  {
491  const size_t i1( element->index() );
492  const VET v1( element->value() );
493  ++element;
494  const size_t i2( element->index() );
495  const VET v2( element->value() );
496  ++element;
497  const size_t i3( element->index() );
498  const VET v3( element->value() );
499  ++element;
500  const size_t i4( element->index() );
501  const VET v4( element->value() );
502  ++element;
503 
504  for( size_t j=0UL; j<N; ++j ) {
505  y[j] += v1 * A(i1,j) + v2 * A(i2,j) + v3 * A(i3,j) + v4 * A(i4,j);
506  }
507  }
508  for( ; element!=end; ++element )
509  {
510  const size_t i1( element->index() );
511  const VET v1( element->value() );
512 
513  for( size_t j=0UL; j<N; ++j ) {
514  y[j] += v1 * A(i1,j);
515  }
516  }
517  }
519  //**********************************************************************************************
520 
521  //**Vectorized assignment to dense vectors******************************************************
535  template< typename VT1 // Type of the left-hand side target vector
536  , typename VT2 // Type of the left-hand side vector operand
537  , typename MT1 > // Type of the right-hand side matrix operand
538  static inline typename EnableIf< UseVectorizedKernel<VT1,VT2,MT1> >::Type
539  selectAssignKernel( VT1& y, const VT2& x, const MT1& A )
540  {
541  typedef IntrinsicTrait<ElementType> IT;
543 
544  BLAZE_INTERNAL_ASSERT( x.nonZeros() != 0UL, "Invalid number of non-zero elements" );
545 
546  const size_t N( A.columns() );
547 
548  ConstIterator element( x.begin() );
549  const ConstIterator end( x.end() );
550 
551  const size_t iend( x.nonZeros() & size_t(-4) );
552  BLAZE_INTERNAL_ASSERT( ( x.nonZeros() - ( x.nonZeros() % 4UL ) ) == iend, "Invalid end calculation" );
553 
554  if( iend > 3UL )
555  {
556  const size_t i1( element->index() );
557  const IntrinsicType v1( set( element->value() ) );
558  ++element;
559  const size_t i2( element->index() );
560  const IntrinsicType v2( set( element->value() ) );
561  ++element;
562  const size_t i3( element->index() );
563  const IntrinsicType v3( set( element->value() ) );
564  ++element;
565  const size_t i4( element->index() );
566  const IntrinsicType v4( set( element->value() ) );
567  ++element;
568 
569  for( size_t j=0UL; j<N; j+=IT::size ) {
570  y.store( j, v1 * A.load(i1,j) + v2 * A.load(i2,j) + v3 * A.load(i3,j) + v4 * A.load(i4,j) );
571  }
572  }
573  else
574  {
575  const size_t i1( element->index() );
576  const IntrinsicType v1( set( element->value() ) );
577  ++element;
578 
579  for( size_t j=0UL; j<N; j+=IT::size ) {
580  y.store( j, v1 * A.load(i1,j) );
581  }
582  }
583 
584  for( size_t i=(iend>3UL)?(4UL):(1UL); (i+4UL)<=iend; i+=4UL )
585  {
586  const size_t i1( element->index() );
587  const IntrinsicType v1( set( element->value() ) );
588  ++element;
589  const size_t i2( element->index() );
590  const IntrinsicType v2( set( element->value() ) );
591  ++element;
592  const size_t i3( element->index() );
593  const IntrinsicType v3( set( element->value() ) );
594  ++element;
595  const size_t i4( element->index() );
596  const IntrinsicType v4( set( element->value() ) );
597  ++element;
598 
599  for( size_t j=0UL; j<N; j+=IT::size ) {
600  y.store( j, y.load(j) + v1 * A.load(i1,j) + v2 * A.load(i2,j) + v3 * A.load(i3,j) + v4 * A.load(i4,j) );
601  }
602  }
603  for( ; element!=end; ++element )
604  {
605  const size_t i1( element->index() );
606  const IntrinsicType v1( set( element->value() ) );
607 
608  for( size_t j=0UL; j<N; j+=IT::size ) {
609  y.store( j, y.load(j) + v1 * A.load(i1,j) );
610  }
611  }
612  }
614  //**********************************************************************************************
615 
616  //**SMP assignment to dense vectors*************************************************************
630  template< typename VT1 // Type of the left-hand side target vector
631  , typename VT2 // Type of the left-hand side vector operand
632  , typename MT1 > // Type of the right-hand side matrix operand
633  static inline typename EnableIf< UseSMPAssignKernel<VT1,VT2,MT1> >::Type
634  selectAssignKernel( VT1& y, const VT2& x, const MT1& A )
635  {
636  smpAssign( y, x * A );
637  }
639  //**********************************************************************************************
640 
641  //**Assignment to sparse vectors****************************************************************
654  template< typename VT2 > // Type of the target sparse vector
655  friend inline void assign( SparseVector<VT2,true>& lhs, const TSVecDMatMultExpr& rhs )
656  {
658 
662 
663  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
664 
665  const ResultType tmp( rhs );
666  smpAssign( ~lhs, tmp );
667  }
669  //**********************************************************************************************
670 
671  //**Addition assignment to dense vectors********************************************************
683  template< typename VT2 > // Type of the target dense vector
684  friend inline void addAssign( DenseVector<VT2,true>& lhs, const TSVecDMatMultExpr& rhs )
685  {
687 
688  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
689 
690  // Evaluation of the left-hand side sparse vector operand
691  LT x( rhs.vec_ );
692  if( x.nonZeros() == 0UL ) return;
693 
694  // Evaluation of the right-hand side dense matrix operand
695  RT A( rhs.mat_ );
696 
697  // Checking the evaluated operands
698  BLAZE_INTERNAL_ASSERT( x.size() == rhs.vec_.size() , "Invalid vector size" );
699  BLAZE_INTERNAL_ASSERT( A.rows() == rhs.mat_.rows() , "Invalid number of rows" );
700  BLAZE_INTERNAL_ASSERT( A.columns() == rhs.mat_.columns(), "Invalid number of columns" );
701  BLAZE_INTERNAL_ASSERT( A.columns() == (~lhs).size() , "Invalid vector size" );
702 
703  // Performing the sparse vector-dense matrix multiplication
704  TSVecDMatMultExpr::selectAddAssignKernel( ~lhs, x, A );
705  }
706  //**********************************************************************************************
707 
708  //**Default addition assignment to dense vectors************************************************
722  template< typename VT1 // Type of the left-hand side target vector
723  , typename VT2 // Type of the left-hand side vector operand
724  , typename MT1 > // Type of the right-hand side matrix operand
725  static inline typename EnableIf< UseDefaultKernel<VT1,VT2,MT1> >::Type
726  selectAddAssignKernel( VT1& y, const VT2& x, const MT1& A )
727  {
729 
730  BLAZE_INTERNAL_ASSERT( x.nonZeros() != 0UL, "Invalid number of non-zero elements" );
731 
732  const size_t N( A.columns() );
733 
734  ConstIterator element( x.begin() );
735  const ConstIterator end( x.end() );
736 
737  for( ; element!=end; ++element ) {
738  for( size_t j=0UL; j<N; ++j ) {
739  y[j] += element->value() * A(element->index(),j);
740  }
741  }
742  }
744  //**********************************************************************************************
745 
746  //**Optimized addition assignment to dense vectors**********************************************
760  template< typename VT1 // Type of the left-hand side target vector
761  , typename VT2 // Type of the left-hand side vector operand
762  , typename MT1 > // Type of the right-hand side matrix operand
763  static inline typename EnableIf< UseOptimizedKernel<VT1,VT2,MT1> >::Type
764  selectAddAssignKernel( VT1& y, const VT2& x, const MT1& A )
765  {
767 
768  BLAZE_INTERNAL_ASSERT( x.nonZeros() != 0UL, "Invalid number of non-zero elements" );
769 
770  const size_t N( A.columns() );
771 
772  ConstIterator element( x.begin() );
773  const ConstIterator end( x.end() );
774 
775  const size_t iend( x.nonZeros() & size_t(-4) );
776  BLAZE_INTERNAL_ASSERT( ( x.nonZeros() - ( x.nonZeros() % 4UL ) ) == iend, "Invalid end calculation" );
777 
778  for( size_t i=0UL; (i+4UL)<=iend; i+=4UL )
779  {
780  const size_t i1( element->index() );
781  const VET v1( element->value() );
782  ++element;
783  const size_t i2( element->index() );
784  const VET v2( element->value() );
785  ++element;
786  const size_t i3( element->index() );
787  const VET v3( element->value() );
788  ++element;
789  const size_t i4( element->index() );
790  const VET v4( element->value() );
791  ++element;
792 
793  for( size_t j=0UL; j<N; ++j ) {
794  y[j] += v1 * A(i1,j) + v2 * A(i2,j) + v3 * A(i3,j) + v4 * A(i4,j);
795  }
796  }
797  for( ; element!=end; ++element )
798  {
799  const size_t i1( element->index() );
800  const VET v1( element->value() );
801 
802  for( size_t j=0UL; j<N; ++j ) {
803  y[j] += v1 * A(i1,j);
804  }
805  }
806  }
808  //**********************************************************************************************
809 
810  //**Vectorized addition assignment to dense vectors*********************************************
824  template< typename VT1 // Type of the left-hand side target vector
825  , typename VT2 // Type of the left-hand side vector operand
826  , typename MT1 > // Type of the right-hand side matrix operand
827  static inline typename EnableIf< UseVectorizedKernel<VT1,VT2,MT1> >::Type
828  selectAddAssignKernel( VT1& y, const VT2& x, const MT1& A )
829  {
830  typedef IntrinsicTrait<ElementType> IT;
832 
833  BLAZE_INTERNAL_ASSERT( x.nonZeros() != 0UL, "Invalid number of non-zero elements" );
834 
835  const size_t N( A.columns() );
836 
837  ConstIterator element( x.begin() );
838  const ConstIterator end( x.end() );
839 
840  const size_t iend( x.nonZeros() & size_t(-4) );
841  BLAZE_INTERNAL_ASSERT( ( x.nonZeros() - ( x.nonZeros() % 4UL ) ) == iend, "Invalid end calculation" );
842 
843  for( size_t i=0UL; (i+4UL)<=iend; i+=4UL )
844  {
845  const size_t i1( element->index() );
846  const IntrinsicType v1( set( element->value() ) );
847  ++element;
848  const size_t i2( element->index() );
849  const IntrinsicType v2( set( element->value() ) );
850  ++element;
851  const size_t i3( element->index() );
852  const IntrinsicType v3( set( element->value() ) );
853  ++element;
854  const size_t i4( element->index() );
855  const IntrinsicType v4( set( element->value() ) );
856  ++element;
857 
858  for( size_t j=0UL; j<N; j+=IT::size ) {
859  y.store( j, y.load(j) + v1 * A.load(i1,j) + v2 * A.load(i2,j) + v3 * A.load(i3,j) + v4 * A.load(i4,j) );
860  }
861  }
862  for( ; element!=end; ++element )
863  {
864  const size_t i1( element->index() );
865  const IntrinsicType v1( set( element->value() ) );
866 
867  for( size_t j=0UL; j<N; j+=IT::size ) {
868  y.store( j, y.load(j) + v1 * A.load(i1,j) );
869  }
870  }
871  }
873  //**********************************************************************************************
874 
875  //**SMP addition assignment to dense vectors****************************************************
889  template< typename VT1 // Type of the left-hand side target vector
890  , typename VT2 // Type of the left-hand side vector operand
891  , typename MT1 > // Type of the right-hand side matrix operand
892  static inline typename EnableIf< UseSMPAssignKernel<VT1,VT2,MT1> >::Type
893  selectAddAssignKernel( VT1& y, const VT2& x, const MT1& A )
894  {
895  smpAddAssign( y, x * A );
896  }
898  //**********************************************************************************************
899 
900  //**Addition assignment to sparse vectors*******************************************************
901  // No special implementation for the addition assignment to sparse vectors.
902  //**********************************************************************************************
903 
904  //**Subtraction assignment to dense vectors*****************************************************
916  template< typename VT2 > // Type of the target dense vector
917  friend inline void subAssign( DenseVector<VT2,true>& lhs, const TSVecDMatMultExpr& rhs )
918  {
920 
921  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
922 
924 
925  // Evaluation of the left-hand side sparse vector operand
926  LT x( rhs.vec_ );
927  if( x.nonZeros() == 0UL ) return;
928 
929  // Evaluation of the right-hand side dense matrix operand
930  RT A( rhs.mat_ );
931 
932  // Checking the evaluated operands
933  BLAZE_INTERNAL_ASSERT( x.size() == rhs.vec_.size() , "Invalid vector size" );
934  BLAZE_INTERNAL_ASSERT( A.rows() == rhs.mat_.rows() , "Invalid number of rows" );
935  BLAZE_INTERNAL_ASSERT( A.columns() == rhs.mat_.columns(), "Invalid number of columns" );
936  BLAZE_INTERNAL_ASSERT( A.columns() == (~lhs).size() , "Invalid vector size" );
937 
938  // Performing the sparse vector-dense matrix multiplication
939  TSVecDMatMultExpr::selectSubAssignKernel( ~lhs, x, A );
940  }
941  //**********************************************************************************************
942 
943  //**Default subtraction assignment to dense vectors*********************************************
957  template< typename VT1 // Type of the left-hand side target vector
958  , typename VT2 // Type of the left-hand side vector operand
959  , typename MT1 > // Type of the right-hand side matrix operand
960  static inline typename EnableIf< UseDefaultKernel<VT1,VT2,MT1> >::Type
961  selectSubAssignKernel( VT1& y, const VT2& x, const MT1& A )
962  {
964 
965  BLAZE_INTERNAL_ASSERT( x.nonZeros() != 0UL, "Invalid number of non-zero elements" );
966 
967  const size_t N( A.columns() );
968 
969  ConstIterator element( x.begin() );
970  const ConstIterator end( x.end() );
971 
972  for( ; element!=end; ++element ) {
973  for( size_t j=0UL; j<N; ++j ) {
974  y[j] -= element->value() * A(element->index(),j);
975  }
976  }
977  }
979  //**********************************************************************************************
980 
981  //**Optimized subtraction assignment to dense vectors*******************************************
995  template< typename VT1 // Type of the left-hand side target vector
996  , typename VT2 // Type of the left-hand side vector operand
997  , typename MT1 > // Type of the right-hand side matrix operand
998  static inline typename EnableIf< UseOptimizedKernel<VT1,VT2,MT1> >::Type
999  selectSubAssignKernel( VT1& y, const VT2& x, const MT1& A )
1000  {
1002 
1003  BLAZE_INTERNAL_ASSERT( x.nonZeros() != 0UL, "Invalid number of non-zero elements" );
1004 
1005  const size_t N( A.columns() );
1006 
1007  ConstIterator element( x.begin() );
1008  const ConstIterator end( x.end() );
1009 
1010  const size_t iend( x.nonZeros() & size_t(-4) );
1011  BLAZE_INTERNAL_ASSERT( ( x.nonZeros() - ( x.nonZeros() % 4UL ) ) == iend, "Invalid end calculation" );
1012 
1013  for( size_t i=0UL; (i+4UL)<=iend; i+=4UL )
1014  {
1015  const size_t i1( element->index() );
1016  const VET v1( element->value() );
1017  ++element;
1018  const size_t i2( element->index() );
1019  const VET v2( element->value() );
1020  ++element;
1021  const size_t i3( element->index() );
1022  const VET v3( element->value() );
1023  ++element;
1024  const size_t i4( element->index() );
1025  const VET v4( element->value() );
1026  ++element;
1027 
1028  for( size_t j=0UL; j<N; ++j ) {
1029  y[j] -= v1 * A(i1,j) + v2 * A(i2,j) + v3 * A(i3,j) + v4 * A(i4,j);
1030  }
1031  }
1032  for( ; element!=end; ++element )
1033  {
1034  const size_t i1( element->index() );
1035  const VET v1( element->value() );
1036 
1037  for( size_t j=0UL; j<N; ++j ) {
1038  y[j] -= v1 * A(i1,j);
1039  }
1040  }
1041  }
1043  //**********************************************************************************************
1044 
1045  //**Vectorized subtraction assignment to dense vectors******************************************
1059  template< typename VT1 // Type of the left-hand side target vector
1060  , typename VT2 // Type of the left-hand side vector operand
1061  , typename MT1 > // Type of the right-hand side matrix operand
1062  static inline typename EnableIf< UseVectorizedKernel<VT1,VT2,MT1> >::Type
1063  selectSubAssignKernel( VT1& y, const VT2& x, const MT1& A )
1064  {
1065  typedef IntrinsicTrait<ElementType> IT;
1067 
1068  BLAZE_INTERNAL_ASSERT( x.nonZeros() != 0UL, "Invalid number of non-zero elements" );
1069 
1070  const size_t N( A.columns() );
1071 
1072  ConstIterator element( x.begin() );
1073  const ConstIterator end( x.end() );
1074 
1075  const size_t iend( x.nonZeros() & size_t(-4) );
1076  BLAZE_INTERNAL_ASSERT( ( x.nonZeros() - ( x.nonZeros() % 4UL ) ) == iend, "Invalid end calculation" );
1077 
1078  for( size_t i=0UL; (i+4UL)<=iend; i+=4UL )
1079  {
1080  const size_t i1( element->index() );
1081  const IntrinsicType v1( set( element->value() ) );
1082  ++element;
1083  const size_t i2( element->index() );
1084  const IntrinsicType v2( set( element->value() ) );
1085  ++element;
1086  const size_t i3( element->index() );
1087  const IntrinsicType v3( set( element->value() ) );
1088  ++element;
1089  const size_t i4( element->index() );
1090  const IntrinsicType v4( set( element->value() ) );
1091  ++element;
1092 
1093  for( size_t j=0UL; j<N; j+=IT::size ) {
1094  y.store( j, y.load(j) - v1 * A.load(i1,j) - v2 * A.load(i2,j) - v3 * A.load(i3,j) - v4 * A.load(i4,j) );
1095  }
1096  }
1097  for( ; element!=x.end(); ++element )
1098  {
1099  const size_t i1( element->index() );
1100  const IntrinsicType v1( set( element->value() ) );
1101 
1102  for( size_t j=0UL; j<N; j+=IT::size ) {
1103  y.store( j, y.load(j) - v1 * A.load(i1,j) );
1104  }
1105  }
1106  }
1108  //**********************************************************************************************
1109 
1110  //**SMP subtraction assignment to dense vectors*************************************************
1124  template< typename VT1 // Type of the left-hand side target vector
1125  , typename VT2 // Type of the left-hand side vector operand
1126  , typename MT1 > // Type of the right-hand side matrix operand
1127  static inline typename EnableIf< UseSMPAssignKernel<VT1,VT2,MT1> >::Type
1128  selectSubAssignKernel( VT1& y, const VT2& x, const MT1& A )
1129  {
1130  smpSubAssign( y, x * A );
1131  }
1133  //**********************************************************************************************
1134 
1135  //**Subtraction assignment to sparse vectors****************************************************
1136  // No special implementation for the subtraction assignment to sparse vectors.
1137  //**********************************************************************************************
1138 
1139  //**Multiplication assignment to dense vectors**************************************************
1151  template< typename VT2 > // Type of the target dense vector
1152  friend inline void multAssign( DenseVector<VT2,true>& lhs, const TSVecDMatMultExpr& rhs )
1153  {
1155 
1159 
1160  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
1161 
1162  const ResultType tmp( rhs );
1163  smpMultAssign( ~lhs, tmp );
1164  }
1165  //**********************************************************************************************
1166 
1167  //**Multiplication assignment to sparse vectors*************************************************
1168  // No special implementation for the multiplication assignment to sparse vectors.
1169  //**********************************************************************************************
1170 
1171  //**Compile time checks*************************************************************************
1178  //**********************************************************************************************
1179 };
1180 //*************************************************************************************************
1181 
1182 
1183 
1184 
1185 //=================================================================================================
1186 //
1187 // GLOBAL BINARY ARITHMETIC OPERATORS
1188 //
1189 //=================================================================================================
1190 
1191 //*************************************************************************************************
1222 template< typename T1, typename T2 >
1223 inline const typename DisableIf< IsMatMatMultExpr<T2>, TSVecDMatMultExpr<T1,T2> >::Type
1225 {
1227 
1228  if( (~vec).size() != (~mat).rows() )
1229  throw std::invalid_argument( "Vector and matrix sizes do not match" );
1230 
1231  return TSVecDMatMultExpr<T1,T2>( ~vec, ~mat );
1232 }
1233 //*************************************************************************************************
1234 
1235 
1236 
1237 
1238 //=================================================================================================
1239 //
1240 // GLOBAL RESTRUCTURING BINARY ARITHMETIC OPERATORS
1241 //
1242 //=================================================================================================
1243 
1244 //*************************************************************************************************
1257 template< typename T1 // Type of the left-hand side sparse vector
1258  , typename T2 // Type of the right-hand side dense matrix
1259  , bool SO > // Storage order of the right-hand side dense matrix
1260 inline const typename EnableIf< IsMatMatMultExpr<T2>, MultExprTrait<T1,T2> >::Type::Type
1262 {
1264 
1265  return ( vec * (~mat).leftOperand() ) * (~mat).rightOperand();
1266 }
1267 //*************************************************************************************************
1268 
1269 
1270 
1271 
1272 //=================================================================================================
1273 //
1274 // EXPRESSION TRAIT SPECIALIZATIONS
1275 //
1276 //=================================================================================================
1277 
1278 //*************************************************************************************************
1280 template< typename VT, typename MT, bool AF >
1281 struct SubvectorExprTrait< TSVecDMatMultExpr<VT,MT>, AF >
1282 {
1283  public:
1284  //**********************************************************************************************
1285  typedef typename MultExprTrait< VT, typename SubmatrixExprTrait<const MT,AF>::Type >::Type Type;
1286  //**********************************************************************************************
1287 };
1289 //*************************************************************************************************
1290 
1291 } // namespace blaze
1292 
1293 #endif
Compile time check whether the given type is a computational expression template.This type trait clas...
Definition: IsComputation.h:89
void reset(DynamicMatrix< Type, SO > &m)
Resetting the given dense matrix.
Definition: DynamicMatrix.h:4579
friend void multAssign(DenseVector< VT2, true > &lhs, const TSVecDMatMultExpr &rhs)
Multiplication assignment of a transpose sparse vector-dense matrix multiplication to a dense vector ...
Definition: TSVecDMatMultExpr.h:1152
const DMatDMatMultExpr< T1, T2 > operator*(const DenseMatrix< T1, false > &lhs, const DenseMatrix< T2, false > &rhs)
Multiplication operator for the multiplication of two row-major dense matrices ( ).
Definition: DMatDMatMultExpr.h:4075
TSVecDMatMultExpr< VT, MT > This
Type of this TSVecDMatMultExpr instance.
Definition: TSVecDMatMultExpr.h:182
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: TSVecDMatMultExpr.h:184
Expression object for transpose sparse vector-dense matrix multiplications.The TSVecDMatMultExpr clas...
Definition: Forward.h:143
SelectType< evaluateMatrix, const MRT, MCT >::Type RT
Type for the assignment of the right-hand side dense matrix operand.
Definition: TSVecDMatMultExpr.h:200
SelectType< IsExpression< MT >::value, const MT, const MT & >::Type RightOperand
Composite type of the right-hand side sparse matrix expression.
Definition: TSVecDMatMultExpr.h:194
void smpSubAssign(DenseMatrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP subtraction assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:151
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: TSVecDMatMultExpr.h:234
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:197
VT::ResultType VRT
Result type of the left-hand side sparse vector expression.
Definition: TSVecDMatMultExpr.h:101
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a dense, N-dimensional matrix type...
Definition: DenseMatrix.h:79
void smpMultAssign(DenseVector< VT1, TF1 > &lhs, const Vector< VT2, TF2 > &rhs)
Default implementation of the SMP multiplication assignment of a vector to a dense vector...
Definition: DenseVector.h:178
Header file for the IsSame and IsStrictlySame type traits.
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2384
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:249
VT::CompositeType VCT
Composite type of the left-hand side sparse vector expression.
Definition: TSVecDMatMultExpr.h:105
Header file for the DenseVector base class.
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
Header file for the RequiresEvaluation type trait.
IntrinsicTrait< ElementType >::Type IntrinsicType
Resulting intrinsic element type.
Definition: TSVecDMatMultExpr.h:186
Base class for dense matrices.The DenseMatrix class is a base class for all dense matrix classes...
Definition: DenseMatrix.h:70
bool isAligned() const
Returns whether the operands of the expression are properly aligned in memory.
Definition: TSVecDMatMultExpr.h:320
const ElementType ReturnType
Return type for expression template evaluations.
Definition: TSVecDMatMultExpr.h:187
Constraint on the data type.
Constraint on the data type.
Header file for the MultExprTrait class template.
void smpAddAssign(DenseMatrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP addition assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:121
Compile time check to query the requirement to evaluate an expression.Via this type trait it is possi...
Definition: RequiresEvaluation.h:90
size_t size() const
Returns the current size/dimension of the vector.
Definition: TSVecDMatMultExpr.h:266
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:251
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 DisableIf class template.
friend void addAssign(DenseVector< VT2, true > &lhs, const TSVecDMatMultExpr &rhs)
Addition assignment of a transpose sparse vector-dense matrix multiplication to a dense vector ( )...
Definition: TSVecDMatMultExpr.h:684
Header file for the multiplication trait.
MT::CompositeType MCT
Composite type of the right-hand side dense matrix expression.
Definition: TSVecDMatMultExpr.h:106
Header file for the dense vector SMP implementation.
LeftOperand leftOperand() const
Returns the left-hand side sparse vector operand.
Definition: TSVecDMatMultExpr.h:276
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2388
TSVecDMatMultExpr(const VT &vec, const MT &mat)
Constructor for the TSVecDMatMultExpr class.
Definition: TSVecDMatMultExpr.h:220
Header file for the IsMatMatMultExpr type trait class.
MT::ResultType MRT
Result type of the right-hand side dense matrix expression.
Definition: TSVecDMatMultExpr.h:102
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: TSVecDMatMultExpr.h:310
void assign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the assignment of a matrix to a matrix.
Definition: Matrix.h:179
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a sparse, N-dimensional vector type...
Definition: SparseVector.h:79
Constraint on the data type.
#define BLAZE_CONSTRAINT_MUST_BE_REFERENCE_TYPE(T)
Constraint on the data type.In case the given data type T is not a reference type, a compilation error is created.
Definition: Reference.h:78
SelectType< IsExpression< VT >::value, const VT, const VT & >::Type LeftOperand
Composite type of the left-hand side sparse vector expression.
Definition: TSVecDMatMultExpr.h:191
Constraints on the storage order of matrix types.
Constraint on the data type.
MRT::ElementType MET
Element type of the right-hand side dense matrix expression.
Definition: TSVecDMatMultExpr.h:104
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2382
Header file for the SelectType class template.
Header file for all forward declarations for expression class templates.
MultTrait< VRT, MRT >::Type ResultType
Result type for expression template evaluations.
Definition: TSVecDMatMultExpr.h:183
Constraint on the data type.
Header file for the EnableIf class template.
void smpAssign(DenseMatrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:91
Header file for the SubmatrixExprTrait class template.
#define BLAZE_CONSTRAINT_MUST_BE_ROW_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a row-major dense or sparse matrix t...
Definition: StorageOrder.h:81
Removal of reference modifiers.The RemoveCV type trait removes any reference modifiers from the given...
Definition: RemoveReference.h:69
Intrinsic characteristics of data types.The IntrinsicTrait class template provides the intrinsic char...
Definition: IntrinsicTrait.h:748
Header file for run time assertion macros.
Base template for the MultTrait class.
Definition: MultTrait.h:141
const ResultType CompositeType
Data type for composite expression templates.
Definition: TSVecDMatMultExpr.h:188
Substitution Failure Is Not An Error (SFINAE) class.The EnableIf class template is an auxiliary tool ...
Definition: EnableIf.h:184
Header file for the reset shim.
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: TSVecDMatMultExpr.h:298
Compile time check for data types.This type trait tests whether or not the given template parameter i...
Definition: IsBlasCompatible.h:99
SelectType< evaluateVector, const VRT, VCT >::Type LT
Type for the assignment of the left-hand side sparse vector operand.
Definition: TSVecDMatMultExpr.h:197
Header file for the TVecMatMultExpr base class.
Header file for the RemoveReference type trait.
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
bool canSMPAssign() const
Returns whether the expression can be used in SMP assignments.
Definition: TSVecDMatMultExpr.h:330
RightOperand mat_
Right-hand side dense matrix of the multiplication expression.
Definition: TSVecDMatMultExpr.h:338
LeftOperand vec_
Left-hand side sparse vector of the multiplication expression.
Definition: TSVecDMatMultExpr.h:337
Header file for the IsComputation type trait class.
Header file for the sparse vector SMP implementation.
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:105
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:157
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2379
Header file for basic type definitions.
#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.
VRT::ElementType VET
Element type of the left-hand side sparse vector expression.
Definition: TSVecDMatMultExpr.h:103
const size_t SMP_TSVECDMATMULT_THRESHOLD
SMP sparse vector/row-major dense matrix multiplication threshold.This threshold represents the syste...
Definition: Thresholds.h:217
friend void subAssign(DenseVector< VT2, true > &lhs, const TSVecDMatMultExpr &rhs)
Subtraction assignment of a transpose sparse vector-dense matrix multiplication to a dense vector ( )...
Definition: TSVecDMatMultExpr.h:917
Header file for the IsResizable type trait.
Header file for the thresholds for matrix/vector and matrix/matrix multiplications.
RightOperand rightOperand() const
Returns the right-hand side dense matrix operand.
Definition: TSVecDMatMultExpr.h:286
size_t rows(const Matrix< MT, SO > &m)
Returns the current number of rows of the matrix.
Definition: Matrix.h:138
#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
ResultType::ElementType ElementType
Resulting element type.
Definition: TSVecDMatMultExpr.h:185
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.