Skip to content

Commit

Permalink
Merge pull request #96 from flatironinstitute/mike-refactor-tests
Browse files Browse the repository at this point in the history
TST refactor tests
  • Loading branch information
WardBrian authored Oct 23, 2023
2 parents 5797cac + ff2d6cf commit 1f77130
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 459 deletions.
189 changes: 27 additions & 162 deletions tests/test_t1_backward.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,182 +41,47 @@ def func(points, values):
isign=isign,
)

assert gradcheck(func, inputs, eps=1e-8, atol=1e-5 * N)


#### 1D TESTS ####
Ns = [
5,
8,
10,
15,
16,
63,
100,
101,
assert gradcheck(func, inputs, eps=1e-8, atol=2e-4 * N)


shapes_and_Ns = [
(2, 2),
(2, 51),
(5, 4),
(6, 50),
(101, 10),
((2,), 10),
((5,), 25),
((2, 2), 21),
((20, 21), 51),
((8, 30), 23),
((5, 4, 3), 10),
]

length_modifiers = [-1, 0, 1, 4]


@pytest.mark.parametrize("N", Ns)
@pytest.mark.parametrize("modifier", length_modifiers)
@pytest.mark.parametrize("fftshift", [False, True])
@pytest.mark.parametrize("isign", [-1, 1])
def test_t1_1D_backward_CPU_values(
N: int, modifier: int, fftshift: bool, isign: int
) -> None:
check_t1_backward(N, N + modifier, fftshift, isign, "cpu", False)


@pytest.mark.parametrize("N", Ns)
@pytest.mark.parametrize("modifier", length_modifiers)
@pytest.mark.parametrize("fftshift", [False, True])
@pytest.mark.parametrize("isign", [-1, 1])
def test_t1_1D_backward_CPU_points(
N: int, modifier: int, fftshift: bool, isign: int
) -> None:
check_t1_backward(N, N + modifier, fftshift, isign, "cpu", True)


@pytest.mark.parametrize("N", Ns)
@pytest.mark.parametrize("modifier", length_modifiers)
@pytest.mark.parametrize("fftshift", [False, True])
@pytest.mark.parametrize("isign", [-1, 1])
def test_t1_1D_backward_cuda_values(
N: int, modifier: int, fftshift: bool, isign: int
) -> None:
check_t1_backward(N, N + modifier, fftshift, isign, "cuda", False)


@pytest.mark.parametrize("N", Ns)
@pytest.mark.parametrize("modifier", length_modifiers)
@pytest.mark.parametrize("fftshift", [False, True])
@pytest.mark.parametrize("isign", [-1, 1])
def test_t1_1D_backward_cuda_points(
N: int, modifier: int, fftshift: bool, isign: int
) -> None:
check_t1_backward(N, N + modifier, fftshift, isign, "cuda", True)


#### 2D TESTS ####


Ns = [
3,
# 5,
# 8,
# 10,
# 15,
# 16,
]

length_modifiers = [
0,
1,
-1,
]


@pytest.mark.parametrize("N", Ns)
@pytest.mark.parametrize("modifier", length_modifiers)
@pytest.mark.parametrize("fftshift", [False, True])
@pytest.mark.parametrize("isign", [-1, 1])
def test_t1_2D_backward_CPU_points(
N: int, modifier: int, fftshift: bool, isign: int
) -> None:
check_t1_backward(N, (N, N + modifier), fftshift, isign, "cpu", True)


@pytest.mark.parametrize("N", Ns)
@pytest.mark.parametrize("modifier", length_modifiers)
@pytest.mark.parametrize("output_shape, N", shapes_and_Ns)
@pytest.mark.parametrize("fftshift", [False, True])
@pytest.mark.parametrize("isign", [-1, 1])
def test_t1_2D_backward_CPU_values(
N: int, modifier: int, fftshift: bool, isign: int
) -> None:
check_t1_backward(N, (N, N + modifier), fftshift, isign, "cpu", False)
def test_t1_backward_CPU_points(output_shape, N, fftshift, isign) -> None:
check_t1_backward(N, output_shape, fftshift, isign, "cpu", True)


@pytest.mark.parametrize("N", Ns)
@pytest.mark.parametrize("modifier", length_modifiers)
@pytest.mark.parametrize("output_shape, N", shapes_and_Ns)
@pytest.mark.parametrize("fftshift", [False, True])
@pytest.mark.parametrize("isign", [-1, 1])
def test_t1_2D_backward_cuda_values(
N: int, modifier: int, fftshift: bool, isign: int
) -> None:
check_t1_backward(N, (N, N + modifier), fftshift, isign, "cuda", False)
def test_t1_backward_CPU_values(output_shape, N, fftshift, isign) -> None:
check_t1_backward(N, output_shape, fftshift, isign, "cpu", False)


@pytest.mark.parametrize("N", Ns)
@pytest.mark.parametrize("modifier", length_modifiers)
@pytest.mark.parametrize("output_shape, N", shapes_and_Ns)
@pytest.mark.parametrize("fftshift", [False, True])
@pytest.mark.parametrize("isign", [-1, 1])
def test_t1_2D_backward_cuda_points(
N: int, modifier: int, fftshift: bool, isign: int
) -> None:
check_t1_backward(N, (N, N + modifier), fftshift, isign, "cuda", True)

def test_t1_backward_cuda_points(output_shape, N, fftshift, isign) -> None:
check_t1_backward(N, output_shape, fftshift, isign, "cuda", True)

#### 3D TESTS ####

Ns = [
3,
# 5,
# 8,
]

length_modifiers = [
# -1,
0,
1,
# 4
]


@pytest.mark.parametrize("N", Ns)
@pytest.mark.parametrize("modifier", length_modifiers)
@pytest.mark.parametrize("output_shape, N", shapes_and_Ns)
@pytest.mark.parametrize("fftshift", [False, True])
@pytest.mark.parametrize("isign", [-1, 1])
def test_t1_3D_backward_CPU_values(
N: int, modifier: int, fftshift: bool, isign: int
) -> None:
check_t1_backward(
N, (N, N + modifier, N + 2 * modifier), fftshift, isign, "cpu", False
)


@pytest.mark.parametrize("N", Ns)
@pytest.mark.parametrize("modifier", length_modifiers)
@pytest.mark.parametrize("fftshift", [False, True])
@pytest.mark.parametrize("isign", [-1, 1])
def test_t1_3D_backward_CPU_points(
N: int, modifier: int, fftshift: bool, isign: int
) -> None:
check_t1_backward(
N, (N, N + modifier, N + 2 * modifier), fftshift, isign, "cpu", True
)


@pytest.mark.parametrize("N", Ns)
@pytest.mark.parametrize("modifier", length_modifiers)
@pytest.mark.parametrize("fftshift", [False, True])
@pytest.mark.parametrize("isign", [-1, 1])
def test_t1_3D_backward_cuda_values(
N: int, modifier: int, fftshift: bool, isign: int
) -> None:
check_t1_backward(
N, (N, N + modifier, N + 2 * modifier), fftshift, isign, "cuda", False
)


@pytest.mark.parametrize("N", Ns)
@pytest.mark.parametrize("modifier", length_modifiers)
@pytest.mark.parametrize("fftshift", [False, True])
@pytest.mark.parametrize("isign", [-1, 1])
def test_t1_3D_backward_cuda_points(
N: int, modifier: int, fftshift: bool, isign: int
) -> None:
check_t1_backward(
N, (N, N + modifier, N + 2 * modifier), fftshift, isign, "cuda", True
)
def test_t1_backward_cuda_values(output_shape, N, fftshift, isign) -> None:
check_t1_backward(N, output_shape, fftshift, isign, "cuda", False)
94 changes: 25 additions & 69 deletions tests/test_t1_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,77 +39,33 @@ def check_t1_forward(N: int, dim: int, device: str) -> None:
assert l_1_error < 1e-5 * N**4.5


#### 1D TESTS ####

Ns = [
5,
10,
15,
100,
101,
1000,
1001,
3750,
5000,
5001,
6250,
7500,
]


@pytest.mark.parametrize("N", Ns)
def test_t1_1D_forward_CPU(N: int) -> None:
check_t1_forward(N, 1, "cpu")


@pytest.mark.parametrize("N", Ns)
def test_t1_1D_forward_cuda(N: int) -> None:
check_t1_forward(N, 1, "cuda")


#### 2D TESTS ####
Ns = [
3,
10,
15,
75,
76,
95,
96,
100,
101,
]


@pytest.mark.parametrize("N", Ns)
def test_t1_2D_forward_CPU(N: int) -> None:
check_t1_forward(N, 2, "cpu")


@pytest.mark.parametrize("N", Ns)
def test_t1_2D_forward_cuda(N: int) -> None:
check_t1_forward(N, 2, "cuda")


#### 3D TESTS ####

Ns = [
3,
5,
10,
15,
16,
25,
26,
37,
Ns_and_dims = [
(2, 1),
(3, 1),
(5, 1),
(10, 1),
(100, 1),
(101, 1),
(1000, 1),
(10001, 1),
(2, 2),
(3, 2),
(5, 2),
(10, 2),
(101, 2),
(2, 3),
(3, 3),
(5, 3),
(10, 3),
(37, 3),
]


@pytest.mark.parametrize("N", Ns)
def test_t1_3D_forward_CPU(N: int) -> None:
check_t1_forward(N, 3, "cpu")
@pytest.mark.parametrize("N, dim", Ns_and_dims)
def test_t1_forward_CPU(N, dim) -> None:
check_t1_forward(N, dim, "cpu")


@pytest.mark.parametrize("N", Ns)
def test_t1_3D_forward_cuda(N: int) -> None:
check_t1_forward(N, 3, "cuda")
@pytest.mark.parametrize("N, dim", Ns_and_dims)
def test_t1_forward_cuda(N, dim) -> None:
check_t1_forward(N, dim, "cuda")
Loading

0 comments on commit 1f77130

Please sign in to comment.