Repository navigation
Conversation
Signed-off-by: Ilyass Emssaad <[email protected]>
Member
|
I'm going to ask @darskkaa to review to see whether there are additions here that are still needed. We can drop the tests. |
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.
Summary
Nine public APIs reject read-only NumPy inputs with
ValueError: buffer source array is read-only, because their Cython entrypoints demand writable buffers even though the inputs are only read.
This PR makes those inputs
consttyped 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. No
copies are introduced and writable inputs behave exactly as before.
The ninth API,
util.map_array, needs no change:_remap.pyxalreadyuses
constmemoryviews forinput_arr,input_valsandoutput_vals,and
test_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/unwrap3Dentrypoints and their helpers are const-qualified in
unwrap_2d_ljmu.{h,c}/unwrap_3d_ljmu.{h,c}(audited: the wrappedimage and mask are only read; writes go to internal pixel/voxel structs
and the output array).
unwrap_phasealso no longer tries to zero NaNentries in-place on the caller's array: it copies first, only when NaNs
are present.
denoise_tv_bregman,denoise_bilateral:image(and the lookup tables in the bilateral case) are now
constin_denoise_cy.pyx.inpaint_biharmonic:mask_flatis nowconst npy_bool[::1]in_inpaint.pyx(the wrapper always coerces themask to bool). Note:
const char[::1]does not accept a bool arrayunder Cython 3.3.1, which is why the type is
npy_boolrather thanchar.iradon_sart:imageandprojectionare nowconstin
sart_projection_updateand inbilinear_ray_sum/bilinear_ray_update(_radon_transform.pyx).area_opening,diameter_opening(andmax_tree,max_tree_local_maxima): the image and auxiliary inputs are nowconstin
_max_tree_cy.pyx;parent/sorted_indices/outputstaywritable.
ORB.detect_and_extract:imageis nowconstin_corner_fast,_corner_moravec,_corner_orientations(corner_cy.pyx)and in
_orb_loop(orb_cy.pyx), which the descriptor extraction pathalso goes through.
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:
test_unwrap_phase_read_only,test_unwrap_phase_read_only_nantest_denoise_tv_bregman_read_only,test_denoise_bilateral_read_onlytest_inpaint_biharmonic_read_only(bothsplit_into_regionsvalues)test_iradon_sart_read_onlytest_area_opening_read_only,test_diameter_opening_read_onlytest_corner_read_only,test_orb_read_onlyThe reproducer from the issue (12 differential checks) goes from 8
failures with
ValueError: buffer source array is read-onlybefore thischange to 12/12 passing after it. Neighbouring suites pass:
test_unwrap.py,test_inpaint.py,test_radon_transform.py,test_max_tree.py,test_corner.py,test_orb.py,test_map_array.py(512 passed) andtest_denoise.py(82 passed,89 xfailed — all pre-existing PyWavelets-missing xfails).
ruff checkand
ruff format --checkare clean.Fixes #8423.
Signed-off-by: Ilyass Emssaad [email protected]