Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some warnings when the input x1 is problematic #21

Open
zhengqigao opened this issue Mar 12, 2024 · 0 comments
Open

Add some warnings when the input x1 is problematic #21

zhengqigao opened this issue Mar 12, 2024 · 0 comments

Comments

@zhengqigao
Copy link

Hi,

Thanks for the implementation. After using it, I think adding a warning or raising an error would be highly useful when the input x1 is not an increasing function. For instance, the following interpolated result will be problematic, but if we remove all the .flip([0]), it works just fine. Users might spend a lot of time trying to debug where the error is, but actually the only thing need to do is to reverse the order of x1.

    # the golden underlying function is y= x^2
    x1 = torch.tensor([0, 1, 2, 3, 4, 5], dtype=torch.float32)
    y1 = torch.tensor([0, 1, 4, 9, 16, 25], dtype=torch.float32)

    x2 = torch.tensor([0.5, 1.5, 2.5, 3.5, 4.5], dtype=torch.float32)

    # if we incautiously feed it in a reversed order, the results are problematic
    y2 = interp1d(x1.flip([0]), y1.flip([0]), x2.flip([0])).squeeze(0)

    plt.figure()
    plt.plot(x1,y1, 'original')
    plt.plot(x2,y2.flip(0), 'interpolated')
    plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant