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 add tests for consolidated version #70

Closed
wants to merge 2 commits into from
Closed
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
52 changes: 51 additions & 1 deletion tests/test_1d/test_backward_1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

torch.set_default_tensor_type(torch.DoubleTensor)
torch.set_default_dtype(torch.float64)

torch.manual_seed(0)

######################################################################
# APPLY WRAPPERS
Expand Down Expand Up @@ -116,6 +116,56 @@ def test_t1_backward_CPU_values(
assert gradcheck(apply_finufft1d1(modifier, fftshift, isign), inputs)



@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_consolidated_backward_CPU_values(N: int, modifier: int, fftshift: bool, isign: int) -> None:

points = torch.rand((1, N), dtype=torch.float64) * 2 * np.pi
values = torch.randn(N, dtype=torch.complex128)

points.requires_grad = False
values.requires_grad = True

inputs = (points, values)

def func(points, values):
return pytorch_finufft.functional.finufft_type1.apply(
points, values, (N + modifier,), None, fftshift, dict(isign=isign)
)

assert gradcheck(func, inputs)


@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_consolidated_backward_CPU_points(N: int, modifier: int, fftshift: bool, isign: int) -> None:

points = torch.rand((1, N), dtype=torch.float64) * 2 * np.pi
values = torch.randn(N, dtype=torch.complex128)

points.requires_grad = True
values.requires_grad = False

inputs = (points, values)

def func(points, values):
return pytorch_finufft.functional.finufft_type1.apply(
points, values, (N + modifier,), None, fftshift, dict(isign=isign)
)

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







######################################################################
# TYPE 2 TESTS
######################################################################
Expand Down
14 changes: 7 additions & 7 deletions tests/test_2d/test_backward_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ def f(

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

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


Expand Down
58 changes: 54 additions & 4 deletions tests/test_3d/test_backward_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,15 @@ def f(

Ns = [
3,
# 5,
# 8,
5,
8,
17,
Comment on lines +68 to +70
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is running pretty slowly - I assume because of these new cases in 3d

]

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

Expand Down Expand Up @@ -190,6 +191,55 @@ def test_t1_backward_CPU_points_z(
assert gradcheck(apply_finufft3d1(modifier, fftshift, isign), inputs)




@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_consolidated_backward_CPU_values(N: int, modifier: int, fftshift: bool, isign: int) -> None:

points = torch.rand((3, N), dtype=torch.float64) * 2 * np.pi
values = torch.randn(N, dtype=torch.complex128)

points.requires_grad = False
values.requires_grad = True

inputs = (points, values)

def func(points, values):
return pytorch_finufft.functional.finufft_type1.apply(
points, values, (N,N + modifier, N + 2 * modifier), None, fftshift, dict(isign=isign)
)

assert gradcheck(func, inputs)


@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_consolidated_backward_CPU_points(N: int, modifier: int, fftshift: bool, isign: int) -> None:

points = torch.rand((3, N), dtype=torch.float64) * 2 * np.pi
values = torch.randn(N, dtype=torch.complex128)

points.requires_grad = True
values.requires_grad = False

inputs = (points, values)

def func(points, values):
return pytorch_finufft.functional.finufft_type1.apply(
points, values, (N,N + modifier, N + 2 * modifier), None, fftshift, dict(isign=isign)
)

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





######################################################################
# TYPE 2 TESTS
######################################################################
Expand Down
Loading