Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooONNXFunc.cxx
Go to the documentation of this file.
1/*
2 * Project: RooFit
3 * Authors:
4 * Jonas Rembser, CERN 04/2026
5 *
6 * Copyright (c) 2026, CERN
7 *
8 * Redistribution and use in source and binary forms,
9 * with or without modification, are permitted according to the terms
10 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)
11 */
12
13#include <RooONNXFunc.h>
14
15#include <RooMsgService.h>
16
17#include <TBuffer.h>
18#include <TInterpreter.h>
19#include <TSystem.h>
20
21#include <fstream>
22#include <mutex>
23
24/**
25 \file RooONNXFunc.cxx
26 \class RooONNXFunc
27 \ingroup Roofit
28
29 RooONNXFunc wraps an ONNX model as a RooAbsReal, allowing it to be used as
30 a building block in likelihoods, fits, and statistical analyses without
31 additional boilerplate code. The class supports models with **one or more
32 statically-shaped input tensors** and a **single scalar output**. The class
33 was designed to share workspaces with neural functions for combined fits in
34 RooFit-based frameworks written in C++. Therefore, the RooONNXFunc doesn't
35 depend on any Python packages and fully supports ROOT IO,
36
37 The ONNX model is evaluated through compiled C++ code generated at runtime
38 using **TMVA SOFIE**. Automatic differentiation is supported via
39 [Clad](https://github.com/vgvassilev/clad), allowing RooFit to access
40 analytical gradients for fast minimization with Minuit 2.
41
42 The ONNX model is stored internally as a byte payload and serialized together
43 with the RooONNXFunc object using ROOT I/O. Upon reading from a file or
44 workspace, the runtime backend is rebuilt automatically.
45
46 ### Input handling
47
48 The model inputs are provided as a list of tensors, where each tensor is
49 represented by a RooArgList of RooAbsReal objects. The order of the inputs
50 defines the feature ordering passed to the ONNX model.
51 Optionally, users can validate that the ONNX model has the expected input
52
53 ### Example (C++)
54
55 \code
56 // Define input variables
57 RooRealVar x{"x", "x", 0.0};
58 RooRealVar y{"y", "y", 0.0};
59 RooRealVar z{"z", "z", 0.0};
60
61 // Construct ONNX function, building the std::vector<RooArgList> in-place
62 RooONNXFunc func{
63 "func", "func",
64 {{x, y}, {z}},
65 "model.onnx"
66 };
67
68 // Evaluate
69 double val = func.getVal();
70 std::cout << "Model output: " << val << std::endl;
71 \endcode
72
73 ### Example (Python)
74
75 \code{.py}
76 import ROOT
77
78 # Define variables
79 x = ROOT.RooRealVar("x", "x", 0.0)
80 y = ROOT.RooRealVar("y", "y", 0.0)
81 z = ROOT.RooRealVar("z", "z", 0.0)
82
83 # Create ONNX function
84 func = ROOT.RooONNXFunc(
85 "func", "func",
86 [[x, y], [z]],
87 "model.onnx"
88 )
89
90 # Evaluate
91 print("Model output:", func.getVal())
92 \endcode
93
94 */
95
96namespace {
97
98std::vector<std::uint8_t> fileToBytes(std::string const &filePath)
99{
100 // Read file into byte vector
101 std::ifstream file(filePath, std::ios::binary);
102 if (!file) {
103 std::ostringstream os;
104 os << "failed to open file '" << filePath << "'";
105 throw std::runtime_error(os.str());
106 }
107
108 file.seekg(0, std::ios::end);
109 const std::streamsize size = file.tellg();
110 file.seekg(0, std::ios::beg);
111
112 if (size <= 0) {
113 std::ostringstream os;
114 os << "file '" << filePath << "' is empty";
115 throw std::runtime_error(os.str());
116 }
117
118 std::vector<std::uint8_t> bytes(static_cast<std::size_t>(size));
119 file.read(reinterpret_cast<char *>(bytes.data()), size);
120
121 if (!file) {
122 std::ostringstream os;
123 os << "error while reading file '" << filePath << "'";
124 throw std::runtime_error(os.str());
125 }
126
127 return bytes;
128}
129
130template <typename Fn>
131Fn resolveLazy(std::string const &name, const char *code)
132{
133 static Fn fn = nullptr;
134 static std::once_flag flag;
135
136 std::call_once(flag, [&] {
137 // Try to declare the code
138 if (!gInterpreter->Declare(code)) {
139 throw std::runtime_error(std::string("ROOT JIT Declare failed for code defining ") + name);
140 }
141
142 // Try to resolve the symbol
143 void *symbol = reinterpret_cast<void *>(gInterpreter->ProcessLine((name + ";").c_str()));
144
145 if (!symbol) {
146 throw std::runtime_error(std::string("ROOT JIT failed to resolve symbol: ") + name);
147 }
148
149 fn = reinterpret_cast<Fn>(symbol);
150
151 if (!fn) {
152 throw std::runtime_error(std::string("ROOT JIT produced null function pointer for: ") + name);
153 }
154 });
155
156 return fn;
157}
158
159template <typename T>
160std::string toPtrString(T *ptr, std::string const &castType)
161{
162 return TString::Format("reinterpret_cast<%s>(0x%zx)", (castType + "*").c_str(), reinterpret_cast<std::size_t>(ptr))
163 .Data();
164}
165
166// Expression for the offset into a flat input buffer to the i-th tensor:
167// i=0: "0"; i=1: "inputTensorDims[0].total_size()";
168// i=2: "inputTensorDims[0].total_size() + inputTensorDims[1].total_size()"
169std::string flatOffsetExpr(std::size_t i)
170{
171 if (i == 0)
172 return "0";
173 std::string out;
174 for (std::size_t j = 0; j < i; ++j) {
175 if (j > 0)
176 out += " + ";
177 out += "inputTensorDims[" + std::to_string(j) + "].total_size()";
178 }
179 return out;
180}
181
182} // namespace
183
184void RooFit::Detail::AnyWithVoidPtr::emplace(std::string const &typeName)
185{
186 auto anyPtrSession = toPtrString(this, "RooFit::Detail::AnyWithVoidPtr");
187 gInterpreter->ProcessLine((anyPtrSession + "->emplace<" + typeName + ">();").c_str());
188}
189
191 /// Uniform thunk signature regardless of input-tensor count.
192 /// Args: (Session*, output, flat input buffer).
193 using Func = void (*)(void *, float *, float const *);
194
197 RooFit::Detail::AnyWithVoidPtr _zero_session; ///< Zero-weight session, the tangent for forward-mode derivatives.
198 Func _func = nullptr;
199 std::size_t _nInputTensors = 0;
200 bool _codegenDeclared = false;
201};
202
203/**
204 Construct a RooONNXFunc from an ONNX model file.
205
206 \param name Name of the RooFit object
207 \param title Title of the RooFit object
208 \param inputTensors Vector of RooArgList, each representing one input tensor.
209 The variables in each RooArgList match to each flattened input tensor.
210 \param onnxFile Path to the ONNX model file. The file is read and stored
211 internally as a byte payload for persistence with RooWorkspace.
212 \param inputNames Optional list of ONNX input node names. If provided, these
213 are used to validate that the ONNX model has the structure expected by
214 your RooFit code.
215 \param inputShapes Optional list of tensor shapes corresponding to each input
216 tensor. If provided, these are used to validate that the ONNX models
217 input tensors have the shape that you expect. If omitted, only the
218 total size of each tensor is checked.
219 */
220RooONNXFunc::RooONNXFunc(const char *name, const char *title, const std::vector<RooArgList> &inputTensors,
221 const std::string &onnxFile, const std::vector<std::string> & /*inputNames*/,
222 const std::vector<std::vector<int>> & /*inputShapes*/)
223 : RooAbsReal{name, title}, _onnxBytes{fileToBytes(onnxFile)}
224{
225 initialize();
226
227 for (std::size_t i = 0; i < inputTensors.size(); ++i) {
228 std::string istr = std::to_string(i);
229 _inputTensors.emplace_back(
230 std::make_unique<RooListProxy>(("!inputs_" + istr).c_str(), ("Input tensor " + istr).c_str(), this));
231 _inputTensors.back()->addTyped<RooAbsReal>(inputTensors[i]);
232 }
233}
234
235RooONNXFunc::RooONNXFunc(const RooONNXFunc &other, const char *newName)
236 : RooAbsReal{other, newName}, _onnxBytes{other._onnxBytes}, _runtime{other._runtime}, _funcName{other._funcName}
237{
238 for (std::size_t i = 0; i < other._inputTensors.size(); ++i) {
239 _inputTensors.emplace_back(std::make_unique<RooListProxy>("!inputs", this, *other._inputTensors[i]));
240 }
241}
242
244{
245 _inputBuffer.clear();
246 _inputBuffer.reserve(_inputTensors.size());
247
248 for (auto const &tensorList : _inputTensors) {
249 for (auto const *real : static_range_cast<RooAbsReal const *>(*tensorList)) {
250 _inputBuffer.push_back(static_cast<float>(real->getVal(tensorList->nset())));
251 }
252 }
253}
254
256{
257 if (_runtime) {
258 return;
259 }
260
261 _runtime = std::make_unique<RuntimeCache>();
262
263 // We are jitting the SOFIE invocation lazily at runtime, to avoid the
264 // link-time dependency to the SOFIE parser library.
265 if (gSystem->Load("libROOTTMVASofieParser") < 0) {
266 throw std::runtime_error("RooONNXFunc: cannot load ONNX file since SOFIE ONNX parser is missing."
267 " Please build ROOT with tmva=ON.");
268 }
269 using OnnxToCpp = std::string (*)(std::uint8_t const *, std::size_t, const char *);
270 auto onnxToCppWithSofie = resolveLazy<OnnxToCpp>("_RooONNXFunc_onnxToCppWithSofie",
271 R"(
272#include "TMVA/RModelParser_ONNX.hxx"
273
274std::string _RooONNXFunc_onnxToCppWithSofie(std::uint8_t const *onnxBytes, std::size_t onnxBytesSize, const char *outputName)
275{
276 namespace SOFIE = TMVA::Experimental::SOFIE;
277
278 std::string buffer{reinterpret_cast<const char *>(onnxBytes), onnxBytesSize};
279 std::istringstream stream{buffer};
280
281 SOFIE::RModel rmodel = SOFIE::RModelParser_ONNX{}.Parse(stream, outputName);
282 rmodel.SetOptimizationLevel(SOFIE::OptimizationLevel::kBasic);
283 rmodel.Generate(SOFIE::Options::kNoWeightFile);
284
285 std::stringstream ss{};
286 rmodel.PrintGenerated(ss);
287 return ss.str();
288}
289)");
290
291 static int counter = 0;
292 _funcName = "roo_onnx_func_" + std::to_string(counter);
293 std::string namespaceName = "TMVA_SOFIE_" + _funcName + "";
294 counter++;
295
296 std::string modelCode = onnxToCppWithSofie(_onnxBytes.data(), _onnxBytes.size(), _funcName.c_str());
297 gInterpreter->Declare(modelCode.c_str());
298
299 auto nInputTensors = static_cast<unsigned long>(
300 gInterpreter->ProcessLine(("std::size(" + namespaceName + "::inputTensorDims);").c_str()));
301 _runtime->_nInputTensors = nInputTensors;
302
303 // Evaluation thunk with a uniform signature regardless of the input-tensor count:
304 // takes a flat float buffer and splits it into the per-tensor pointers expected by
305 // SOFIE's doInfer.
306 {
307 std::ostringstream ss;
308 ss << "namespace " << namespaceName << " {\n"
309 << "void roo_eval_thunk(void *session_void, float *out, float const *flat_input) {\n"
310 << " auto *session = reinterpret_cast<Session *>(session_void);\n"
311 << " doInfer(*session";
312 for (std::size_t i = 0; i < nInputTensors; ++i) {
313 ss << ", flat_input + (" << flatOffsetExpr(i) << ")";
314 }
315 ss << ", out);\n"
316 << "}\n"
317 << "} // namespace " << namespaceName << "\n";
318 gInterpreter->Declare(ss.str().c_str());
320
321 std::string sessionName = "::TMVA_SOFIE_" + _funcName + "::Session";
322
323 _runtime->_session.emplace(sessionName);
324
325 _runtime->_func = reinterpret_cast<RuntimeCache::Func>(gInterpreter->ProcessLine(
326 ("static_cast<void(*)(void *, float *, float const *)>(" + namespaceName + "::roo_eval_thunk);").c_str()));
327}
328
329/// Name of the function that RooFit codegen calls. Declares it on first use,
330/// so that only codegen users pay for the Clad differentiation.
331std::string RooONNXFunc::outerWrapperName() const
332{
334 return "TMVA_SOFIE_" + funcName() + "::roo_outer_wrapper";
335}
336
338{
339 if (_runtime->_codegenDeclared) {
340 return;
341 }
342 _runtime->_codegenDeclared = true;
343
344 const std::size_t nInputTensors = _runtime->_nInputTensors;
345 std::string namespaceName = "TMVA_SOFIE_" + _funcName;
346 std::string sessionName = "::" + namespaceName + "::Session";
347 auto ptrSession = toPtrString(_runtime->_session.ptr, sessionName);
348
349 // Comma-separated list "<prefix>0, <prefix>1, ..." over the input tensors.
350 auto perTensor = [&](std::string const &prefix) {
351 std::string out;
352 for (std::size_t i = 0; i < nInputTensors; ++i) {
353 out += (i > 0 ? ", " : "") + prefix + std::to_string(i);
354 }
355 return out;
356 };
357
358 // Per-input-tensor parameter / argument lists used by the JIT'd code below.
359 std::string innerParams = perTensor("float const *input");
360 std::string innerArgs = perTensor("input");
361 std::string innerTangentParams = perTensor("float const *d_input");
362 std::string innerTangentArgs = perTensor("d_input");
363 std::string outerDoubleParams = perTensor("double const *input");
364 std::string tangentDoubleParams = perTensor("double const *d_input");
365 std::string cladInputs = perTensor("input"); // for clad::gradient param spec
366
367 // Non-template inner / wrapper functions, generated with the right number of inputs.
368 {
369 std::ostringstream ss;
370 ss << "namespace " << namespaceName << " {\n\n"
371 << "float roo_inner_wrapper(Session const &session, " << innerParams << ") {\n"
372 << " float out = 0.;\n"
373 << " doInfer(session, " << innerArgs << ", &out);\n"
374 << " return out;\n"
375 << "}\n\n"
376 << "float roo_wrapper(Session const &session, " << innerParams << ") {\n"
377 << " return roo_inner_wrapper(session, " << innerArgs << ");\n"
378 << "}\n\n"
379 << "} // namespace " << namespaceName << "\n";
380 gInterpreter->Declare(ss.str().c_str());
381 }
382
383 // hardcode the gradient for now
384 _runtime->_d_session.emplace(sessionName);
385 auto ptrDSession = toPtrString(_runtime->_d_session.ptr, sessionName);
386
387 gInterpreter->Declare("#include <Math/CladDerivator.h>");
388
389 gInterpreter->ProcessLine(("clad::gradient(" + namespaceName + "::roo_wrapper, \"" + cladInputs + "\");").c_str());
390
391 // The codegen call site (CodegenImpl::codegenImpl(RooONNXFunc)) passes one
392 // double-array argument per input tensor. Emit roo_outer_wrapper and the matching
393 // custom-derivative pullback with the corresponding number of parameters.
394 {
395 std::ostringstream ss;
396 ss << "namespace " << namespaceName << " {\n\n"
397 << "double roo_outer_wrapper(" << outerDoubleParams << ") {\n"
398 << " auto &session = *" << ptrSession << ";\n";
399 for (std::size_t i = 0; i < nInputTensors; ++i) {
400 ss << " float inputFlt" << i << "[inputTensorDims[" << i << "].total_size()];\n"
401 << " for (std::size_t i = 0; i < std::size(inputFlt" << i << "); ++i) {\n"
402 << " inputFlt" << i << "[i] = input" << i << "[i];\n"
403 << " }\n";
404 }
405 ss << " return roo_inner_wrapper(session";
406 for (std::size_t i = 0; i < nInputTensors; ++i) {
407 ss << ", inputFlt" << i;
408 }
409 ss << ");\n"
410 << "}\n\n"
411 << "} // namespace " << namespaceName << "\n\n"
412 << "namespace clad::custom_derivatives {\n"
413 << "namespace " << namespaceName << " {\n\n"
414 << "void roo_outer_wrapper_pullback(" << outerDoubleParams << ", double d_y";
415 for (std::size_t i = 0; i < nInputTensors; ++i) {
416 ss << ", double *d_input" << i;
417 }
418 ss << ") {\n"
419 << " using namespace ::" << namespaceName << ";\n";
420 for (std::size_t i = 0; i < nInputTensors; ++i) {
421 ss << " float inputFlt" << i << "[inputTensorDims[" << i << "].total_size()];\n"
422 << " float d_inputFlt" << i << "[::std::size(inputFlt" << i << ")];\n"
423 << " for (::std::size_t i = 0; i < ::std::size(inputFlt" << i << "); ++i) {\n"
424 << " inputFlt" << i << "[i] = input" << i << "[i];\n"
425 << " d_inputFlt" << i << "[i] = 0;\n"
426 << " }\n";
427 }
428 ss << " auto *session = " << ptrSession << ";\n"
429 << " auto *d_session = " << ptrDSession << ";\n"
430 << " roo_inner_wrapper_pullback(*session";
431 for (std::size_t i = 0; i < nInputTensors; ++i) {
432 ss << ", inputFlt" << i;
433 }
434 ss << ", d_y, d_session";
435 for (std::size_t i = 0; i < nInputTensors; ++i) {
436 ss << ", d_inputFlt" << i;
437 }
438 ss << ");\n";
439 for (std::size_t i = 0; i < nInputTensors; ++i) {
440 ss << " for (::std::size_t i = 0; i < ::std::size(inputFlt" << i << "); ++i) {\n"
441 << " d_input" << i << "[i] += d_inputFlt" << i << "[i];\n"
442 << " }\n";
443 }
444 ss << "}\n\n"
445 << "} // namespace " << namespaceName << "\n"
446 << "} // namespace clad::custom_derivatives\n";
447 if (!gInterpreter->Declare(ss.str().c_str())) {
448 throw std::runtime_error("RooONNXFunc: failed to declare the code for RooFit codegen and Clad");
449 }
450 }
451
452 // Clad Hessians are reverse-over-forward, so the opaque roo_outer_wrapper also needs a
453 // custom pushforward and pushforward_pullback. If declaring them fails, only Hessians
454 // are unavailable.
455
456 // Generates roo_inner_wrapper_pushforward as a by-product, like the gradient above
457 // does for roo_inner_wrapper_pullback.
458 gInterpreter->ProcessLine(("clad::differentiate(" + namespaceName + "::roo_wrapper, \"input0[0]\");").c_str());
459
460 // Weights are constant, so their tangent is zero. The intermediate tensors of
461 // this session serve as tangent scratch space.
462 _runtime->_zero_session.emplace(sessionName);
463 auto ptrZeroSession = toPtrString(_runtime->_zero_session.ptr, sessionName);
464 gInterpreter->ProcessLine((ptrZeroSession + "->SetWeightsToZero();").c_str());
465
466 // roo_dir = grad . d_input. Its pullback, generated by differentiating roo_dir_outer,
467 // gives all that the pushforward_pullback needs: H . d_input in the input adjoints and
468 // the gradient in the d_input adjoints. Differentiating w.r.t. d_input also avoids a
469 // clad bug: for a non-varied pointer argument, clad finds no custom helper pullback
470 // with the reduced signature and silently differentiates the BLAS calls, yielding zero.
471 {
472 std::ostringstream ss;
473 ss << "namespace " << namespaceName << " {\n\n"
474 << "float roo_dir(Session const &session, Session const &zeroSession, " << innerParams << ", "
475 << innerTangentParams << ") {\n"
476 << " return roo_inner_wrapper_pushforward(session, " << innerArgs << ", zeroSession, " << innerTangentArgs
477 << ").pushforward;\n"
478 << "}\n\n"
479 << "float roo_dir_outer(Session const &session, Session const &zeroSession, " << innerParams << ", "
480 << innerTangentParams << ") {\n"
481 << " return roo_dir(session, zeroSession, " << innerArgs << ", " << innerTangentArgs << ");\n"
482 << "}\n\n"
483 << "} // namespace " << namespaceName << "\n";
484 gInterpreter->Declare(ss.str().c_str());
485 }
486 gInterpreter->ProcessLine(
487 ("clad::gradient(" + namespaceName + "::roo_dir_outer, \"" + cladInputs + ", " + innerTangentArgs + "\");")
488 .c_str());
489
490 {
491 std::ostringstream ss;
492
493 // Emits the sessions and float copies of the inputs and the tangents.
494 auto emitPrologue = [&]() {
495 ss << " using namespace ::" << namespaceName << ";\n"
496 << " auto &session = *" << ptrSession << ";\n"
497 << " auto &zeroSession = *" << ptrZeroSession << ";\n";
498 for (std::size_t i = 0; i < nInputTensors; ++i) {
499 ss << " float inputFlt" << i << "[inputTensorDims[" << i << "].total_size()];\n"
500 << " float dInputFlt" << i << "[inputTensorDims[" << i << "].total_size()];\n"
501 << " for (::std::size_t i = 0; i < ::std::size(inputFlt" << i << "); ++i) {\n"
502 << " inputFlt" << i << "[i] = input" << i << "[i];\n"
503 << " dInputFlt" << i << "[i] = d_input" << i << "[i];\n"
504 << " }\n";
505 }
506 };
507
508 ss << "namespace clad::custom_derivatives {\n"
509 << "namespace " << namespaceName << " {\n\n"
510 << "clad::ValueAndPushforward<double, double> roo_outer_wrapper_pushforward(" << outerDoubleParams << ", "
511 << tangentDoubleParams << ") {\n";
512 emitPrologue();
513 ss << " auto vp = roo_inner_wrapper_pushforward(session, " << perTensor("inputFlt") << ", zeroSession, "
514 << perTensor("dInputFlt") << ");\n"
515 << " return {vp.value, vp.pushforward};\n"
516 << "}\n\n";
517
518 ss << "void roo_outer_wrapper_pushforward_pullback(" << outerDoubleParams << ", " << tangentDoubleParams
519 << ", clad::ValueAndPushforward<double, double> d_y, " << perTensor("double *d_out_input") << ", "
520 << perTensor("double *d_out_d_input") << ") {\n";
521 emitPrologue();
522 // Fresh adjoint sessions per call: clad's second-order pullback doesn't reset
523 // their adjoint state, so reused ones would accumulate it across calls.
524 ss << " Session dSession1;\n"
525 << " Session dSession2;\n";
526 for (std::size_t i = 0; i < nInputTensors; ++i) {
527 ss << " float hvpFlt" << i << "[inputTensorDims[" << i << "].total_size()] = {};\n"
528 << " float gradFlt" << i << "[inputTensorDims[" << i << "].total_size()] = {};\n";
529 }
530 ss << " roo_dir_pullback(session, zeroSession, " << perTensor("inputFlt") << ", " << perTensor("dInputFlt")
531 << ", 1.F, &dSession1, &dSession2, " << perTensor("hvpFlt") << ", " << perTensor("gradFlt") << ");\n";
532 for (std::size_t i = 0; i < nInputTensors; ++i) {
533 ss << " for (::std::size_t i = 0; i < ::std::size(inputFlt" << i << "); ++i) {\n"
534 << " d_out_input" << i << "[i] += d_y.value * gradFlt" << i << "[i] + d_y.pushforward * hvpFlt" << i
535 << "[i];\n"
536 << " d_out_d_input" << i << "[i] += d_y.pushforward * gradFlt" << i << "[i];\n"
537 << " }\n";
538 }
539 ss << "}\n\n"
540 << "} // namespace " << namespaceName << "\n"
541 << "} // namespace clad::custom_derivatives\n";
542 if (!gInterpreter->Declare(ss.str().c_str())) {
543 coutW(Fitting) << "RooONNXFunc::declareCodegenFunctions(" << GetName()
544 << "): failed to declare the custom derivatives for Clad Hessians" << std::endl;
545 }
546 }
547}
548
549double RooONNXFunc::evaluate() const
550{
552
553 float out = 0.f;
554 _runtime->_func(_runtime->_session.ptr, &out, _inputBuffer.data());
555 return static_cast<double>(out);
556}
557
559{
560 if (R__b.IsReading()) {
562 this->initialize();
563 } else {
565 }
566}
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
#define coutW(a)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t bytes
char name[80]
Definition TGX11.cxx:142
#define gInterpreter
R__EXTERN TSystem * gSystem
Definition TSystem.h:582
friend void RooRefArray::Streamer(TBuffer &)
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:63
RooONNXFunc wraps an ONNX model as a RooAbsReal, allowing it to be used as a building block in likeli...
Definition RooONNXFunc.h:21
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
std::vector< std::uint8_t > _onnxBytes
Persisted ONNX model bytes.
Definition RooONNXFunc.h:55
std::string outerWrapperName() const
Name of the function that RooFit codegen calls.
std::shared_ptr< RuntimeCache > _runtime
! Transient runtime information.
Definition RooONNXFunc.h:56
void declareCodegenFunctions() const
Declare the code that RooFit codegen calls, and its Clad derivatives.
std::vector< float > _inputBuffer
!
Definition RooONNXFunc.h:57
std::size_t nInputTensors() const
Definition RooONNXFunc.h:33
static TClass * Class()
std::vector< std::unique_ptr< RooListProxy > > _inputTensors
Inputs mapping to flattened input tensors.
Definition RooONNXFunc.h:54
RooONNXFunc()=default
void initialize()
Build transient runtime backend on first use.
std::string funcName() const
Definition RooONNXFunc.h:36
void fillInputBuffer() const
Gather current RooFit inputs into a contiguous feature buffer.
std::string _funcName
!
Definition RooONNXFunc.h:58
Buffer base class used for serializing objects.
Definition TBuffer.h:43
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=nullptr)=0
Bool_t IsReading() const
Definition TBuffer.h:86
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
const char * Data() const
Definition TString.h:385
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2460
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Definition TSystem.cxx:1880
RooFit::Detail::AnyWithVoidPtr _d_session
void(*)(void *, float *, float const *) Func
Uniform thunk signature regardless of input-tensor count.
RooFit::Detail::AnyWithVoidPtr _session
RooFit::Detail::AnyWithVoidPtr _zero_session
Zero-weight session, the tangent for forward-mode derivatives.