提交 3796417a authored 作者: abergeron's avatar abergeron 提交者: GitHub

Merge pull request #6084 from nouiz/tests

speed up tests, fix compiledir cache crash and old unpickling.
...@@ -447,6 +447,10 @@ def get_safe_part(key): ...@@ -447,6 +447,10 @@ def get_safe_part(key):
# Find the md5 hash part. # Find the md5 hash part.
c_link_key = key[1] c_link_key = key[1]
# In case in the future, we don't have an md5 part and we have
# such stuff in the cache. In that case, we can set None, and the
# rest of the cache mechanism will just skip that key.
md5 = None
for key_element in c_link_key[1:]: for key_element in c_link_key[1:]:
if (isinstance(key_element, string_types) and if (isinstance(key_element, string_types) and
key_element.startswith('md5:')): key_element.startswith('md5:')):
...@@ -743,7 +747,11 @@ class ModuleCache(object): ...@@ -743,7 +747,11 @@ class ModuleCache(object):
time_now = time.time() time_now = time.time()
# Go through directories in alphabetical order to ensure consistent # Go through directories in alphabetical order to ensure consistent
# behavior. # behavior.
try:
subdirs = sorted(os.listdir(self.dirname)) subdirs = sorted(os.listdir(self.dirname))
except OSError:
# This can happen if the dir don't exist.
subdirs = []
files, root = None, None # To make sure the "del" below works files, root = None, None # To make sure the "del" below works
for subdirs_elem in subdirs: for subdirs_elem in subdirs:
# Never clean/remove lock_dir # Never clean/remove lock_dir
......
...@@ -77,7 +77,7 @@ def cleanup(): ...@@ -77,7 +77,7 @@ def cleanup():
if len(keydata.keys) == 0: if len(keydata.keys) == 0:
shutil.rmtree(os.path.join(compiledir, directory)) shutil.rmtree(os.path.join(compiledir, directory))
except EOFError: except (EOFError, AttributeError):
_logger.error( _logger.error(
"Could not read key file '%s'. To complete " "Could not read key file '%s'. To complete "
"the clean-up, please remove manually " "the clean-up, please remove manually "
...@@ -159,6 +159,10 @@ def print_compiledir_content(): ...@@ -159,6 +159,10 @@ def print_compiledir_content():
nb_keys[len(keydata.keys)] += 1 nb_keys[len(keydata.keys)] += 1
except IOError: except IOError:
pass pass
except AttributeError:
_logger.error(
"Could not read key file '%s'.",
filename)
print_title("Theano cache: %s" % compiledir, overline='=', underline='=') print_title("Theano cache: %s" % compiledir, overline='=', underline='=')
print() print()
......
...@@ -803,7 +803,8 @@ if (py_%(name)s == NULL) { %(freefunc)s(%(name)s); } ...@@ -803,7 +803,8 @@ if (py_%(name)s == NULL) { %(freefunc)s(%(name)s); }
self.header_dirs = () self.header_dirs = ()
self.libraries = () self.libraries = ()
self.lib_dirs = () self.lib_dirs = ()
self.extra_support_code = "" if not hasattr(self, 'version'):
self.version = None
class CDataTypeConstant(graph.Constant): class CDataTypeConstant(graph.Constant):
......
...@@ -147,7 +147,7 @@ def test_batch_normalization_train(): ...@@ -147,7 +147,7 @@ def test_batch_normalization_train():
utt.seed_rng() utt.seed_rng()
for axes in ('per-activation', 'spatial', (1, 2, 3, 4)): for axes in ('per-activation', 'spatial', (1, 2, 3, 4)):
for vartype in (T.tensor5, T.tensor4, T.tensor3, T.matrix, T.vector): for vartype in (T.tensor5, T.tensor3, T.vector):
x, scale, bias, running_mean, running_var = (vartype(n) x, scale, bias, running_mean, running_var = (vartype(n)
for n in ('x', 'scale', 'bias', for n in ('x', 'scale', 'bias',
'running_mean', 'running_mean',
...@@ -338,7 +338,7 @@ def test_batch_normalization_train_broadcast(): ...@@ -338,7 +338,7 @@ def test_batch_normalization_train_broadcast():
def test_batch_normalization_test(): def test_batch_normalization_test():
for axes in ('per-activation', 'spatial', (1, 2, 3, 4)): for axes in ('per-activation', 'spatial', (1, 2, 3, 4)):
for vartype in (T.tensor5, T.tensor4, T.tensor3, T.matrix, T.vector): for vartype in (T.tensor5, T.tensor3, T.vector):
x, scale, bias, mean, var = (vartype(n) x, scale, bias, mean, var = (vartype(n)
for n in ('x', 'scale', 'bias', 'mean', 'var')) for n in ('x', 'scale', 'bias', 'mean', 'var'))
ndim = x.ndim ndim = x.ndim
......
...@@ -380,7 +380,7 @@ class TestRepeatOp(utt.InferShapeTester): ...@@ -380,7 +380,7 @@ class TestRepeatOp(utt.InferShapeTester):
self.numpy_unsupported_dtypes = ('uint32', 'int64', 'uint64') self.numpy_unsupported_dtypes = ('uint32', 'int64', 'uint64')
def test_repeatOp(self): def test_repeatOp(self):
for ndim in range(3): for ndim in [1, 3]:
x = T.TensorType(config.floatX, [False] * ndim)() x = T.TensorType(config.floatX, [False] * ndim)()
a = np.random.random((10, ) * ndim).astype(config.floatX) a = np.random.random((10, ) * ndim).astype(config.floatX)
...@@ -438,13 +438,13 @@ class TestRepeatOp(utt.InferShapeTester): ...@@ -438,13 +438,13 @@ class TestRepeatOp(utt.InferShapeTester):
@attr('slow') @attr('slow')
def test_infer_shape(self): def test_infer_shape(self):
for ndim in range(4): for ndim in [1, 3]:
x = T.TensorType(config.floatX, [False] * ndim)() x = T.TensorType(config.floatX, [False] * ndim)()
shp = (np.arange(ndim) + 1) * 5 shp = (np.arange(ndim) + 1) * 3
a = np.random.random(shp).astype(config.floatX) a = np.random.random(shp).astype(config.floatX)
for axis in self._possible_axis(ndim): for axis in self._possible_axis(ndim):
for dtype in tensor.integer_dtypes: for dtype in ["int8", "uint8", "uint64"]:
r_var = T.scalar(dtype=dtype) r_var = T.scalar(dtype=dtype)
r = np.asarray(3, dtype=dtype) r = np.asarray(3, dtype=dtype)
if dtype in self.numpy_unsupported_dtypes: if dtype in self.numpy_unsupported_dtypes:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论