From 21ef9d43d9c3d2d1435b37a17b9035ab75487fba Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Thu, 19 Apr 2018 08:32:15 -0500 Subject: [PATCH 1/2] MAINT: numpy.core.multiarray_tests was renamed NumPy has renamed `numpy.core.multiarray_tests` to `numpy.core._multiarray_tests` in its master branch. Make code work with current development version of NumPy. --- mkl_fft/_pydfti.pyx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mkl_fft/_pydfti.pyx b/mkl_fft/_pydfti.pyx index d3d7b783..10f9e75d 100644 --- a/mkl_fft/_pydfti.pyx +++ b/mkl_fft/_pydfti.pyx @@ -26,7 +26,11 @@ import numpy as np cimport numpy as cnp -from numpy.core.multiarray_tests import internal_overlap +try: + from numpy.core.multiarray_tests import internal_overlap +except ModuleNotFoundError: + # Module has been renamed in NumPy 1.15 + from numpy.core._multiarray_tests import internal_overlap from libc.string cimport memcpy From d4cd3009a106e057d51a9e3111a3458c7b383fce Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Thu, 19 Apr 2018 13:06:01 -0500 Subject: [PATCH 2/2] BUG: Fixed issue #4 Because assignment `a[tind] = func(...)` amounts to overwriting data in array `a`, a copy is needed, if not already made. ```ipython In [1]: import numpy as np, mkl_fft In [2]: x = np.random.randn(4,4,4) In [3]: xc = x.copy() In [4]: y = mkl_fft._numpy_fft.rfftn(x) In [5]: yc = y.copy() In [6]: z = mkl_fft._numpy_fft.irfftn(y) In [7]: np.allclose(y, yc) Out[7]: True In [8]: np.allclose(z, x) Out[8]: True ``` --- mkl_fft/_pydfti.pyx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/mkl_fft/_pydfti.pyx b/mkl_fft/_pydfti.pyx index 10f9e75d..f594d4ab 100644 --- a/mkl_fft/_pydfti.pyx +++ b/mkl_fft/_pydfti.pyx @@ -105,12 +105,12 @@ cdef int _datacopied(cnp.ndarray arr, object orig): Strict check for `arr` not sharing any data with `original`, under the assumption that arr = asarray(original) """ - if arr is orig: - return 0 if not cnp.PyArray_Check(orig) and PyObject_HasAttrString(orig, '__array__'): return 0 + if isinstance(orig, np.ndarray) and (arr is ( orig)): + return 0 arr_obj = arr - return 1 if arr_obj.base is None else 0 + return 1 if (arr_obj.base is None) else 0 def fft(x, n=None, axis=-1, overwrite_x=False): @@ -812,7 +812,7 @@ def rfftn_numpy(x, s=None, axes=None): no_trim = (s is None) and (axes is None) s, axes = _cook_nd_args(a, s, axes) la = axes[-1] - # trim array, so that rfft_numpy avoid doing + # trim array, so that rfft_numpy avoids doing # unnecessary computations if not no_trim: a = _trim_array(a, s, axes) @@ -847,6 +847,10 @@ def irfftn_numpy(x, s=None, axes=None): a = _fix_dimensions(a, s, axes) ovr_x = True if _datacopied( a, x) else False if len(set(axes)) == len(axes) and len(axes) == a.ndim and len(axes) > 2: + # due to need to write into a, we must copy + if not ovr_x: + a = a.copy() + ovr_x = True ss, aa = _remove_axis(s, axes, la) ind = [slice(None,None,1),] * len(s) for ii in range(a.shape[la]): @@ -854,8 +858,7 @@ def irfftn_numpy(x, s=None, axes=None): tind = tuple(ind) a[tind] = _fftnd_impl( a[tind], shape=ss, axes=aa, - overwrite_x=ovr_x, direction=-1) - ovr_x = True + overwrite_x=True, direction=-1) else: for ii in range(len(axes)-1): a = ifft(a, s[ii], axes[ii], overwrite_x=ovr_x)