Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
SOFIEHelpers.hxx
Go to the documentation of this file.
1#ifndef TMVA_SOFIE_SOFIE_HELPERS
2#define TMVA_SOFIE_SOFIE_HELPERS
3
4
5#include <type_traits>
6#include <utility>
7#include <vector>
8#include <string>
9
10
11namespace TMVA{
12namespace Experimental{
13
14///Helper class used by SOFIEFunctor to wrap the
15///infer signature interface to RDataFrame
16template <typename I, typename F, typename T>
18
19template <std::size_t... N, typename Session_t, typename T>
20class SofieFunctorHelper<std::index_sequence<N...>, Session_t, T> {
21 /// this is the magic to define the operator() with N fixed parameter arguments
22 template <std::size_t Idx>
23 using AlwaysT = T;
24
25 std::vector<std::vector<T>> fInput;
26 std::vector<Session_t> fSessions;
27
28public:
29
30 SofieFunctorHelper(unsigned int nslots = 0, const std::string & filename = "") :
31 fInput(1)
32 {
33 // create Sessions according to given number of slots.
34 // if number of slots is zero create a single session
35 if (nslots < 1) nslots = 1;
36 fInput.resize(nslots);
37 fSessions.reserve(nslots);
38 for (unsigned int i = 0; i < nslots; i++) {
39 if (filename.empty())
40 fSessions.emplace_back();
41 else
42 fSessions.emplace_back(filename);
43 }
44 }
45
46 double operator()(unsigned slot, AlwaysT<N>... args) {
47 fInput[slot] = {args...};
48 auto y = fSessions[slot].infer(fInput[slot].data());
49 return y[0];
50 }
51};
52
53/// SofieFunctor : used to wrap the infer function of the
54/// generated model by SOFIE in a RDF compatible signature.
55/// The number of slots is an optional parameter used to
56/// create multiple SOFIE Sessions, which can be run in a parallel
57/// model evaluation. One should use as number of slots the number of slots used by
58/// RDataFrame. By default, in case of `nslots=0`, only a single Session will be created
59/// and the Functor cannot be run in parallel.
60/// Examples of using the SofieFunctor are the C++ tutorial TMVA_SOFIE_RDataFrame.C
61/// and the Python tutorial TMVA_SOFIE_RDataFrame.py which makes use of the ROOT JIT
62/// to compile on the fly the generated SOFIE model.
63template <std::size_t N, typename Session_t>
64auto SofieFunctor(unsigned int nslots = 0, const std::string & weightsFile = "") -> SofieFunctorHelper<std::make_index_sequence<N>, Session_t, float>
65{
66 return SofieFunctorHelper<std::make_index_sequence<N>, Session_t, float>(nslots, weightsFile);
67}
68
69}//Experimental
70}//TMVA
71
72#endif //TMVA_SOFIE_SOFIE_HELPERS
#define N
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
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 filename
TRObject operator()(const T1 &t1) const
Helper class used by SOFIEFunctor to wrap the infer signature interface to RDataFrame.
Double_t y[n]
Definition legend1.C:17
auto SofieFunctor(unsigned int nslots=0, const std::string &weightsFile="") -> SofieFunctorHelper< std::make_index_sequence< N >, Session_t, float >
SofieFunctor : used to wrap the infer function of the generated model by SOFIE in a RDF compatible si...
create variable transformations