Hi all,

I am looking for a way to use `np.PyArray_MultiIterNew2` in Cython to
broadcast parameters of a function. The requirement is that the two
arguments can be scalar and/or sequences. Using the usual `np.broadcast`
function works well but is slow when iterating over the broadcasted input in
a tight loop. I want to achieve the same using the C API.

Currently, if I used `(<double*>np.PyArray_MultiIter_DATA(bcast, i))[0]` to
iterate over the input when one of them is a scalar,
I get no errors, but I notice the output of the parent function returns an
array of zeros, which implies this approach didn't work. After
investigating, it seems that np.PyArray_MultiIter_DATA only accepts numpy
arrays.

I could write a function to handle all combinations of
scalar/array/list/tuple, and create temporary arrays to store the input
data, but that seems daunting and error prone. Is there a way I can achieve
this and have scalar arguments passed to np.PyArray_MultiIter_DATA be
converted to same-element arrays without writing my own code from scratch?

Any suggestions are welcome.



--
Sent from: http://numpy-discussion.10968.n7.nabble.com/
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@python.org
https://mail.python.org/mailman/listinfo/numpy-discussion

Reply via email to