@@ -19,16 +19,17 @@ def fft1(x):
19
19
return np .sum (x * np .exp (phase ), axis = 1 )
20
20
21
21
22
- @pytest .mark .xfail (reason = 'TODO' )
23
22
class TestFFTShift :
24
23
25
24
def test_fft_n (self ):
26
- assert_raises (ValueError , np .fft .fft , [1 , 2 , 3 ], 0 )
25
+ assert_raises (( ValueError , RuntimeError ) , np .fft .fft , [1 , 2 , 3 ], 0 )
27
26
28
27
29
- @pytest .mark .xfail (reason = 'TODO' )
30
28
class TestFFT1D :
31
29
30
+ def setup_method (self ):
31
+ np .random .seed (123456 )
32
+
32
33
def test_identity (self ):
33
34
maxlen = 512
34
35
x = random (maxlen ) + 1j * random (maxlen )
@@ -40,13 +41,15 @@ def test_identity(self):
40
41
xr [0 :i ], atol = 1e-12 )
41
42
42
43
def test_fft (self ):
44
+
45
+ np .random .seed (1234 )
43
46
x = random (30 ) + 1j * random (30 )
44
- assert_allclose (fft1 (x ), np .fft .fft (x ), atol = 1e-6 )
45
- assert_allclose (fft1 (x ), np .fft .fft (x , norm = "backward" ), atol = 1e-6 )
47
+ assert_allclose (fft1 (x ), np .fft .fft (x ), atol = 2e-5 )
48
+ assert_allclose (fft1 (x ), np .fft .fft (x , norm = "backward" ), atol = 2e-5 )
46
49
assert_allclose (fft1 (x ) / np .sqrt (30 ),
47
- np .fft .fft (x , norm = "ortho" ), atol = 1e -6 )
50
+ np .fft .fft (x , norm = "ortho" ), atol = 5e -6 )
48
51
assert_allclose (fft1 (x ) / 30. ,
49
- np .fft .fft (x , norm = "forward" ), atol = 1e -6 )
52
+ np .fft .fft (x , norm = "forward" ), atol = 5e -6 )
50
53
51
54
@pytest .mark .parametrize ('norm' , (None , 'backward' , 'ortho' , 'forward' ))
52
55
def test_ifft (self , norm ):
@@ -55,8 +58,8 @@ def test_ifft(self, norm):
55
58
x , np .fft .ifft (np .fft .fft (x , norm = norm ), norm = norm ),
56
59
atol = 1e-6 )
57
60
# Ensure we get the correct error message
58
- with pytest .raises (ValueError ,
59
- match = 'Invalid number of FFT data points' ):
61
+ with pytest .raises (( ValueError , RuntimeError ) ,
62
+ match = 'Invalid number of data points' ):
60
63
np .fft .ifft ([], norm = norm )
61
64
62
65
def test_fft2 (self ):
@@ -175,7 +178,7 @@ def test_irfftn(self):
175
178
def test_hfft (self ):
176
179
x = random (14 ) + 1j * random (14 )
177
180
x_herm = np .concatenate ((random (1 ), x , random (1 )))
178
- x = np .concatenate ((x_herm , x [:: - 1 ] .conj ()))
181
+ x = np .concatenate ((x_herm , np . flip ( x ) .conj ()))
179
182
assert_allclose (np .fft .fft (x ), np .fft .hfft (x_herm ), atol = 1e-6 )
180
183
assert_allclose (np .fft .hfft (x_herm ),
181
184
np .fft .hfft (x_herm , norm = "backward" ), atol = 1e-6 )
@@ -187,7 +190,7 @@ def test_hfft(self):
187
190
def test_ihfft (self ):
188
191
x = random (14 ) + 1j * random (14 )
189
192
x_herm = np .concatenate ((random (1 ), x , random (1 )))
190
- x = np .concatenate ((x_herm , x [:: - 1 ] .conj ()))
193
+ x = np .concatenate ((x_herm , np . flip ( x ) .conj ()))
191
194
assert_allclose (x_herm , np .fft .ihfft (np .fft .hfft (x_herm )), atol = 1e-6 )
192
195
assert_allclose (x_herm , np .fft .ihfft (np .fft .hfft (x_herm ,
193
196
norm = "backward" ), norm = "backward" ), atol = 1e-6 )
@@ -234,7 +237,6 @@ def test_dtypes(self, dtype):
234
237
assert_allclose (np .fft .irfft (np .fft .rfft (x )), x , atol = 1e-6 )
235
238
236
239
237
- @pytest .mark .xfail (reason = 'TODO' )
238
240
@pytest .mark .parametrize (
239
241
"dtype" ,
240
242
[np .float32 , np .float64 , np .complex64 , np .complex128 ])
@@ -246,16 +248,20 @@ def test_dtypes(self, dtype):
246
248
def test_fft_with_order (dtype , order , fft ):
247
249
# Check that FFT/IFFT produces identical results for C, Fortran and
248
250
# non contiguous arrays
249
- rng = np .random .RandomState (42 )
250
- X = rng .rand (8 , 7 , 13 ).astype (dtype , copy = False )
251
+ # rng = np.random.RandomState(42)
252
+ rng = np .random
253
+ X = rng .rand (8 , 7 , 13 ).astype (dtype ) #, copy=False)
251
254
# See discussion in pull/14178
252
- _tol = 8.0 * np .sqrt (np .log2 (X .size )) * np .finfo (X .dtype ).eps
255
+ _tol = float ( 8.0 * np .sqrt (np .log2 (X .size )) * np .finfo (X .dtype ).eps )
253
256
if order == 'F' :
257
+ pytest .skip ("Fortran order arrays" )
254
258
Y = np .asfortranarray (X )
255
259
else :
256
260
# Make a non contiguous array
257
- Y = X [::- 1 ]
258
- X = np .ascontiguousarray (X [::- 1 ])
261
+ Z = np .empty ((16 , 7 , 13 ), dtype = X .dtype )
262
+ Z [::2 ] = X
263
+ Y = Z [::2 ]
264
+ X = Y .copy ()
259
265
260
266
if fft .__name__ .endswith ('fft' ):
261
267
for axis in range (3 ):
@@ -274,7 +280,6 @@ def test_fft_with_order(dtype, order, fft):
274
280
raise ValueError ()
275
281
276
282
277
- @pytest .mark .xfail (reason = 'TODO' )
278
283
@pytest .mark .skipif (IS_WASM , reason = "Cannot start thread" )
279
284
class TestFFTThreadSafe :
280
285
threads = 16
0 commit comments