Skip to content

update fft tests #2502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions dpnp/tests/test_fft.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,9 +563,13 @@ def test_basic(self, dtype, n, norm):

result = dpnp.fft.hfft(ia, n=n, norm=norm)
expected = numpy.fft.hfft(a, n=n, norm=norm)
# check_only_type_kind=True since NumPy always returns float64
# but dpnp return float32 if input is float32
assert_dtype_allclose(result, expected, check_only_type_kind=True)
# TODO: change to the commented line when mkl_fft-2.0.0 is released
# and being used with Intel NumPy >= 2.0.0
flag = True
# flag = True if numpy_version() < "2.0.0" else False
assert_dtype_allclose(
result, expected, factor=24, check_only_type_kind=flag
)

@pytest.mark.parametrize(
"dtype", get_all_dtypes(no_none=True, no_complex=True)
Expand All @@ -579,7 +583,7 @@ def test_inverse(self, dtype, n, norm):
result = dpnp.fft.ihfft(ia, n=n, norm=norm)
expected = numpy.fft.ihfft(a, n=n, norm=norm)
flag = True if numpy_version() < "2.0.0" else False
assert_dtype_allclose(result, expected, check_only_type_kind=True)
assert_dtype_allclose(result, expected, check_only_type_kind=flag)

def test_error(self):
a = dpnp.ones(11)
Expand All @@ -600,14 +604,18 @@ class TestIrfft:
@pytest.mark.parametrize("n", [None, 5, 18])
@pytest.mark.parametrize("norm", [None, "backward", "forward", "ortho"])
def test_basic(self, dtype, n, norm):
a = generate_random_numpy_array(11)
a = generate_random_numpy_array(11, dtype=dtype)
ia = dpnp.array(a)

result = dpnp.fft.irfft(ia, n=n, norm=norm)
expected = numpy.fft.irfft(a, n=n, norm=norm)
# check_only_type_kind=True since NumPy always returns float64
# but dpnp return float32 if input is float32
assert_dtype_allclose(result, expected, check_only_type_kind=True)
# TODO: change to the commented line when mkl_fft-2.0.0 is released
# and being used with Intel NumPy >= 2.0.0
flag = True
# flag = True if numpy_version() < "2.0.0" else False
assert_dtype_allclose(
result, expected, factor=24, check_only_type_kind=flag
)

@pytest.mark.parametrize("dtype", get_complex_dtypes())
@pytest.mark.parametrize("n", [None, 5, 8])
Expand Down Expand Up @@ -771,8 +779,11 @@ def test_float16(self):

expected = numpy.fft.rfft(a)
result = dpnp.fft.rfft(ia)
# check_only_type_kind=True since Intel NumPy returns complex128
assert_dtype_allclose(result, expected, check_only_type_kind=True)
# TODO: change to the commented line when mkl_fft-2.0.0 is released
# and being used with Intel NumPy >= 2.0.0
flag = True
# flag = True if numpy_version() < "2.0.0" else False
assert_dtype_allclose(result, expected, check_only_type_kind=flag)

@testing.with_requires("numpy>=2.0.0")
@pytest.mark.parametrize("xp", [numpy, dpnp])
Expand Down Expand Up @@ -954,7 +965,8 @@ def test_1d_array(self):

result = dpnp.fft.irfftn(ia)
expected = numpy.fft.irfftn(a)
# TODO: change to the commented line when mkl_fft-gh-180 is merged
# TODO: change to the commented line when mkl_fft-2.0.0 is released
# and being used with Intel NumPy >= 2.0.0
flag = True
# flag = True if numpy_version() < "2.0.0" else False
assert_dtype_allclose(result, expected, check_only_type_kind=flag)
Loading