npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
SimpleScalarProduct.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_SIMPLESCALARPRODUCT_HH_
2 #define NPSTAT_SIMPLESCALARPRODUCT_HH_
3 
4 /*!
5 // \file SimpleScalarProduct.hh
6 //
7 // \brief A simple code to calculate scalar products with unit weight function
8 //
9 // Author: I. Volobouev
10 //
11 // February 2023
12 */
13 
14 #include <cassert>
15 
16 #include "npstat/nm/PreciseType.hh"
17 
18 namespace npstat {
19  template<typename Real>
21  {
22  inline Real operator()(const Real* x, const Real* y,
23  const unsigned long len) const
24  {
25  typedef typename PreciseType<Real>::type Precise;
26  Precise sum = Precise();
27  if (len)
28  {
29  assert(x);
30  assert(y);
31  for (unsigned long i=0; i<len; ++i)
32  sum += static_cast<Precise>(*x++ * *y++);
33  }
34  return static_cast<Real>(sum);
35  }
36  };
37 }
38 
39 #endif // NPSTAT_SIMPLESCALARPRODUCT_HH_
Compile-time deduction of an appropriate precise numeric type.
Definition: AbsArrayProjector.hh:14
Definition: SimpleScalarProduct.hh:21