question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support passing in LowLevelCallable as argument to jitted function

See original GitHub issue

With 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:open
  • Created 5 years ago
  • Reactions:4
  • Comments:14 (13 by maintainers)

github_iconTop GitHub Comments

2reactions
pvcommented, Jul 10, 2018

The PyCapsule is the canonical format of the function pointer, and any ctypes/cffi/Cython inputs are converted to that form by LowLevelCallable.__init__. The function 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 of scipy.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

2reactions
sklamcommented, May 29, 2018

This is definitely something we can do fairly quickly; esp if all you need to do on a LowLevelCallable is just to call it.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found