Replace matlab_find with numpy functions in mapgen#609
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #609 +/- ##
==========================================
- Coverage 75.06% 75.04% -0.02%
==========================================
Files 57 57
Lines 8126 8128 +2
Branches 1582 1584 +2
==========================================
Hits 6100 6100
Misses 1405 1405
- Partials 621 623 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Greptile Summary
This PR replaces MATLAB-compatibility shim calls (
matlab_find,ind2sub,sub2ind,matlab_assign) with native NumPy equivalents inmake_lineand the DIMENSION 1 block ofmake_bowlinmapgen.py. The index-arithmetic equivalence is correct:matlab_find(diff == min(diff))[0]→np.argmin(diff)preserves first-occurrence tie-breaking, and the 1-based ↔ 0-based offset adjustments are properly removed.make_line, six identical index-selection sites are simplified:np.argmin(diff)replaces thematlab_findround-trip, and the downstreamposs_x[index[0] - 1]accesses become plainposs_x[index].make_bowl, the DIMENSION 1 forward/backward surface-extraction pipeline is rewritten usingnp.where+ direct 3-D array assignment, correctly mapping the flipped backward index via(Nx - 1) - index_back_flipped. DIMENSION 2 and DIMENSION 3 are left unchanged, still relying onmatlab_find.Confidence Score: 4/5
The changed logic is a correct mechanical translation from MATLAB-style helpers to native NumPy — index equivalence holds in both make_line and the make_bowl DIMENSION 1 block. The only concern is that DIMENSION 2 and DIMENSION 3 of make_bowl were not migrated, leaving the function internally inconsistent.
The six make_line sites and the make_bowl DIMENSION 1 block all translate cleanly, and the 0-based/1-based offset adjustments are handled correctly throughout. The remaining make_bowl dimensions still use the old matlab_find path, which is not a correctness issue but does leave an incomplete job that will need a follow-up.
kwave/utils/mapgen.py — specifically the DIMENSION 2 (lines ~1745–1763) and DIMENSION 3 (lines ~1783–1801) blocks in make_bowl, which still use the old matlab_find pattern.
Important Files Changed
matlab_find-based index arithmetic withnp.argmininmake_lineand withnp.where/direct array indexing in the DIMENSION 1 block ofmake_bowl; DIMENSION 2 and DIMENSION 3 inmake_bowlstill use the oldmatlab_findpatternFlowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[pixel_map shape Nx x Ny x Nz] --> B[min along axis 0\nvalue_forw, index_forw] A --> C[flip along axis 0\nthen min along axis 0\nvalue_back, index_back] B --> D["np.where(value_forw < THRESHOLD)\ny_coords_forw, z_coords_forw"] C --> E["np.where(value_back < THRESHOLD)\ny_coords_back, z_coords_back"] D --> F["x_ind_forw = index_forw[y, z]"] E --> G["x_ind_back_flipped = index_back[y, z]\nx_ind_back = (Nx-1) - x_ind_back_flipped"] F --> H["bowl_sm[x_ind_forw, y_coords_forw, z_coords_forw] = 1"] G --> I["bowl_sm[x_ind_back, y_coords_back, z_coords_back] = 1"]Comments Outside Diff (1)
kwave/utils/mapgen.py, line 1745-1763 (link)matlab_findThe DIMENSION 1 block was fully migrated to native numpy operations, but DIMENSION 2 (lines 1745–1763) and DIMENSION 3 (lines 1783–1801) still use
matlab_find,ind2sub,sub2ind, andmatlab_assign. This leaves the refactoring half-done and makes the three dimension blocks inconsistent with each other.Reviews (1): Last reviewed commit: "Merge branch 'master' into chore/do-not-..." | Re-trigger Greptile