Skip to content

Commit 5403e52

Browse files
committed
test: added dtype checks for more tests
1 parent c9de6f5 commit 5403e52

8 files changed

Lines changed: 366 additions & 141 deletions

File tree

pytests/test_pad.py

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
from pylops.basicoperators import Pad
1616
from pylops.utils import dottest
1717

18-
par1 = {"ny": 11, "nx": 11, "pad": ((0, 2), (4, 5)), "dtype": "float64"} # square
19-
par2 = {"ny": 21, "nx": 11, "pad": ((3, 1), (0, 3)), "dtype": "float64"} # rectangular
18+
par1 = {"ny": 11, "nx": 11, "pad": ((0, 2), (4, 5))} # square
19+
par2 = {"ny": 21, "nx": 11, "pad": ((3, 1), (0, 3))} # rectangular
2020

2121
np.random.seed(10)
2222

@@ -36,26 +36,46 @@ def test_Pad_2d_negative(par):
3636

3737

3838
@pytest.mark.parametrize("par", [(par1)])
39-
def test_Pad1d(par):
40-
"""Dot-test and adjoint for Pad operator on 1d signal"""
41-
Pop = Pad(dims=par["ny"], pad=par["pad"][0], dtype=par["dtype"])
42-
assert dottest(Pop, Pop.shape[0], Pop.shape[1], backend=backend)
39+
@pytest.mark.parametrize("dtype", [np.float32, np.float64])
40+
def test_Pad1d(par, dtype):
41+
"""Dot-test and forward/adjoint for Pad operator on 1d signal"""
42+
Pop = Pad(dims=par["ny"], pad=par["pad"][0], dtype=dtype)
43+
assert dottest(
44+
Pop,
45+
Pop.shape[0],
46+
Pop.shape[1],
47+
rtol=1e-4 if dtype == np.float32 else 1e-6,
48+
backend=backend,
49+
)
4350

44-
x = np.arange(par["ny"], dtype=par["dtype"]) + 1.0
51+
x = np.arange(par["ny"], dtype=dtype) + 1.0
4552
y = Pop * x
46-
xinv = Pop.H * y
47-
assert_array_equal(x, xinv)
53+
xadj = Pop.H * y
54+
55+
assert y.dtype == dtype
56+
assert xadj.dtype == dtype
57+
assert_array_equal(x, xadj)
4858

4959

5060
@pytest.mark.parametrize("par", [(par1), (par2)])
51-
def test_Pad2d(par):
61+
@pytest.mark.parametrize("dtype", [np.float32, np.float64])
62+
def test_Pad2d(par, dtype):
5263
"""Dot-test and adjoint for Pad operator on 2d signal"""
53-
Pop = Pad(dims=(par["ny"], par["nx"]), pad=par["pad"], dtype=par["dtype"])
54-
assert dottest(Pop, Pop.shape[0], Pop.shape[1], backend=backend)
64+
Pop = Pad(dims=(par["ny"], par["nx"]), pad=par["pad"], dtype=dtype)
65+
assert dottest(
66+
Pop,
67+
Pop.shape[0],
68+
Pop.shape[1],
69+
rtol=1e-4 if dtype == np.float32 else 1e-6,
70+
backend=backend,
71+
)
5572

56-
x = (np.arange(par["ny"] * par["nx"], dtype=par["dtype"]) + 1.0).reshape(
73+
x = (np.arange(par["ny"] * par["nx"], dtype=dtype) + 1.0).reshape(
5774
par["ny"], par["nx"]
5875
)
5976
y = Pop * x.ravel()
6077
xadj = Pop.H * y
78+
79+
assert y.dtype == dtype
80+
assert xadj.dtype == dtype
6181
assert_array_equal(x.ravel(), xadj)

0 commit comments

Comments
 (0)