CMS 3D CMS Logo

interpolate.h
Go to the documentation of this file.
1 #ifndef NPSTAT_INTERPOLATE_HH_
2 #define NPSTAT_INTERPOLATE_HH_
3 
16 
17 namespace npstat {
22  template <typename T>
23  inline T interpolate_linear(const double x, const T& f0, const T& f1) {
24  const typename ProperDblFromCmpl<T>::type dx = 1.0 - x;
25  return f0 * dx + f1 * static_cast<typename ProperDblFromCmpl<T>::type>(x);
26  }
27 
32  template <typename T>
33  inline T interpolate_quadratic(const double x, const T& f0, const T& f1, const T& f2) {
34  static const typename ProperDblFromCmpl<T>::type two = 2.0;
35  const typename ProperDblFromCmpl<T>::type dx = x - 1.0;
36  return f1 + ((f2 - f0) / two + ((f2 - f1) + (f0 - f1)) * (dx / two)) * dx;
37  }
38 
43  template <typename T>
44  inline T interpolate_cubic(const double x, const T& f0, const T& f1, const T& f2, const T& f3) {
45  return interpolate_linear(
46  x * (3.0 - x) / 2.0, interpolate_linear(x / 3.0, f0, f3), interpolate_linear(x - 1.0, f1, f2));
47  }
48 
50 
60  template <typename T>
61  unsigned interpolation_coefficients(T* buffer, unsigned bufLen, const T& f0, const T& f1);
62  template <typename T>
63  unsigned interpolation_coefficients(T* buffer, unsigned bufLen, const T& f0, const T& f1, const T& f2);
64  template <typename T>
65  unsigned interpolation_coefficients(T* buffer, unsigned bufLen, const T& f0, const T& f1, const T& f2, const T& f3);
67 } // namespace npstat
68 
70 
71 namespace npstat {
72  template <typename T>
73  unsigned interpolation_coefficients(T* buffer, const unsigned bufLen, const T& f0, const T& f1) {
74  if (bufLen <= 1U)
76  "In npstat::interpolation_coefficients: "
77  "insufficient length of the output buffer");
78  buffer[0] = f0;
79  buffer[1] = f1 - f0;
80  return 2U;
81  }
82 
83  template <typename T>
84  unsigned interpolation_coefficients(T* buffer, const unsigned bufLen, const T& f0, const T& f1, const T& f2) {
85  if (bufLen <= 2U)
87  "In npstat::interpolation_coefficients: "
88  "insufficient length of the output buffer");
89  buffer[0] = f0;
90  buffer[1] = static_cast<T>((f1 - f2 + 3 * (f1 - f0)) / 2.0);
91  buffer[2] = static_cast<T>(((f0 - f1) + (f2 - f1)) / 2.0);
92  return 3U;
93  }
94 
95  template <typename T>
97  T* buffer, const unsigned bufLen, const T& f0, const T& f1, const T& f2, const T& f3) {
98  if (bufLen <= 3U)
100  "In npstat::interpolation_coefficients: "
101  "insufficient length of the output buffer");
102  buffer[0] = f0;
103  buffer[1] = static_cast<T>((11 * (f1 - f0) + 7 * (f1 - f2) + 2 * (f3 - f2)) / 6.0);
104  buffer[2] = static_cast<T>((2 * (f0 - f1) + 3 * (f2 - f1) + (f2 - f3)) / 2.0);
105  buffer[3] = static_cast<T>(((f3 - f0) + 3 * (f1 - f2)) / 6.0);
106  return 4U;
107  }
108 } // namespace npstat
109 
110 #endif // NPSTAT_INTERPOLATE_HH_
T interpolate_cubic(const double x, const T &f0, const T &f1, const T &f2, const T &f3)
Definition: interpolate.h:44
T interpolate_quadratic(const double x, const T &f0, const T &f1, const T &f2)
Definition: interpolate.h:33
Compile-time deduction of the underlying floating point type from the given complex type...
Exceptions for the npstat namespace.
float x
unsigned interpolation_coefficients(T *buffer, unsigned bufLen, const T &f0, const T &f1)
Definition: interpolate.h:73
long double T
T interpolate_linear(const double x, const T &f0, const T &f1)
Definition: interpolate.h:23