提交 bd5ee99c authored 作者: Frederic Bastien's avatar Frederic Bastien

Ignore more frequently the mrg rng state in the old back-end. fix gh-4823

上级 06b1fb7b
...@@ -41,7 +41,7 @@ def flatten(l): ...@@ -41,7 +41,7 @@ def flatten(l):
return rval return rval
def contains_nan(arr, node=None): def contains_nan(arr, node=None, var=None):
""" """
Test whether a numpy.ndarray contains any `np.nan` values. Test whether a numpy.ndarray contains any `np.nan` values.
...@@ -50,6 +50,7 @@ def contains_nan(arr, node=None): ...@@ -50,6 +50,7 @@ def contains_nan(arr, node=None):
arr : np.ndarray or output of any Theano op arr : np.ndarray or output of any Theano op
node : None or an Apply instance. node : None or an Apply instance.
If arr is the output of a Theano op, the node associated to it. If arr is the output of a Theano op, the node associated to it.
var : The Theano symbolic variable.
Returns Returns
------- -------
...@@ -68,6 +69,8 @@ def contains_nan(arr, node=None): ...@@ -68,6 +69,8 @@ def contains_nan(arr, node=None):
return False return False
elif isinstance(arr, np.random.mtrand.RandomState): elif isinstance(arr, np.random.mtrand.RandomState):
return False return False
elif var and getattr(var.tag, 'is_rng', False):
return False
elif isinstance(arr, slice): elif isinstance(arr, slice):
return False return False
elif arr.size == 0: elif arr.size == 0:
...@@ -86,7 +89,7 @@ def contains_nan(arr, node=None): ...@@ -86,7 +89,7 @@ def contains_nan(arr, node=None):
return np.isnan(np.min(arr)) return np.isnan(np.min(arr))
def contains_inf(arr, node=None): def contains_inf(arr, node=None, var=None):
""" """
Test whether a numpy.ndarray contains any `np.inf` values. Test whether a numpy.ndarray contains any `np.inf` values.
...@@ -95,6 +98,7 @@ def contains_inf(arr, node=None): ...@@ -95,6 +98,7 @@ def contains_inf(arr, node=None):
arr : np.ndarray or output of any Theano op arr : np.ndarray or output of any Theano op
node : None or an Apply instance. node : None or an Apply instance.
If the output of a Theano op, the node associated to it. If the output of a Theano op, the node associated to it.
var : The Theano symbolic variable.
Returns Returns
------- -------
...@@ -114,6 +118,8 @@ def contains_inf(arr, node=None): ...@@ -114,6 +118,8 @@ def contains_inf(arr, node=None):
return False return False
elif isinstance(arr, np.random.mtrand.RandomState): elif isinstance(arr, np.random.mtrand.RandomState):
return False return False
elif var and getattr(var.tag, 'is_rng', False):
return False
elif isinstance(arr, slice): elif isinstance(arr, slice):
return False return False
elif arr.size == 0: elif arr.size == 0:
...@@ -235,11 +241,11 @@ class NanGuardMode(Mode): ...@@ -235,11 +241,11 @@ class NanGuardMode(Mode):
error = False error = False
sio = StringIO() sio = StringIO()
if nan_is_error: if nan_is_error:
if contains_nan(value, nd): if contains_nan(value, nd, var):
print('NaN detected', file=sio) print('NaN detected', file=sio)
error = True error = True
if inf_is_error: if inf_is_error:
if contains_inf(value, nd): if contains_inf(value, nd, var):
print('Inf detected', file=sio) print('Inf detected', file=sio)
error = True error = True
if big_is_error: if big_is_error:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论