Skip to content

Commit 49cd009

Browse files
committed
finish
1 parent ec0994b commit 49cd009

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

roofit/roofitcore/inc/RooFit/CodegenContext.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,6 @@ class CodegenContext {
203203
unsigned _indent = 0;
204204
/// @brief Index to get unique names for temporary variables.
205205
mutable int _tmpVarIdx = 0;
206-
/// @brief A map to keep track of list names as assigned by addResult.
207-
std::unordered_map<RooFit::UniqueId<RooAbsCollection>::Value_t, std::string> _listNames;
208206
std::vector<double> _xlArr;
209207
std::vector<std::string> _collectedFunctions;
210208
};

roofit/roofitcore/inc/RooFit/Detail/MathFuncs.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,23 @@ double stepFunctionIntegral(double xmin, double xmax, std::size_t nBins, DoubleA
812812

813813
} // namespace RooFit::Detail::MathFuncs
814814

815+
inline void fillFromWorkspace(double *out, std::size_t n, double const *wksp, double const *idx)
816+
{
817+
for (std::size_t i = 0; i < n; ++i) {
818+
out[i] += wksp[static_cast<int>(idx[i])];
819+
}
820+
}
821+
815822
namespace clad::custom_derivatives {
823+
824+
inline void fillFromWorkspace_pullback(double *, std::size_t n, double const *, double const *idx, double *d_out,
825+
std::size_t *, double *d_wksp, double *)
826+
{
827+
for (std::size_t i = 0; i < n; ++i) {
828+
d_wksp[static_cast<int>(idx[i])] += d_out[i];
829+
}
830+
}
831+
816832
namespace RooFit::Detail::MathFuncs {
817833

818834
// Clad can't generate the pullback for binNumber because of the
@@ -826,6 +842,7 @@ void binNumber_pullback(Types...)
826842
}
827843

828844
} // namespace RooFit::Detail::MathFuncs
845+
829846
} // namespace clad::custom_derivatives
830847

831848
#endif

roofit/roofitcore/src/RooFit/CodegenContext.cxx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -220,25 +220,24 @@ std::string CodegenContext::buildArg(RooAbsCollection const &in, std::string con
220220
return "nullptr";
221221
}
222222

223-
auto it = _listNames.find(in.uniqueId().value());
224-
if (it != _listNames.end())
225-
return it->second;
226-
227223
std::string savedName = getTmpVarName();
228224
bool canSaveOutside = true;
229225

226+
std::vector<double> indices;
227+
indices.reserve(in.size());
228+
230229
std::stringstream declStrm;
231-
declStrm << arrayType << " " << savedName << "[]{";
230+
declStrm << arrayType << " " << savedName << "[" << in.size() << "]{};\n";
232231
for (const auto arg : in) {
233-
declStrm << getResult(*arg) << ",";
232+
getResult(*arg); // fill the result cache
233+
indices.push_back(_nodeNames.at(arg->namePtr()));
234234
canSaveOutside = canSaveOutside && isScopeIndependent(arg);
235235
}
236-
declStrm.seekp(-1, declStrm.cur);
237-
declStrm << "};\n";
236+
237+
declStrm << "fillFromWorkspace(" << savedName << ", " << in.size() << ", wksp, " << buildArg(indices) << ");\n";
238238

239239
addToCodeBody(declStrm.str(), canSaveOutside);
240240

241-
_listNames.insert({in.uniqueId().value(), savedName});
242241
return savedName;
243242
}
244243

0 commit comments

Comments
 (0)