提交 0fea0093 authored 作者: Arnaud Bergeron's avatar Arnaud Bergeron

Get rid of ghetto 2.4 code.

上级 9a8eda51
...@@ -5751,40 +5751,24 @@ def _test_autocast_custom(): ...@@ -5751,40 +5751,24 @@ def _test_autocast_custom():
orig_autocast = autocast_float.dtypes orig_autocast = autocast_float.dtypes
# Test that autocast_float_as sets the autocast dtype correctly # Test that autocast_float_as sets the autocast dtype correctly
try: # ghetto 2.4 version of with with autocast_float_as('float32'):
ac = autocast_float_as('float32')
ac.__enter__()
assert autocast_float.dtypes == ('float32',) assert autocast_float.dtypes == ('float32',)
finally:
ac.__exit__()
assert autocast_float.dtypes == orig_autocast assert autocast_float.dtypes == orig_autocast
try: # ghetto 2.4 version of with
ac = autocast_float_as('float64') with autocast_float_as('float64'):
ac.__enter__()
assert autocast_float.dtypes == ('float64',) assert autocast_float.dtypes == ('float64',)
finally:
ac.__exit__()
assert autocast_float.dtypes == orig_autocast assert autocast_float.dtypes == orig_autocast
# Test that we can set it back to something, and nest it # Test that we can set it back to something, and nest it
try: # ghetto 2.4 version of with with autocast_float_as('float32'):
ac = autocast_float_as('float32')
ac.__enter__()
assert autocast_float.dtypes == ('float32',) assert autocast_float.dtypes == ('float32',)
try: # ghetto 2.4 version of with with autocast_float_as('float64'):
ac2 = autocast_float_as('float64')
ac2.__enter__()
assert autocast_float.dtypes == ('float64',) assert autocast_float.dtypes == ('float64',)
finally:
ac2.__exit__()
assert autocast_float.dtypes == ('float32',) assert autocast_float.dtypes == ('float32',)
finally:
ac.__exit__()
assert autocast_float.dtypes == orig_autocast assert autocast_float.dtypes == orig_autocast
# Test that the autocasting dtype is used correctly in expression-building # Test that the autocasting dtype is used correctly in expression-building
try: # ghetto 2.4 version of with with autocast_float_as('float32'):
ac = autocast_float_as('float32')
ac.__enter__()
assert (dvector() + 1.1).dtype == 'float64' assert (dvector() + 1.1).dtype == 'float64'
assert (fvector() + 1.1).dtype == 'float32' assert (fvector() + 1.1).dtype == 'float32'
assert (fvector() + theano._asarray(1.1, dtype='float64')).dtype == \ assert (fvector() + theano._asarray(1.1, dtype='float64')).dtype == \
...@@ -5794,13 +5778,9 @@ def _test_autocast_custom(): ...@@ -5794,13 +5778,9 @@ def _test_autocast_custom():
assert (dvector() + 1).dtype == 'float64' assert (dvector() + 1).dtype == 'float64'
assert (fvector() + 1).dtype == 'float32' assert (fvector() + 1).dtype == 'float32'
finally:
ac.__exit__()
# Test that the autocasting dtype is used correctly in expression-building # Test that the autocasting dtype is used correctly in expression-building
try: # ghetto 2.4 version of with with autocast_float_as('float64'):
ac = autocast_float_as('float64')
ac.__enter__()
assert (dvector() + 1.1).dtype == 'float64' assert (dvector() + 1.1).dtype == 'float64'
assert (fvector() + 1.1).dtype == 'float64' assert (fvector() + 1.1).dtype == 'float64'
assert (fvector() + 1.0).dtype == 'float64' assert (fvector() + 1.0).dtype == 'float64'
...@@ -5811,13 +5791,9 @@ def _test_autocast_custom(): ...@@ -5811,13 +5791,9 @@ def _test_autocast_custom():
assert (dvector() + 1).dtype == 'float64' assert (dvector() + 1).dtype == 'float64'
assert (fvector() + 1).dtype == 'float32' assert (fvector() + 1).dtype == 'float32'
finally:
ac.__exit__()
# Test that the autocasting dtype is used correctly in expression-building # Test that the autocasting dtype is used correctly in expression-building
try: # ghetto 2.4 version of with with autocast_float_as('float32', 'float64'):
ac = autocast_float_as('float32', 'float64')
ac.__enter__()
assert (dvector() + 1.1).dtype == 'float64' assert (dvector() + 1.1).dtype == 'float64'
assert (fvector() + 1.1).dtype == theano.config.floatX assert (fvector() + 1.1).dtype == theano.config.floatX
assert (fvector() + 1.0).dtype == 'float32' assert (fvector() + 1.0).dtype == 'float32'
...@@ -5834,14 +5810,8 @@ def _test_autocast_custom(): ...@@ -5834,14 +5810,8 @@ def _test_autocast_custom():
assert (ivector() + numpy.int8(1)).dtype == 'int32' assert (ivector() + numpy.int8(1)).dtype == 'int32'
assert (wvector() + numpy.int8(1)).dtype == 'int16' assert (wvector() + numpy.int8(1)).dtype == 'int16'
assert (bvector() + numpy.int8(1)).dtype == 'int8' assert (bvector() + numpy.int8(1)).dtype == 'int8'
try: # ghetto 2.4 version of with with autocast_float_as('float64'):
ac2 = autocast_float_as('float64')
ac2.__enter__()
assert (fvector() + 1.0).dtype == 'float64' assert (fvector() + 1.0).dtype == 'float64'
finally:
ac2.__exit__()
finally:
ac.__exit__()
def _test_autocast_numpy(): def _test_autocast_numpy():
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论