提交 f08fe14e authored 作者: Ian Goodfellow's avatar Ian Goodfellow

gave connection_pattern a "node" argument to support ops with

variable #s of inputs
上级 71a8d3aa
...@@ -98,7 +98,7 @@ following methods: ...@@ -98,7 +98,7 @@ following methods:
lifetime of self. Op instances should be immutable in this lifetime of self. Op instances should be immutable in this
sense. sense.
.. function:: connection_pattern(): .. function:: connection_pattern( node ):
Optional method; sometimes needed for gradient.grad to Optional method; sometimes needed for gradient.grad to
work correctly. work correctly.
...@@ -109,6 +109,10 @@ following methods: ...@@ -109,6 +109,10 @@ following methods:
elements of inputs[input_idx] have an effect on the elements of elements of inputs[input_idx] have an effect on the elements of
outputs[output_idx]. outputs[output_idx].
The ``node'' parameter is needed to determine the number of
inputs. Some ops such as Subtensor take a variable number of
inputs.
If no connection_pattern is specified, gradient.grad will If no connection_pattern is specified, gradient.grad will
assume that all inputs have some elements connected to some assume that all inputs have some elements connected to some
elements of all outputs. elements of all outputs.
......
...@@ -526,7 +526,7 @@ def _populate_var_to_node_to_idx(outputs, wrt): ...@@ -526,7 +526,7 @@ def _populate_var_to_node_to_idx(outputs, wrt):
# that does type checking and supplies the default value # that does type checking and supplies the default value
# if the method is not implemented # if the method is not implemented
if hasattr(node.op,'connection_pattern'): if hasattr(node.op,'connection_pattern'):
connection_pattern = node.op.connection_pattern() connection_pattern = node.op.connection_pattern(node)
if not isinstance(connection_pattern, list): if not isinstance(connection_pattern, list):
raise TypeError("Op.connection_pattern should return " + \ raise TypeError("Op.connection_pattern should return " + \
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论