Blaze 3.9
DVecSVecInnerExpr.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_EXPRESSIONS_DVECSVECINNEREXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_DVECSVECINNEREXPR_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <blaze/math/Aliases.h>
54#include <blaze/util/Types.h>
56
57
58namespace blaze {
59
60//=================================================================================================
61//
62// GLOBAL BINARY ARITHMETIC OPERATORS
63//
64//=================================================================================================
65
66//*************************************************************************************************
97template< typename VT1 // Type of the left-hand side dense vector
98 , typename VT2 > // Type of the right-hand side sparse vector
99inline decltype(auto)
100 operator*( const DenseVector<VT1,true>& lhs, const SparseVector<VT2,false>& rhs )
101{
103
104 using CT1 = CompositeType_t<VT1>; // Composite type of the left-hand side dense vector expression
105 using CT2 = CompositeType_t<VT2>; // Composite type of the right-hand side sparse vector expression
106 using XT1 = RemoveReference_t<CT1>; // Auxiliary type for the left-hand side composite type
107 using XT2 = RemoveReference_t<CT2>; // Auxiliary type for the right-hand side composite type
108 using ET1 = ElementType_t<XT1>; // Element type of the left-hand side dense vector expression
109 using ET2 = ElementType_t<XT2>; // Element type of the right-hand side sparse vector expression
110 using MultType = MultTrait_t<ET1,ET2>; // Multiplication result type
111
116
117 if( (*lhs).size() != (*rhs).size() ) {
118 BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
119 }
120
121 CT1 left ( *lhs );
122 CT2 right( *rhs );
123
124 auto element( right.begin() );
125 auto end ( right.end() );
126
127 MultType sp{};
128
129 if( element != end ) {
130 sp = left[ element->index() ] * element->value();
131 ++element;
132 for( ; element!=end; ++element )
133 sp += left[ element->index() ] * element->value();
134 }
135
136 return sp;
137}
138//*************************************************************************************************
139
140} // namespace blaze
141
142#endif
Header file for auxiliary alias declarations.
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.
Definition: Aliases.h:110
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.
Definition: Aliases.h:190
Constraint on the transpose flag of vector types.
Header file for the function trace functionality.
Deactivation of problematic macros.
Header file for the multiplication trait.
Header file for the RemoveReference type trait.
Constraint on the transpose flag of vector types.
Base class for N-dimensional dense vectors.
Definition: DenseVector.h:77
Base class for sparse vectors.
Definition: SparseVector.h:72
Constraint on the data type.
Constraint on the data type.
Header file for the DenseVector base class.
Header file for the SparseVector base class.
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_VECTOR_TYPE(T)
Constraint on the data type.
Definition: SparseVector.h:61
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE(T)
Constraint on the data type.
Definition: DenseVector.h:61
#define BLAZE_CONSTRAINT_MUST_BE_COLUMN_VECTOR_TYPE(T)
Constraint on the data type.
Definition: ColumnVector.h:61
#define BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE(T)
Constraint on the data type.
Definition: RowVector.h:61
typename MultTrait< T1, T2 >::Type MultTrait_t
Auxiliary alias declaration for the MultTrait class template.
Definition: MultTrait.h:165
MT::Iterator end(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:584
typename RemoveReference< T >::Type RemoveReference_t
Auxiliary alias declaration for the RemoveReference type trait.
Definition: RemoveReference.h:95
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.
Definition: Exception.h:235
#define BLAZE_FUNCTION_TRACE
Function trace macro.
Definition: FunctionTrace.h:94
Header file for the exception macros of the math module.
Header file for basic type definitions.