Skip to content

Commit cdc254c

Browse files
jtrammpaulromano
andauthored
Fix for Issue Loading MGXS Data Files with LLVM 20 or Newer (#3368)
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
1 parent 07f5334 commit cdc254c

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/mgxs.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,21 @@ void Mgxs::metadata_from_hdf5(hid_t xs_id, const vector<double>& temperature,
9999
case TemperatureMethod::NEAREST:
100100
// Determine actual temperatures to read
101101
for (const auto& T : temperature) {
102-
auto i_closest = xt::argmin(xt::abs(temps_available - T))[0];
102+
// Determine the closest temperature value
103+
// NOTE: the below block could be replaced with the following line,
104+
// though this gives a runtime error if using LLVM 20 or newer,
105+
// likely due to a bug in xtensor.
106+
// auto i_closest = xt::argmin(xt::abs(temps_available - T))[0];
107+
double closest = std::numeric_limits<double>::max();
108+
int i_closest = 0;
109+
for (int i = 0; i < temps_available.size(); i++) {
110+
double diff = std::abs(temps_available[i] - T);
111+
if (diff < closest) {
112+
closest = diff;
113+
i_closest = i;
114+
}
115+
}
116+
103117
double temp_actual = temps_available[i_closest];
104118
if (std::fabs(temp_actual - T) < settings::temperature_tolerance) {
105119
if (std::find(temps_to_read.begin(), temps_to_read.end(),

0 commit comments

Comments
 (0)