Skip to content

Commit 4e3b7d5

Browse files
fix for issue 29
1 parent b93acc6 commit 4e3b7d5

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

mkl_fft/src/mklfft.c.src

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,20 +287,27 @@ __cached_notinplace_@DftiCompute_MODE@_@MKL_IN_TYPE@_@MKL_OUT_TYPE@(
287287
/**end repeat**/
288288

289289
/*
290-
* For an array, iterating though indexes [i1, i2), fixing others to zero,
290+
* For an array, iterating though indexes [i1, i2], fixing others to zero,
291291
* and _assuming_ these pointers form a regular lattice, compute distance
292292
* between adjacent pointers on that lattice.
293293
*
294294
*/
295295
static NPY_INLINE MKL_LONG
296296
compute_distance(npy_intp *x_strides, npy_intp *x_shape, npy_intp x_itemsize, int x_rank, int i1, int i2, int c_contig, int f_contig) {
297297

298+
/* i1 equals (axis == 0), hence if (i1) {...} is equivalent to if (axis == 0) {...} */
298299
if (c_contig) {
300+
/* Assuming
301+
x_strides == (x_itemsize * prod(x_shape[k], 0 <k <= x_rank-1), ..., x_itemsize * x_shape[x_rank-1], x_itemsize)
302+
*/
299303
return (i1) ? 1 : _to_mkl_long(x_shape[x_rank-1]);
300304
}
301305

302306
if (f_contig) {
303-
return (i1) ? _to_mkl_long(x_shape[x_rank-1]) : 1;
307+
/* Assuming
308+
x_strides == (x_itemsize, x_itemsize * x_shape[0], ..., x_itemsize * prod(x_shape[k], 0<=k < x_rank-1))
309+
*/
310+
return (i1) ? _to_mkl_long(x_shape[0]) : 1;
304311
}
305312

306313
/* Right now, this is dead branch of code, since compute_distance is only called if array is ONESEGMENT,

mkl_fft/tests/test_fft1d.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,17 @@ def test_array5(self):
324324
f2 = mkl_fft.fft(z1.reshape(z1.shape), axis=-1)
325325
assert_allclose(f1, f2, atol=2e-15)
326326

327+
def test_array6(self):
328+
"""Inputs with Fortran layout are handled correctly, issue 29"""
329+
z = self.az3
330+
z = z.astype(z.dtype, order='F')
331+
y1 = mkl_fft.fft(z, axis=0)
332+
y2 = mkl_fft.fft(self.az3, axis=0)
333+
assert_allclose(y1, y2, atol=2e-15)
334+
y1 = mkl_fft.fft(z, axis=-1)
335+
y2 = mkl_fft.fft(self.az3, axis=-1)
336+
assert_allclose(y1, y2, atol=2e-15)
337+
327338

328339
class Test_mklfft_rfft(TestCase):
329340
def setUp(self):

mkl_fft/tests/test_fftnd.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ def test_cf_contig(self):
115115
r_tol, a_tol = _get_rtol_atol(ar)
116116
d_ccont = ar.copy()
117117
d_fcont = np.asfortranarray(d_ccont)
118-
f1 = mkl_fft.fft(d_ccont)
119-
f2 = mkl_fft.fft(d_fcont)
120-
assert_allclose(f1, f2, rtol=r_tol, atol=a_tol)
118+
for a in range(ar.ndim):
119+
f1 = mkl_fft.fft(d_ccont, axis=a)
120+
f2 = mkl_fft.fft(d_fcont, axis=a)
121+
assert_allclose(f1, f2, rtol=r_tol, atol=a_tol)

0 commit comments

Comments
 (0)