Skip to content

Commit

Permalink
FIX consolidated backward working for 2D now
Browse files Browse the repository at this point in the history
  • Loading branch information
eickenberg committed Oct 5, 2023
1 parent e1ce8f9 commit f63c4d9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
3 changes: 1 addition & 2 deletions pytorch_finufft/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -1691,7 +1691,6 @@ def backward(
_mode_ordering = ctx.mode_ordering
finufftkwargs = ctx.finufftkwargs


points, values = ctx.saved_tensors

start_points = -(np.array(grad_output.shape) // 2)
Expand All @@ -1712,7 +1711,7 @@ def backward(
# wrt points

if _mode_ordering != 0:
coord_ramps = torch.fft.ifftshift(coord_ramps)
coord_ramps = torch.fft.ifftshift(coord_ramps, dim=tuple(range(1, ndim+1)))

ramped_grad_output = coord_ramps * grad_output[np.newaxis] * 1j * _i_sign

Expand Down
22 changes: 22 additions & 0 deletions tests/test_2d/test_backward_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,28 @@ def func(points, values):
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((2, 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), None, fftshift, dict(isign=isign)
)

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


@pytest.mark.parametrize("N", Ns)
@pytest.mark.parametrize("modifier", length_modifiers)
@pytest.mark.parametrize("fftshift", [True, False])
Expand Down

0 comments on commit f63c4d9

Please sign in to comment.