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

skimage.segmentation.quickshift signature is missing from API docs #2017

Merged
merged 1 commit into from
Mar 19, 2016

Conversation

soupault
Copy link
Member

Should fix #2005 .

@soupault soupault added bug 📄 type: Documentation Updates, fixes and additions to documentation labels Mar 19, 2016
@soupault
Copy link
Member Author

That's interesting:

[1/1] Cythonizing /home/travis/build/scikit-image/scikit-image/skimage/segmentation/_quickshift.pyx
Error compiling Cython file:
------------------------------------------------------------
...
                        dist = 0
                        for channel in range(channels):
                            dist += (current_pixel_p[channel] -
                                     image_c[r_, c_, channel])**2
                        dist += (r - r_)**2 + (c - c_)**2
                        densities[r, c] += exp(-dist / (2 * kernel_size**2))
                                                    ^
------------------------------------------------------------
skimage/segmentation/_quickshift.pyx:115:53: Coercion from Python not allowed without the GIL
Error compiling Cython file:
------------------------------------------------------------
...
                        dist = 0
                        for channel in range(channels):
                            dist += (current_pixel_p[channel] -
                                     image_c[r_, c_, channel])**2
                        dist += (r - r_)**2 + (c - c_)**2
                        densities[r, c] += exp(-dist / (2 * kernel_size**2))
                                                    ^
------------------------------------------------------------
skimage/segmentation/_quickshift.pyx:115:53: Operation not allowed without gil
Error compiling Cython file:
------------------------------------------------------------
...
                        dist = 0
                        for channel in range(channels):
                            dist += (current_pixel_p[channel] -
                                     image_c[r_, c_, channel])**2
                        dist += (r - r_)**2 + (c - c_)**2
                        densities[r, c] += exp(-dist / (2 * kernel_size**2))
                                              ^
------------------------------------------------------------
skimage/segmentation/_quickshift.pyx:115:47: Converting to Python object not allowed without gil
Error compiling Cython file:
------------------------------------------------------------
...
                        dist = 0
                        for channel in range(channels):
                            dist += (current_pixel_p[channel] -
                                     image_c[r_, c_, channel])**2
                        dist += (r - r_)**2 + (c - c_)**2
                        densities[r, c] += exp(-dist / (2 * kernel_size**2))
                                                         ^
------------------------------------------------------------
skimage/segmentation/_quickshift.pyx:115:58: Operation not allowed without gil
Error compiling Cython file:
------------------------------------------------------------
...
                        dist = 0
                        for channel in range(channels):
                            dist += (current_pixel_p[channel] -
                                     image_c[r_, c_, channel])**2
                        dist += (r - r_)**2 + (c - c_)**2
                        densities[r, c] += exp(-dist / (2 * kernel_size**2))
                                                                      ^
------------------------------------------------------------
skimage/segmentation/_quickshift.pyx:115:71: Operation not allowed without gil
Traceback (most recent call last):
  File "setup.py", line 146, in <module>
    **extra
  File "/home/travis/venv/lib/python2.6/site-packages/numpy/distutils/core.py", line 135, in setup
    config = configuration()
  File "setup.py", line 69, in configuration
    config.add_subpackage('skimage')
  File "/home/travis/venv/lib/python2.6/site-packages/numpy/distutils/misc_util.py", line 1002, in add_subpackage
    caller_level = 2)
  File "/home/travis/venv/lib/python2.6/site-packages/numpy/distutils/misc_util.py", line 971, in get_subpackage
    caller_level = caller_level + 1)
  File "/home/travis/venv/lib/python2.6/site-packages/numpy/distutils/misc_util.py", line 908, in _get_configuration_from_setup_py
    config = setup_module.configuration(*args)
  File "skimage/setup.py", line 24, in configuration
    config.add_subpackage('segmentation')
  File "/home/travis/venv/lib/python2.6/site-packages/numpy/distutils/misc_util.py", line 1002, in add_subpackage
    caller_level = 2)
  File "/home/travis/venv/lib/python2.6/site-packages/numpy/distutils/misc_util.py", line 971, in get_subpackage
    caller_level = caller_level + 1)
  File "/home/travis/venv/lib/python2.6/site-packages/numpy/distutils/misc_util.py", line 908, in _get_configuration_from_setup_py
    config = setup_module.configuration(*args)
  File "skimage/segmentation/setup.py", line 17, in configuration
    cython(['_quickshift.pyx'], working_path=base_path)
  File "/home/travis/build/scikit-image/scikit-image/skimage/_build.py", line 50, in cython
    cythonize(pyxfile)
  File "/home/travis/venv/lib/python2.6/site-packages/Cython/Build/Dependencies.py", line 877, in cythonize
    cythonize_one(*args)
  File "/home/travis/venv/lib/python2.6/site-packages/Cython/Build/Dependencies.py", line 997, in cythonize_one
    raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: /home/travis/build/scikit-image/scikit-image/skimage/segmentation/_quickshift.pyx

@@ -14,7 +14,7 @@ from ..util import img_as_float
from ..color import rgb2lab


def quickshift(image, ratio=1., float kernel_size=5, max_dist=10,
def quickshift(image, ratio=1.0, kernel_size=5, max_dist=10,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kernel_size is used in a nested for-loop in this function. It seems like we should precompute the value used in that loop and store it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(as a cdef)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, already working on that.

@blink1073
Copy link
Member

@soupault, that error makes sense given my comments above.

@@ -112,7 +113,7 @@ def quickshift(image, ratio=1.0, kernel_size=5, max_dist=10,
dist += (current_pixel_p[channel] -
image_c[r_, c_, channel])**2
dist += (r - r_)**2 + (c - c_)**2
densities[r, c] += exp(-dist / (2 * kernel_size**2))
densities[r, c] += exp(-dist / (2 * kernel_size_c**2))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about cdef float kernel_size_sq = kernel_size**2 instead (it was a float before, and this saves taking the square each time).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sorry, you are right.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fairly certain that the compiler is smart to optimize, but why not go all the way and make it inv_neg_kernel_size_sqr = -0.5 / kernel_size**2? The loss in precision shouldn't matter too much in this case I assume.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ahojnnes I fully agree, but, in my opinion, this should be an another PR. One can find other things (incl. TODO ⚡) which should be addressed.

@blink1073
Copy link
Member

LGTM

cdef int kernel_size_c = kernel_size
cdef int w = 3 * kernel_size_c
cdef float kernel_size_sq = kernel_size**2
cdef int w = int(3 * kernel_size)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, maybe ceil?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ahojnnes Should I use cnp.ceil or np.ceil here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't matter too much, but cnp.ceil should be a wrapper around the ceil function in <math.h> and therefore faster in Cython code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, clear. I've already made the change.

@ahojnnes
Copy link
Member

THanks @soupault!

ahojnnes added a commit that referenced this pull request Mar 19, 2016
skimage.segmentation.quickshift signature is missing from API docs
@ahojnnes ahojnnes merged commit 1e9aac2 into scikit-image:master Mar 19, 2016
@soupault soupault deleted the fix_doc_quickshift branch March 19, 2016 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📄 type: Documentation Updates, fixes and additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

skimage.segmentation.quickshift signature is missing from API docs
3 participants