Skip to content

A slight mismatch in the results compared to scipy? #6

@ysBach

Description

@ysBach

I found this repo very useful and tried it to see if I can completely replace some interpolation that I used for my package.

While testing, I found a slight mismatch with scipy:

from fast_interp import interp1d, interp2d
from scipy import interpolate as si
import numpy as np

npt = 15
xvals, dx = np.linspace(0, 2*np.pi, npt, retstep=True)
yvals = np.exp(xvals)*np.exp(np.sin(xvals))*np.cos(xvals/4)
interpolater = interp1d(xvals.min(), xvals.max(), dx, yvals, k=3, p=False)
scipy_interp = si.interp1d(xvals, yvals, kind="cubic")

fig, axs = plt.subplots(2, 1, figsize=(8, 5), sharex=False, sharey=False, gridspec_kw={"height_ratios": [3, 1] })

xx = np.linspace(0, 2*np.pi, 1000)
axs[0].plot(xvals, yvals, "o")
axs[0].plot(xx, interpolater(xx), lw=0.5, label="fast_interp")
axs[0].plot(xx, scipy_interp(xx), lw=0.5, label="scipy interp1d")
axs[1].plot(xx, scipy_interp(xx) - interpolater(xx))
axs[0].legend()
axs[1].set(title = "difference (scipy's interp1d - fast_interp)")
plt.tight_layout()
plt.show();

image

Maybe I am missing something or found a bug??

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions