Support passing in LowLevelCallable as argument to jitted function
See original GitHub issueWith the recent support for passing in numba jitted functions as arguments (https://github.com/numba/numba/pull/2801), it would also be nice to also support passing in scipy.LowLevelCallable
objects. These have become common in the scipy ecosystem, and would be useful for downstream projects considering numba adoption.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:14 (13 by maintainers)
Top Results From Across the Web
Passing arguments to scipy.LowLevelCallable while using ...
I wonder if I can pass the arguments as array as user_data to the function f2 . From documentation for nquad , found...
Read more >numba/numba - Gitter
You can rewrite mysum2 as a @numba.jit function ... integrand with scipy.integrate.quad and passing other arguments to the integrand using LowLevelCallable.
Read more >scipy.LowLevelCallable — SciPy v1.9.3 Manual
User data to pass on to the callback function. signaturestr, optional ... The argument function can be one of: PyCapsule, whose name contains...
Read more >Prettier LowLevelCallables with Numba JIT and decorators
It turns out Numba cfuncs can call Numba jitted functions, so, ... Numba jit and Numba cfunc to make a LowLevelCallable suitable for...
Read more >Creating C callbacks with @cfunc - Numba
The @cfunc decorator has a similar usage to @jit , but with an important ... the C callback's signature will pass low-level pointer...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The PyCapsule is the canonical format of the function pointer, and any ctypes/cffi/Cython inputs are converted to that form by
LowLevelCallable.__init__
. Thefunction
attribute exists mainly for function pointer object life cycle management, and should not be used as the way to call the function in Numba, as you then throw Cython etc. compatibility away — you can just ignore it’s there.The intended usage is that you know beforehand the C signature(s) you support — then you can cast the LowLevelCallable to a suitable function pointer (or fail doing so, if your signature is not equivalent match). In particular, giving a generic way to call a given arbitrary LowLevelCallable is not really part of the design. While that may sound strange in the context of Numba, it should make sense when you consider that this is intended to be usable from hand-written C without JIT and with minimal hassle and speed impact.
Insofar as what Numba might do here, one possibility is to offer a convenience function that takes a Numba-format signature(s) and a LowLevelCallable object, and produces a function pointer (or NULL/error). One particular issue that you probably encounter here is allowing C integer types of the same size on the platform be considered equivalent.
In addition, something numba-specific could be added here: https://github.com/scipy/scipy/blob/master/scipy/_lib/_ccallback.py#L134 so that you could write
scipy.LowLevelCallable(some_numba_cfunc)
instead ofscipy.LowLevelCallable(some_numba_cfunc.ctypes)
.https://mail.python.org/pipermail/scipy-dev/2018-July/022919.html https://mail.python.org/pipermail/scipy-dev/2018-July/022920.html
This is definitely something we can do fairly quickly; esp if all you need to do on a
LowLevelCallable
is just to call it.