提交 58eecf0e authored 作者: Sina Honari's avatar Sina Honari

updating tests and functions by upcasting int8 indices

上级 8d5f3b4e
...@@ -1122,17 +1122,10 @@ Theano indexing with a "mask" (incorrect approach): ...@@ -1122,17 +1122,10 @@ Theano indexing with a "mask" (incorrect approach):
>>> t = theano.tensor.arange(9).reshape((3,3)) >>> t = theano.tensor.arange(9).reshape((3,3))
>>> t[t > 4].eval() # an array with shape (3, 3, 3) >>> t[t > 4].eval() # an array with shape (3, 3, 3)
array([[[0, 1, 2],
[0, 1, 2], Traceback (most recent call last):
[0, 1, 2]], ...
<BLANKLINE> TypeError: TensorType does not support boolean mask for indexing such as tensor[x==0]. If you are indexing on purpose with an int8, please cast it to int32
[[0, 1, 2],
[0, 1, 2],
[3, 4, 5]],
<BLANKLINE>
[[3, 4, 5],
[3, 4, 5],
[3, 4, 5]]])
Getting a Theano result like NumPy: Getting a Theano result like NumPy:
......
...@@ -696,12 +696,14 @@ def bincount(x, weights=None, minlength=None, assert_nonneg=False): ...@@ -696,12 +696,14 @@ def bincount(x, weights=None, minlength=None, assert_nonneg=False):
if minlength is not None: if minlength is not None:
max_value = theano.tensor.maximum(max_value, minlength) max_value = theano.tensor.maximum(max_value, minlength)
# Note: we do not use inc_subtensor(out[x], ...) in the following lines,
# since out[x] raises an exception if the indices (x) are int8.
if weights is None: if weights is None:
out = theano.tensor.zeros([max_value], dtype=x.dtype) out = theano.tensor.zeros([max_value], dtype=x.dtype)
out = theano.tensor.inc_subtensor(out[x], 1) out = theano.tensor.advanced_inc_subtensor1(out, 1, x)
else: else:
out = theano.tensor.zeros([max_value], dtype=weights.dtype) out = theano.tensor.zeros([max_value], dtype=weights.dtype)
out = theano.tensor.inc_subtensor(out[x], weights) out = theano.tensor.advanced_inc_subtensor1(out, weights, x)
return out return out
......
...@@ -6988,7 +6988,7 @@ class T_get_scalar_constant_value(unittest.TestCase): ...@@ -6988,7 +6988,7 @@ class T_get_scalar_constant_value(unittest.TestCase):
assert get_scalar_constant_value(mv[0]) == 1 assert get_scalar_constant_value(mv[0]) == 1
assert get_scalar_constant_value(mv[1]) == 2 assert get_scalar_constant_value(mv[1]) == 2
assert get_scalar_constant_value(mv[2]) == 3 assert get_scalar_constant_value(mv[2]) == 3
assert get_scalar_constant_value(mv[numpy.int8(0)]) == 1 assert get_scalar_constant_value(mv[numpy.int32(0)]) == 1
assert get_scalar_constant_value(mv[numpy.int64(1)]) == 2 assert get_scalar_constant_value(mv[numpy.int64(1)]) == 2
assert get_scalar_constant_value(mv[numpy.uint(2)]) == 3 assert get_scalar_constant_value(mv[numpy.uint(2)]) == 3
t = theano.scalar.Scalar('int64') t = theano.scalar.Scalar('int64')
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论