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

MAINT: Rewrote scipy.ndimage.find_object function in cython #5006

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -155,6 +155,7 @@ scipy/linalg/fblas.pyf
scipy/linalg/flapack.pyf
scipy/linalg/src/id_dist/src/*_subr_*.f
scipy/ndimage/src/_ni_label.c
scipy/ndimage/src/_ni_measure.c
scipy/optimize/cobyla/_cobylamodule.c
scipy/optimize/lbfgsb/_lbfgsbmodule.c
scipy/optimize/minpack2/minpack2module.c
Expand Down
2 changes: 2 additions & 0 deletions scipy/ndimage/bento.info
Expand Up @@ -9,3 +9,5 @@ Library:
src/ni_support.c
Extension: _ni_label
Sources: src/_ni_label.c
Extension: _ni_measure.pyx
Sources: src/_ni_measure.pyx
8 changes: 5 additions & 3 deletions scipy/ndimage/measurements.py
Expand Up @@ -35,6 +35,7 @@
from . import _ni_support
from . import _ni_label
from . import _nd_image
from . import _ni_measure
from . import morphology

__all__ = ['label', 'find_objects', 'labeled_comprehension', 'sum', 'mean',
Expand Down Expand Up @@ -264,11 +265,12 @@ def find_objects(input, max_label=0):
if numpy.iscomplexobj(input):
raise TypeError('Complex type not supported')

if input.dtype == np.bool:
input = input.view(np.uint8)

if max_label < 1:
max_label = input.max()

return _nd_image.find_objects(input, max_label)

return _ni_measure._findObjects(input.flatten(), input.shape, max_label)

def labeled_comprehension(input, labels, index, func, out_dtype, default, pass_positions=False):
"""
Expand Down
5 changes: 5 additions & 0 deletions scipy/ndimage/setup.py
Expand Up @@ -23,6 +23,11 @@ def configuration(parent_package='', top_path=None):
include_dirs=['src']+[get_include()],
)

config.add_extension("_ni_measure",
sources=["src/_ni_measure.c",],
include_dirs=['src']+[get_include()],
)

config.add_data_dir('tests')

return config
Expand Down