Allow getting pointer (address) to Numba's int/float variables
See original GitHub issueFeature Request
For example I have some cffi or ctypes function that has a pointer int64_t * as one of its argument. I need to call this function passing pointer (address) of single-value np.int64 variable. I found a way how to get and pass a pointer to any element of Numpy array, using .ctypes property. But didn’t find any way of passing a pointer to int64 (np.int64 or numba.int64). Example code:
import numba, numpy as np
@numba.njit(cache = True)
def f():
a = np.zeros((10,), dtype = np.int64)
aptr = a[1:3].ctypes
b = np.int64
bptr = b.ctypes
c = numba.int64
cptr = c.ctypes
f()
In code above Numpy array has .ctypes property, returning aptr that can be easily passed as cffi function’s int64_t * argument. But single-value variables b and c don’t have same .ctypes property to get pointer of type int64_t * (compile error Unknown attribute 'ctypes' of type class(int64)). Neither I found any special function to get such pointer.
Maybe such address-getting special function exists somewhere in Numba’s library, can anyone point me please to such function? Otherwise it would be nice to implement such.
As a workaround I was creating single-element Numpy array, copying int value into this element and then passing arr[0:1].ctypes to function. After function completes I copy value from array back to single-value variable. But this workaround is very inefficient especially if to create array every time.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:13 (6 by maintainers)

Top Related StackOverflow Question
I don’t expect issues with this. My concern was around more general support for taking the address of variables, where you do something like:
@polkovnikov
I don’t see a reason why the following code should not work for (i8/i16/i32/i64/f32/f64) , but I haven’t tested it thoroughly.
Example