@@ -1151,53 +1151,6 @@ def clone_get_equiv(
11511151 return memo
11521152
11531153
1154- def clone_replace (
1155- output : Collection [Variable ],
1156- replace : Optional [
1157- Union [Iterable [Tuple [Variable , Variable ]], Dict [Variable , Variable ]]
1158- ] = None ,
1159- ** rebuild_kwds ,
1160- ) -> List [Variable ]:
1161- """Clone a graph and replace subgraphs within it.
1162-
1163- It returns a copy of the initial subgraph with the corresponding
1164- substitutions.
1165-
1166- Parameters
1167- ----------
1168- output
1169- PyTensor expression that represents the computational graph.
1170- replace
1171- Dictionary describing which subgraphs should be replaced by what.
1172- rebuild_kwds
1173- Keywords to `rebuild_collect_shared`.
1174-
1175- """
1176- from pytensor .compile .function .pfunc import rebuild_collect_shared
1177-
1178- items : Union [List [Tuple [Variable , Variable ]], Tuple [Tuple [Variable , Variable ], ...]]
1179- if isinstance (replace , dict ):
1180- items = list (replace .items ())
1181- elif isinstance (replace , (list , tuple )):
1182- items = replace
1183- elif replace is None :
1184- items = []
1185- else :
1186- raise ValueError (
1187- "replace is neither a dictionary, list, "
1188- f"tuple or None ! The value provided is { replace } ,"
1189- f"of type { type (replace )} "
1190- )
1191- tmp_replace = [(x , x .type ()) for x , y in items ]
1192- new_replace = [(x , y ) for ((_ , x ), (_ , y )) in zip (tmp_replace , items )]
1193- _ , _outs , _ = rebuild_collect_shared (output , [], tmp_replace , [], ** rebuild_kwds )
1194-
1195- # TODO Explain why we call it twice ?!
1196- _ , outs , _ = rebuild_collect_shared (_outs , [], new_replace , [], ** rebuild_kwds )
1197-
1198- return cast (List [Variable ], outs )
1199-
1200-
12011154def general_toposort (
12021155 outputs : Iterable [T ],
12031156 deps : Callable [[T ], Union [OrderedSet , List [T ]]],
0 commit comments