Skip to content

Commit

Permalink
Avoid instroducing the cycle itself
Browse files Browse the repository at this point in the history
  • Loading branch information
lamblin committed Oct 3, 2013
1 parent 1897f31 commit 84ef2c9
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions theano/tensor/opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -908,11 +908,20 @@ def update_shape(self, r, other_r):
# For now, we consider 2 cases of uninformative other_shape[i]:
# - Shape_i(i)(other_r);
# - Shape_i(i)(r).
# Another case where we want to use r_shape[i] is when
# other_shape[i] actually depends on r_shape[i]. In that case,
# we do not want to substitute an expression with another that
# is strictly more complex. Such a substitution could also lead
# to cycles: if (in the future) r_shape[i] gets replaced by an
# expression of other_shape[i], other_shape[i] may end up
# depending on itself.
if (ps.owner
and isinstance(getattr(ps.owner, 'op', None), Shape_i)
and ps.owner.op.i == i
and ps.owner.inputs[0] in (r, other_r)):
merged_shape.append(r_shape[i])
elif r_shape[i] in theano.gof.graph.ancestors([other_shape[i]]):
merged_shape.append(r_shape[i])
else:
merged_shape.append(other_shape[i])
assert all([(not hasattr(r.type, "broadcastable") or
Expand Down

0 comments on commit 84ef2c9

Please sign in to comment.