Looks correct. You can set a flag self._func.trust_input=True
after you first define _func
. That will skip checking the type of the inputs which can cause quise some overhead when calling the function.
If you are interested we could add this as a utility directly in PyTensor (our current backend/fork of Aesara).
We would probably tweak it slightly in that case. Usually we use FunctionGraph
to represent inner graphs and only compile as a function later on. There is an example of a new Loop Op that we are building you can have a look at: Implement new Loop and Scan operators by ricardoV94 ¡ Pull Request #191 ¡ pymc-devs/pytensor ¡ GitHub (specifically look at pytensor/loop/op.py::Loop)