PyO3 / rust-numpy

PyO3-based Rust bindings of the NumPy C-API
BSD 2-Clause "Simplified" License
1.11k stars 106 forks source link

Support writing custom NumPy ufuncs in Rust #399

Open mhostetter opened 11 months ago

mhostetter commented 11 months ago

Add support for writing custom NumPy ufuncs in Rust.

Discussed in https://github.com/PyO3/rust-numpy/discussions/398

Originally posted by **mhostetter** October 29, 2023 Is it possible to write a custom NumPy ufunc in Rust and then apply it on arrays (with the requisite broadcasting) from either Rust or Python? My application is writing finite field arithmetic ufuncs. I previously implemented this in Python and wrapped in Numba. I'm curious if I can replicate in Rust and achieve better performance. Forgive the question if it's obvious. I didn't find an answer in documentation.
kngwyu commented 11 months ago

I think this is possible through the unsafe raw NumPy API we are exposing now, but we haven't provided a higher-level Rust API for achieving this. This is not our intention, but we just haven't received an urgent request. Definitely worth considering to implement that, but I'm not sure how difficult it is.