4 template <
typename VectorT>
5 Eigen::VectorXi searchsorted(
const VectorT& x,
const VectorT& y) {
10 Eigen::VectorXi out(nX);
12 for (
int iX=0; iX < nX; iX++) {
13 while (iY < nY && x[iX] > y[iY]) iY++;
19 template <
typename MatrixT,
typename VectorT>
20 MatrixT interp2d(
const VectorT& xNew,
const VectorT& xOld,
const MatrixT& yOld) {
22 int nNew = xNew.size();
23 int nOld = xOld.size();
24 MatrixT yNew(nNew, yOld.cols());
25 Eigen::VectorXi new2old = searchsorted(xNew, xOld);
26 for (
int iNew=0; iNew < nNew; iNew++) {
27 int iOldAbove = new2old(iNew);
29 yNew.row(iNew) = yOld.row(0);
30 else if (iOldAbove == nOld)
31 yNew.row(iNew) = yOld.row(nOld-1);
33 double t = (xNew(iNew) - xOld(iOldAbove-1)) / (xOld(iOldAbove) - xOld(iOldAbove-1));
34 yNew.row(iNew) = yOld.row(iOldAbove-1)*(1-t) + yOld.row(iOldAbove)*t;