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

better error message (and partial code clarification)

上级 eab4cada
......@@ -600,11 +600,27 @@ def get_scalar_constant_value(v):
# This is needed when we take the grad as the Shape op
# are not already changed into MakeVector
if (v.owner.inputs[0].owner and
isinstance(v.owner.inputs[0].owner.op,
owner = v.owner
leftmost_parent = owner.inputs[0]
if (leftmost_parent.owner and
isinstance(leftmost_parent.owner.op,
theano.tensor.Shape)):
if v.owner.inputs[0].owner.inputs[0].type.broadcastable[
v.owner.op.idx_list[0]]:
owner = v.owner
op = owner.op
idx_list = op.idx_list
idx = idx_list[0]
grandparent = leftmost_parent.owner.inputs[0]
gp_broadcastable = grandparent.type.broadcastable
ndim = grandparent.type.ndim
assert ndim == len(gp_broadcastable)
if not (idx < len(gp_broadcastable)):
raise ValueError("You are taking x.shape[i] on some tensor x, "
"but x.ndim is %d and i is %d, so this is deterministically "
"an index error." % (ndim, idx))
if gp_broadcastable[idx]:
return numpy.asarray(1)
raise NotScalarConstantError(v)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论