As user Anycorn pointed out the source code in Section "Old Question" compiles and runs with the very newest version of Eigen on Bitbucket:
$hg showconfig
bundle.mainreporoot=/usr/local/eigen
paths.default=https://bitbucket.org/eigen/eigen
/usr/local/eigen
$hg identify
fabd880592ac tip
/usr/local/eigen
I've tested the principle with the following code:
/**
Spline interpolation with AD.
*/
#include <iostream>
#include <fstream>
#include <Eigen/Eigen>
#include <unsupported/Eigen/AutoDiff>
#include <unsupported/Eigen/Splines>
constexpr const double array[] = {
1.0, 2.0,
3.0, 4.0,
5.0, 1.0,
6.0, 2.0
};
constexpr size_t nCols=2;
constexpr size_t rowSize=sizeof(array)/sizeof(double)/nCols;
constexpr size_t derOrder=1;
typedef Eigen::Map<Eigen::Matrix<double,1,rowSize>,Eigen::Unaligned,Eigen::InnerStride<nCols> > Map;
typedef Eigen::Spline<double,nCols-1> Spline;
constexpr size_t interpolOrder=3;
constexpr double xStart=array[0];
constexpr double xStop=array[nCols*(rowSize-1)];
constexpr double xDelta=xStop-xStart;
const Spline spline=Eigen::SplineFitting<Spline>::Interpolate(Map(
const_cast<double*>(array)+1),
interpolOrder,
(Map(const_cast<double*>(array)).array()-xStart)/xDelta);
typedef Eigen::AutoDiffScalar<Eigen::Matrix<double,1,2> > DerType;
DerType f(const DerType& x){
DerType ret;
auto y = spline.derivatives<1>((x.value()-xStart)/xDelta);
ret.value() = y(0,0);
ret.derivatives() = x.derivatives()*y(0,1)/xDelta;
return ret;
}
int main() {
std::ofstream of("/temp/test.dat");
constexpr size_t n=101;
const double xStart=0.0;
const double xStop=6.0;
const double dx=(xStop-xStart)/(n-1);
double x=xStart;
for(size_t i=0; i!=n; i++, x+=dx) {
DerType xAD(x,DerType::DerType(1.0,1.0));
auto yAD = f(xAD);
of << x << ' ' << yAD.value() << ' ' << yAD.derivatives()[0] << '\n';
}
of.close();
return 0;
}
/*
Local Variables:
compile-command: "g++ -g -std=c++11 -I/usr/local/include/eigen3 eigenInterpolAD.cc -o a.exe && (echo \"Running\"; ./a.exe);"
End:
*/
The following plot of the generated data shows that the code works fine now with the hg-version of Eigen. The red curve is the interpolating spline and the green curve is its derivative.