提交 1661f0bc authored 作者: Arnaud Bergeron's avatar Arnaud Bergeron

Switch subtensor check to bool and fix some things in tensor.

上级 27654022
...@@ -302,7 +302,7 @@ class NumpyAutocaster(object): ...@@ -302,7 +302,7 @@ class NumpyAutocaster(object):
# returns either an exact x_==x, or the last cast x_ # returns either an exact x_==x, or the last cast x_
return x_ return x_
autocast_int = NumpyAutocaster(('int16', 'int32', 'int64')) autocast_int = NumpyAutocaster(('int8', 'int16', 'int32', 'int64'))
autocast_float = NumpyAutocaster(('float16', 'float32', 'float64')) autocast_float = NumpyAutocaster(('float16', 'float32', 'float64'))
...@@ -379,16 +379,10 @@ def constant_or_value(x, rtype, name=None, ndim=None, dtype=None): ...@@ -379,16 +379,10 @@ def constant_or_value(x, rtype, name=None, ndim=None, dtype=None):
x_ = autocast_float(x) x_ = autocast_float(x)
elif isinstance(x, numpy.ndarray): elif isinstance(x, numpy.ndarray):
x_ = x x_ = x
# Currently we do not have a bool dtype in Theano.
# So we upcast it to uint8 to avoid breaking our interface for
# constant.
if x.dtype == 'bool':
x_ = numpy.asarray(x_, dtype='uint8')
else: else:
# Here x is probably a list or a tuple. If it contains a long, # Here x is probably a list or a tuple. If it contains a
# we will behave like the current NumPy version: 1.7 and below, # long, we will behave like the current NumPy version: it
# it will only work if the long fits in int64. For NumPy 1.7.1+, # will work if the long fits in int64 or uint64.
# it will work if the long fits in int64 or uint64.
x_ = numpy.asarray(x) x_ = numpy.asarray(x)
assert type(x_) in [numpy.ndarray, numpy.memmap] assert type(x_) in [numpy.ndarray, numpy.memmap]
...@@ -520,11 +514,6 @@ def _allclose(a, b, rtol=None, atol=None): ...@@ -520,11 +514,6 @@ def _allclose(a, b, rtol=None, atol=None):
if atol is not None: if atol is not None:
atol_ = atol atol_ = atol
# Work around bug in Numpy, see
# http://projects.scipy.org/numpy/ticket/1684
if str(b.dtype) in int_dtypes and (numpy.absolute(b) < 0).any():
b = theano._asarray(b, dtype='float64')
return numpy.allclose(a, b, atol=atol_, rtol=rtol_) return numpy.allclose(a, b, atol=atol_, rtol=rtol_)
......
...@@ -341,15 +341,9 @@ class TensorType(Type): ...@@ -341,15 +341,9 @@ class TensorType(Type):
return False return False
if a.dtype != b.dtype: if a.dtype != b.dtype:
return False return False
if 'int' in str(a.dtype): if 'float' not in str(a.dtype):
return numpy.all(a == b) return numpy.all(a == b)
else: else:
# work around a numpy.allclose bug:
# http://projects.scipy.org/numpy/ticket/1672
if a.ndim == 0 and numpy.isinf(a):
a = a.reshape(1)
b = b.reshape(1)
cmp = theano.tensor.basic._allclose(a, b, rtol=rtol, atol=atol) cmp = theano.tensor.basic._allclose(a, b, rtol=rtol, atol=atol)
if cmp: if cmp:
# Numpy claims they are close, this is good enough for us. # Numpy claims they are close, this is good enough for us.
......
...@@ -471,13 +471,11 @@ class _tensor_py_operators(object): ...@@ -471,13 +471,11 @@ class _tensor_py_operators(object):
def check_bool(args_el): def check_bool(args_el):
try: try:
if isinstance(args_el, (numpy.bool_, bool)) or \ if isinstance(args_el, (numpy.bool_, bool)) or \
args_el.dtype == 'int8' or args_el.dtype == 'uint8': args_el.dtype == 'bool':
raise TypeError(('TensorType does not support boolean ' raise TypeError('TensorType does not support boolean '
'mask for indexing such as tensor[x==0]. ' 'mask for indexing such as tensor[x==0]. '
'Instead you can use non_zeros() such as ' 'Instead you can use non_zeros() such as '
'tensor[(x == 0).nonzeros()]. ' 'tensor[(x == 0).nonzeros()]. ')
'If you are indexing on purpose with an '
'int8, please cast it to int16.'))
except AttributeError: except AttributeError:
pass pass
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论