10
10
import hypothesis .strategies as st
11
11
12
12
13
- import numpy as np
14
- from numpy import ma
15
- from numpy .testing import (
16
- assert_ , assert_equal , assert_array_equal , assert_almost_equal ,
17
- assert_array_almost_equal , assert_raises , assert_allclose , IS_PYPY ,
18
- assert_warns , assert_raises_regex , suppress_warnings , HAS_REFCOUNT , IS_WASM
13
+ import torch_np as np
14
+ # from numpy import ma
15
+ from torch_np .testing import (assert_ , assert_equal , assert_array_equal , assert_almost_equal ,
16
+ assert_array_almost_equal , assert_allclose , # IS_PYPY,
17
+ assert_warns , assert_raises_regex , suppress_warnings , # HAS_REFCOUNT, IS_WASM
19
18
)
20
- import numpy .lib .function_base as nfb
19
+ from pytest import raises as assert_raises
20
+
21
+ HAS_REFCOUNT = True
22
+ IS_WASM = False
23
+ IS_PYPY = False
24
+
25
+ import numpy .lib .function_base as nfb # FIXME: remove
21
26
from numpy .random import rand
27
+
22
28
from numpy .lib import (
23
29
add_newdoc_ufunc , angle , average , bartlett , blackman , corrcoef , cov ,
24
30
delete , diff , digitize , extract , flipud , gradient , hamming , hanning ,
25
31
i0 , insert , interp , kaiser , meshgrid , msort , piecewise , place , rot90 ,
26
32
select , setxor1d , sinc , trapz , trim_zeros , unwrap , unique , vectorize
27
33
)
28
- from numpy . core . numeric import normalize_axis_tuple
34
+ from torch_np . _util import normalize_axis_tuple
29
35
30
36
31
37
def get_mat (n ):
@@ -644,8 +650,8 @@ class TestCumsum:
644
650
def test_basic (self ):
645
651
ba = [1 , 2 , 10 , 11 , 6 , 5 , 4 ]
646
652
ba2 = [[1 , 2 , 3 , 4 ], [5 , 6 , 7 , 9 ], [10 , 3 , 4 , 5 ]]
647
- for ctype in [np .int8 , np .uint8 , np .int16 , np .uint16 , np . int32 ,
648
- np .uint32 , np . float32 , np .float64 , np .complex64 ,
653
+ for ctype in [np .int8 , np .uint8 , np .int16 , np .int32 ,
654
+ np .float32 , np .float64 , np .complex64 ,
649
655
np .complex128 ]:
650
656
a = np .array (ba , ctype )
651
657
a2 = np .array (ba2 , ctype )
@@ -667,7 +673,7 @@ class TestProd:
667
673
def test_basic (self ):
668
674
ba = [1 , 2 , 10 , 11 , 6 , 5 , 4 ]
669
675
ba2 = [[1 , 2 , 3 , 4 ], [5 , 6 , 7 , 9 ], [10 , 3 , 4 , 5 ]]
670
- for ctype in [np .int16 , np .uint16 , np . int32 , np . uint32 ,
676
+ for ctype in [np .int16 , np .int32 ,
671
677
np .float32 , np .float64 , np .complex64 , np .complex128 ]:
672
678
a = np .array (ba , ctype )
673
679
a2 = np .array (ba2 , ctype )
@@ -687,7 +693,7 @@ class TestCumprod:
687
693
def test_basic (self ):
688
694
ba = [1 , 2 , 10 , 11 , 6 , 5 , 4 ]
689
695
ba2 = [[1 , 2 , 3 , 4 ], [5 , 6 , 7 , 9 ], [10 , 3 , 4 , 5 ]]
690
- for ctype in [np .int16 , np .uint16 , np . int32 , np . uint32 ,
696
+ for ctype in [np .int16 , np .int32 ,
691
697
np .float32 , np .float64 , np .complex64 , np .complex128 ]:
692
698
a = np .array (ba , ctype )
693
699
a2 = np .array (ba2 , ctype )
@@ -1183,8 +1189,7 @@ def test_values(self):
1183
1189
assert_raises (ValueError , gradient , np .arange (1 ), edge_order = 2 )
1184
1190
assert_raises (ValueError , gradient , np .arange (2 ), edge_order = 2 )
1185
1191
1186
- @pytest .mark .parametrize ('f_dtype' , [np .uint8 , np .uint16 ,
1187
- np .uint32 , np .uint64 ])
1192
+ @pytest .mark .parametrize ('f_dtype' , [np .uint8 , ])
1188
1193
def test_f_decreasing_unsigned_int (self , f_dtype ):
1189
1194
f = np .array ([5 , 4 , 3 , 2 , 1 ], dtype = f_dtype )
1190
1195
g = gradient (f )
@@ -1199,8 +1204,7 @@ def test_f_signed_int_big_jump(self, f_dtype):
1199
1204
dfdx = gradient (f , x )
1200
1205
assert_array_equal (dfdx , [(maxint + 1 ) // 2 ]* 2 )
1201
1206
1202
- @pytest .mark .parametrize ('x_dtype' , [np .uint8 , np .uint16 ,
1203
- np .uint32 , np .uint64 ])
1207
+ @pytest .mark .parametrize ('x_dtype' , [np .uint8 , ])
1204
1208
def test_x_decreasing_unsigned (self , x_dtype ):
1205
1209
x = np .array ([3 , 2 , 1 ], dtype = x_dtype )
1206
1210
f = np .array ([0 , 2 , 4 ])
@@ -1249,7 +1253,7 @@ class TestTrimZeros:
1249
1253
a = np .array ([0 , 0 , 1 , 0 , 2 , 3 , 4 , 0 ])
1250
1254
b = a .astype (float )
1251
1255
c = a .astype (complex )
1252
- d = a .astype (object )
1256
+ # d = a.astype(object)
1253
1257
1254
1258
def values (self ):
1255
1259
attr_names = ('a' , 'b' , 'c' , 'd' )
@@ -1291,9 +1295,9 @@ def test_size_zero(self):
1291
1295
@pytest .mark .parametrize (
1292
1296
'arr' ,
1293
1297
[np .array ([0 , 2 ** 62 , 0 ]),
1294
- np .array ([0 , 2 ** 63 , 0 ]),
1295
- np .array ([0 , 2 ** 64 , 0 ])]
1296
- )
1298
+ # np.array([0, 2**63, 0]), # FIXME
1299
+ # np.array([0, 2**64, 0])
1300
+ ] )
1297
1301
def test_overflow (self , arr ):
1298
1302
slc = np .s_ [1 :2 ]
1299
1303
res = trim_zeros (arr )
@@ -1358,6 +1362,7 @@ def _foo2(x, y=1.0, z=0.0):
1358
1362
return y * math .floor (x ) + z
1359
1363
1360
1364
1365
+ @pytest .mark .skip (reason = 'vectorize not implemented' )
1361
1366
class TestVectorize :
1362
1367
1363
1368
def test_simple (self ):
@@ -1596,6 +1601,7 @@ def test_otypes(self):
1596
1601
x = np .arange (5 )
1597
1602
assert_array_equal (f (x ), x )
1598
1603
1604
+ @pytest .mark .skip (reason = 'no _parse_gufunc_signature' )
1599
1605
def test_parse_gufunc_signature (self ):
1600
1606
assert_equal (nfb ._parse_gufunc_signature ('(x)->()' ), ([('x' ,)], [()]))
1601
1607
assert_equal (nfb ._parse_gufunc_signature ('(x,y)->()' ),
@@ -2238,7 +2244,7 @@ def test_extreme(self):
2238
2244
assert_array_almost_equal (c , np .array ([[1. , - 1. ], [- 1. , 1. ]]))
2239
2245
assert_ (np .all (np .abs (c ) <= 1.0 ))
2240
2246
2241
- @pytest .mark .parametrize ("test_type" , [np .half , np .single , np .double , np . longdouble ])
2247
+ @pytest .mark .parametrize ("test_type" , [np .half , np .single , np .double ])
2242
2248
def test_corrcoef_dtype (self , test_type ):
2243
2249
cast_A = self .A .astype (test_type )
2244
2250
res = corrcoef (cast_A , dtype = test_type )
@@ -2344,7 +2350,7 @@ def test_unit_fweights_and_aweights(self):
2344
2350
aweights = self .unit_weights ),
2345
2351
self .res1 )
2346
2352
2347
- @pytest .mark .parametrize ("test_type" , [np .half , np .single , np .double , np . longdouble ])
2353
+ @pytest .mark .parametrize ("test_type" , [np .half , np .single , np .double ])
2348
2354
def test_cov_dtype (self , test_type ):
2349
2355
cast_x1 = self .x1 .astype (test_type )
2350
2356
res = cov (cast_x1 , dtype = test_type )
@@ -3005,8 +3011,7 @@ def test_linear_nan_1D(self, dtype):
3005
3011
] + [(np .float16 , np .float16 ),
3006
3012
(np .float32 , np .float32 ),
3007
3013
(np .float64 , np .float64 ),
3008
- (np .longdouble , np .longdouble ),
3009
- (np .dtype ("O" ), np .float64 )]
3014
+ ]
3010
3015
3011
3016
@pytest .mark .parametrize (["input_dtype" , "expected_dtype" ], H_F_TYPE_CODES )
3012
3017
@pytest .mark .parametrize (["method" , "expected" ],
@@ -3566,6 +3571,7 @@ def test_quantile_monotonic(self, method):
3566
3571
quantile = np .quantile ([0. , 1. , 2. , 3. ], p0 , method = method )
3567
3572
assert_equal (np .sort (quantile ), quantile )
3568
3573
3574
+ @pytest .mark .skip (reason = 'no hypothesis' )
3569
3575
@hypothesis .given (
3570
3576
arr = arrays (dtype = np .float64 ,
3571
3577
shape = st .integers (min_value = 3 , max_value = 1000 ),
@@ -3584,6 +3590,7 @@ def test_quantile_scalar_nan(self):
3584
3590
assert_equal (np .quantile (a , 0.5 ), np .nan )
3585
3591
3586
3592
3593
+ @pytest .mark .skip (reason = 'no hypothesis' )
3587
3594
class TestLerp :
3588
3595
@hypothesis .given (t0 = st .floats (allow_nan = False , allow_infinity = False ,
3589
3596
min_value = 0 , max_value = 1 ),
0 commit comments