Skip to content

Fix for Issue Loading MGXS Data Files with LLVM 20 or Newer #3368

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 3 commits into from
Apr 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/mgxs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,21 @@ void Mgxs::metadata_from_hdf5(hid_t xs_id, const vector<double>& temperature,
case TemperatureMethod::NEAREST:
// Determine actual temperatures to read
for (const auto& T : temperature) {
auto i_closest = xt::argmin(xt::abs(temps_available - T))[0];
// Determine the closest temperature value
// NOTE: the below block could be replaced with the following line,
// though this gives a runtime error if using LLVM 20 or newer,
// likely due to a bug in xtensor.
// auto i_closest = xt::argmin(xt::abs(temps_available - T))[0];
double closest = std::numeric_limits<double>::max();
int i_closest = 0;
for (int i = 0; i < temps_available.size(); i++) {
double diff = std::abs(temps_available[i] - T);
if (diff < closest) {
closest = diff;
i_closest = i;
}
}

double temp_actual = temps_available[i_closest];
if (std::fabs(temp_actual - T) < settings::temperature_tolerance) {
if (std::find(temps_to_read.begin(), temps_to_read.end(),
Expand Down