提交 49785840 authored 作者: Frederic Bastien's avatar Frederic Bastien

remove bincount uint64 restriction, it was a left over from the numpy implementation

上级 817ff62b
...@@ -504,18 +504,6 @@ def bincount(x, weights=None, minlength=None, assert_nonneg=False): ...@@ -504,18 +504,6 @@ def bincount(x, weights=None, minlength=None, assert_nonneg=False):
.. versionadded:: 0.6 .. versionadded:: 0.6
""" """
compatible_type = ('int8', 'int16', 'int32', 'int64',
'uint8', 'uint16', 'uint32')
unsupported_dtypes = ('uint64',)
if x.dtype in unsupported_dtypes:
raise TypeError(
("Input dtype %s is not supported, "
% unsupported_dtypes), x.dtype)
if x.dtype not in compatible_type:
raise TypeError("Inputs dtype must be an integer.")
if x.ndim != 1: if x.ndim != 1:
raise TypeError("Inputs must be of dimension 1.") raise TypeError("Inputs must be of dimension 1.")
......
...@@ -138,48 +138,36 @@ class TestBinCountOp(utt.InferShapeTester): ...@@ -138,48 +138,36 @@ class TestBinCountOp(utt.InferShapeTester):
'uint8', 'uint16', 'uint32', 'uint64'): 'uint8', 'uint16', 'uint32', 'uint64'):
x = T.vector('x', dtype=dtype) x = T.vector('x', dtype=dtype)
# uint64 always fails a = np.random.random_integers(50, size=(25)).astype(dtype)
# int64 and uint32 also fail if python int are 32-bit weights = np.random.random((25,)).astype(config.floatX)
int_bitwidth = theano.gof.python_int_bitwidth()
if int_bitwidth == 64: f1 = theano.function([x], bincount(x))
numpy_unsupported_dtypes = ('uint64',) f2 = theano.function([x, w], bincount(x, weights=w))
if int_bitwidth == 32:
numpy_unsupported_dtypes = ('uint32', 'int64', 'uint64') def ref(data, w=None, minlength=None):
# uint64 always fails size = data.max() + 1
if dtype in numpy_unsupported_dtypes: if minlength:
self.assertRaises(TypeError, bincount, x) size = max(size, minlength)
if w:
else: out = np.zeros(size, dtype=weights.dtype)
a = np.random.random_integers(50, size=(25)).astype(dtype) for i in range(data.shape[0]):
weights = np.random.random((25,)).astype(config.floatX) out[data[i]] += weights[i]
else:
f1 = theano.function([x], bincount(x)) out = np.zeros(size, dtype=a.dtype)
f2 = theano.function([x, w], bincount(x, weights=w)) for i in range(data.shape[0]):
out[data[i]] += 1
def ref(data, w=None, minlength=None): return out
size = data.max() + 1 assert (ref(a) == f1(a)).all()
if minlength: assert np.allclose(ref(a, w), f2(a, weights))
size = max(size, minlength) f3 = theano.function([x], bincount(x, minlength=55))
if w: f4 = theano.function([x], bincount(x, minlength=5))
out = np.zeros(size, dtype=weights.dtype) assert (ref(a, minlength=55) == f3(a)).all()
for i in range(data.shape[0]): assert (ref(a, minlength=5) == f4(a)).all()
out[data[i]] += weights[i] # skip the following test when using unsigned ints
else: if not dtype.startswith('u'):
out = np.zeros(size, dtype=a.dtype) a[0] = -1
for i in range(data.shape[0]): f5 = theano.function([x], bincount(x, assert_nonneg=True))
out[data[i]] += 1 self.assertRaises(AssertionError, f5, a)
return out
assert (ref(a) == f1(a)).all()
assert np.allclose(ref(a, w), f2(a, weights))
f3 = theano.function([x], bincount(x, minlength=55))
f4 = theano.function([x], bincount(x, minlength=5))
assert (ref(a, minlength=55) == f3(a)).all()
assert (ref(a, minlength=5) == f4(a)).all()
# skip the following test when using unsigned ints
if not dtype.startswith('u'):
a[0] = -1
f5 = theano.function([x], bincount(x, assert_nonneg=True))
self.assertRaises(AssertionError, f5, a)
def test_bincountOp(self): def test_bincountOp(self):
w = T.vector('w') w = T.vector('w')
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论