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

TST/MAINT: ndimage: follow-ups for array API standard support #21280

Open
3 of 5 tasks
lucascolley opened this issue Jul 28, 2024 · 6 comments
Open
3 of 5 tasks

TST/MAINT: ndimage: follow-ups for array API standard support #21280

lucascolley opened this issue Jul 28, 2024 · 6 comments
Labels
array types Items related to array API support and input array validation (see gh-18286) maintenance Items related to regular maintenance tasks scipy.ndimage

Comments

@lucascolley
Copy link
Member

lucascolley commented Jul 28, 2024

Follow-ups from gh-21150:

@shivanimall
Copy link

shivanimall commented Feb 19, 2025

According to #18867 and docs , the following file should also have support for torch, however, it currently does not, is this in works?

scipy/ndimage/_support_alternative_backends.py (specifically, delegate_xp function)

Thanks for the help!

@lucascolley
Copy link
Member Author

lucascolley commented Feb 19, 2025

hi @shivanimall ! _support_alternative_backends.py delegates to existing implementations for CuPy and JAX where they exist, and converts arrays to NumPy and back otherwise when they are on CPU.

Could you clarify what 'support for torch' you are interested in? Are there existing torch implementations of the https://docs.scipy.org/doc/scipy/reference/ndimage.html APIs which we could delegate to?

@shivanimall
Copy link

shivanimall commented Feb 19, 2025

Thanks @lucascolley, I am hoping to pass in PyTorch tensors (on GPU) to scipy.ndimage.map_coordinates, which currently fails as the function (map_coordinates) still internally tries to convert to numpy array

@shivanimall
Copy link

shivanimall commented Feb 19, 2025

Currently, PyTorch has an existing implementation of grid sample which is similar to map_coordinates however, it changes the range of coordinates to -1 to 1. I would like to avoid this normalisation, if possible. So, I resorted to using scipy's functionality for the geometric transform.

Would this mean using torch.compile with numpy arrays (into scipy function)?

@lucascolley
Copy link
Member Author

If you want to keep your arrays on the GPU, then I don't think torch.compile can help here, given that ndimage.map_coordinates is implemented on NumPy arrays which are CPU-only.

@shivanimall
Copy link

shivanimall commented Feb 20, 2025

thanks @lucascolley

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
array types Items related to array API support and input array validation (see gh-18286) maintenance Items related to regular maintenance tasks scipy.ndimage
Projects
None yet
Development

No branches or pull requests

2 participants