24    0,     0,      0,    -1/2, 0, 1/2, 0,     0,     0,
 
   25    0,     0,      1/12, -2/3, 0, 2/3, -1/12, 0,     0,
 
   26    0,     -1/60,  3/20, -3/4, 0, 3/4, -3/20, 1/60,  0,
 
   27    1/280, -4/105, 1/5,  -4/5, 0, 4/5, -1/5,  4/105, -1/280
 
   35    0,      0,     0,     1,   -2,      1,   0,     0,     0,
 
   36    0,      0,     -1/12, 4/3, -5/2,    4/3, -1/12, 0,     0,
 
   37    0,      1/90,  -3/20, 3/2, -49/18,  3/2, -3/20, 1/90,  0,
 
   38    -1/560, 8/315, -1/5,  8/5, -205/72, 8/5, -1/5,  8/315, -1/560
 
   53T 
D1Forward(
const std::vector<T>& vs, 
int index, 
int hstep = 1)
 
   55    assert(index >= 0 && index < 
int(vs.size()) && 
"index not in range of vs");
 
   56    assert(index <= 
int(vs.size()) && 
"index must not be last point");
 
   57    return (-vs[index] + vs[std::size_t(index) + hstep]) / double(hstep);
 
   71T 
D1Backward(
const std::vector<T>& vs, 
int index, 
int hstep = 1)
 
   73    assert(index >= 0 && index < 
int(vs.size()) && 
"index not in range of vs");
 
   74    assert(index >= hstep && 
"index must not be first point");
 
   75    return (-vs[index - hstep] + vs[index]) / double(hstep);
 
   89T 
D1Central(
const std::vector<T>& vs, 
int index, 
int hstep = 1)
 
   91    assert(index >= 0 && index < 
int(vs.size()) && 
"index not in range of vs");
 
   92    assert(index - hstep >= 0 && 
"index out of range");
 
   93    assert(index + hstep < 
int(vs.size()) && 
"index out of range");
 
   94    return ((-0.5) * vs[index - hstep] +
 
   95            (0.5) * vs[std::size_t(index) + hstep]) /
 
  114    assert(index >= 0 && index < 
int(vs.size()) && 
"index not in range of vs");
 
  115    assert(index - 2 * hstep >= 0 && 
"index out of range\n");
 
  116    assert(index - 1 * hstep >= 0 && 
"index out of range\n");
 
  117    assert(index + 1 * hstep < 
int(vs.size()) && 
"index out of range\n");
 
  118    assert(index + 2 * hstep < 
int(vs.size()) && 
"index out of range\n");
 
  121        (1.0/12) * vs[index - 2 * hstep] +
 
  122        (-2.0/3) * vs[index - hstep] +
 
  123         (2.0/3) * vs[std::size_t(index) + hstep] +
 
  124       (-1.0/12) * vs[std::size_t(index) + 2 * hstep]) /
 
  141T 
D1At(
const std::vector<T>& vs, 
int index, 
int hstep = 1)
 
  143    if (index - hstep < 0) {
 
  145    } 
else if (index + hstep > 
int(vs.size()) - 1) {
 
  148        index - hstep < hstep || index + hstep >= 
int(vs.size()) - hstep) {
 
  164std::vector<T> 
D1(
const std::vector<T>& vs, 
int hstep = 1)
 
  167    dvs.reserve(vs.size());
 
  168    for (std::size_t i = 0; i < vs.size(); ++i) {
 
  169        dvs.push_back(
D1At(vs, i, hstep));
 
  181T 
D2Forward(
const std::vector<T>& vs, 
int index, 
int hstep = 1)
 
  183    assert(index >= 0 && index < 
int(vs.size()) && 
"index out of range");
 
  184    assert(index + hstep < 
int(vs.size()) && 
"index out of range");
 
  185    assert(index + 2 * hstep < 
int(vs.size()) && 
"index out of  range");
 
  186    return (vs[index] + (-2.0) * vs[std::size_t(index) + hstep] +
 
  187            vs[std::size_t(index) + 2 * hstep]) /
 
  188           double(hstep * hstep);
 
  198T 
D2Backward(
const std::vector<T>& vs, 
int index, 
int hstep = 1)
 
  200    assert(index >= 0 && index < 
int(vs.size()) && 
"index out of range");
 
  201    assert(index - 2 * hstep >= 0 && 
"index out of range");
 
  202    assert(index - 1 * hstep >= 0 && 
"index out of range");
 
  203    return (vs[index - 2 * hstep] + (-2.0) * vs[index - hstep] + vs[index]) /
 
  204           double(hstep * hstep);
 
  214T 
D2Central(
const std::vector<T>& vs, 
int index, 
int hstep = 1)
 
  216    assert(index >= 0 && index < 
int(vs.size()) && 
"index not in range of vs");
 
  217    assert(index - hstep >= 0 && 
"index out of range");
 
  218    assert(index + hstep < 
int(vs.size()) && 
"index out of range");
 
  219    return (vs[index - hstep] + (-2.0) * vs[index] +
 
  220            vs[std::size_t(index) + hstep]) /
 
  221           double(hstep * hstep);
 
  235    assert(index >= 0 && index < 
int(vs.size()) && 
"index not in range of vs");
 
  236    assert(index - 2 * hstep >= 0 && 
"index out of range");
 
  237    assert(index - 1 * hstep >= 0 && 
"index out of range");
 
  238    assert(index + 1 * hstep < 
int(vs.size()) && 
"index out of range");
 
  239    assert(index + 2 * hstep < 
int(vs.size()) && 
"index out of range");
 
  242       (-1.0/12) * vs[index - 2 * hstep] +
 
  243         (4.0/3) * vs[index - hstep] +
 
  244        (-5.0/2) * vs[index] +
 
  245         (4.0/3) * vs[std::size_t(index) + hstep] +
 
  246       (-1.0/12) * vs[std::size_t(index) + 2 * hstep]) /
 
  247           double(hstep * hstep);
 
  263T 
D2At(
const std::vector<T>& vs, 
int index, 
int hstep = 1)
 
  265    if (index - hstep < 0) {
 
  267    } 
else if (index + hstep > 
int(vs.size()) - 1) {
 
  270        index - hstep < hstep || index + hstep >= 
int(vs.size()) - hstep) {
 
  283std::vector<T> 
D2(
const std::vector<T>& vs, 
int hstep = 1)
 
  286    dvs.reserve(vs.size());
 
  287    for (std::size_t i = 0; i < vs.size(); ++i) {
 
  288        dvs.push_back(
D2At(vs, i, hstep));
 
std::vector< T > D2(const std::vector< T > &vs, int hstep=1)
Calculate the second derivative for a vector of sampled points.
 
T D2At(const std::vector< T > &vs, int index, int hstep=1)
Calculate the second derivative for a sampled point.
 
T D1Forward(const std::vector< T > &vs, int index, int hstep=1)
Calculate the first derivative for a sampled point.
 
static constexpr std::array< std::array< double, 9 >, 4 > D1_CENTRAL_DIFF_COEFFS
 
T D1At(const std::vector< T > &vs, int index, int hstep=1)
Calculate the first derivative for a sampled point.
 
std::vector< T > D1(const std::vector< T > &vs, int hstep=1)
Calculate the first derivative for a vector of sampled points.
 
T D2Central(const std::vector< T > &vs, int index, int hstep=1)
Calculate the second derivative for a sampled point.
 
static constexpr std::array< std::array< double, 9 >, 4 > D2_CENTRAL_DIFF_COEFFS
 
T D1Central(const std::vector< T > &vs, int index, int hstep=1)
Calculate the first derivative for a sampled point.
 
T D1Backward(const std::vector< T > &vs, int index, int hstep=1)
Calculate the first derivative for a sampled point.
 
T D2Backward(const std::vector< T > &vs, int index, int hstep=1)
Calculate the second derivative for a sampled point.
 
T D1FivePointStencil(const std::vector< T > &vs, int index, int hstep=1)
Calculate the first derivative for a sampled point using a five-point stencil.
 
T D2FivePointStencil(const std::vector< T > &vs, int index, int hstep=1)
Calculate the second derivative for a sampled point using a five-point stencil.
 
T D2Forward(const std::vector< T > &vs, int index, int hstep=1)
Calculate the second derivative for a sampled point.
 
Segmentation algorithms and utilities library