提交 20e5b721 authored 作者: Ricardo Vieira's avatar Ricardo Vieira 提交者: Ricardo Vieira

Short-circuit givens validation when it's empty

上级 2b2a7a54
...@@ -546,26 +546,27 @@ def construct_pfunc_ins_and_outs( ...@@ -546,26 +546,27 @@ def construct_pfunc_ins_and_outs(
"variables in the inputs list." "variables in the inputs list."
) )
# Check that we are not using `givens` to replace input variables, because if givens:
# this typically does nothing, contrary to what one may expect. # Check that we are not using `givens` to replace input variables, because
in_var_set = set(in_variables) # this typically does nothing, contrary to what one may expect.
try: in_var_set = set(in_variables)
givens_pairs = list(givens.items()) try:
except AttributeError: givens_pairs = list(givens.items())
givens_pairs = givens except AttributeError:
for x, y in givens_pairs: givens_pairs = givens
if x in in_var_set: for x, y in givens_pairs:
raise RuntimeError( if x in in_var_set:
f"You are trying to replace variable '{x}' through the " raise RuntimeError(
"`givens` parameter, but this variable is an input to your " f"You are trying to replace variable '{x}' through the "
"function. Replacing inputs is currently forbidden because it " "`givens` parameter, but this variable is an input to your "
"has no effect. One way to modify an input `x` to a function " "function. Replacing inputs is currently forbidden because it "
"evaluating f(x) is to define a new input `y` and use " "has no effect. One way to modify an input `x` to a function "
"`pytensor.function([y], f(x), givens={x: g(y)})`. Another " "evaluating f(x) is to define a new input `y` and use "
"solution consists in using `pytensor.clone_replace`, e.g. like this: " "`pytensor.function([y], f(x), givens={x: g(y)})`. Another "
"`pytensor.function([x], " "solution consists in using `pytensor.clone_replace`, e.g. like this: "
"pytensor.clone_replace(f(x), replace={x: g(x)}))`." "`pytensor.function([x], "
) "pytensor.clone_replace(f(x), replace={x: g(x)}))`."
)
if not fgraph: if not fgraph:
# Extend the outputs with the updates on input variables so they are # Extend the outputs with the updates on input variables so they are
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论