提交 b97a7b0e authored 作者: jotterbach's avatar jotterbach

changing `assert` to `AssertionError`

This `assert` statement does not provide any error message making debugging this case hard. Moreover, `assert` is eliminated when using optimized python code (https://docs.python.org/2.7/reference/simple_stmts.html#the-assert-statement), introducing a potential bug into the system. Explicitly checking and raising an AssertionError will prevent this from happening.
上级 ad4e2a09
...@@ -431,7 +431,8 @@ def grad(cost, wrt, consider_constant=None, ...@@ -431,7 +431,8 @@ def grad(cost, wrt, consider_constant=None,
from theano import tensor from theano import tensor
if cost is None: if cost is None:
assert known_grads is not None if known_grads is None:
raise AssertionError("cost and known_grads can't both be None.")
if cost is not None and isinstance(cost.type, NullType): if cost is not None and isinstance(cost.type, NullType):
raise ValueError("Can't differentiate a NaN cost." raise ValueError("Can't differentiate a NaN cost."
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论