コード例 #1
0
def test_convolve(shape1, shape2, n1, n2, dx):
    x = _random_array(shape1, n1)
    y = _random_array(shape2, n2)

    c1 = convolve(x, y, dx)
    s1 = shape1 + [1] * (len(shape2) - len(shape1))
    s2 = shape2 + [1] * (len(shape1) - len(shape2))
    if len(shape2) <= len(shape1):
        c2 = ifftn(fftn(x).reshape(s1) * fftn(ifftshift(y)).reshape(s2))
    else:
        c2 = ifftn(fftn(ifftshift(x)).reshape(s1) * fftn(y).reshape(s2))

    assert c1.shape == c2.shape
    np.testing.assert_allclose(c1, c2, 1e-5, 1e-5)
コード例 #2
0
def test_plan(shape, n):
    x = _random_array(shape, n)
    f1, x1 = plan_fft(x)
    f2, x2 = plan_ifft(x)
    x1[...], x2[...] = x, x

    np.testing.assert_allclose(f1(), fftn(x), 1e-5)
    np.testing.assert_allclose(f2(), ifftn(x), 1e-5)
コード例 #3
0
def test_fftshift(shape, n):
    x = _random_array(shape, n) + 1
    y = fftshift(fftn(x))
    z = ifftn(ifftshift(y))
    Y = x.copy()
    fftshift_phase(Y)
    Y = fftn(Y)

    np.testing.assert_allclose(x, z, 1e-5, 1e-5)
    np.testing.assert_allclose(y, Y, 1e-5, 1e-5)