提交 8db86bef authored 作者: Frederic's avatar Frederic

Better error message. It would raise error during compilation (and probably crash later).

上级 32f8a112
...@@ -2654,14 +2654,20 @@ class Alloc(gof.Op): ...@@ -2654,14 +2654,20 @@ class Alloc(gof.Op):
sh = [as_tensor_variable(s) for s in shape] sh = [as_tensor_variable(s) for s in shape]
bcast = [] bcast = []
for i, s in enumerate(sh): for i, s in enumerate(sh):
if s.type.dtype[:3] not in ('int', 'uin'):
if config.exception_verbosity == 'high': if config.exception_verbosity == 'high':
s_as_str = '\n' + min_informative_str(s) s_as_str = '\n' + min_informative_str(s)
else: else:
s_as_str = str(s) s_as_str = str(s)
if s.type.dtype[:3] not in ('int', 'uin'):
raise TypeError('Shape arguments to Alloc must be integers, ' raise TypeError('Shape arguments to Alloc must be integers, '
'but argument %s is not for apply node: %s' % 'but argument %s is not for apply node: %s' %
(i, s_as_str)) (i, s_as_str))
if s.ndim != 0:
raise TypeError(
'Each shape dimensions to Alloc must be scalars, '
'but dimensions %s is not for apply node: %s' %
(i, s_as_str))
# if s is constant 1, then we're broadcastable in that dim # if s is constant 1, then we're broadcastable in that dim
try: try:
const_shp = get_scalar_constant_value(s) const_shp = get_scalar_constant_value(s)
......
...@@ -2026,6 +2026,7 @@ AllocTester = makeBroadcastTester( ...@@ -2026,6 +2026,7 @@ AllocTester = makeBroadcastTester(
bad_shape12=(rand(7), numpy.int32(7), numpy.int32(5)), bad_shape12=(rand(7), numpy.int32(7), numpy.int32(5)),
), ),
bad_build=dict( bad_build=dict(
vec=(rand(1), [numpy.int32(2)]),
too_big32=(rand(6, 2, 4), numpy. too_big32=(rand(6, 2, 4), numpy.
int32(6), numpy.int32(2)), int32(6), numpy.int32(2)),
too_big32b=(rand(6, 2, 4), numpy. too_big32b=(rand(6, 2, 4), numpy.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论