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 fSessions.emplace_back(filename);
40 }
41 }
42
43 double operator()(unsigned slot, AlwaysT<N>... args) {
44 fInput[slot] = {args...};
45 auto y = fSessions[slot].infer(fInput[slot].data());
46 return y[0];
47 }
48};
49
50/// SofieFunctor : used to wrap the infer function of the
51/// generated model by SOFIE in a RDF compatible signature.
52/// The number of slots is an optional parameter used to
53/// create multiple SOFIE Sessions, which can be run in a parallel
54/// model evaluation. One shouild use as number of slots the number of slots used by
55/// RDataFrame. By default, in case of `nslots=0`, only a single Session will be created
56/// and the Functor cannot be run in parallel.
57/// Examples of using the SofieFunctor are the C++ tutorial TMVA_SOFIE_RDataFrame.C
58/// and the Python tutorial TMVA_SOFIE_RDataFrame.py which makes use of the ROOT JIT
59/// to compile on the fly the generated SOFIE model.
60template <std::size_t N, typename Session_t>
61auto SofieFunctor(unsigned int nslots = 0, const std::string & weightsFile = "") -> SofieFunctorHelper<std::make_index_sequence<N>, Session_t, float>
62{
63 return SofieFunctorHelper<std::make_index_sequence<N>, Session_t, float>(nslots, weightsFile);
64}
65
66}//Experimental
67}//TMVA
68
69#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