Esempio n. 1
0
    def test_fft(self, backend):
        x = torch.randn(2, 2, 2)

        y = torch.empty_like(x)
        y[0, 0, :] = x[0, 0, :] + x[0, 1, :] + x[1, 0, :] + x[1, 1, :]
        y[0, 1, :] = x[0, 0, :] - x[0, 1, :] + x[1, 0, :] - x[1, 1, :]
        y[1, 0, :] = x[0, 0, :] + x[0, 1, :] - x[1, 0, :] - x[1, 1, :]
        y[1, 1, :] = x[0, 0, :] - x[0, 1, :] - x[1, 0, :] + x[1, 1, :]

        z = backend.fft(x, direction='C2C')

        assert torch.allclose(y, z)

        z = backend.fft(x, direction='C2C', inverse=True)

        z = z * 4.0

        assert torch.allclose(y, z)

        z = backend.fft(x, direction='C2R', inverse=True)

        z = z * 4.0

        assert z.shape == x.shape[:-1]
        assert torch.allclose(y[..., 0], z)
Esempio n. 2
0
    def test_fft_exceptions(self, backend_device):
        backend, device = backend_device

        with pytest.raises(RuntimeError) as record:
            backend.fft(torch.empty(2, 2), direction='C2R', inverse=False)
        assert 'done with an inverse' in record.value.args[0]

        x = torch.rand(4, 4, 1)
        x = x.to(device)
        with pytest.raises(TypeError) as record:
            backend.fft(x)
        assert 'complex' in record.value.args[0]

        x = torch.randn(4, 4, 2)
        x = x.to(device)
        y = x[::2, ::2]

        with pytest.raises(RuntimeError) as record:
            backend.fft(y)
        assert 'must be contiguous' in record.value.args[0]