@@ -938,58 +938,50 @@ def graph_inputs(
938
938
939
939
def required_graph_inputs (
940
940
graph : Variable [Any , Any ] | Iterable [Variable [Any , Any ]],
941
- ) -> list [Variable [ Any , Any ] ]:
941
+ ) -> Generator [Variable , None , None ]:
942
942
"""
943
943
Get the inputs into PyTensor variables
944
944
945
945
Parameters
946
946
----------
947
- graph: PyTensor `Variable` instances
947
+ graph: PyTensor `Variable` instances
948
948
Output `Variable` instances from which to search backward through
949
949
owners.
950
950
951
951
Returns
952
952
-------
953
- List of tensor variables that are input nodes with no owner, in the order
953
+ Tensor variables that are input nodes with no owner, in the order
954
954
found by a left-recursive depth-first search started at the nodes in `graphs`.
955
955
956
956
Examples
957
957
--------
958
- >>> import pytensor as pt
959
- >>> x=pt.vector('x')
960
- >>> y=pt.constant('y')
961
- >>> z = pt.mul(x*y)
962
- >>> required_graph_inputs([a])
963
- [[[ 0 1 2 3]
964
- [ 4 5 6 7]
965
- [ 8 9 10 11]]
966
-
967
- [[12 13 14 15]
968
- [16 17 18 19]
969
- [20 21 22 23]]]
970
-
971
-
972
- >>> pt.matrix_transpose(x).eval()
973
- [[[ 0 4 8]
974
- [ 1 5 9]
975
- [ 2 6 10]
976
- [ 3 7 11]]
977
-
978
- [[12 16 20]
979
- [13 17 21]
980
- [14 18 22]
981
- [15 19 23]]]
958
+
959
+ .. code-block:: python
960
+
961
+ import pytensor
962
+ import pytensor.tensor as pt
963
+
964
+ x = pt.vector('x')
965
+ y = pt.constant(2)
966
+ z = pt.mul(x*y)
967
+
968
+ pytensor.dprint(graph_inputs([z]))
969
+ # x [id A]
970
+ # 2 [id B]
971
+
972
+ pytensor.dprint(required_graph_inputs([z]))
973
+ # x [id A]
982
974
"""
983
975
from pytensor .compile .sharedvalue import SharedVariable
984
976
985
977
if isinstance (graph , Variable ):
986
978
graph = [graph ]
987
979
988
- return [
980
+ return (
989
981
v
990
982
for v in graph_inputs (graph )
991
983
if isinstance (v , Variable ) and not isinstance (v , Constant | SharedVariable )
992
- ]
984
+ )
993
985
994
986
995
987
def vars_between (
0 commit comments