Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TST refactor tests #96

Merged
merged 6 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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