提交 33530514 authored 作者: Olivier Delalleau's avatar Olivier Delalleau

Fixed some test names so that names reported by nosetests can be used to re-run tests.

This is needed e.g. for the --with-id option of nosetests to work properly.
上级 4b570d40
...@@ -920,7 +920,8 @@ test_shared_options = theano.tensor.tests.test_sharedvar.makeSharedTester( ...@@ -920,7 +920,8 @@ test_shared_options = theano.tensor.tests.test_sharedvar.makeSharedTester(
theano_fct_ = theano.tensor.exp, theano_fct_ = theano.tensor.exp,
ref_fct_ = numpy.exp, ref_fct_ = numpy.exp,
cast_value_ = cuda.as_cuda_array, cast_value_ = cuda.as_cuda_array,
op_by_matrix_ = True) op_by_matrix_ = True,
name='test_shared_options')
#This test the case when the shared constructor view an ndarray as input #This test the case when the shared constructor view an ndarray as input
test_shared_options2 = theano.tensor.tests.test_sharedvar.makeSharedTester( test_shared_options2 = theano.tensor.tests.test_sharedvar.makeSharedTester(
...@@ -937,7 +938,8 @@ test_shared_options2 = theano.tensor.tests.test_sharedvar.makeSharedTester( ...@@ -937,7 +938,8 @@ test_shared_options2 = theano.tensor.tests.test_sharedvar.makeSharedTester(
theano_fct_ = theano.tensor.exp, theano_fct_ = theano.tensor.exp,
ref_fct_ = numpy.exp, ref_fct_ = numpy.exp,
cast_value_ = numpy.asarray, cast_value_ = numpy.asarray,
op_by_matrix_ = True) op_by_matrix_ = True,
name='test_shared_options')
if __name__ == '__main__': if __name__ == '__main__':
test_many_arg_elemwise() test_many_arg_elemwise()
......
...@@ -584,7 +584,9 @@ test_shared_options=theano.tensor.tests.test_sharedvar.makeSharedTester( ...@@ -584,7 +584,9 @@ test_shared_options=theano.tensor.tests.test_sharedvar.makeSharedTester(
test_internal_type_ = scipy.sparse.issparse, test_internal_type_ = scipy.sparse.issparse,
theano_fct_ = lambda a: dense_from_sparse(a*2.), theano_fct_ = lambda a: dense_from_sparse(a*2.),
ref_fct_ = lambda a: numpy.asarray((a*2).todense()), ref_fct_ = lambda a: numpy.asarray((a*2).todense()),
cast_value_ = scipy.sparse.csr_matrix) cast_value_ = scipy.sparse.csr_matrix,
name='test_shared_options',
)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -304,8 +304,23 @@ def rand_of_dtype(shape, dtype): ...@@ -304,8 +304,23 @@ def rand_of_dtype(shape, dtype):
else: else:
raise TypeError() raise TypeError()
def makeBroadcastTester(op, expected, checks = {}, **kwargs): def makeBroadcastTester(op, expected, checks = {}, name=None, **kwargs):
name = str(op) + "Tester" name = str(op)
# Here we ensure the test name matches the name of the variable defined in
# this script. This is needed to properly identify the test e.g. with the
# --with-id option of nosetests, or simply to rerun a specific test that
# failed.
capitalize = False
if name.startswith('Elemwise{') and name.endswith(',no_inplace}'):
# For instance: Elemwise{add,no_inplace} -> Add
name = name[9:-12]
capitalize = True
elif name.endswith('_inplace'):
# For instance: sub_inplace -> SubInplace
capitalize = True
if capitalize:
name = ''.join([x.capitalize() for x in name.split('_')])
name += "Tester"
if kwargs.has_key('inplace'): if kwargs.has_key('inplace'):
if kwargs['inplace']: if kwargs['inplace']:
_expected = expected _expected = expected
...@@ -504,7 +519,7 @@ if config.floatX=='float32': ...@@ -504,7 +519,7 @@ if config.floatX=='float32':
# float32. # float32.
# This is probably caused by our way of computing the gradient error. # This is probably caused by our way of computing the gradient error.
div_grad_rtol=0.025 div_grad_rtol=0.025
DivTester = makeBroadcastTester(op = true_div, TrueDivTester = makeBroadcastTester(op = true_div,
expected = lambda x, y: check_floatX((x, y), x / y), expected = lambda x, y: check_floatX((x, y), x / y),
good = _good_broadcast_div_mod_normal_float, good = _good_broadcast_div_mod_normal_float,
# integers = (randint(2, 3), randint_nonzero(2, 3)), # integers = (randint(2, 3), randint_nonzero(2, 3)),
...@@ -513,7 +528,7 @@ DivTester = makeBroadcastTester(op = true_div, ...@@ -513,7 +528,7 @@ DivTester = makeBroadcastTester(op = true_div,
grad = _grad_broadcast_div_mod_normal, grad = _grad_broadcast_div_mod_normal,
grad_rtol=div_grad_rtol, grad_rtol=div_grad_rtol,
) )
DivInplaceTester = makeBroadcastTester(op = inplace.true_div_inplace, TrueDivInplaceTester = makeBroadcastTester(op = inplace.true_div_inplace,
expected = lambda x, y: x / y, expected = lambda x, y: x / y,
good = _good_broadcast_div_mod_normal_float_inplace, good = _good_broadcast_div_mod_normal_float_inplace,
grad = _grad_broadcast_div_mod_normal, grad = _grad_broadcast_div_mod_normal,
......
...@@ -23,7 +23,9 @@ def makeSharedTester(shared_constructor_, ...@@ -23,7 +23,9 @@ def makeSharedTester(shared_constructor_,
theano_fct_, theano_fct_,
ref_fct_, ref_fct_,
cast_value_ = numpy.asarray, cast_value_ = numpy.asarray,
op_by_matrix_ = False): op_by_matrix_=False,
name=None,
):
""" """
This is a generic fct to allow reusing the same test function This is a generic fct to allow reusing the same test function
for many shared variable of many types. for many shared variable of many types.
...@@ -46,7 +48,12 @@ def makeSharedTester(shared_constructor_, ...@@ -46,7 +48,12 @@ def makeSharedTester(shared_constructor_,
:param ref_fct_: A reference function that should return the same value as the theano_fct_ :param ref_fct_: A reference function that should return the same value as the theano_fct_
:param cast_value_: A callable that cast an ndarray into the internal shared variable representation :param cast_value_: A callable that cast an ndarray into the internal shared variable representation
:param op_by_matrix_: When we do inplace operation on the an internal type object, should we do it with a scalar or a matrix of the same value. :param op_by_matrix_: When we do inplace operation on the an internal type object, should we do it with a scalar or a matrix of the same value.
:param name: This string is used to set the returned class' __name__
attribute. This is needed for nosetests to properly tag the
test with its correct name, rather than use the generic
SharedTester name. This parameter is mandatory (keeping the
default None value will raise an error), and must be set to
the name of the variable that will hold the returned class.
:note: :note:
We must use /= as sparse type don't support other inplace operation. We must use /= as sparse type don't support other inplace operation.
...@@ -607,7 +614,8 @@ def makeSharedTester(shared_constructor_, ...@@ -607,7 +614,8 @@ def makeSharedTester(shared_constructor_,
assert not x_shared.type.values_eq(x, y) assert not x_shared.type.values_eq(x, y)
assert not x_shared.type.values_eq_approx(x, y) assert not x_shared.type.values_eq_approx(x, y)
assert name is not None
SharedTester.__name__ = name
return SharedTester return SharedTester
...@@ -625,4 +633,5 @@ test_shared_options=makeSharedTester( ...@@ -625,4 +633,5 @@ test_shared_options=makeSharedTester(
theano_fct_ = lambda a: a*2, theano_fct_ = lambda a: a*2,
ref_fct_ = lambda a: numpy.asarray((a*2)), ref_fct_ = lambda a: numpy.asarray((a*2)),
cast_value_ = numpy.asarray, cast_value_ = numpy.asarray,
op_by_matrix_ = False) op_by_matrix_ = False,
name='test_shared_options')
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论