예제 #1
0
    def test_backward_fft(self, dtype):
        t = dtype
        idtype = odtype = edtype = cupy.dtype(t)
        shape = self.shape
        length = cupy.core.internal.prod(shape[1:])

        a = testing.shaped_random(shape, cupy, dtype)
        out = cupy.empty_like(a)

        plan = cufft.XtPlanNd(shape[1:],
                              shape[1:],
                              1,
                              length,
                              idtype,
                              shape[1:],
                              1,
                              length,
                              odtype,
                              shape[0],
                              edtype,
                              order='C',
                              last_axis=-1,
                              last_size=None)
        plan.fft(a, out, cufft.CUFFT_INVERSE)

        if len(shape) <= 2:
            out_cp = cupy.fft.ifft(a)
        else:
            out_cp = cupy.fft.ifftn(a, axes=(-1, -2))
        testing.assert_allclose(out / length, out_cp)
예제 #2
0
    def test_backward_fft_complex32(self):
        t = 'E'
        idtype = odtype = edtype = t
        old_shape = self.shape
        shape = list(self.shape)
        shape[-1] = 2 * shape[-1]
        shape = tuple(shape)

        a = testing.shaped_random(shape, cupy, cupy.float16)
        out = cupy.empty_like(a)

        shape = old_shape
        length = cupy.core.internal.prod(shape[1:])
        plan = cufft.XtPlanNd(shape[1:],
                              shape[1:],
                              1,
                              length,
                              idtype,
                              shape[1:],
                              1,
                              length,
                              odtype,
                              shape[0],
                              edtype,
                              order='C',
                              last_axis=-1,
                              last_size=None)
        plan.fft(a, out, cufft.CUFFT_INVERSE)

        a_cp = a.astype(cupy.float32)  # upcast
        a_cp = a_cp.view(cupy.complex64)
        if len(shape) <= 2:
            out_cp = cupy.fft.ifft(a_cp)
        else:
            out_cp = cupy.fft.ifftn(a_cp, axes=(-1, -2))
        out_cp = out_cp.view(cupy.float32)
        out_cp = out_cp.astype(cupy.float16)  # downcast

        # We shouldn't expect getting high accuracy, as both computations have
        # precision losses...
        testing.assert_allclose(out / length, out_cp, rtol=1E-1, atol=1E-1)