Skip to content

Commit

Permalink
BUG: fftpack: fix data overwriting in FFT routines (#1353)
Browse files Browse the repository at this point in the history
The _fix_shape helper routine in some cases returns slices of the input
array, which does not create copies. In those cases, one should not set
overwrite_x=1.
  • Loading branch information
pv committed Jan 31, 2011
1 parent 5f4860a commit 3ea2016
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions scipy/fftpack/basic.py
Expand Up @@ -113,23 +113,23 @@ def _fix_shape(x, n, axis):
index = [slice(None)]*len(s)
index[axis] = slice(0,n)
x = x[index]
return x, False
else:
index = [slice(None)]*len(s)
index[axis] = slice(0,s[axis])
s[axis] = n
z = zeros(s,x.dtype.char)
z[index] = x
x = z
return x
return z, True


def _raw_fft(x, n, axis, direction, overwrite_x, work_function):
""" Internal auxiliary function for fft, ifft, rfft, irfft."""
if n is None:
n = x.shape[axis]
elif n != x.shape[axis]:
x = _fix_shape(x,n,axis)
overwrite_x = 1
x, copy_made = _fix_shape(x,n,axis)
overwrite_x = overwrite_x or copy_made
if axis == -1 or axis == len(x.shape)-1:
r = work_function(x,n,direction,overwrite_x=overwrite_x)
else:
Expand Down Expand Up @@ -208,8 +208,8 @@ def fft(x, n=None, axis=-1, overwrite_x=0):
if n is None:
n = tmp.shape[axis]
elif n != tmp.shape[axis]:
tmp = _fix_shape(tmp,n,axis)
overwrite_x = 1
tmp, copy_made = _fix_shape(tmp,n,axis)
overwrite_x = overwrite_x or copy_made

if axis == -1 or axis == len(tmp.shape) - 1:
return work_function(tmp,n,1,0,overwrite_x)
Expand Down Expand Up @@ -261,8 +261,8 @@ def ifft(x, n=None, axis=-1, overwrite_x=0):
if n is None:
n = tmp.shape[axis]
elif n != tmp.shape[axis]:
tmp = _fix_shape(tmp,n,axis)
overwrite_x = 1
tmp, copy_made = _fix_shape(tmp,n,axis)
overwrite_x = overwrite_x or copy_made

if axis == -1 or axis == len(tmp.shape) - 1:
return work_function(tmp,n,-1,1,overwrite_x)
Expand Down Expand Up @@ -379,7 +379,7 @@ def _raw_fftnd(x, s, axes, direction, overwrite_x, work_function):
# No need to swap axes, array is in C order
if noaxes:
for i in axes:
x = _fix_shape(x, s[i], i)
x, copy_made = _fix_shape(x, s[i], i)
#print x.shape, s
return work_function(x,s,direction,overwrite_x=overwrite_x)

Expand All @@ -403,7 +403,7 @@ def _raw_fftnd(x, s, axes, direction, overwrite_x, work_function):
shape[waxes] = s

for i in range(len(waxes)):
x = _fix_shape(x, s[i], waxes[i])
x, copy_made = _fix_shape(x, s[i], waxes[i])

r = work_function(x, shape, direction, overwrite_x=overwrite_x)

Expand Down

0 comments on commit 3ea2016

Please sign in to comment.