13
13
assert_ , assert_equal , assert_raises_regex ,
14
14
assert_array_equal , assert_almost_equal , assert_array_almost_equal ,
15
15
assert_warns , # assert_array_max_ulp, HAS_REFCOUNT, IS_WASM
16
+ assert_allclose ,
16
17
)
17
18
from numpy .core ._rational_tests import rational
18
19
@@ -2368,7 +2369,6 @@ def test_dtype_str_bytes(self, likefunc, dtype):
2368
2369
assert result .strides == (4 , 1 )
2369
2370
2370
2371
2371
- @pytest .mark .xfail (reason = "TODO" )
2372
2372
class TestCorrelate :
2373
2373
def _setup (self , dt ):
2374
2374
self .x = np .array ([1 , 2 , 3 , 4 , 5 ], dtype = dt )
@@ -2390,20 +2390,13 @@ def test_float(self):
2390
2390
assert_array_almost_equal (z , self .z1_4 )
2391
2391
z = np .correlate (self .y , self .x , 'full' )
2392
2392
assert_array_almost_equal (z , self .z2 )
2393
- z = np .correlate (self .x [:: - 1 ] , self .y , 'full' )
2393
+ z = np .correlate (np . flip ( self .x ) , self .y , 'full' )
2394
2394
assert_array_almost_equal (z , self .z1r )
2395
- z = np .correlate (self .y , self .x [:: - 1 ] , 'full' )
2395
+ z = np .correlate (self .y , np . flip ( self .x ) , 'full' )
2396
2396
assert_array_almost_equal (z , self .z2r )
2397
2397
z = np .correlate (self .xs , self .y , 'full' )
2398
2398
assert_array_almost_equal (z , self .zs )
2399
2399
2400
- def test_object (self ):
2401
- self ._setup (Decimal )
2402
- z = np .correlate (self .x , self .y , 'full' )
2403
- assert_array_almost_equal (z , self .z1 )
2404
- z = np .correlate (self .y , self .x , 'full' )
2405
- assert_array_almost_equal (z , self .z2 )
2406
-
2407
2400
def test_no_overwrite (self ):
2408
2401
d = np .ones (100 )
2409
2402
k = np .ones (3 )
@@ -2415,16 +2408,17 @@ def test_complex(self):
2415
2408
x = np .array ([1 , 2 , 3 , 4 + 1j ], dtype = complex )
2416
2409
y = np .array ([- 1 , - 2j , 3 + 1j ], dtype = complex )
2417
2410
r_z = np .array ([3 - 1j , 6 , 8 + 1j , 11 + 5j , - 5 + 8j , - 4 - 1j ], dtype = complex )
2418
- r_z = r_z [:: - 1 ] .conjugate ()
2411
+ r_z = np . flip ( r_z ) .conjugate ()
2419
2412
z = np .correlate (y , x , mode = 'full' )
2420
2413
assert_array_almost_equal (z , r_z )
2421
2414
2422
2415
def test_zero_size (self ):
2423
- with pytest .raises (ValueError ):
2416
+ with pytest .raises (( ValueError , RuntimeError ) ):
2424
2417
np .correlate (np .array ([]), np .ones (1000 ), mode = 'full' )
2425
- with pytest .raises (ValueError ):
2418
+ with pytest .raises (( ValueError , RuntimeError ) ):
2426
2419
np .correlate (np .ones (1000 ), np .array ([]), mode = 'full' )
2427
2420
2421
+ @pytest .mark .skip (reason = 'do not implement deprecated behavior' )
2428
2422
def test_mode (self ):
2429
2423
d = np .ones (100 )
2430
2424
k = np .ones (3 )
@@ -2441,7 +2435,6 @@ def test_mode(self):
2441
2435
np .correlate (d , k , mode = None )
2442
2436
2443
2437
2444
- @pytest .mark .xfail (reason = "TODO" )
2445
2438
class TestConvolve :
2446
2439
def test_object (self ):
2447
2440
d = [1. ] * 100
@@ -2455,6 +2448,7 @@ def test_no_overwrite(self):
2455
2448
assert_array_equal (d , np .ones (100 ))
2456
2449
assert_array_equal (k , np .ones (3 ))
2457
2450
2451
+ @pytest .mark .skip (reason = 'do not implement deprecated behavior' )
2458
2452
def test_mode (self ):
2459
2453
d = np .ones (100 )
2460
2454
k = np .ones (3 )
@@ -2470,6 +2464,16 @@ def test_mode(self):
2470
2464
with assert_raises (TypeError ):
2471
2465
np .convolve (d , k , mode = None )
2472
2466
2467
+ def test_numpy_doc_examples (self ):
2468
+ conv = np .convolve ([1 , 2 , 3 ], [0 , 1 , 0.5 ])
2469
+ assert_allclose (conv , [0. , 1. , 2.5 , 4. , 1.5 ], atol = 1e-15 )
2470
+
2471
+ conv = np .convolve ([1 , 2 , 3 ], [0 , 1 , 0.5 ], 'same' )
2472
+ assert_allclose (conv , [1. , 2.5 , 4. ], atol = 1e-15 )
2473
+
2474
+ conv = np .convolve ([1 , 2 , 3 ], [0 , 1 , 0.5 ], 'valid' )
2475
+ assert_allclose (conv , [2.5 ], atol = 1e-15 )
2476
+
2473
2477
2474
2478
class TestDtypePositional :
2475
2479
0 commit comments