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
MAINT: Rewrote scipy.ndimage.find_object function in cython #5006
base: main
Are you sure you want to change the base?
Conversation
@aman-iitj the test failures on TravisCI are real |
d44d959
to
e8a2979
Compare
@rgommers All the tests passed on my laptop. Even I checked the file in IPython and I am getting correct output for the failed test cases in travis. Have I missed something? |
I guess so. TravisCI runs 64-bit Linux. Maybe you're on another OS or bit-ness, and this is a 32/64-bit issue or a compiler dependent bug. |
@aman-iitj it would be good to write more informative commit messages, that use the prefixes and format described in http://docs.scipy.org/doc/numpy-dev/dev/gitwash/development_workflow.html#writing-the-commit-message |
e8a2979
to
a83b747
Compare
@rgommers Yes, I am working on 32 -bit system. |
Hi Aman, Thanks for making this first PR. On a first scan of your code, I wasn't able to find anything obviously wrong that would lead to the test failures. But I did get the impression (which may be wrong) that it mimics too closely what the existing C implementation did, which makes it more complicated than could be achievable with Cython. I'll try to turn that loose generic comment into actionable recommendations in the next few days: hopefully as we address those we can figure out where is the bug in your code. |
Thanks for going through the code and suggestions @jaimefrio . |
0d20cf7
to
7b63879
Compare
@jaimefrio @rgommers TravisCI tests have passed :) |
684a44d
to
472af3d
Compare
@jaimefrio Have you gone through the find_objects function. I have added 2 more functions using PointIterator in the PR. Please have a look at _ni_morphology.pyx file also. |
a4f0973
to
4f0df27
Compare
7b63879
to
be33ea5
Compare
We shold also add the necessary configuration to the Bento build files. |
scipy/ndimage/src/_ni_measure.pyx
Outdated
np.npy_bool contiguous | ||
|
||
ctypedef struct PyArrayObject: | ||
int nd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not being used anywhere right now. If there is an advantage in using this over ndarray.ndim
lets do it, if not we can remove it from here.
Try all the following together, I'm pretty sure it should work:
What errors are you getting when you try that? |
@jaimefrio i declared inux-gnu-gcc' failed with exit status 1\n"] In [40]: reload(_ni_measure) Error compiling Cython file: ------------------------------------------------------------ ... ##################################################################### ctypedef void (*func_p)(void *data, np.flatiter iti, np.intp_t max_label, int *regions, int rank) nogil cdef * funcp get_funcs(np.ndarray[data_t] input): ^ ------------------------------------------------------------ _ni_measure.pyx:49:5: Expected an identifier, found '*' Error compiling Cython file: ------------------------------------------------------------ ... ##################################################################### ctypedef void (*func_p)(void *data, np.flatiter iti, np.intp_t max_label, int *regions, int rank) nogil cdef * funcp get_funcs(np.ndarray[data_t] input): ^ ------------------------------------------------------------ _ni_measure.pyx:49:13: Syntax error in C variable declaration |
If i declare it like this In [41]: reload(_ni_measure) Error compiling Cython file: ------------------------------------------------------------ ... ##################################################################### ctypedef void (*func_p)(void *data, np.flatiter iti, np.intp_t max_label, int *regions, int rank) nogil cdef funcp get_funcs(np.ndarray[data_t] input): ^ ------------------------------------------------------------ _ni_measure.pyx:49:5: 'funcp' is not a type identifier Error compiling Cython file: ------------------------------------------------------------ ... np.flatiter _iti PyArrayIterObject *iti # func_p findObjectsPoint = funcs func_p findObjectsPoint = get_funcs(input_raw.take([0])) ^ ------------------------------------------------------------ _ni_measure.pyx:109:43: no suitable method found |
I missed an underscore, the type should be |
@jaimefrio Sorry for the silly mistake. I was sleepy yesterday. In [6]: import _ni_measure Error compiling Cython file: ------------------------------------------------------------ ... ctypedef void (*func_p)(void *data, np.flatiter iti, np.intp_t max_label, int *regions, int rank) nogil cdef func_p get_funcs(np.ndarray[data_t] input): return ( findObjectsPoint[data_t]) ^ ------------------------------------------------------------ _ni_measure.pyx:50:29: Cannot assign type 'object (int8_t *, flatiter, int, int *, int)' to 'void (*)(void *, flatiter, int, int *, int) nogil' Error compiling Cython file: ------------------------------------------------------------ ... |
In [8]: import _ni_measure Error compiling Cython file: ------------------------------------------------------------ ... ##################################################################### ctypedef void (*func_p)(void *data, np.flatiter iti, np.intp_t max_label, int *regions, int rank) nogil cdef *func_p get_funcs(np.ndarray[data_t] input): ^ ------------------------------------------------------------ _ni_measure.pyx:49:5: Expected an identifier, found '*' Error compiling Cython file: ------------------------------------------------------------ ... ##################################################################### ctypedef void (*func_p)(void *data, np.flatiter iti, np.intp_t max_label, int *regions, int rank) nogil cdef *func_p get_funcs(np.ndarray[data_t] input): ^ ------------------------------------------------------------ _ni_measure.pyx:49:13: Syntax error in C variable declaration |
The |
@jaimefrio I have already tried all the combinations of casting and functions declarations but nothing is working except casting with As you have suggested in function |
b95edfe
to
b7e2bbc
Compare
b7e2bbc
to
86208e5
Compare
fa85ba4
to
49214c1
Compare
8c13886
to
cf226db
Compare
cf226db
to
22f64f8
Compare
|
||
cdef inline findObjectsPoint(data_t *data, np.flatiter _iti, np.intp_t max_label, | ||
int *regions, int rank): | ||
cdef int kk =0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after =
.
@jaimefrio It doesn't works. I am still getting same errors. |
@jaimefrio Even If I change the declaration of function as: cpdef findObjectsPoint(): cdef np.intp_t s_index = - 1 return s_index and I call it using
the file doesn't compiles. It gives the same error. Should I remove the function findObjectspoint() and update the array |
@jaimefrio. How we are proceeding on it? Please have a look at my previous comments. |
Jaime @jaimefrio where does this PR stand in your ongoing ndimage refactor --- something left here, or can it be closed? |
MAINT: Rewrote scipy.ndimage.find_object function in cython.