test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  {
25  const typename ProperDblFromCmpl<T>::type dx = 1.0 - x;
26  return f0*dx + f1*static_cast<typename ProperDblFromCmpl<T>::type>(x);
27  }
28 
33  template<typename T>
34  inline T interpolate_quadratic(const double x, const T& f0,
35  const T& f1, const T& f2)
36  {
37  static const typename ProperDblFromCmpl<T>::type two = 2.0;
38  const typename ProperDblFromCmpl<T>::type dx = x - 1.0;
39  return f1 + ((f2 - f0)/two + ((f2 - f1) + (f0 - f1))*(dx/two))*dx;
40  }
41 
46  template<typename T>
47  inline T interpolate_cubic(const double x, const T& f0, const T& f1,
48  const T& f2, const T& f3)
49  {
50  return interpolate_linear(x*(3.0 - x)/2.0,
51  interpolate_linear(x/3.0, f0, f3),
52  interpolate_linear(x - 1.0, f1, f2));
53  }
54 
56 
66  template<typename T>
67  unsigned interpolation_coefficients(T* buffer, unsigned bufLen,
68  const T& f0, const T& f1);
69  template<typename T>
70  unsigned interpolation_coefficients(T* buffer, unsigned bufLen,
71  const T& f0, const T& f1, const T& f2);
72  template<typename T>
73  unsigned interpolation_coefficients(T* buffer, unsigned bufLen,
74  const T& f0, const T& f1,
75  const T& f2, const T& f3);
77 }
78 
80 
81 namespace npstat {
82  template<typename T>
83  unsigned interpolation_coefficients(T* buffer, const unsigned bufLen,
84  const T& f0, const T& f1)
85  {
86  if (bufLen <= 1U) throw npstat::NpstatInvalidArgument(
87  "In npstat::interpolation_coefficients: "
88  "insufficient length of the output buffer");
89  buffer[0] = f0;
90  buffer[1] = f1 - f0;
91  return 2U;
92  }
93 
94  template<typename T>
95  unsigned interpolation_coefficients(T* buffer, const unsigned bufLen,
96  const T& f0, const T& f1, const T& f2)
97  {
98  if (bufLen <= 2U) throw npstat::NpstatInvalidArgument(
99  "In npstat::interpolation_coefficients: "
100  "insufficient length of the output buffer");
101  buffer[0] = f0;
102  buffer[1] = static_cast<T>((f1 - f2 + 3*(f1 - f0))/2.0);
103  buffer[2] = static_cast<T>(((f0 - f1) + (f2 - f1))/2.0);
104  return 3U;
105  }
106 
107  template<typename T>
108  unsigned interpolation_coefficients(T* buffer, const unsigned bufLen,
109  const T& f0, const T& f1,
110  const T& f2, const T& f3)
111  {
112  if (bufLen <= 3U) throw npstat::NpstatInvalidArgument(
113  "In npstat::interpolation_coefficients: "
114  "insufficient length of the output buffer");
115  buffer[0] = f0;
116  buffer[1] = static_cast<T>((11*(f1 - f0)+7*(f1 - f2)+2*(f3 - f2))/6.0);
117  buffer[2] = static_cast<T>((2*(f0 - f1)+3*(f2 - f1)+(f2 - f3))/2.0);
118  buffer[3] = static_cast<T>(((f3 - f0) + 3*(f1 - f2))/6.0);
119  return 4U;
120  }
121 }
122 
123 
124 #endif // NPSTAT_INTERPOLATE_HH_
125 
T interpolate_cubic(const double x, const T &f0, const T &f1, const T &f2, const T &f3)
Definition: interpolate.h:47
T interpolate_quadratic(const double x, const T &f0, const T &f1, const T &f2)
Definition: interpolate.h:34
Compile-time deduction of the underlying floating point type from the given complex type...
Exceptions for the npstat namespace.
Definition: DDAxes.h:10
unsigned interpolation_coefficients(T *buffer, unsigned bufLen, const T &f0, const T &f1)
Definition: interpolate.h:83
long double T
T interpolate_linear(const double x, const T &f0, const T &f1)
Definition: interpolate.h:23