Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update some function to fit numba4.3 #74

Open
yxdragon opened this issue Dec 11, 2019 · 4 comments
Open

update some function to fit numba4.3 #74

yxdragon opened this issue Dec 11, 2019 · 4 comments

Comments

@yxdragon
Copy link
Member

yxdragon commented Dec 11, 2019

as numba update a lot, many function does not work now.
I want to modify all functions in jit(nopython=True) mode.

But I failed to modify a function (spend two hours)
@jni I think you are aware of numba, can you help to rewrite the function below?
https://github.com/Image-Py/imagepy/blob/master/imagepy/ipyalg/graph/sknw.py

@jit(nopython=True)
def neighbors(shape):
    dim = len(shape)
    block = np.ones([3]*dim)
    block[tuple([1]*dim)] = 0
    idx = np.where(block>0)
    idx = np.array(idx, dtype=np.uint8).T
    idx = np.array(idx-[1]*dim)
    acc = np.cumprod((1,)+shape[::-1][:-1])
    return np.dot(idx, acc[::-1])

in the old version, this function need not jit, but now, if function a call function b and a is a jit function, then b must be jit too.
thanks!

@jni
Copy link

jni commented Dec 11, 2019

@yxdragon hello again! Long time no see! 😊

I’m not sure what this function is supposed to do? Is this the same as this scikit-image function?

https://github.com/scikit-image/scikit-image/blob/master/skimage/morphology/_util.py#L54

What we do is precompute this in Python then pass the resulting array into Numba/Cython as an input.

@yxdragon
Copy link
Member Author

@jni there are some functions using numba in imagepy.ipyalg. As numba update to 0.43, these functions do not work now. I want to repair them, but it seems not easy to me.

As the function "neighbors" upon, (that is the code in sknw, I learn from your skan. the function count the neighbors pixel's index in ravel coordinate)

It works well in numba0.41, and very fast. but now, it doesnot work. So did your skan works now? And can you help to modify it? or give some guide?

@jni
Copy link

jni commented Dec 12, 2019

did your skan works now?

Yes, it's working with the latest numba, I just checked. The trick is that I never or rarely use NumPy functions inside my Numba code. Everything NumPy I precompute in a non-compiled function, and then I pass in pre-allocated arrays to Numba. Only simple for-loops are involved in Numba.

The above function should not need to be jitted: it creates a very small array that you can reuse. So, make that a pure Python function, return the array, and and pass the resulting array to the jitted functions that need it.

@yxdragon
Copy link
Member Author

ok, split the all function into python part and jit part. now all function can work with numba 0.46, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants