提交 2c6139c6 authored 作者: Frederic Bastien's avatar Frederic Bastien

fix autocast to tensor for numpy.float32 and numpy.float64.

上级 d8389753
......@@ -165,8 +165,17 @@ class NumpyAutocaster(object):
self.dtypes = tuple(dtypes)
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')
dtype = None
if isinstance(x, numpy.float64) and 'float64' in self.dtypes:
dtype = 'float64'
elif isinstance(x, numpy.float32) and 'float32' in self.dtypes:
dtype = 'float32'
elif isinstance(x, float) and config.floatX in self.dtypes and config.floatX == 'float32':
dtype = config.floatX
if dtype:
return theano._asarray(x, dtype=dtype)
for dtype in self.dtypes:
x_ = theano._asarray(x, dtype=dtype)
if numpy.all(x == x_):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论