All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TSVecDVecMultExpr.h
Go to the documentation of this file.
1 //=================================================================================================
20 //=================================================================================================
21 
22 #ifndef _BLAZE_MATH_EXPRESSIONS_TSVECDVECMULTEXPR_H_
23 #define _BLAZE_MATH_EXPRESSIONS_TSVECDVECMULTEXPR_H_
24 
25 
26 //*************************************************************************************************
27 // Includes
28 //*************************************************************************************************
29 
30 #include <stdexcept>
38 #include <blaze/util/Types.h>
40 
41 
42 namespace blaze {
43 
44 //=================================================================================================
45 //
46 // GLOBAL BINARY ARITHMETIC OPERATORS
47 //
48 //=================================================================================================
49 
50 //*************************************************************************************************
81 template< typename T1 // Type of the left-hand side sparse vector
82  , typename T2 > // Type of the right-hand side dense vector
83 inline const typename MultTrait<typename T1::ElementType,typename T2::ElementType>::Type
85 {
87 
88  typedef typename T1::CompositeType Lhs; // Composite type of the left-hand side sparse vector expression
89  typedef typename T2::CompositeType Rhs; // Composite type of the right-hand side dense vector expression
90  typedef typename RemoveReference<Lhs>::Type X1; // Auxiliary type for the left-hand side composite type
91  typedef typename RemoveReference<Rhs>::Type X2; // Auxiliary type for the right-hand side composite type
92  typedef typename X1::ElementType ET1; // Element type of the left-hand side sparse vector expression
93  typedef typename X2::ElementType ET2; // Element type of the right-hand side dense vector expression
94  typedef typename MultTrait<ET1,ET2>::Type MultType; // Multiplication result type
95  typedef typename X1::ConstIterator ConstIterator; // Iterator type of the left-hand sparse vector expression
96 
101 
102  if( (~lhs).size() != (~rhs).size() )
103  throw std::invalid_argument( "Vector sizes do not match" );
104 
105  if( (~lhs).nonZeros() == 0UL ) return MultType();
106 
107  Lhs left ( ~lhs );
108  Rhs right( ~rhs );
109 
110  ConstIterator element( left.begin() );
111  MultType sp( element->value() * right[ element->index() ] );
112  ++element;
113 
114  for( ; element!=left.end(); ++element )
115  sp += element->value() * right[ element->index() ];
116 
117  return sp;
118 }
119 //*************************************************************************************************
120 
121 } // namespace blaze
122 
123 #endif