提交 9a354a4b authored 作者: Frederic Bastien's avatar Frederic Bastien

make the autocast work correctly when we change floatX during the execution

上级 5b971be5
...@@ -3,10 +3,6 @@ __docformat__ = "restructuredtext en" ...@@ -3,10 +3,6 @@ __docformat__ = "restructuredtext en"
from basic import * from basic import *
if config.floatX == 'float32':
# change the default casting behaviour for python floats to always cast to float32
autocast_float.dtypes = ('float32',)
import opt import opt
import blas import blas
import xlogx import xlogx
......
...@@ -164,6 +164,9 @@ class NumpyAutocaster(object): ...@@ -164,6 +164,9 @@ class NumpyAutocaster(object):
def __init__(self, dtypes): def __init__(self, dtypes):
self.dtypes = tuple(dtypes) self.dtypes = tuple(dtypes)
def __call__(self, x): def __call__(self, x):
# change the default casting behaviour for python floats to always cast to float32
if config.floatX == 'float32' and config.floatX in self.dtypes:
return theano._asarray(x, dtype='float32')
for dtype in self.dtypes: for dtype in self.dtypes:
x_ = theano._asarray(x, dtype=dtype) x_ = theano._asarray(x, dtype=dtype)
if numpy.all(x == x_): if numpy.all(x == x_):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论