Skip to content

Commit eaf343a

Browse files
authored
Backport gh-2202 (#2218)
This PR backports of #2202 from development branch to `maintenance/0.16.x`.
1 parent 39439dd commit eaf343a

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
## [0.16.1] - 12/XX/2024
7+
## [0.16.1] - 12/05/2024
88

99
This is a bug-fix release.
1010

@@ -18,6 +18,7 @@ This is a bug-fix release.
1818

1919
* Resolved an issue with Compute Follows Data inconsistency in `dpnp.extract` function [#2172](https://github.com/IntelPython/dpnp/pull/2172)
2020
* Resolves an import error when using `dpnp` in virtual environment on Linux [#2199](https://github.com/IntelPython/dpnp/pull/2199)
21+
* Fixed incorrect result produced by `dpnp.fft.fft` function when input array has negative strides [#2202](https://github.com/IntelPython/dpnp/pull/2202)
2122
* Resolved a compilation error when building with DPC++ 2025.1 compiler [#2211](https://github.com/IntelPython/dpnp/pull/2211)
2223

2324
## [0.16.0] - 10/14/2024

dpnp/fft/dpnp_utils_fft.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,13 @@ def _commit_descriptor(a, forward, in_place, c2c, a_strides, index, batch_fft):
7878
shape = a_shape[index:]
7979
strides = (0,) + a_strides[index:]
8080
if c2c: # c2c FFT
81+
assert dpnp.issubdtype(a.dtype, dpnp.complexfloating)
8182
if a.dtype == dpnp.complex64:
8283
dsc = fi.Complex64Descriptor(shape)
8384
else:
8485
dsc = fi.Complex128Descriptor(shape)
8586
else: # r2c/c2r FFT
87+
assert dpnp.issubdtype(a.dtype, dpnp.inexact)
8688
if a.dtype in [dpnp.float32, dpnp.complex64]:
8789
dsc = fi.Real32Descriptor(shape)
8890
else:
@@ -262,12 +264,14 @@ def _copy_array(x, complex_input):
262264
in-place FFT can be performed.
263265
"""
264266
dtype = x.dtype
267+
copy_flag = False
265268
if numpy.min(x.strides) < 0:
266269
# negative stride is not allowed in OneMKL FFT
267270
# TODO: support for negative strides will be added in the future
268271
# versions of OneMKL, see discussion in MKLD-17597
269272
copy_flag = True
270-
elif complex_input and not dpnp.issubdtype(dtype, dpnp.complexfloating):
273+
274+
if complex_input and not dpnp.issubdtype(dtype, dpnp.complexfloating):
271275
# c2c/c2r FFT, if input is not complex, convert to complex
272276
copy_flag = True
273277
if dtype in [dpnp.float16, dpnp.float32]:
@@ -279,8 +283,6 @@ def _copy_array(x, complex_input):
279283
# float32 or float64 depending on device capabilities
280284
copy_flag = True
281285
dtype = map_dtype_to_device(dpnp.float64, x.sycl_device)
282-
else:
283-
copy_flag = False
284286

285287
if copy_flag:
286288
x_copy = dpnp.empty_like(x, dtype=dtype, order="C")

tests/test_fft.py

+10
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,16 @@ def test_fft_validate_out(self):
379379
out = dpnp.empty((10,), dtype=dpnp.float32)
380380
assert_raises(TypeError, dpnp.fft.fft, a, out=out)
381381

382+
@pytest.mark.parametrize(
383+
"dtype", get_all_dtypes(no_none=True, no_bool=True)
384+
)
385+
def test_negative_stride(self, dtype):
386+
a = dpnp.arange(10, dtype=dtype)
387+
result = dpnp.fft.fft(a[::-1])
388+
expected = numpy.fft.fft(a.asnumpy()[::-1])
389+
390+
assert_dtype_allclose(result, expected, check_only_type_kind=True)
391+
382392

383393
class TestFft2:
384394
def setup_method(self):

0 commit comments

Comments
 (0)