提交 6d953fa1 authored 作者: Olivier Delalleau's avatar Olivier Delalleau

Added an option to setsubtensor to be able to suppress the deprecation warning during tests

上级 07198d23
...@@ -3040,10 +3040,19 @@ class SubtensorPrinter: ...@@ -3040,10 +3040,19 @@ class SubtensorPrinter:
pprint.assign(lambda pstate, r: r.owner and isinstance(r.owner.op, Subtensor), SubtensorPrinter()) pprint.assign(lambda pstate, r: r.owner and isinstance(r.owner.op, Subtensor), SubtensorPrinter())
def setsubtensor(x, y, idx_list, inplace=False):
print >> sys.stderr, "tensor.setsubtensor is deprecated - please use set_subtensor" def setsubtensor(x, y, idx_list, inplace=False, show_warning=True):
# Note that `show_warning` should only be set to False by tests, in order
# to make sure this old code is still working.
if show_warning:
print >> sys.stderr, (
"tensor.setsubtensor is deprecated - please use set_subtensor")
the_op = IncSubtensor(idx_list, inplace, set_instead_of_inc=True) the_op = IncSubtensor(idx_list, inplace, set_instead_of_inc=True)
return the_op(x, y, *Subtensor.collapse(idx_list, lambda entry: isinstance(entry, Variable))) return the_op(x, y, *Subtensor.collapse(
idx_list,
lambda entry: isinstance(entry, Variable)))
def incsubtensor(x, y, idx_list, inplace=False, show_warning=True): def incsubtensor(x, y, idx_list, inplace=False, show_warning=True):
# Note that `show_warning` should only be set to False by tests, in order # Note that `show_warning` should only be set to False by tests, in order
# to make sure this old code is still working. # to make sure this old code is still working.
...@@ -3052,6 +3061,7 @@ def incsubtensor(x, y, idx_list, inplace=False, show_warning=True): ...@@ -3052,6 +3061,7 @@ def incsubtensor(x, y, idx_list, inplace=False, show_warning=True):
the_op = IncSubtensor(idx_list, inplace, set_instead_of_inc=False) the_op = IncSubtensor(idx_list, inplace, set_instead_of_inc=False)
return the_op(x, y, *Subtensor.collapse(idx_list, lambda entry: isinstance(entry, Variable))) return the_op(x, y, *Subtensor.collapse(idx_list, lambda entry: isinstance(entry, Variable)))
def set_subtensor(x, y, inplace=False): def set_subtensor(x, y, inplace=False):
"""Return x with the given subtensor overwritten by y. """Return x with the given subtensor overwritten by y.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论