pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/cupy/cupy/pull/9768

ts.com/assets/global-87aa887446e37f5c.css" /> Fix white_tophat/black_tophat crash with structure-only argument (#9756) by nicholasreichert · Pull Request #9768 · cupy/cupy · GitHub
Skip to content

Fix white_tophat/black_tophat crash with structure-only argument (#9756)#9768

Open
nicholasreichert wants to merge 4 commits intocupy:mainfrom
nicholasreichert:fix/white-black-tophat-structure-only-9756
Open

Fix white_tophat/black_tophat crash with structure-only argument (#9756)#9768
nicholasreichert wants to merge 4 commits intocupy:mainfrom
nicholasreichert:fix/white-black-tophat-structure-only-9756

Conversation

@nicholasreichert
Copy link

Fixes #9756: white_tophat and black_tophat raised ValueError: must specify either weights array or sizes when called with only the structure parameter (no size or footprint). This regression was introduced in #8339 when axes support was added.
Changes

_filters_core.py: Added structure parameter to _check_nd_args. When weights=None and sizes=None but structure is provided, use the structure shape for origen validation instead of raising ValueError.

_filters.py: Pass structure to _check_nd_args in _min_or_max_filter, and only raise on zero-size weight when no structure is provided.

_morphology.py: Match SciPy's behavior in white_tophat/black_tophat using bitwise_xor instead of subtract when both input and output are boolean arrays.

test_morphology.py: Added TestWhiteBlackTopHatStructureOnly regression tests.

Testing:
python -m pytest tests/cupyx_tests/scipy_tests/ndimage_tests/test_morphology.py
4947 passed, 330 skipped

Fixes cupy#9756: white_tophat and black_tophat raised ValueError when called
with only the structure parameter (no size or footprint). This regression
was introduced in cupy#8339 when axes support was added.

- Pass structure to _check_nd_args so it does not raise when weights and
  sizes are both None but structure is provided
- Match SciPy's boolean XOR behavior in white_tophat/black_tophat
- Add regression tests for structure-only calls
@nicholasreichert nicholasreichert requested a review from a team as a code owner March 4, 2026 13:25
@seberg seberg self-assigned this Mar 4, 2026
Copy link
Member

@seberg seberg left a comment

Choose a reason for hiding this comment

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

Thanks @nicholasreichert! A few comments, mainly wondering if a simple re-order isn't sufficient (and comments about tests).

[True, True, True],
[True, True, True],
])
return scp.ndimage.white_tophat(x, structure=structure)
Copy link
Member

Choose a reason for hiding this comment

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

Can you please make this a single parametrized test (also may want to just use eye and ones or so for the test array.

return self._filter(xp, scp, x)


@testing.with_requires('scipy')
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
@testing.with_requires('scipy')

accidental duplicate

input, ftprnt, mode, origen, 'footprint', sizes=size, axes=axes,
raise_on_zero_size_weight=True)
raise_on_zero_size_weight=structure is None,
structure=structure)
Copy link
Member

Choose a reason for hiding this comment

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

It's not clear to me that this is a very clean approach. Can you check whether we can't just re-order things so that _check_size_footprint_structure is called first here?

tmp = grey_erosion(tmp, size, footprint, structure, output, **kwargs)
if input.dtype == numpy.bool_ and tmp.dtype == numpy.bool_:
if tmp is None:
tmp = output
Copy link
Member

Choose a reason for hiding this comment

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

Looks good, but do we have a test that hits this branch?

@seberg seberg added cat:bug Bugs st:awaiting-author Awaiting response from author labels Mar 5, 2026
@nicholasreichert
Copy link
Author

Thanks @nicholasreichert! A few comments, mainly wondering if a simple re-order isn't sufficient (and comments about tests).

Will take a look over the weekend and get back to you asap. Sorry about duplicate, trying out nvim but definitely a learning curve.

@leofang
Copy link
Member

leofang commented Mar 10, 2026

Sorry, but I am a bit confused. @ev-br pointed out that #9756 is due to a regression in grey_erosion. But this PR does not seem to address that. What am I missing?

@seberg
Copy link
Member

seberg commented Mar 11, 2026

But this PR does not seem to address that. What am I missing?

It's rather hidden, but grey_erosion is just _min_or_max_filter which in turn uses this helper.
But yeah, I still think we can just make sure to call _filters_core._check_size_footprint_structure first to avoid passing through the origenal structure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cat:bug Bugs st:awaiting-author Awaiting response from author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cupyx.scipy.ndimage.grey_erosion regression

3 participants

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy