提交 cfa867b3 authored 作者: Anatoly Rubanov's avatar Anatoly Rubanov 提交者: Brandon T. Willard

add tests for checks in make_node

上级 72e2da25
...@@ -12,20 +12,20 @@ from aesara.tensor.signal.pool import ( ...@@ -12,20 +12,20 @@ from aesara.tensor.signal.pool import (
AveragePoolGrad, AveragePoolGrad,
DownsampleFactorMaxGradGrad, DownsampleFactorMaxGradGrad,
MaxPoolGrad, MaxPoolGrad,
PoolGrad,
Pool, Pool,
PoolGrad,
max_pool_2d_same_size, max_pool_2d_same_size,
pool_2d, pool_2d,
pool_3d, pool_3d,
) )
from aesara.tensor.type import ( from aesara.tensor.type import (
TensorType, TensorType,
fmatrix,
dmatrix, dmatrix,
dtensor3, dtensor3,
dtensor4, dtensor4,
ftensor4, fmatrix,
ftensor3, ftensor3,
ftensor4,
ivector, ivector,
tensor, tensor,
tensor4, tensor4,
...@@ -1296,33 +1296,35 @@ class TestDownsampleFactorMax(utt.InferShapeTester): ...@@ -1296,33 +1296,35 @@ class TestDownsampleFactorMax(utt.InferShapeTester):
@staticmethod @staticmethod
def checks_helper(func, x, ws, stride, pad): def checks_helper(func, x, ws, stride, pad):
with pytest.raises( with pytest.raises(
ValueError, ValueError, match=r"You can't provide a tuple value to both 'ws' and 'ds'."
match=r"You can't provide a tuple value to both 'ws' and 'ds'."): ):
func(x, ds=ws, ws=ws) func(x, ds=ws, ws=ws)
with pytest.raises( with pytest.raises(
ValueError, ValueError, match="You must provide a tuple value for the window size."
match="You must provide a tuple value for the window size."): ):
func(x) func(x)
with pytest.raises( with pytest.raises(
ValueError, ValueError,
match=r"You can't provide a tuple value to both 'st and 'stride'."): match=r"You can't provide a tuple value to both 'st and 'stride'.",
):
func(x, ws=ws, st=stride, stride=stride) func(x, ws=ws, st=stride, stride=stride)
with pytest.raises( with pytest.raises(
ValueError, ValueError,
match=r"You can't provide a tuple value to both 'padding' and pad."): match=r"You can't provide a tuple value to both 'padding' and pad.",
):
func(x, ws=ws, pad=pad, padding=pad) func(x, ws=ws, pad=pad, padding=pad)
def test_pool_2d_checks(self): def test_pool_2d_checks(self):
x = fmatrix() x = fmatrix()
self.checks_helper(pool_2d, x, ws=(1, 1), stride=(1, 1), pad=(1, 1)) self.checks_helper(pool_2d, x, ws=(1, 1), stride=(1, 1), pad=(1, 1))
with pytest.raises( with pytest.raises(
NotImplementedError, NotImplementedError, match="pool_2d requires a dimension >= 2"
match="pool_2d requires a dimension >= 2"): ):
pool_2d(input=vector(), ws=(1, 1)) pool_2d(input=vector(), ws=(1, 1))
with pytest.deprecated_call(): with pytest.deprecated_call():
...@@ -1335,8 +1337,8 @@ class TestDownsampleFactorMax(utt.InferShapeTester): ...@@ -1335,8 +1337,8 @@ class TestDownsampleFactorMax(utt.InferShapeTester):
self.checks_helper(pool_3d, x, ws=(1, 1, 1), stride=(1, 1, 1), pad=(1, 1, 1)) self.checks_helper(pool_3d, x, ws=(1, 1, 1), stride=(1, 1, 1), pad=(1, 1, 1))
with pytest.raises( with pytest.raises(
NotImplementedError, NotImplementedError, match="pool_3d requires a dimension >= 3"
match="pool_3d requires a dimension >= 3"): ):
pool_3d(input=fmatrix(), ws=(1, 1, 1)) pool_3d(input=fmatrix(), ws=(1, 1, 1))
with pytest.deprecated_call(): with pytest.deprecated_call():
...@@ -1349,7 +1351,58 @@ class TestDownsampleFactorMax(utt.InferShapeTester): ...@@ -1349,7 +1351,58 @@ class TestDownsampleFactorMax(utt.InferShapeTester):
self.checks_helper(func, x, ws=(1, 1), stride=(1, 1), pad=(1, 1)) self.checks_helper(func, x, ws=(1, 1), stride=(1, 1), pad=(1, 1))
with pytest.raises( with pytest.raises(TypeError, match="imgshape must have at least 3 dimensions"):
TypeError,
match="imgshape must have at least 3 dimensions"):
func(x, (2, 2), ndim=3) func(x, (2, 2), ndim=3)
def test_Pool_make_node_checks(self):
x = fmatrix()
with pytest.raises(
NotImplementedError, match="padding works only with ignore_border=True"
):
op = Pool(ignore_border=False, ndim=2)
op(x, (1, 1), pad=(1, 1))
with pytest.raises(
NotImplementedError, match="padding must be smaller than strides"
):
op = Pool(ignore_border=True, ndim=2)
op(x, (1, 1), pad=(2, 2))
with pytest.raises(TypeError):
op = Pool(ignore_border=True, ndim=3)
op(x, (1, 1))
op = Pool(ignore_border=True, ndim=2)
with pytest.raises(TypeError, match="Pool downsample parameters must be ints."):
op(x, (1.0, 1.0))
with pytest.raises(TypeError, match="Stride parameters must be ints."):
op(x, (1, 1), stride=(1.0, 1.0))
with pytest.raises(TypeError, match="Padding parameters must be ints."):
op(x, (2, 2), pad=(1.0, 1.0))
def test_MaxPoolGrad_make_node_checks(self):
x = fmatrix()
op = MaxPoolGrad(ignore_border=True, ndim=2)
with pytest.raises(TypeError, match="Pool downsample parameters must be ints."):
op(x, maxout=[[1, 1], [1, 1]], gz=[[1, 1], [1, 1]], ws=(1.0, 1, 0))
with pytest.raises(TypeError, match="Stride parameters must be ints."):
op(
x,
maxout=[[1, 1], [1, 1]],
gz=[[1, 1], [1, 1]],
ws=(1, 1),
stride=(1.0, 1.0),
)
with pytest.raises(TypeError, match="Padding parameters must be ints."):
op(
x,
maxout=[[1, 1], [1, 1]],
gz=[[1, 1], [1, 1]],
ws=(1, 1),
pad=(1.0, 1.0),
)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论