File tree 2 files changed +13
-10
lines changed
2 files changed +13
-10
lines changed Original file line number Diff line number Diff line change @@ -940,37 +940,39 @@ def explicit_graph_inputs(
940
940
graph : Variable [Any , Any ] | Iterable [Variable [Any , Any ]],
941
941
) -> Generator [Variable , None , None ]:
942
942
"""
943
- Get the inputs into PyTensor variables
943
+ Get the root variables needed as inputs to a function that computes `graph`
944
944
945
945
Parameters
946
946
----------
947
- graph: TensorVariable
948
- Output `Variable` instances from which to search backward through
947
+ graph : TensorVariable
948
+ Output `Variable` instances for which to search backward through
949
949
owners.
950
950
951
951
Returns
952
952
-------
953
- Tensor variables that are input nodes with no owner, in the order
954
- found by a left-recursive depth-first search started at the nodes in `graphs`.
953
+ iterable
954
+ Generator of root Variables (without owner) needed to compile a function that evaluates `graphs`.
955
955
956
956
Examples
957
957
--------
958
958
959
959
.. code-block:: python
960
960
961
961
import pytensor
962
+ import numpy as np
962
963
import pytensor.tensor as pt
964
+ from pytensor.graph.basic import explicit_graph_inputs
963
965
964
966
x = pt.vector('x')
965
967
y = pt.constant(2)
966
968
z = pt.mul(x*y)
967
969
968
- pytensor.dprint(graph_inputs([z] ))
969
- # x [id A]
970
- # 2 [id B]
970
+ out = list(explicit_graph_inputs(z ))
971
+ f = pytensor.function([x], out)
972
+ eval = f(np.array([1, 2, 3]))
971
973
972
- pytensor.dprint(explicit_graph_inputs([z]) )
973
- # x [id A ]
974
+ print(eval )
975
+ # [array([1., 2., 3.]) ]
974
976
"""
975
977
from pytensor .compile .sharedvalue import SharedVariable
976
978
Original file line number Diff line number Diff line change @@ -532,6 +532,7 @@ def test_explicit_graph_inputs():
532
532
533
533
res = list (explicit_graph_inputs ([a ]))
534
534
res1 = list (explicit_graph_inputs (b ))
535
+
535
536
assert res , res1 == [x ]
536
537
537
538
You can’t perform that action at this time.
0 commit comments