Hi,I am optimising my Python code using Cython for scikit-image and hence rely heavily on numpy. I have a couple of questions in this regard.
- I need to pass a `cnp.float_t[:, ::1]` and `cnp.uint8_t[:, ::1]` memviews as an argument to a function call.
- I use `np.logical_xor`, `np.transpose` and `np.where` function calls which are pipelined in my Python implementation, which after profiling turns out has a heavy overhead. Any alternate implementations to this?
Feel free to submit a pull request, and Cython developers will handle
it. Personally, I see no reason why an explicit mention of this fact
would be in any way inappropriate for the pyximport docs.
On Jul 21, 2013 3:45 PM, "Yury V. Zaytsev" <yu...@shurup.com> wrote:
> I would look through the results for the inpaint_point and check whether
> all loops are properly converted to C loops, C math primitives are used
> instead of Python builtins where appropriate, etc.
>
Yes, the loops seem to be a dark shade of yellow. How can I write a C equivalent of
`for i, j in array_view:`
And also the best possible C equivalent for a `list` ? Any inbuilt data type?
Chintak
I've just had a closer look at what you are doing in ep_neighbor and
it's a performance killer:
You are gradually filling in a Python list (!) and then make a NumPy
array out of it by copying and re-arranging all the data (!!), just to
use it as a source of tuples in `for i_nb, j_nb in nb_view` (!!!).
A very obvious solution is to get rid of this function altogether,
especially since it's just a couple of lines, and you'll lose function
call overhead as a bonus.
As to your other question, it's not immediately obvious what are the
dimensions of center_ind_view, but, in general, a more efficient way of
iterating memory views is something along these lines:
for i in range(view.shape[0]):
for j in range(view.shape[1]):
view[i, j] = ...
http://docs.cython.org/src/userguide/memoryviews.html