Emit direct pybind callable pointers with full-signature casts - #197
Emit direct pybind callable pointers with full-signature casts#197dellaert wants to merge 3 commits into
Conversation
Downstream GTSAM auditI audited this wrapper against a full GTSAM migration, regenerating the same 21 modules from
That is a 73.0% reduction in generated lambdas and a 95.6% reduction in declarations requiring explicit adapter annotations. The migration also consolidated reduced-arity/defaulted families such as The remaining 27 adapters are accounted for: 14 function-template calls, four ref-qualified members, six real Python/STL conversions, and three inheritance/overload-registration blockers. Validation on the downstream branch: wrapper suite 125 passed, stable and unstable Python extensions built, 61 focused Python tests passed, and both SmartProjection C++ test targets passed. The GTSAM integration also contains a small follow-up beyond this PR for type-qualifying |
Downstream compile-time and binary-size auditI built the audited GTSAM For the isolated wrapper rebuild, I touched the same 20 generated wrapper translation units in each already-built tree, then recompiled and relinked both Python modules:
Stripped Python module sizes:
The clean end-to-end stable+unstable build was 683.39 s vs 406.94 s (−40.5%), but that number also includes native GTSAM differences, so the wrapper-only result above is the more relevant comparison. Both resulting module pairs imported successfully. Caveat: this is an end-to-end downstream migration result, combining direct callable pointers with the accompanying exact-signature/interface consolidation. It does not attribute the whole gain to pointer emission alone. The unstable size reduction is also strongly affected by removal of the deprecated PoseRTV wrapper. |
|
I don't really like the |
|
@ProfFan I'm not in love with it either, but I spent a lot of time in tokens to reduce the number of lambdas needed to a very small number, like 27 or so. Some of that work is simply making the wrapper better. So it's not lost work, per se. But this solution definitely does work. |
|
|
Let me also spin some experiments |
Summary
@pybind_lambdaas an explicit escape hatch for wrapper signatures that intentionally differ from C++ declarationsMotivation
Bare callable addresses and
py::overload_castcannot select an exact declaration when a C++ header contains overloads omitted from the wrapper interface. Full-signature casts retain genuine function/member-function pointers while reliably selecting the interface-declared signature. Intentional wrapper/C++ signature mismatches continue to use@pybind_lambda.Validation
Previously run on this branch before push:
conda run -n py312 python -m pytest tests/test_pybind_wrapper.py— 18 passedconda run -n py312 python -m pytest tests— 123 passedgit diff --check— passedNo tests or builds were run while creating this PR.