TSVecSVecMultExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_TSVECSVECMULTEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_TSVECSVECMULTEXPR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
48 #include <blaze/util/Exception.h>
50 #include <blaze/util/Types.h>
52 
53 
54 namespace blaze {
55 
56 //=================================================================================================
57 //
58 // GLOBAL BINARY ARITHMETIC OPERATORS
59 //
60 //=================================================================================================
61 
62 //*************************************************************************************************
90 template< typename T1 // Type of the left-hand side sparse vector
91  , typename T2 > // Type of the right-hand side sparse vector
92 inline const typename MultTrait<typename T1::ElementType,typename T2::ElementType>::Type
94 {
96 
97  typedef typename T1::CompositeType Lhs; // Composite type of the left-hand side sparse vector expression
98  typedef typename T2::CompositeType Rhs; // Composite type of the right-hand side sparse vector expression
99  typedef typename RemoveReference<Lhs>::Type X1; // Auxiliary type for the left-hand side composite type
100  typedef typename RemoveReference<Rhs>::Type X2; // Auxiliary type for the right-hand side composite type
101  typedef typename X1::ElementType E1; // Element type of the left-hand side sparse vector expression
102  typedef typename X2::ElementType E2; // Element type of the right-hand side sparse vector expression
103  typedef typename MultTrait<E1,E2>::Type MultType; // Multiplication result type
104  typedef typename X1::ConstIterator LeftIterator; // Iterator type of the left-hand sparse vector expression
105  typedef typename X2::ConstIterator RightIterator; // Iterator type of the right-hand sparse vector expression
106 
111 
112  if( (~lhs).size() != (~rhs).size() ) {
113  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
114  }
115 
116  if( (~lhs).nonZeros() == 0UL || (~rhs).nonZeros() == 0UL ) return MultType();
117 
118  Lhs left ( ~lhs );
119  Rhs right( ~rhs );
120  const LeftIterator lend( left.end() );
121  const RightIterator rend( right.end() );
122  LeftIterator l( left.begin() );
123  RightIterator r( right.begin() );
124  MultType sp = MultType();
125 
126  for( ; l!=lend && r!=rend; ++l ) {
127  while( r->index() < l->index() && ++r != rend ) {}
128  if( r!=rend && l->index() == r->index() ) {
129  sp = l->value() * r->value();
130  ++r;
131  break;
132  }
133  }
134 
135  for( ; l!=lend && r!=rend; ++l ) {
136  while( r->index() < l->index() && ++r != rend ) {}
137  if( r!=rend && l->index() == r->index() ) {
138  sp += l->value() * r->value();
139  ++r;
140  }
141  }
142 
143  return sp;
144 }
145 //*************************************************************************************************
146 
147 } // namespace blaze
148 
149 #endif
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exceptionThis macro encapsulates the default way of...
Definition: Exception.h:187
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:7820
Header file for basic type definitions.
Header file for the SparseVector base class.
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector)
Returns the current size/dimension of the vector.
Definition: Vector.h:252
#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:79
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2588
BLAZE_ALWAYS_INLINE size_t nonZeros(const Matrix< MT, SO > &matrix)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:378
Constraint on the transpose flag of vector types.
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:2592
#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
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2586
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:138
Header file for the RemoveReference type trait.
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:118
#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
#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:79
Header file for exception macros.
Constraint on the transpose flag of vector types.
Header file for the FunctionTrace class.