TDVecDVecMultExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_TDVECDVECMULTEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_TDVECDVECMULTEXPR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <stdexcept>
45 #include <blaze/math/Intrinsics.h>
47 #include <blaze/util/DisableIf.h>
48 #include <blaze/util/EnableIf.h>
50 #include <blaze/util/Types.h>
53 
54 
55 namespace blaze {
56 
57 //=================================================================================================
58 //
59 // CLASS DEFINITION
60 //
61 //=================================================================================================
62 
63 //*************************************************************************************************
68 template< typename T1 // Type of the left-hand side dense vector
69  , typename T2 > // Type of the right-hand side dense vector
70 struct TDVecDVecMultExprHelper
71 {
72  //**Type definitions****************************************************************************
74  typedef typename RemoveReference< typename T1::CompositeType >::Type CT1;
75 
77  typedef typename RemoveReference< typename T2::CompositeType >::Type CT2;
78  //**********************************************************************************************
79 
80  //**********************************************************************************************
81  enum { value = CT1::vectorizable &&
82  CT2::vectorizable &&
83  IsSame< typename CT1::ElementType, typename CT2::ElementType>::value &&
84  IntrinsicTrait< typename CT1::ElementType >::addition &&
85  IntrinsicTrait< typename CT2::ElementType >::multiplication };
86  //**********************************************************************************************
87 };
89 //*************************************************************************************************
90 
91 
92 
93 
94 //=================================================================================================
95 //
96 // GLOBAL BINARY ARITHMETIC OPERATORS
97 //
98 //=================================================================================================
99 
100 //*************************************************************************************************
126 template< typename T1 // Type of the left-hand side dense vector
127  , typename T2 > // Type of the right-hand side dense vector
128 inline typename DisableIf< TDVecDVecMultExprHelper<T1,T2>,
129  const typename MultTrait<typename T1::ElementType,typename T2::ElementType>::Type >::Type
131 {
133 
134  if( (~lhs).size() != (~rhs).size() )
135  throw std::invalid_argument( "Vector sizes do not match" );
136 
137  typedef typename T1::CompositeType Lhs;
138  typedef typename T2::CompositeType Rhs;
139  typedef typename T1::ElementType ET1;
140  typedef typename T2::ElementType ET2;
141  typedef typename MultTrait<ET1,ET2>::Type MultType;
142 
143  if( (~lhs).size() == 0UL ) return MultType();
144 
145  Lhs left ( ~lhs );
146  Rhs right( ~rhs );
147 
148  MultType sp( left[0UL] * right[0UL] );
149 
150  for( size_t i=1UL; i<left.size(); ++i )
151  sp += left[i] * right[i];
152 
153  return sp;
154 }
155 //*************************************************************************************************
156 
157 
158 //*************************************************************************************************
186 template< typename T1 // Type of the left-hand side dense vector
187  , typename T2 > // Type of the right-hand side dense vector
188 inline typename EnableIf< TDVecDVecMultExprHelper<T1,T2>,
189  const typename MultTrait<typename T1::ElementType,typename T2::ElementType>::Type >::Type
191 {
193 
194  if( (~lhs).size() != (~rhs).size() )
195  throw std::invalid_argument( "Vector sizes do not match" );
196 
197  typedef typename T1::CompositeType Lhs;
198  typedef typename T2::CompositeType Rhs;
199  typedef typename T1::ElementType ET1;
200  typedef typename T2::ElementType ET2;
201  typedef typename MultTrait<ET1,ET2>::Type MultType;
202  typedef IntrinsicTrait<MultType> IT;
203 
204  if( (~lhs).size() == 0UL ) return MultType();
205 
206  Lhs left ( ~lhs );
207  Rhs right( ~rhs );
208 
209  typename IT::Type xmm1, xmm2, xmm3, xmm4;
210 
211  const size_t N ( left.size() );
212  const size_t end( N - N % (IT::size*4UL) );
213 
214  for( size_t i=0UL; i<end; i+=IT::size*4UL ) {
215  xmm1 = xmm1 + ( left.load(i ) * right.load(i ) );
216  xmm2 = xmm2 + ( left.load(i+IT::size ) * right.load(i+IT::size ) );
217  xmm3 = xmm3 + ( left.load(i+IT::size*2UL) * right.load(i+IT::size*2UL) );
218  xmm4 = xmm4 + ( left.load(i+IT::size*3UL) * right.load(i+IT::size*3UL) );
219  }
220 
221  MultType sp( sum( xmm1 + xmm2 + xmm3 + xmm4 ) );
222 
223  for( size_t i=end; i<N; ++i )
224  sp += left[i] * right[i];
225 
226  return sp;
227 }
228 //*************************************************************************************************
229 
230 } // namespace blaze
231 
232 #endif
BLAZE_ALWAYS_INLINE int16_t sum(const sse_int16_t &a)
Returns the sum of all elements in the 16-bit integral intrinsic vector.
Definition: Reduction.h:63
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:8247
Header file for basic type definitions.
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector)
Returns the current size/dimension of the vector.
Definition: Vector.h:264
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:258
Header file for the IsSame and IsStrictlySame type traits.
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2507
Header file for the DenseVector base class.
Header file for the DisableIf class template.
Header file for the multiplication trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2505
Header file for the EnableIf class template.
Intrinsic characteristics of data types.The IntrinsicTrait class template provides the intrinsic char...
Definition: IntrinsicTrait.h:749
Base template for the MultTrait class.
Definition: MultTrait.h:150
Header file for the RemoveReference type trait.
Header file for all intrinsic functionality.
#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 the FunctionTrace class.