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