File indexing completed on 2025-01-30 10:23:04
0001 #ifndef TMVA_SOFIE_SOFIE_HELPERS
0002 #define TMVA_SOFIE_SOFIE_HELPERS
0003
0004
0005 #include <type_traits>
0006 #include <utility>
0007 #include <vector>
0008 #include <string>
0009
0010
0011 namespace TMVA{
0012 namespace Experimental{
0013
0014
0015
0016 template <typename I, typename F, typename T>
0017 class SofieFunctorHelper;
0018
0019 template <std::size_t... N, typename Session_t, typename T>
0020 class SofieFunctorHelper<std::index_sequence<N...>, Session_t, T> {
0021
0022 template <std::size_t Idx>
0023 using AlwaysT = T;
0024
0025 std::vector<std::vector<T>> fInput;
0026 std::vector<Session_t> fSessions;
0027
0028 public:
0029
0030 SofieFunctorHelper(unsigned int nslots = 0, const std::string & filename = "") :
0031 fInput(1)
0032 {
0033
0034
0035 if (nslots < 1) nslots = 1;
0036 fInput.resize(nslots);
0037 fSessions.reserve(nslots);
0038 for (unsigned int i = 0; i < nslots; i++) {
0039 if (filename.empty())
0040 fSessions.emplace_back();
0041 else
0042 fSessions.emplace_back(filename);
0043 }
0044 }
0045
0046 double operator()(unsigned slot, AlwaysT<N>... args) {
0047 fInput[slot] = {args...};
0048 auto y = fSessions[slot].infer(fInput[slot].data());
0049 return y[0];
0050 }
0051 };
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063 template <std::size_t N, typename Session_t>
0064 auto SofieFunctor(unsigned int nslots = 0, const std::string & weightsFile = "") -> SofieFunctorHelper<std::make_index_sequence<N>, Session_t, float>
0065 {
0066 return SofieFunctorHelper<std::make_index_sequence<N>, Session_t, float>(nslots, weightsFile);
0067 }
0068
0069 }
0070 }
0071
0072 #endif