Skip to content

Commit da618ee

Browse files
Fix unexpected behavior of fft call on clongdouble type on win32
clongdouble dtype on Windows is of the same size of cdouble dtype, hence attempt to convert array to cdouble type in PyArray_FROM_OTF does not change the typenum. The dispatch in mkl_fft assumes that typenum is either CDOUBLE or CFLOAT for complex inputs, and hence a gap. Set NPY_ENSURECOPY flag in the call to PyArray_FROM_OTF to ensure that coercion results in typenum precisely either CFLOAT or CDOUBLE.
1 parent 01e9cf9 commit da618ee

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

mkl_fft/_pydfti.pyx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ def _fft1d_impl(x, n=None, axis=-1, overwrite_arg=False, direction=+1, double fs
321321
# so we cast to complex double and operate in place
322322
try:
323323
x_arr = <cnp.ndarray> cnp.PyArray_FROM_OTF(
324-
x_arr, cnp.NPY_CDOUBLE, cnp.NPY_BEHAVED)
324+
x_arr, cnp.NPY_CDOUBLE, cnp.NPY_BEHAVED | cnp.NPY_ENSURECOPY)
325325
except:
326326
raise ValueError("First argument must be a complex or real sequence of single or double precision")
327327
x_type = cnp.PyArray_TYPE(x_arr)
@@ -545,7 +545,7 @@ def _rr_fft1d_impl2(x, n=None, axis=-1, overwrite_arg=False, double fsc=1.0):
545545
else:
546546
try:
547547
x_arr = <cnp.ndarray> cnp.PyArray_FROM_OTF(
548-
x_arr, cnp.NPY_DOUBLE, cnp.NPY_BEHAVED)
548+
x_arr, cnp.NPY_DOUBLE, cnp.NPY_BEHAVED | cnp.NPY_ENSURECOPY)
549549
except:
550550
raise TypeError("1st argument must be a real sequence")
551551
x_type = cnp.PyArray_TYPE(x_arr)
@@ -601,7 +601,7 @@ def _rr_ifft1d_impl2(x, n=None, axis=-1, overwrite_arg=False, double fsc=1.0):
601601
# so we cast to complex double and operate in place
602602
try:
603603
x_arr = <cnp.ndarray> cnp.PyArray_FROM_OTF(
604-
x_arr, cnp.NPY_DOUBLE, cnp.NPY_BEHAVED)
604+
x_arr, cnp.NPY_DOUBLE, cnp.NPY_BEHAVED | cnp.NPY_ENSURECOPY)
605605
except:
606606
raise ValueError("First argument should be a real or a complex sequence of single or double precision")
607607
x_type = cnp.PyArray_TYPE(x_arr)
@@ -669,7 +669,7 @@ def _rc_fft1d_impl(x, n=None, axis=-1, overwrite_arg=False, double fsc=1.0):
669669
else:
670670
# we must cast the input to doubles and allocate the output,
671671
try:
672-
requirement = cnp.NPY_BEHAVED
672+
requirement = cnp.NPY_BEHAVED | cnp.NPY_ENSURECOPY
673673
if x_type is cnp.NPY_LONGDOUBLE:
674674
requirement = requirement | cnp.NPY_FORCECAST
675675
x_arr = <cnp.ndarray> cnp.PyArray_FROM_OTF(

0 commit comments

Comments
 (0)