提交 9e83b193 authored 作者: Brandon T. Willard's avatar Brandon T. Willard 提交者: Brandon T. Willard

Remove unnecessary exception arguments from TensorType.filter

上级 5b58807d
......@@ -205,33 +205,18 @@ class TensorType(CType):
f" got {data.ndim} with shape {data.shape}."
)
if not data.flags.aligned:
try:
msg = "object buffer" + str(data.data)
except AttributeError:
msg = ""
raise TypeError(
"The numpy.ndarray object is not aligned."
" Aesara C code does not support that.",
msg,
"object shape",
data.shape,
"object strides",
data.strides,
"object dtype",
data.dtype,
)
i = 0
for b in self.broadcastable:
if b and data.shape[i] != 1:
raise TypeError(
"Non-unit value on shape on a broadcastable" " dimension.",
data.shape,
self.broadcastable,
)
raise TypeError("Non-unit value on shape on a broadcastable dimension.")
i += 1
if self.filter_checks_isfinite and not np.all(np.isfinite(data)):
raise ValueError("non-finite elements not allowed")
raise ValueError("Non-finite elements not allowed")
return data
def filter_variable(self, other, allow_convert=True):
......
......@@ -19,6 +19,20 @@ def test_filter_variable():
with pytest.raises(TypeError):
test_type.filter(test_type())
test_type = TensorType(config.floatX, [True, False])
with pytest.raises(TypeError):
test_type.filter(np.empty((0, 1), dtype=config.floatX))
with pytest.raises(TypeError, match=".*not aligned.*"):
test_val = np.empty((1, 2), dtype=config.floatX)
test_val.flags.aligned = False
test_type.filter(test_val)
with pytest.raises(ValueError, match="Non-finite"):
test_type.filter_checks_isfinite = True
test_type.filter(np.full((1, 2), np.inf, dtype=config.floatX))
def test_filter_strict():
test_type = TensorType(config.floatX, [])
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论