xtensor-interpolate
is an unofficial extension to the xtensor
library
offering spline interpolation via internal bindings to Paul Dierckx's Fortran
package, FITPACK.
The FITPACK library is used in SciPy to build
the back-end of scipy.interpolate
;xtensor-interpolate
aims to provide a
familiar API to anyone experienced with this Python package.
xtensor
If you would like to build the test suite, you will also need a copy of
googletest
. Optionally this can be downloaded and linked during the build
step if you do not already have a copy.
If compiling on Windows you will also need a complete MinGW development
environment. This is required to compile the bundled Fortran component with
gfortran
.
Installation from source is streamlined with CMake.
mkdir build
cd build
cmake ..
make install
The cmake
step of the process can be customized with a number of flags.
-
-DCMAKE_INSTALLATION_PREFIX=...
to change where you wantxtensor-interpolate
to install to. -
-DBUILD_TESTS=ON
to build the unit test suite. This requiresgoogletest
.- You can target the unit tests directly with
make xtest
, or just build the executable withmake test_xtensor_interpolate
.
- You can target the unit tests directly with
-
-DDOWNLOAD_GTEST=ON
to download and compilegoogletest
as part of the build step. Note thatgoogletest
will not actually be installed to your system directories, and is just statically linked into the test executable.- Use
Dgtest_disable_pthreads=ON
to compile a single-threaded version ofgoogletest
. This is required when using Windows and MinGW.
- Use
#include <cmath> // M_PI
#include "xtensor/xbuilder.hpp" // linspace
#include "xtensor/xtensor.hpp" // xtensor
#include "xtensor-interpolate/xinterpolate.hpp" // splrep, splev
xt::xtensor<double, 1> x =
{ -3.141, -2.443, -1.745, -1.047, -0.349, 0.349, 1.047, 1.745, 2.443, 3.141 };
xt::xtensor<double, 1> y =
{ 0., -0.643, -0.985, -0.866, -0.342, 0.342, 0.866, 0.985, 0.643, 0. };
// Find the B-spline representation of the above points.
auto tck = xt::interpolate::splrep(x, y);
// Evaluate the B-spline over a new range of data points.
xt::xtensor<double, 1> xs = xt::linspace<double>(-M_PI, M_PI, 100);
xt::xtensor<double, 1> ys = xt::interpolate::splev(xs, tck);
Plotted, this data looks like:
This software is licensed under the BSD-2-Clause license. See the LICENSE file for details.