(use_cases_howto_py_function_py)= # Macro **"howtoLoadFunction.py"** ## Objective The goal of this macro is only to show how to load a C++ function in python as this could be of use for instance when producing a surrogate model (all of them can be exported in C++ and even though the recommended way to handle these is through the {{uranie}} classes, it might happen that one wants to put one's hand on it). Our example is taken from the `UserFunction.C` file provided with the {{uranie}} sources (look for it in the the `"$URANIESYS/share/uranie/macros"` folder). The `operation` function only compute the product, ratio, sum and difference between two provided inputs (just checking for consistency that the denominator of the ratio is not equal to zero). The code is shown here for illustration purpose. {{ "```{literalinclude} " + parent_dir + "/roottest/uranie/doc/UserFunctions.C" + "\n" + ":language: cpp\n" + ":lines: 209-220\n" + "```" }} ## Macro {{uranie}} {{ "```{literalinclude} " + parent_dir + "/roottest/uranie/doc/overview/use_cases/python/howtoLoadFunction.py\n" + ":language: python\n" + ":lines: 1-5,11-24\n" + "```" }} The first block simply loads the input file `UserFunctions.C` through the {{root}}'s interface. {{ "```{literalinclude} " + parent_dir + "/roottest/uranie/doc/overview/use_cases/python/howtoLoadFunction.py\n" + ":language: python\n" + ":lines: 13\n" + "```" }} Once done, the input and output `np.array` object are created, the former with provided values to be tested, the latter only filled with zeros. Calling the function is simply done by providing input and output arrays to the function operator that is now stored within {{root}} by doing: {{ "```{literalinclude} " + parent_dir + "/roottest/uranie/doc/overview/use_cases/python/howtoLoadFunction.py\n" + ":language: python\n" + ":lines: 20\n" + "```" }} The output of this macro is shown in [](#use_cases_howto_py_function_py_console). (use_cases_howto_py_function_py_console)= ## Console {{ "```{literalinclude} " + parent_dir + "/roottest/build/uranie/doc/overview/use_cases/python/howtoLoadFunction.log\n" + ":language: none\n" + "```" }}