libpspm
cubic_spline.h File Reference
#include <vector>
#include <cassert>
#include <iomanip>
Include dependency graph for cubic_spline.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  Spline
 
class  BandMatrix
 

Typedefs

typedef double Float
 

Functions

void thomas_solve (double *a, double *b, double *c, double *d, int n)
 
template<typename T >
int my_lower_bound (const T &val, const T *arr, const int arrlen)
 
template<typename T >
int my_upper_bound (const T &val, T *arr, int arrlen)
 

Typedef Documentation

◆ Float

typedef double Float

Definition at line 8 of file cubic_spline.h.

Function Documentation

◆ my_lower_bound()

template<typename T >
int my_lower_bound ( const T &  val,
const T *  arr,
const int  arrlen 
)

Definition at line 63 of file cubic_spline.h.

64 {
65  int it, first=0, last=arrlen;
66  int count, step;
67  count = arrlen;
68  while (count>0)
69  {
70  it = first; step=count/2;
71  it += step;
72  if (arr[it] < val) {
73  first=++it;
74  count-=step+1;
75  }
76  else count=step;
77  }
78  return first;
79 }
Here is the caller graph for this function:

◆ my_upper_bound()

template<typename T >
int my_upper_bound ( const T &  val,
T *  arr,
int  arrlen 
)

Definition at line 88 of file cubic_spline.h.

89 {
90  int it, first=0, last=arrlen;
91  int count, step;
92  count = arrlen;
93  while (count>0)
94  {
95  it = first; step=count/2;
96  it += step;
97  if (!(val<arr[it])) {
98  first=++it;
99  count-=step+1;
100  }
101  else count=step;
102  }
103  return first;
104 }

◆ thomas_solve()

void thomas_solve ( double *  a,
double *  b,
double *  c,
double *  d,
int  n 
)
inline

Definition at line 35 of file cubic_spline.h.

35  {
36  n--; // since we start from x0 (not x1) JAI: Therefore last valid index is n for a,b, n-1 for c
37  c[0] /= b[0];
38  d[0] /= b[0];
39 
40  for (int i = 1; i < n; i++) {
41  c[i] /= b[i] - a[i]*c[i-1];
42  d[i] = (d[i] - a[i]*d[i-1]) / (b[i] - a[i]*c[i-1]);
43  }
44 
45  d[n] = (d[n] - a[n]*d[n-1]) / (b[n] - a[n]*c[n-1]);
46 
47  for (int i = n; i-- > 0;) {
48  d[i] -= c[i]*d[i+1]; // JAI: note, i is in [0, n-1]
49  }
50 }
Here is the caller graph for this function: