def make_node(self, condition, *monitored_vars):
# Ensure that condition is a theano tensor
if not isinstance(condition, theano.Variable):
condition = theano.tensor.as_tensor_variable(condition)
# Validate that the condition is a scalar (else it is not obvious how
# is should be evaluated)
assert (condition.ndim == 0)
# Because the user might be tempted to instantiate PdbBreakpoint only
# once and apply it many times on different number of inputs, we must
# create a new instance of the op here, define the instance attributes
# (view_map and var_types) in that instance and then apply it on the
# inputs.
new_op = PdbBreakpoint(name=self.name)
new_op.view_map = {}
new_op.inp_types = []
for i in range(len(monitored_vars)):
# Every output i is a view of the input i+1 because of the input
# condition.
new_op.view_map[i] = [i + 1]
new_op.inp_types.append(monitored_vars[i].type)
# Build the Apply node
inputs = [condition] + list(monitored_vars)
outputs = [inp.type() for inp in monitored_vars]
return Apply(op=new_op, inputs=inputs, outputs=outputs)
评论列表
文章目录