提交 9d5e1145 authored 作者: James Bergstra's avatar James Bergstra

Added THEANO_CMP_SLOPPY environment variable.

上级 f43f33af
...@@ -4,6 +4,7 @@ __docformat__ = "restructuredtext en" ...@@ -4,6 +4,7 @@ __docformat__ = "restructuredtext en"
import __builtin__ import __builtin__
import sys # for sys.maxint import sys # for sys.maxint
import os # for getenv THEANO_CMP_SLOPPY
import traceback #for overriding Op.__call__ import traceback #for overriding Op.__call__
if sys.version_info >= (2,5): if sys.version_info >= (2,5):
import functools import functools
...@@ -199,20 +200,33 @@ def _wrap_tensor_into_member(x): ...@@ -199,20 +200,33 @@ def _wrap_tensor_into_member(x):
return compile.module.Member(constant(x)) return compile.module.Member(constant(x))
compile.module.register_wrapper(_obj_is_wrappable_as_tensor, _wrap_tensor_into_member) compile.module.register_wrapper(_obj_is_wrappable_as_tensor, _wrap_tensor_into_member)
#If you change those value in test don't forget to put them back when the test end. if int(os.getenv('THEANO_CMP_SLOPPY', 0)):
#Don't forget the case when the test fail. # This environment variable is a quick-and-dirty way to get low-precision comparisons.
float_atol = 1e-5 # For a more precise setting of these tolerances set them explicitly in your user code by
float_rtol = 1e-3 # Sensible?? # assigning, for example, "theano.tensor.basic.float32_atol = ..."
float32_atol = 1e-4
float32_rtol = 1e-3
float64_rtol = 1e-4
float64_atol = 1e-3
else:
#If you change those value in test don't forget to put them back when the test end.
#Don't forget the case when the test fail.
float32_atol = 1e-5
float32_rtol = 1e-3
# defaults in numpy.allclose
float64_rtol = 1.0000000000000001e-05
float64_atol = 1e-8
def _allclose(a, b): def _allclose(a, b):
narrow = 'float32', 'complex64' narrow = 'float32', 'complex64'
if (str(a.dtype) in narrow) or (str(b.dtype) in narrow): if (str(a.dtype) in narrow) or (str(b.dtype) in narrow):
atol = float_atol atol = float32_atol
rtol = float_rtol rtol = float32_rtol
return numpy.allclose(a,b, atol=atol, rtol=rtol)
else: else:
# keep defaults of in numpy.allclose atol = float64_atol
return numpy.allclose(a,b) rtol = float64_rtol
return numpy.allclose(a,b, atol=atol, rtol=rtol)
class TensorType(Type): class TensorType(Type):
"""Symbolic `Type` representing a numpy.ndarray value.""" """Symbolic `Type` representing a numpy.ndarray value."""
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论