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>
48 #include <blaze/math/Exception.h>
53 #include <blaze/util/Types.h>
55 
56 
57 namespace blaze {
58 
59 //=================================================================================================
60 //
61 // GLOBAL BINARY ARITHMETIC OPERATORS
62 //
63 //=================================================================================================
64 
65 //*************************************************************************************************
96 template< typename VT1 // Type of the left-hand side dense vector
97  , typename VT2 > // Type of the right-hand side sparse vector
98 inline decltype(auto)
99  operator*( const DenseVector<VT1,true>& lhs, const SparseVector<VT2,false>& rhs )
100 {
102 
103  using CT1 = CompositeType_t<VT1>; // Composite type of the left-hand side dense vector expression
104  using CT2 = CompositeType_t<VT2>; // Composite type of the right-hand side sparse vector expression
105  using XT1 = RemoveReference_t<CT1>; // Auxiliary type for the left-hand side composite type
106  using XT2 = RemoveReference_t<CT2>; // Auxiliary type for the right-hand side composite type
107  using ET1 = ElementType_t<XT1>; // Element type of the left-hand side dense vector expression
108  using ET2 = ElementType_t<XT2>; // Element type of the right-hand side sparse vector expression
109  using MultType = MultTrait_t<ET1,ET2>; // Multiplication result type
110 
115 
116  if( (~lhs).size() != (~rhs).size() ) {
117  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
118  }
119 
120  CT1 left ( ~lhs );
121  CT2 right( ~rhs );
122 
123  auto element( right.begin() );
124  auto end ( right.end() );
125 
126  MultType sp{};
127 
128  if( element != end ) {
129  sp = left[ element->index() ] * element->value();
130  ++element;
131  for( ; element!=end; ++element )
132  sp += left[ element->index() ] * element->value();
133  }
134 
135  return sp;
136 }
137 //*************************************************************************************************
138 
139 } // namespace blaze
140 
141 #endif
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.This macro encapsulates the default way o...
Definition: Exception.h:235
Header file for auxiliary alias declarations.
Header file for basic type definitions.
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: ColumnVector.h:61
Header file for the DenseVector base class.
typename RemoveReference< T >::Type RemoveReference_t
Auxiliary alias declaration for the RemoveReference type trait.The RemoveReference_t alias declaratio...
Definition: RemoveReference.h:95
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.The ElementType_t alias declaration provide...
Definition: Aliases.h:170
Constraint on the transpose flag of vector types.
Header file for the multiplication trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:76
#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:61
Constraint on the data type.
Header file for the exception macros of the math module.
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:438
Constraint on the data type.
typename MultTrait< T1, T2 >::Type MultTrait_t
Auxiliary alias declaration for the MultTrait class template.The MultTrait_t alias declaration provid...
Definition: MultTrait.h:240
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.The CompositeType_t alias declaration pro...
Definition: Aliases.h:90
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:94
constexpr size_t size(const Matrix< MT, SO > &matrix) noexcept
Returns the total number of elements of the matrix.
Definition: Matrix.h:530
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:61
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:138
#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: RowVector.h:61
Constraint on the transpose flag of vector types.
Header file for the function trace functionality.