feat: add flat inverse / Bragg-peak convenience wrappers (#122) - #141
Open
grzanka wants to merge 3 commits into
Open
feat: add flat inverse / Bragg-peak convenience wrappers (#122)#141grzanka wants to merge 3 commits into
grzanka wants to merge 3 commits into
Conversation
Add self-contained, re-entrant wrappers to dedx_wrappers.h that manage
workspace and config lifetimes internally, suitable for flat-API consumers
(e.g. JavaScript/WASM) that cannot hold libdedx objects:
- dedx_get_inverse_csda_simple()
- dedx_get_inverse_stp_simple()
- dedx_get_bragg_peak_stp_simple()
Each allocates a fresh workspace per call and sets cfg.ion_a via the
nucleon-number accessor before loading the config.
Bragg-peak support did not previously exist, so add a reusable core
function dedx_get_bragg_peak_stp() to dedx_tools.{h,c} that locates the
stopping-power maximum (reusing the existing peak finder) and returns the
peak mass stopping power.
Add tests/test_wrappers.c covering round-trip inversion of CSDA range and
stopping power, the Bragg-peak value, and the unsupported-combination
error path. All 28 ctest cases pass; clang-format and clang-tidy clean.
The Doxygen claimed "0 = low-energy, 1 = high-energy", but the implementation treats side < 0 as the low-energy branch and side >= 0 (including 0) as the high-energy branch. Document the actual behavior.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #141 +/- ##
==========================================
+ Coverage 72.73% 75.69% +2.96%
==========================================
Files 12 12
Lines 1643 1728 +85
Branches 300 319 +19
==========================================
+ Hits 1195 1308 +113
+ Misses 448 420 -28 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
Adds new “flat API” convenience wrappers (workspace/config lifetime managed per call) for inverse CSDA, inverse stopping power, and Bragg-peak stopping power; introduces a reusable core Bragg-peak helper in dedx_tools and corresponding tests.
Changes:
- Add
dedx_get_inverse_csda_simple(),dedx_get_inverse_stp_simple(), anddedx_get_bragg_peak_stp_simple()wrappers indedx_wrappers. - Add core
dedx_get_bragg_peak_stp()implementation indedx_tools. - Add
tests/test_wrappers.ccovering inversion round-trips, Bragg peak value, and an unsupported-combination path.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_wrappers.c | New test coverage for the added wrapper APIs (inverse CSDA/STP + Bragg peak + error path). |
| src/dedx_wrappers.c | Implements new one-call wrapper functions allocating/cleaning config+workspace internally. |
| src/dedx_tools.c | Adds core Bragg-peak stopping power helper built on existing peak-finder logic. |
| include/dedx_wrappers.h | Exposes the new wrapper APIs with Doxygen documentation. |
| include/dedx_tools.h | Updates inverse-STP docs and adds Bragg-peak API declaration/docs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Assert the exact error code (DEDX_ERR_ION_NOT_SUPPORTED) and -1 return for all three flat wrappers on an unsupported combination, instead of only checking err != DEDX_OK (Copilot review). - Clarify the loading preconditions/side effects in the Doxygen for dedx_get_inverse_stp() (loads internally) and dedx_get_bragg_peak_stp() (auto-loads when not already loaded), which previously claimed the configuration must already be loaded (Copilot review). - Add tests for the low-energy inverse-STP branch, the Bragg-peak core helper (success + ion_a guard), and the documented auto-load behavior, raising patch coverage above the 70% target. All 28 ctest cases pass; clang-format and clang-tidy clean.
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.
Add self-contained, re-entrant wrappers to dedx_wrappers.h that manage
workspace and config lifetimes internally, suitable for flat-API consumers
(e.g. JavaScript/WASM) that cannot hold libdedx objects:
Each allocates a fresh workspace per call and sets cfg.ion_a via the
nucleon-number accessor before loading the config.
Bragg-peak support did not previously exist, so add a reusable core
function dedx_get_bragg_peak_stp() to dedx_tools.{h,c} that locates the
stopping-power maximum (reusing the existing peak finder) and returns the
peak mass stopping power.
Add tests/test_wrappers.c covering round-trip inversion of CSDA range and
stopping power, the Bragg-peak value, and the unsupported-combination
error path. All 28 ctest cases pass; clang-format and clang-tidy clean.