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>
38 #include <blaze/util/Types.h>
39 
40 
41 namespace blaze {
42 
43 //=================================================================================================
44 //
45 // GLOBAL BINARY ARITHMETIC OPERATORS
46 //
47 //=================================================================================================
48 
49 //*************************************************************************************************
80 template< typename T1 // Type of the left-hand side dense vector
81  , typename T2 > // Type of the right-hand side sparse vector
82 inline const typename MultTrait<typename T1::ElementType,typename T2::ElementType>::Type
84 {
85  using boost::remove_reference;
86 
87  typedef typename T1::CompositeType Lhs; // Composite type of the left-hand side dense vector expression
88  typedef typename T2::CompositeType Rhs; // Composite type of the right-hand side sparse vector expression
89  typedef typename remove_reference<Lhs>::type X1; // Auxiliary type for the left-hand side composite type
90  typedef typename remove_reference<Rhs>::type X2; // Auxiliary type for the right-hand side composite type
91  typedef typename X1::ElementType ET1; // Element type of the left-hand side dense vector expression
92  typedef typename X2::ElementType ET2; // Element type of the right-hand side sparse vector expression
93  typedef typename MultTrait<ET1,ET2>::Type MultType; // Multiplication result type
94  typedef typename X2::ConstIterator ConstIterator; // Iterator type of the right-hand sparse vector expression
95 
100 
101  if( (~lhs).size() != (~rhs).size() )
102  throw std::invalid_argument( "Vector sizes do not match" );
103 
104  if( (~rhs).nonZeros() == 0UL ) return MultType();
105 
106  Lhs left ( ~lhs );
107  Rhs right( ~rhs );
108 
109  ConstIterator element( right.begin() );
110  MultType sp( left[ element->index() ] * element->value() );
111  ++element;
112 
113  for( ; element!=right.end(); ++element )
114  sp += left[ element->index() ] * element->value();
115 
116  return sp;
117 }
118 //*************************************************************************************************
119 
120 } // namespace blaze
121 
122 #endif