Skip to content

Commit 44a4b7a

Browse files
Fix insidious issue where 1D complex and real transforms of C-contiguous and F-contiguous arrays of array rank > 2 holding the same data would differ.
The discrepancy comes from attempt to formulate 1D transform over such arrays as a single call to DftiCompute on equidistant vectors. For this to work, in out-of-place mode, both input and output must both be either C-contiguous or F-contiguous. Previously the output was always allocated as C-contiguous empty blob.
1 parent 069ced6 commit 44a4b7a

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

mkl_fft/_pydfti.pyx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def ifft(x, n=None, axis=-1, overwrite_x=False):
124124
cdef cnp.ndarray pad_array(cnp.ndarray x_arr, cnp.npy_intp n, int axis, int realQ):
125125
"Internal utility to zero-pad input array along given axis"
126126
cdef cnp.ndarray b_arr "b_arrayObject"
127-
cdef int x_type, b_type, b_ndim
127+
cdef int x_type, b_type, b_ndim, x_arr_is_fortran
128128
cdef cnp.npy_intp *b_shape
129129

130130
x_type = cnp.PyArray_TYPE(x_arr)
@@ -140,8 +140,9 @@ cdef cnp.ndarray pad_array(cnp.ndarray x_arr, cnp.npy_intp n, int axis, int real
140140
b_shape[axis] = n
141141

142142
# allocating temporary buffer
143+
x_arr_is_fortran = cnp.PyArray_CHKFLAGS(x_arr, cnp.NPY_F_CONTIGUOUS)
143144
b_arr = <cnp.ndarray> cnp.PyArray_EMPTY(
144-
b_ndim, b_shape, <cnp.NPY_TYPES> b_type, 0) # 0 for C-contiguous
145+
b_ndim, b_shape, <cnp.NPY_TYPES> b_type, x_arr_is_fortran) # 0 for C-contiguous
145146
PyMem_Free(b_shape)
146147

147148
ind = [slice(0, None, None), ] * b_ndim
@@ -227,6 +228,7 @@ cdef cnp.ndarray __allocate_result(cnp.ndarray x_arr, long n_, long axis_, int f
227228
"""
228229
cdef cnp.npy_intp *f_shape
229230
cdef cnp.ndarray f_arr "ff_arrayObject"
231+
cdef int x_arr_is_fortran
230232

231233
f_ndim = cnp.PyArray_NDIM(x_arr)
232234

@@ -237,8 +239,9 @@ cdef cnp.ndarray __allocate_result(cnp.ndarray x_arr, long n_, long axis_, int f
237239
f_shape[axis_] = n_
238240

239241
# allocating output buffer
242+
x_arr_is_fortran = cnp.PyArray_CHKFLAGS(x_arr, cnp.NPY_F_CONTIGUOUS)
240243
f_arr = <cnp.ndarray> cnp.PyArray_EMPTY(
241-
f_ndim, f_shape, <cnp.NPY_TYPES> f_type, 0) # 0 for C-contiguous
244+
f_ndim, f_shape, <cnp.NPY_TYPES> f_type, x_arr_is_fortran) # 0 for C-contiguous
242245
PyMem_Free(f_shape);
243246

244247
return f_arr

0 commit comments

Comments
 (0)