gEconpy.model.compile.compile_function#
- gEconpy.model.compile.compile_function(inputs, outputs, backend, cache=None, stack_return=False, pop_return=False, return_symbolic=False, **kwargs)#
Dispatch compilation of a sympy function to one of three possible backends: numpy, or pytensor.
- Parameters:
- inputs: list[sp.Symbol]
The inputs to the function.
- outputs: list[Union[sp.Symbol, sp.Expr]]
The outputs of the function.
- backend: str, one of “numpy” or “pytensor”
The backend to use for the compiled function.
- cache: dict, optional
A dictionary mapping from pytensor symbols to sympy expressions. Used to prevent duplicate mappings from sympy symbol to pytensor symbol from being created. Default is a empty dictionary, implying no other functions have been compiled yet.
Ignored if backend is not “pytensor”.
- stack_return: bool, optional
If True, the function will return a single numpy array with all outputs. Otherwise it will return a tuple of numpy arrays. Default is False.
- pop_return: bool, optional
If True, the function will return only the 0th element of the output. Used to remove the list wrapper around scalar outputs. Default is False.
- return_symbolic: bool, default True
If True, when mode=”pytensor”, the will return a symbolic pytensor computation graph instead of a compiled function. Ignored when mode is not “pytensor”.
- Returns:
- f:
Callable A python function that computes the outputs from the inputs.
- cache:
dict A dictionary mapping from sympy symbols to pytensor symbols.
- f: