Thanks to everyone who contributed, especially @Jaime.
I experimented a bit and came to this conclusion:
1) In addition to rounding errors, both methods mentioned by me have the same result.
2) They both take a lot of time
3) I tried the scipy version, but it would reject the take_sorted flag. My scipy version may be outdated. I suspect that if this flag is raised, scipy internally sorts arrays. But the values ββare sorted only in the opposite direction, so this does not need to be done.
In any case, I will use the reverse direction method:
np.interp(x, xp[::-1], fp[::-1])
Just remember that in this case you will also have to undo left and right if you need them.
chw21
source share