I am wrapping C++ code and would need to store numpy.ndarrays intermediately so that I can process them in parallel:
There is a (variable) number of such arrays that is coming from the python call and I would like to call a C++ function on them (possibly in parallel using prange). The C++ function takes a <float*> as input.
def doAll(*listArg):
n=len(listArg)
vector[float*] listArrayFloat = vector[float*]( <size_t> n) #here is the problem
vector[Result] listOut = vector[Result]( <size_t> n)
for i,obj in ennumerate(listArg):
listArrayFloat[i] = <float*> obj.data
for i in prange(n):
listOut[i] = cppFunct(listArrayFloat[i])
I was both unsuccessful in vector[float*] and vector[ numpy.ndarray[]] so there is probably something I am missing. Maybe you have an idea on how to make things working. Thanks
With my best regards,
--
Jérôme Kieffer <jerome....@terre-adelie.org>
PS: this works:
def doOne(ndarray inp not None):
cdef Result out
out = cppFunct(<float*> inp.data)
cdef vector[float*] lstInput
for obj in listArg:
if isinstance(obj,numpy.ndarray):
lstInput.push_back(<float*> obj.data)
which seems to work.
This raises another question:
Do you know why vector.push_back() or vector.size() have no "nogil" mention in the pxd file?
Thanks.
--
Jérôme Kieffer <goo...@terre-adelie.org>
Yep, that would do it, assuming your data is contiguous.
> This raises another question:
> Do you know why vector.push_back() or vector.size() have no "nogil" mention in the pxd file?
Because you don't need the gil to call them. Yeah, it's a wart.
- Robert