Repository navigation
Conversation
Signed-off-by: Ilyass Emssaad <[email protected]>
Contributor
|
@stefanv reviewed as asked in #8427. OK: the Fine but not needed: the Issues:
|
… pass on main Drop the 7 new read-only tests that already pass on upstream main (scikit-image#8424/scikit-image#8426 landed the underlying fixes); only unwrap_phase and ORB still fail there. Keeps test_unwrap_phase_read_only, test_unwrap_phase_read_only_nan and test_orb_read_only. Signed-off-by: Ilyass Emssaad <[email protected]>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #8427, rebased onto current main. Since #8427 opened, upstream landed most of this fix: #8424 (corner_fast/moravec/orientations) and #8426 (denoise/inpaint/radon/max_tree consts, part of #8423). On current main only 2 of the 8 APIs still reject read-only input:
unwrap_phaseandORB.detect_and_extract. This PR fixes those two, and keeps the extraconstparams in denoise/radon/max_tree/inpaint (harmless, no effect for callers) plus the regression tests that still fail on main.Summary
Eight public APIs rejected read-only NumPy inputs with
ValueError: buffer source array is read-only, because their Cython entry points demanded writable buffers even though the inputs are only read. Six of them were fixed upstream by #8424 and #8426. The two that still fail on main,restoration.unwrap_phaseandfeature.ORB.detect_and_extract, are fixed here by making their inputsconsttyped memoryviews, so read-only arrays (from memory-mapped data, read-only shared data, or zero-copy pipelines) are accepted and give results identical to the same writable data.One copy is introduced, and only in one place:
unwrap_phasecopies the input when NaNs are present, because the NaN entries are zeroed before unwrapping andnp.asarraymay return the caller's read-only array unchanged. Without the copy, read-only input with NaNs would still fail. No other copies are introduced, and writable inputs behave exactly as before.The ninth API,
util.map_array, needs no change:_remap.pyxalready usesconstmemoryviews forinput_arr,input_valsandoutput_vals, andtest_map_array_read_only(gh-6378) already covers it.What changed
unwrap_phase(1D/2D/3D):image/maskare nowconstin_unwrap_1d/2d/3d.pyx; the Cunwrap2D/unwrap3Dentry points and their helpers are const-qualified inunwrap_2d_ljmu.{h,c}/unwrap_3d_ljmu.{h,c}(audited: the wrapped image and mask are only read; writes go to internal pixel/voxel structs and the output array).unwrap_phasealso no longer tries to zero NaN entries in-place on the caller's array: it copies first, only when NaNs are present.denoise_tv_bregman,denoise_bilateral: extraconstparams in_denoise_cy.pyxbeyond what Accept read-only input in more Cython kernels #8426 covered.inpaint_biharmonic: extraconstparams in_inpaint.pyxbeyond Accept read-only input in more Cython kernels #8426 (upstream'sconst unsigned charmask kept as their deliberate choice).iradon_sart: extraconstparams in_radon_transform.pyxbeyond Accept read-only input in more Cython kernels #8426.area_opening,diameter_opening(andmax_tree,max_tree_local_maxima): extraconstparams in_max_tree_cy.pyxbeyond Accept read-only input in more Cython kernels #8426;parent/sorted_indices/outputstay writable.ORB.detect_and_extract:imageis nowconstin_orb_loop(orb_cy.pyx), which the descriptor extraction path goes through. (_corner_fast,_corner_moravec,_corner_orientationswere covered by Accept read-only input in corner_fast, corner_moravec and corner_orientations #8424.)Tests
New regression tests in both
tests/skimage2/andtests/skimage/(the trees are mirrors) — each compares read-only vs identical writable input for exact equality. Only the tests that fail on main are kept; the other 7 were dropped in this revision because they already pass on main (review feedback):test_unwrap_phase_read_only,test_unwrap_phase_read_only_nantest_orb_read_onlyTrimmed tree, CPU-only, all 14 affected test files in both trees: 712 passed, 178 xfailed (all pre-existing, mostly missing PyWavelets), 0 failures.
ruff checkandruff format --checkare clean.Fixes #8423.
Signed-off-by: Ilyass Emssaad [email protected]