提交 c0987620 authored 作者: Sina Honari's avatar Sina Honari

Raising error for Indexing subtensor with a Boolean mask

上级 dc49660f
......@@ -383,7 +383,7 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
subi = 0
data = numpy.asarray(rand(2, 3), dtype=self.dtype)
n = self.shared(data)
z = scal.constant(subi)
z = scal.constant(subi).astype('int32')
t = n[z:, z]
gn = theano.tensor.grad(theano.tensor.sum(theano.tensor.exp(t)), n)
......
from __future__ import absolute_import, print_function, division
import collections
import copy
import traceback as tb
import warnings
......@@ -466,6 +467,25 @@ class _tensor_py_operators(object):
# SLICING/INDEXING
def __getitem__(self, args):
def check_bool(args_el):
try:
if isinstance(args_el, (numpy.bool_, bool)) or \
args_el.dtype == 'int8' or args_el.dtype == 'uint8':
raise 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'))
except AttributeError:
pass
if not isinstance(args_el, theano.tensor.Variable) and \
isinstance(args_el, collections.Iterable):
for el in args_el:
check_bool(el)
check_bool(args)
if (isinstance(args, list) and
any([isinstance(a, slice) for a in args])):
pass
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论