|
26 | 26 |
|
27 | 27 | import numpy as np |
28 | 28 | cimport numpy as cnp |
29 | | -from numpy.core.multiarray_tests import internal_overlap |
| 29 | +try: |
| 30 | + from numpy.core.multiarray_tests import internal_overlap |
| 31 | +except ModuleNotFoundError: |
| 32 | + # Module has been renamed in NumPy 1.15 |
| 33 | + from numpy.core._multiarray_tests import internal_overlap |
30 | 34 |
|
31 | 35 | from libc.string cimport memcpy |
32 | 36 |
|
@@ -101,12 +105,12 @@ cdef int _datacopied(cnp.ndarray arr, object orig): |
101 | 105 | Strict check for `arr` not sharing any data with `original`, |
102 | 106 | under the assumption that arr = asarray(original) |
103 | 107 | """ |
104 | | - if arr is orig: |
105 | | - return 0 |
106 | 108 | if not cnp.PyArray_Check(orig) and PyObject_HasAttrString(orig, '__array__'): |
107 | 109 | return 0 |
| 110 | + if isinstance(orig, np.ndarray) and (arr is (<cnp.ndarray> orig)): |
| 111 | + return 0 |
108 | 112 | arr_obj = <object> arr |
109 | | - return 1 if arr_obj.base is None else 0 |
| 113 | + return 1 if (arr_obj.base is None) else 0 |
110 | 114 |
|
111 | 115 |
|
112 | 116 | def fft(x, n=None, axis=-1, overwrite_x=False): |
@@ -808,7 +812,7 @@ def rfftn_numpy(x, s=None, axes=None): |
808 | 812 | no_trim = (s is None) and (axes is None) |
809 | 813 | s, axes = _cook_nd_args(a, s, axes) |
810 | 814 | la = axes[-1] |
811 | | - # trim array, so that rfft_numpy avoid doing |
| 815 | + # trim array, so that rfft_numpy avoids doing |
812 | 816 | # unnecessary computations |
813 | 817 | if not no_trim: |
814 | 818 | a = _trim_array(a, s, axes) |
@@ -843,15 +847,18 @@ def irfftn_numpy(x, s=None, axes=None): |
843 | 847 | a = _fix_dimensions(a, s, axes) |
844 | 848 | ovr_x = True if _datacopied(<cnp.ndarray> a, x) else False |
845 | 849 | if len(set(axes)) == len(axes) and len(axes) == a.ndim and len(axes) > 2: |
| 850 | + # due to need to write into a, we must copy |
| 851 | + if not ovr_x: |
| 852 | + a = a.copy() |
| 853 | + ovr_x = True |
846 | 854 | ss, aa = _remove_axis(s, axes, la) |
847 | 855 | ind = [slice(None,None,1),] * len(s) |
848 | 856 | for ii in range(a.shape[la]): |
849 | 857 | ind[la] = ii |
850 | 858 | tind = tuple(ind) |
851 | 859 | a[tind] = _fftnd_impl( |
852 | 860 | a[tind], shape=ss, axes=aa, |
853 | | - overwrite_x=ovr_x, direction=-1) |
854 | | - ovr_x = True |
| 861 | + overwrite_x=True, direction=-1) |
855 | 862 | else: |
856 | 863 | for ii in range(len(axes)-1): |
857 | 864 | a = ifft(a, s[ii], axes[ii], overwrite_x=ovr_x) |
|
0 commit comments