All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TDVecSVecMultExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_TDVECSVECMULTEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_TDVECSVECMULTEXPR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <stdexcept>
51 #include <blaze/util/Types.h>
53 
54 
55 namespace blaze {
56 
57 //=================================================================================================
58 //
59 // GLOBAL BINARY ARITHMETIC OPERATORS
60 //
61 //=================================================================================================
62 
63 //*************************************************************************************************
94 template< typename T1 // Type of the left-hand side dense vector
95  , typename T2 > // Type of the right-hand side sparse vector
96 inline const typename MultTrait<typename T1::ElementType,typename T2::ElementType>::Type
98 {
100 
101  typedef typename T1::CompositeType Lhs; // Composite type of the left-hand side dense vector expression
102  typedef typename T2::CompositeType Rhs; // Composite type of the right-hand side sparse vector expression
103  typedef typename RemoveReference<Lhs>::Type X1; // Auxiliary type for the left-hand side composite type
104  typedef typename RemoveReference<Rhs>::Type X2; // Auxiliary type for the right-hand side composite type
105  typedef typename X1::ElementType ET1; // Element type of the left-hand side dense vector expression
106  typedef typename X2::ElementType ET2; // Element type of the right-hand side sparse vector expression
107  typedef typename MultTrait<ET1,ET2>::Type MultType; // Multiplication result type
108  typedef typename X2::ConstIterator ConstIterator; // Iterator type of the right-hand sparse vector expression
109 
114 
115  if( (~lhs).size() != (~rhs).size() )
116  throw std::invalid_argument( "Vector sizes do not match" );
117 
118  if( (~rhs).nonZeros() == 0UL ) return MultType();
119 
120  Lhs left ( ~lhs );
121  Rhs right( ~rhs );
122 
123  ConstIterator element( right.begin() );
124  MultType sp( left[ element->index() ] * element->value() );
125  ++element;
126 
127  for( ; element!=right.end(); ++element )
128  sp += left[ element->index() ] * element->value();
129 
130  return sp;
131 }
132 //*************************************************************************************************
133 
134 } // namespace blaze
135 
136 #endif
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
Header file for the SparseVector base class.
#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
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2408
Header file for the DenseVector base class.
Header file for the multiplication trait.
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2412
size_t nonZeros(const Matrix< MT, SO > &m)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:224
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.
Constraint on the data type.
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2406
Constraint on the data type.
Removal of reference modifiers.The RemoveCV type trait removes any reference modifiers from the given...
Definition: RemoveReference.h:69
Base template for the MultTrait class.
Definition: MultTrait.h:141
Header file for the RemoveReference type trait.
#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
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
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 FunctionTrace class.