Exemplo n.º 1
0
def test_fft3d_direction_error(fake_data_deterministic):
    """Test _fft3d error in direction kwarg."""
    data, is_random = fake_data_deterministic

    # test giving a bogus direction
    with pytest.raises(ValueError) as cm:
        zreion._fft3d(data, data.shape, direction="blah")
    assert str(
        cm.value).startswith('"direction" must be "f" or "b", got "blah"')

    return
Exemplo n.º 2
0
def test_fft3d_rank_errors(fake_data_deterministic):
    """Test _fft3d errors with data rank."""
    data, is_random = fake_data_deterministic
    with pytest.raises(ValueError) as cm:
        zreion._fft3d(data, (0, ), direction="f")
    assert str(cm.value).startswith("data_shape must have 3 dimensions")

    data_1d = data[0, 0, :]
    with pytest.raises(ValueError) as cm:
        zreion._fft3d(data_1d, data.shape, direction="f")
    assert str(
        cm.value).startswith("input array must be a 3-dimensional array")

    return
Exemplo n.º 3
0
def test_fft3d_backward_double(fake_data):
    """Test backward _fft3d function with double-precision."""
    data, is_random = fake_data
    data = np.asarray(data, dtype=np.float64)
    fake_data_ft = np.asarray(np.fft.rfftn(data), dtype=np.complex128)

    # run zreion fft
    input_shape = data.shape
    zreion_fft = zreion._fft3d(fake_data_ft, input_shape, direction="b")
    assert np.allclose(zreion_fft, data)
    assert zreion_fft.dtype.type is np.float64

    return
Exemplo n.º 4
0
def test_fft3d_backward(fake_data):
    """Test backward _fft3d function."""
    data, is_random = fake_data
    # use numpy as reference FFT
    fake_data_ft = np.asarray(np.fft.rfftn(data), dtype=np.complex64)

    # run zreion fft
    input_shape = data.shape
    zreion_fft = zreion._fft3d(fake_data_ft, input_shape, direction="b")
    assert np.allclose(zreion_fft, data, atol=1e-6)
    assert zreion_fft.dtype.type is np.float32

    return
Exemplo n.º 5
0
def test_fft3d_forward_double_precision(fake_data):
    """Test _fft3d function with double-precision."""
    data, is_random = fake_data
    data = np.asarray(data, dtype=np.float64)

    # use numpy as reference FFT
    numpy_fft = np.fft.rfftn(data)

    # run zreion fft
    input_shape = data.shape
    zreion_fft = zreion._fft3d(data, input_shape, direction="f")
    assert np.allclose(numpy_fft, zreion_fft)
    assert zreion_fft.dtype.type is np.complex128

    return
Exemplo n.º 6
0
def test_fft3d_forward(fake_data):
    """Test _fft3d function."""
    data, is_random = fake_data

    # use numpy as reference FFT
    numpy_fft = np.fft.rfftn(data)

    # run zreion fft
    input_shape = data.shape
    zreion_fft = zreion._fft3d(data, input_shape, direction="f")
    # need relatively high tolerance because numpy fft is internally done at
    # double precision, seemingly without a way to change it
    assert np.allclose(numpy_fft, zreion_fft, atol=1e-4)
    assert zreion_fft.dtype.type is np.complex64

    return
Exemplo n.º 7
0
def test_fft3d_datatype_errors(fake_data_deterministic):
    """Test _fft3d errors with bad datatypes."""
    data, is_random = fake_data_deterministic

    # test using incorrect direction for real data
    with pytest.raises(ValueError) as cm:
        zreion._fft3d(data, data.shape, direction="b")
    assert str(cm.value).startswith("a backward transform requires")

    # test using incorrect direction for complex data
    complex_data = np.asarray(data, dtype=np.complex64)
    with pytest.raises(ValueError) as cm:
        zreion._fft3d(complex_data, data.shape, direction="f")
    assert str(cm.value).startswith("a forward transform requires")

    # test using integer datatype
    int_data = np.asarray(data, dtype=np.int32)
    with pytest.raises(ValueError) as cm:
        zreion._fft3d(int_data, data.shape, direction="f")
    assert str(cm.value).startswith("a forward transform requires")

    return