Use pybind for rd_region, rd_sum_tstep and rd_sum_vector#1259
Use pybind for rd_region, rd_sum_tstep and rd_sum_vector#1259eivindjahren wants to merge 12 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR migrates the Python ResdataRegion implementation from cwrap ResdataPrototype bindings to a dedicated pybind11 extension module (resdata.grid._rd_region), aligning it with the codebase’s ongoing move toward pybind-based bindings.
Changes:
- Replaced
ResdataRegion’s cwrap prototypes with calls into a new pybind11 module (resdata.grid._rd_region). - Added new pybind11 module implementation for
rd_regionin C++. - Registered the new module in
lib/CMakeLists.txtfor build integration.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| python/resdata/grid/rd_region.py | Switches ResdataRegion to use the new _rd_region pybind11 functions and adjusts copying/equality accordingly. |
| lib/resdata/rd_region_pybind.cpp | Introduces the pybind11 module _rd_region implementing the rd_region API surface. |
| lib/CMakeLists.txt | Adds _rd_region to the set of built pybind11 modules. |
Comments suppressed due to low confidence (2)
lib/resdata/rd_region_pybind.cpp:238
- The active index list is returned as a borrowed C reference but
createCReferenceis called without a parent object. This breaks the expected.parent()relationship (see region tests) and can allow the IntVector to outlive the owning region. Passselfas the parent when creating the reference.
m.def("_get_active_list", [](py::handle self) {
return IntVector().attr("createCReference")(
reinterpret_cast<std::uintptr_t>(
rd_region_get_active_list(from_cwrap<rd_region_type>(self))));
});
lib/resdata/rd_region_pybind.cpp:243
- The global index list is created as a C reference without associating it with its owning region. To preserve lifetime/ownership semantics (and keep parity with other bindings using
createCReference(..., self)), passselfas the parent.
m.def("_get_global_list", [](py::handle self) {
return IntVector().attr("createCReference")(
reinterpret_cast<std::uintptr_t>(
rd_region_get_global_list(from_cwrap<rd_region_type>(self))));
});
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
e9608d2 to
41c0a2a
Compare
41c0a2a to
1e68481
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (2)
lib/resdata/rd_region_pybind.cpp:420
- The closing
} // namespaceat the end of the file matches the anonymous namespace that currently wrapsPYBIND11_MODULE. If the module is moved to global scope, this trailing namespace-closer should be removed as well; otherwise you’ll end up with an extra unmatched brace or keep the init symbol hidden.
}
} // namespace
lib/resdata/rd_region.cpp:334
- Throwing a string literal here (
throw("...")) throws aconst char*and bypassesstd::exception-based handling (including pybind11’s default translators). Preferstd::invalid_argument(or similar) so the exception is well-typed and consistently translated.
rd_data_type data_type = rd_kw_get_data_type(rd_kw);
rd_region_assert_kw(region, rd_kw, &global_kw);
if (!rd_type_is_numeric(data_type))
throw("select by in_interval is only supported for float and integer "
"keywords");
a6e950a to
7f3298c
Compare
56acf04 to
cbd327f
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
lib/resdata/rd_region.cpp:648
- The error message for an invalid k-slice interval is incorrect: this branch checks
k1 > k2but throws "i1 > i2". The message should reflect the actual parameters being validated.
if (k1 > k2)
throw std::logic_error("i1 > i2");
cbd327f to
5135c07
Compare
No description provided.