Repository navigation
Use size_t for indices in grid, layer, and fault_block - #1308
Merged
Merged
Conversation
eivindjahren
force-pushed
the
grid_size_t
branch
3 times, most recently
from
October 28, 2026 11:16
7de44ed to
acb2f6c
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The pybind constructor still forwards int arguments to fields changed to size_t, causing narrowing that breaks binding compilation.
1 open issue
What changed in this PR
This PR migrates grid, layer, and fault-block indices to size_t, updating related APIs, Python bindings, and tests. It also changes coarse-group counts to report distinct groups rather than the highest group number.
Changes:
- Replace signed indices and sentinel values with
size_tand optional results across related C++ components. - Update Python interfaces and input validation, including
Nonefor out-of-column depth lookups. - Adapt regression tests for unsigned indices, invalid inputs, and sparse coarse-group numbering.
| File | Description |
|---|---|
| tests/rd_tests/test_rd_grid_regular.py | Test out-of-column depth results. |
| tests/rd_tests/test_rd_grid_misc.py | Update invalid-coordinate expectations. |
| tests/rd_tests/test_rd_grid_coarse.py | Expect distinct coarse-group counts. |
| tests/rd_tests/test_grid.py | Add malformed-input and unsigned-index tests. |
| tests/rd_tests/test_fault_blocks.py | Test invalid layer and cell indices. |
| python/resdata/grid/rd_grid.py | Validate dimensions and handle optional results. |
| lib/tests/test_rd_region.cpp | Adapt region tests to unsigned indices. |
| lib/tests/test_rd_grid_xyz_lookup.cpp | Test optional coordinate-lookup results. |
| lib/tests/test_rd_grid_regular.cpp | Adapt grid tests to revised APIs. |
| lib/tests/test_rd_grid_nnc_lgr.cpp | Update indices and test negative refinement identifiers. |
| lib/tests/test_rd_grid_coarse.cpp | Test sparse and extreme coarse-group numbers. |
| lib/tests/test_rd_grid_bounds_checking.cpp | Use unsigned fixture dimensions and sizes. |
| lib/tests/test_nnc_info.cpp | Use unsigned refinement identifiers. |
| lib/tests/test_layer.cpp | Adapt layer tests and corner indexing. |
| lib/tests/test_fault_block_layer.cpp | Update layer fixtures and bounds tests. |
| lib/resdata/tests/rd_nnc_vector.cpp | Update connection-vector types and assertions. |
| lib/resdata/tests/rd_nnc_test.cpp | Adapt connection lookup checks. |
| lib/resdata/tests/rd_nnc_info_test.cpp | Update connection metadata tests. |
| lib/resdata/tests/rd_layer.cpp | Use unsigned layer coordinates and lists. |
| lib/resdata/tests/rd_grid_volume.cpp | Update volume-test indices and formatting. |
| lib/resdata/tests/rd_grid_reset_actnum.cpp | Assert optional active-index results. |
| lib/resdata/tests/rd_grid_lgr_name.cpp | Update refinement-name lookup assertions. |
| lib/resdata/tests/rd_grid_layer_contains.cpp | Use unsigned coordinate lookup outputs. |
| lib/resdata/tests/rd_grid_init_fwrite.cpp | Update export loops and numeric conversions. |
| lib/resdata/tests/rd_grid_export.cpp | Use unsigned geometry buffer sizes. |
| lib/resdata/tests/rd_grid_dx_dy_dz.cpp | Update dimension-test indices. |
| lib/resdata/tests/rd_grid_cell_contains_wellpath.cpp | Adapt wellpath lookup results and diagnostics. |
| lib/resdata/tests/rd_grid_add_nnc.cpp | Update connection indices and assertions. |
| lib/resdata/tests/rd_fault_block_layer.cpp | Adapt fault-layer test indices. |
| lib/resdata/tests/rd_dualp.cpp | Update dual-porosity index assertions. |
| lib/resdata/tests/rd_coarse_test.cpp | Validate coarse bounds and optional indices. |
| lib/resdata/rd_subsidence.cpp | Use unsigned cache sizes and loops. |
| lib/resdata/rd_region.cpp | Migrate region indices and clamp signed intervals. |
| lib/resdata/rd_region_pybind.cpp | Accept unsigned region coordinates. |
| lib/resdata/rd_grid_pybind.cpp | Update index bindings and reject negative export indices. |
| lib/resdata/rd_grid_cache.cpp | Use unsigned cached grid indices. |
| lib/resdata/rd_grav.cpp | Update cache indexing and validate density identifiers. |
| lib/resdata/rd_grav_common.cpp | Use unsigned gravity calculation indices. |
| lib/resdata/rd_coarse_cell.cpp | Use optional indices and unsigned coarse-cell bounds. |
| lib/resdata/rd_box.cpp | Adapt box traversal to optional active indices. |
| lib/resdata/nnc_vector.cpp | Migrate connection indices and bounds-check access. |
| lib/resdata/nnc_info.cpp | Use optional refinement-map entries. |
| lib/resdata/layer.cpp | Migrate layer indexing and adjust boundary arithmetic. |
| lib/resdata/layer_pybind.cpp | Accept unsigned layer dimensions and coordinates. |
| lib/resdata/fault_block.cpp | Migrate cell indices and guard neighbor subtraction. |
| lib/resdata/fault_block_layer.cpp | Use optional block-map entries and unsigned coordinates. |
| lib/resdata/fault_block_layer_pybind.cpp | Accept unsigned layer indices. |
| lib/private-include/detail/resdata/rd_grid_zcorn.hpp | Add unsigned corner-index helper. |
| lib/private-include/detail/resdata/rd_grid_cache.hpp | Expose unsigned cache sizes and indices. |
| lib/private-include/detail/resdata/layer_cxx.hpp | Update edge-tracing index types. |
| lib/include/resdata/rd_region.hpp | Update region index APIs and templates. |
| lib/include/resdata/rd_grid.hpp | Declare unsigned indices and optional lookup results. |
| lib/include/resdata/rd_coarse_cell.hpp | Expose revised coarse-cell bounds and indices. |
| lib/include/resdata/rd_box.hpp | Update box bounds and index lists. |
| lib/include/resdata/nnc_vector.hpp | Update connection-vector interfaces. |
| lib/include/resdata/nnc_info.hpp | Update connection metadata interfaces. |
| lib/include/resdata/layer.hpp | Declare unsigned layer coordinates and counts. |
| lib/include/resdata/fault_block.hpp | Update fault-cell fields and index interfaces. |
| lib/include/resdata/fault_block_layer.hpp | Update layer-index declarations. |
Review effort: Balanced
eivindjahren
force-pushed
the
grid_size_t
branch
from
October 28, 2026 11:35
acb2f6c to
6c57556
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Regression tests are missing for slice clamping and out-of-range intervals across all three axes, and for decreasing or mixed-direction diagonal interpolation at zero-coordinate boundaries.
2 open issues
1 resolved since last review
Review effort: Balanced
ajaust
reviewed
Oct 28, 2026
ajaust
left a comment
Collaborator
There was a problem hiding this comment.
Nice work. I left some comments.
eivindjahren
force-pushed
the
grid_size_t
branch
2 times, most recently
from
October 29, 2026 07:34
7d3aeff to
0514208
Compare
eivindjahren
force-pushed
the
grid_size_t
branch
from
October 29, 2026 07:35
0514208 to
bccea94
Compare
Validate conversions from signed to unsigned at the Python boundary. Functions now raise TypeError on negative indices.
Coarse groups are now kept in an unordered_map keyed by an int group id. Negative CORSNUM values mean no group, and huge values no longer cause out-of-bounds writes or unbounded allocation. rd_grid_get_num_coarse_groups returns the number of groups present, and rd_grid_iget_coarse_group returns nullptr for unknown ids. rd_grid_compare_coarse_cells now compares every group.
eivindjahren
force-pushed
the
grid_size_t
branch
from
October 29, 2026 07:39
a3bf153 to
f366971
Compare
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.


This changes the actual number returned by Grid::coarse_groups when groups are non-contiguous. This seems reasonable as it is within the documentation of the function.