0

I have been working on porting a python library to C++ because I need to make a program relying on it but the fact it's in python using cython and various libs like scipy etc would make it hard to port it to various platforms. I was able to find libraries such as xtensor that help me adapt the NumPy calls to equivalent code in order to port the code in an accurate manner, however I'm kind of struggling at this line:

interp_func = interpolate.interp1d(
    nonzero_indices, continuous_f0[continuous_f0 > 0], kind=kind
)

it seems to rely on the interp1d function of scipy, and I can't really find any equivalents in C++

I wonder if anyone knows of a way I could adapt this line in C++ ?

If it helps here is a link to the full original code of the function i'm working on https://github.com/r9y9/nnmnkwii/blob/master/nnmnkwii/preprocessing/f0.py

  • You might want to take a look at [this question](https://stackoverflow.com/questions/9394867). Many implementation there are C++, not C. But it's linear, unlike interp1d with which you can choose the interpolation method. – YiFei Aug 20 '21 at 16:35
  • I am working in C++ anyway, but yeah that's my main issue, i'd need one with various interpolation methods to be accurate to the original library source – Pikachuk Aug 20 '21 at 16:40
  • the other issue is that the answer seems to require a third argument "x_new" when the original function i'm trying to replace only needs two arguments x and y – Pikachuk Aug 20 '21 at 16:55
  • 2
    This `scipy` function, or rather `class`, has a lot of python code to pass the task on to one of various methods.- nearest, linear, spline etc. So you are **not** going to find an exact equivalent elsewhere. But I doubt if any of those methods is doing anything unique, that hasn't been implemented in one of many C++ libraries. Some of the `scipy` methods might even call C/C++ libraries. – hpaulj Aug 20 '21 at 17:45
  • I implemented an `interp`-function is xtesor (see [source](https://github.com/xtensor-stack/xtensor/blob/2618d5a23aebb4dec95d967f0e873d47b2f9f946/include/xtensor/xmath.hpp#L2872)). That might fit your needs? – Tom de Geus Aug 22 '21 at 12:12
  • Like @hpaulj comments, you mind find what you need in the source of scipy. Almost always you will find some C or C++ code. What would be a nice open-source contribution is to add the *scipy* equivalent to the C++ library that you are using. – Tom de Geus Aug 22 '21 at 12:14

0 Answers0