All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TDVecSVecMultExpr.h
Go to the documentation of this file.
1 //=================================================================================================
20 //=================================================================================================
21 
22 #ifndef _BLAZE_MATH_EXPRESSIONS_TDVECSVECMULTEXPR_H_
23 #define _BLAZE_MATH_EXPRESSIONS_TDVECSVECMULTEXPR_H_
24 
25 
26 //*************************************************************************************************
27 // Includes
28 //*************************************************************************************************
29 
30 #include <stdexcept>
31 #include <boost/type_traits/remove_reference.hpp>
39 #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 dense vector
82  , typename T2 > // Type of the right-hand side sparse vector
83 inline const typename MultTrait<typename T1::ElementType,typename T2::ElementType>::Type
85 {
87 
88  using boost::remove_reference;
89 
90  typedef typename T1::CompositeType Lhs; // Composite type of the left-hand side dense vector expression
91  typedef typename T2::CompositeType Rhs; // Composite type of the right-hand side sparse vector expression
92  typedef typename remove_reference<Lhs>::type X1; // Auxiliary type for the left-hand side composite type
93  typedef typename remove_reference<Rhs>::type X2; // Auxiliary type for the right-hand side composite type
94  typedef typename X1::ElementType ET1; // Element type of the left-hand side dense vector expression
95  typedef typename X2::ElementType ET2; // Element type of the right-hand side sparse vector expression
96  typedef typename MultTrait<ET1,ET2>::Type MultType; // Multiplication result type
97  typedef typename X2::ConstIterator ConstIterator; // Iterator type of the right-hand sparse vector expression
98 
103 
104  if( (~lhs).size() != (~rhs).size() )
105  throw std::invalid_argument( "Vector sizes do not match" );
106 
107  if( (~rhs).nonZeros() == 0UL ) return MultType();
108 
109  Lhs left ( ~lhs );
110  Rhs right( ~rhs );
111 
112  ConstIterator element( right.begin() );
113  MultType sp( left[ element->index() ] * element->value() );
114  ++element;
115 
116  for( ; element!=right.end(); ++element )
117  sp += left[ element->index() ] * element->value();
118 
119  return sp;
120 }
121 //*************************************************************************************************
122 
123 } // namespace blaze
124 
125 #endif