1.3.5.3. Use a C++ function interactively

This section describes how to use a C++ function within the python framework. The idea is that every of our surrogate model discussed later-on on can be exported in C++ and so they can be used either throughout the Uranie classes (for instance to evaluate a set of new points) or, for single evaluation, in either C++ or python. This macro will focus on the latter part. This macro is also detailled Macro “howtoLoadFunction.py”.

"""
Example of C++ function in python
"""
import numpy as np
import ROOT

# Loading a function
ROOT.gROOT.LoadMacro("UserFunctions.C")

# Preparing inputs and outputs
inp = np.array([1.2, 0.8])  # input values
out = np.zeros(4)  # output values initialise with 4 zeros

# Call the method, through the ROOT interface
ROOT.operation(inp, out)

# Print the result
print("Results are")
print(out)

The macro shown above, is an example of how to load a function and use it in a single-point estimation. Its result is discussed in Macro “howtoLoadFunction.py”.