SVecDVecInnerExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_SVECDVECINNEREXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_SVECDVECINNEREXPR_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 sparse vector
97  , typename VT2 > // Type of the right-hand side dense vector
98 inline decltype(auto)
99  operator*( const SparseVector<VT1,true>& lhs, const DenseVector<VT2,false>& rhs )
100 {
102 
103  using Lhs = CompositeType_<VT1>; // Composite type of the left-hand side sparse vector expression
104  using Rhs = CompositeType_<VT2>; // Composite type of the right-hand side dense vector expression
105  using X1 = RemoveReference_<Lhs>; // Auxiliary type for the left-hand side composite type
106  using X2 = RemoveReference_<Rhs>; // Auxiliary type for the right-hand side composite type
107  using ET1 = ElementType_<X1>; // Element type of the left-hand side sparse vector expression
108  using ET2 = ElementType_<X2>; // Element type of the right-hand side dense vector expression
109  using MultType = MultTrait_<ET1,ET2>; // Multiplication result type
110  using ConstIterator = ConstIterator_<X1>; // Iterator type of the left-hand sparse vector expression
111 
116 
117  if( (~lhs).size() != (~rhs).size() ) {
118  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
119  }
120 
121  Lhs left ( ~lhs );
122  Rhs right( ~rhs );
123 
124  ConstIterator element( left.begin() );
125  ConstIterator end ( left.end() );
126 
127  MultType sp = MultType();
128 
129  if( element != end ) {
130  sp = element->value() * right[ element->index() ];
131  ++element;
132  for( ; element!=end; ++element )
133  sp += element->value() * right[ element->index() ];
134  }
135 
136  return sp;
137 }
138 //*************************************************************************************************
139 
140 } // namespace blaze
141 
142 #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
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector) noexcept
Returns the current size/dimension of the vector.
Definition: Vector.h:265
Header file for the DenseVector base class.
typename MultTrait< T1, T2 >::Type MultTrait_
Auxiliary alias declaration for the MultTrait class template.The MultTrait_ alias declaration provide...
Definition: MultTrait.h:250
Constraint on the transpose flag of vector types.
typename T::CompositeType CompositeType_
Alias declaration for nested CompositeType type definitions.The CompositeType_ alias declaration prov...
Definition: Aliases.h:83
Header file for the multiplication trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:3087
typename T::ElementType ElementType_
Alias declaration for nested ElementType type definitions.The ElementType_ alias declaration provides...
Definition: Aliases.h:163
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:61
Constraint on the data type.
typename RemoveReference< T >::Type RemoveReference_
Auxiliary alias declaration for the RemoveReference type trait.The RemoveReference_ alias declaration...
Definition: RemoveReference.h:95
Header file for the exception macros of the math module.
BLAZE_ALWAYS_INLINE 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:264
Constraint on the data type.
#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
Header file for the RemoveReference type trait.
typename T::ConstIterator ConstIterator_
Alias declaration for nested ConstIterator type definitions.The ConstIterator_ alias declaration prov...
Definition: Aliases.h:103
#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:130
#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.