提交 788061af authored 作者: Frederic Bastien's avatar Frederic Bastien

Fix the refactoring to keep the difference between the data and the symbolic variable.

上级 0f374035
...@@ -23,14 +23,15 @@ except ImportError: ...@@ -23,14 +23,15 @@ except ImportError:
logger = logging.getLogger("theano.compile.nanguardmode") logger = logging.getLogger("theano.compile.nanguardmode")
def _non_numeric_value(var): def _non_numeric_value(arr, var):
""" """
Checks a variable against non-numeric types such as types, slices, Checks a variable against non-numeric types such as types, slices,
empty arrays, and None, that need not be checked for NaN and Inf values. empty arrays, and None, that need not be checked for NaN and Inf values.
Parameters Parameters
---------- ----------
var : output of any Theano op. arr : the data of that correspond to any Theano Variable
var : The corresponding Theano variable
Returns Returns
------- -------
...@@ -38,17 +39,17 @@ def _non_numeric_value(var): ...@@ -38,17 +39,17 @@ def _non_numeric_value(var):
`True` the value is non-numeric. `True` the value is non-numeric.
""" """
if isinstance(var, theano.gof.type.CDataType._cdata_type): if isinstance(arr, theano.gof.type._cdata_type):
return True return True
elif isinstance(var, np.random.mtrand.RandomState): elif isinstance(arr, np.random.mtrand.RandomState):
return True return True
elif var and getattr(var.tag, 'is_rng', False): elif var and getattr(var.tag, 'is_rng', False):
return False return False
elif isinstance(var, slice): elif isinstance(arr, slice):
return True return True
elif var is None: elif arr is None:
return True return True
elif var.size == 0: elif arr.size == 0:
return True return True
return False return False
...@@ -104,7 +105,7 @@ def contains_nan(arr, node=None, var=None): ...@@ -104,7 +105,7 @@ def contains_nan(arr, node=None, var=None):
construction of a boolean array with the same shape as the input array. construction of a boolean array with the same shape as the input array.
""" """
if _non_numeric_value(arr): if _non_numeric_value(arr, var):
return False return False
elif cuda.cuda_available and isinstance(arr, cuda.CudaNdarray): elif cuda.cuda_available and isinstance(arr, cuda.CudaNdarray):
if (node and hasattr(theano.sandbox, 'rng_mrg') and if (node and hasattr(theano.sandbox, 'rng_mrg') and
...@@ -147,7 +148,7 @@ def contains_inf(arr, node=None, var=None): ...@@ -147,7 +148,7 @@ def contains_inf(arr, node=None, var=None):
boolean array with the same shape as the input array. boolean array with the same shape as the input array.
""" """
if _non_numeric_value(arr): if _non_numeric_value(arr, var):
return False return False
elif cuda.cuda_available and isinstance(arr, cuda.CudaNdarray): elif cuda.cuda_available and isinstance(arr, cuda.CudaNdarray):
if (node and hasattr(theano.sandbox, 'rng_mrg') and if (node and hasattr(theano.sandbox, 'rng_mrg') and
...@@ -301,7 +302,7 @@ class NanGuardMode(Mode): ...@@ -301,7 +302,7 @@ class NanGuardMode(Mode):
error = True error = True
if big_is_error: if big_is_error:
err = False err = False
if _non_numeric_value(var): if _non_numeric_value(value, var):
err = False err = False
elif cuda.cuda_available and isinstance(value, cuda.CudaNdarray): elif cuda.cuda_available and isinstance(value, cuda.CudaNdarray):
compile_gpu_func(False, False, True) compile_gpu_func(False, False, True)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论