-
Notifications
You must be signed in to change notification settings - Fork 3
Exposes more functions to C-API for APFEL++ #337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
f5fee88
Add functions to get and rotate PID basis in C-API
Radonirinaunimi 27a8eff
Merge branch 'master' into apfelxx-capi
Radonirinaunimi 9ded95b
Fix memory leak in `advanced-convolution.cpp`
Radonirinaunimi e03260c
Address review comments
Radonirinaunimi 8eb3156
Merge branch 'master' into apfelxx-capi
Radonirinaunimi d3c7b40
Proposal to expose the subgrid contents of a Grid
Radonirinaunimi 9ed7d3c
Add the correct `C++` file
Radonirinaunimi bd68162
Address comments from Code Review
Radonirinaunimi 770b763
Add `unravel_index` and tests to example
Radonirinaunimi 1d194a3
Fix `pineappl_channels_entry`
Radonirinaunimi 233b9a4
Add empty newline for consistency
Radonirinaunimi 4d2f0c9
Hit missing part in the coverage related to empty grid
Radonirinaunimi 3a9f23b
Remove `mut` from `Subgrid::shape`
cschwan a02beae
Use less `mut` and copy directly
cschwan 7797940
Check that calling `pineappl_grid_subgrid_array` on an empty subgrid …
Radonirinaunimi 9c08d4f
Remove no longer needed include
Radonirinaunimi 9d6f897
Undo interface change to `pineappl_channels_entry`
cschwan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| #include <pineappl_capi.h> | ||
|
|
||
| #include <cassert> | ||
| #include <cstddef> | ||
| #include <iomanip> | ||
| #include <ios> | ||
| #include <iostream> | ||
| #include <sstream> | ||
| #include <string> | ||
| #include <vector> | ||
| #include <numeric> | ||
|
|
||
|
|
||
| std::vector<std::size_t> unravel_index(std::size_t flat_index, const std::vector<std::size_t>& shape) { | ||
| std::size_t ndim = shape.size(); | ||
| std::vector<std::size_t> coords(ndim); | ||
|
|
||
| for (int i = ndim - 1; i >= 0; --i) { | ||
| coords[i] = flat_index % shape[i]; | ||
| flat_index /= shape[i]; | ||
| } | ||
|
|
||
| return coords; | ||
| } | ||
|
|
||
| std::string coords_to_string(const std::vector<std::size_t>& coords) { | ||
| std::ostringstream osstream; | ||
|
|
||
| osstream << "("; | ||
| for (std::size_t i = 0; i < coords.size(); ++i) { | ||
| osstream << coords[i]; | ||
| if (i != coords.size() - 1) { | ||
| osstream << ", "; | ||
| } | ||
| } | ||
| osstream << ")"; | ||
|
|
||
| return osstream.str(); | ||
| } | ||
|
|
||
|
|
||
| int main() { | ||
| std::string filename = "drell-yan-rap-ll.pineappl.lz4"; | ||
|
|
||
| // read the grid from a file | ||
| auto* grid = pineappl_grid_read(filename.c_str()); | ||
|
|
||
| // Determine the number of bins and the index of order and channel | ||
| std::size_t n_bins = pineappl_grid_bin_count(grid); | ||
| std::size_t order = 0; | ||
| std::size_t channel = 0; | ||
|
|
||
| // Get the dimension of the subgrids | ||
| std::size_t subgrid_dim = pineappl_grid_kinematics_len(grid); | ||
|
|
||
| std::cout << std::right << std::setw(10) << "bin" << std::setw(10) << "sg idx" | ||
| << std::setw(6 * subgrid_dim) << "sg coordinates" << std::setw(16) | ||
| << "sg value" << "\n"; | ||
| std::cout << std::right << std::setw(10) << "---" << std::setw(10) << "------" | ||
| << std::setw(6 * subgrid_dim) << "--------------" << std::setw(16) | ||
| << "------------" << "\n"; | ||
|
|
||
| for (std::size_t b = 0; b < n_bins; ++b) { | ||
| std::vector<std::size_t> subgrid_shape(subgrid_dim); | ||
| pineappl_grid_subgrid_shape(grid, b, order, channel, subgrid_shape.data()); | ||
|
|
||
| // Check if the subgrid is not empty | ||
| if (subgrid_shape[0] != 0) { | ||
| std::size_t flat_shape = std::accumulate(subgrid_shape.begin(), | ||
| subgrid_shape.end(), 1, std::multiplies<std::size_t>()); | ||
| std::vector<double> subgrid_array(flat_shape); | ||
|
|
||
| pineappl_grid_subgrid_array(grid, b, order, channel, subgrid_array.data()); | ||
|
|
||
| for (std::size_t index = 0; index < subgrid_array.size(); ++index) { | ||
| if (subgrid_array[index] != 0) { | ||
| // Unravel the index to recover the standard coordinates | ||
| std::vector<std::size_t> coords = unravel_index(index, subgrid_shape); | ||
|
|
||
| std::cout << std::right << std::setw(10) << b << std::setw(10) | ||
| << index << std::setw(6 * subgrid_dim) << coords_to_string(coords) | ||
| << std::setw(16) << subgrid_array[index] << "\n"; | ||
|
|
||
| // Compare to some reference value | ||
| if (b==0 && index==41020) { | ||
| assert(subgrid_array[index] == -4.936156925096015e-07); | ||
| } | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| pineappl_grid_delete(grid); | ||
| } |
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.