Skip to content

Commit 85adb10

Browse files
committed
test_function_base imports (and fails all around)
1 parent 44462a0 commit 85adb10

File tree

2 files changed

+34
-24
lines changed

2 files changed

+34
-24
lines changed

torch_np/testing/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
assert_allclose,
55
assert_almost_equal,
66
assert_array_equal,
7+
assert_array_almost_equal,
8+
assert_raises_regex,
9+
suppress_warnings,
710
assert_equal,
811
assert_warns,
912
)

torch_np/tests/numpy_tests/lib/test_function_base.py

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,28 @@
1010
import hypothesis.strategies as st
1111

1212

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
1918
)
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
2126
from numpy.random import rand
27+
2228
from numpy.lib import (
2329
add_newdoc_ufunc, angle, average, bartlett, blackman, corrcoef, cov,
2430
delete, diff, digitize, extract, flipud, gradient, hamming, hanning,
2531
i0, insert, interp, kaiser, meshgrid, msort, piecewise, place, rot90,
2632
select, setxor1d, sinc, trapz, trim_zeros, unwrap, unique, vectorize
2733
)
28-
from numpy.core.numeric import normalize_axis_tuple
34+
from torch_np._util import normalize_axis_tuple
2935

3036

3137
def get_mat(n):
@@ -644,8 +650,8 @@ class TestCumsum:
644650
def test_basic(self):
645651
ba = [1, 2, 10, 11, 6, 5, 4]
646652
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,
649655
np.complex128]:
650656
a = np.array(ba, ctype)
651657
a2 = np.array(ba2, ctype)
@@ -667,7 +673,7 @@ class TestProd:
667673
def test_basic(self):
668674
ba = [1, 2, 10, 11, 6, 5, 4]
669675
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,
671677
np.float32, np.float64, np.complex64, np.complex128]:
672678
a = np.array(ba, ctype)
673679
a2 = np.array(ba2, ctype)
@@ -687,7 +693,7 @@ class TestCumprod:
687693
def test_basic(self):
688694
ba = [1, 2, 10, 11, 6, 5, 4]
689695
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,
691697
np.float32, np.float64, np.complex64, np.complex128]:
692698
a = np.array(ba, ctype)
693699
a2 = np.array(ba2, ctype)
@@ -1183,8 +1189,7 @@ def test_values(self):
11831189
assert_raises(ValueError, gradient, np.arange(1), edge_order=2)
11841190
assert_raises(ValueError, gradient, np.arange(2), edge_order=2)
11851191

1186-
@pytest.mark.parametrize('f_dtype', [np.uint8, np.uint16,
1187-
np.uint32, np.uint64])
1192+
@pytest.mark.parametrize('f_dtype', [np.uint8, ])
11881193
def test_f_decreasing_unsigned_int(self, f_dtype):
11891194
f = np.array([5, 4, 3, 2, 1], dtype=f_dtype)
11901195
g = gradient(f)
@@ -1199,8 +1204,7 @@ def test_f_signed_int_big_jump(self, f_dtype):
11991204
dfdx = gradient(f, x)
12001205
assert_array_equal(dfdx, [(maxint + 1) // 2]*2)
12011206

1202-
@pytest.mark.parametrize('x_dtype', [np.uint8, np.uint16,
1203-
np.uint32, np.uint64])
1207+
@pytest.mark.parametrize('x_dtype', [np.uint8, ])
12041208
def test_x_decreasing_unsigned(self, x_dtype):
12051209
x = np.array([3, 2, 1], dtype=x_dtype)
12061210
f = np.array([0, 2, 4])
@@ -1249,7 +1253,7 @@ class TestTrimZeros:
12491253
a = np.array([0, 0, 1, 0, 2, 3, 4, 0])
12501254
b = a.astype(float)
12511255
c = a.astype(complex)
1252-
d = a.astype(object)
1256+
# d = a.astype(object)
12531257

12541258
def values(self):
12551259
attr_names = ('a', 'b', 'c', 'd')
@@ -1291,9 +1295,9 @@ def test_size_zero(self):
12911295
@pytest.mark.parametrize(
12921296
'arr',
12931297
[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+
])
12971301
def test_overflow(self, arr):
12981302
slc = np.s_[1:2]
12991303
res = trim_zeros(arr)
@@ -1358,6 +1362,7 @@ def _foo2(x, y=1.0, z=0.0):
13581362
return y*math.floor(x) + z
13591363

13601364

1365+
@pytest.mark.skip(reason='vectorize not implemented')
13611366
class TestVectorize:
13621367

13631368
def test_simple(self):
@@ -1596,6 +1601,7 @@ def test_otypes(self):
15961601
x = np.arange(5)
15971602
assert_array_equal(f(x), x)
15981603

1604+
@pytest.mark.skip(reason='no _parse_gufunc_signature')
15991605
def test_parse_gufunc_signature(self):
16001606
assert_equal(nfb._parse_gufunc_signature('(x)->()'), ([('x',)], [()]))
16011607
assert_equal(nfb._parse_gufunc_signature('(x,y)->()'),
@@ -2238,7 +2244,7 @@ def test_extreme(self):
22382244
assert_array_almost_equal(c, np.array([[1., -1.], [-1., 1.]]))
22392245
assert_(np.all(np.abs(c) <= 1.0))
22402246

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])
22422248
def test_corrcoef_dtype(self, test_type):
22432249
cast_A = self.A.astype(test_type)
22442250
res = corrcoef(cast_A, dtype=test_type)
@@ -2344,7 +2350,7 @@ def test_unit_fweights_and_aweights(self):
23442350
aweights=self.unit_weights),
23452351
self.res1)
23462352

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])
23482354
def test_cov_dtype(self, test_type):
23492355
cast_x1 = self.x1.astype(test_type)
23502356
res = cov(cast_x1, dtype=test_type)
@@ -3005,8 +3011,7 @@ def test_linear_nan_1D(self, dtype):
30053011
] + [(np.float16, np.float16),
30063012
(np.float32, np.float32),
30073013
(np.float64, np.float64),
3008-
(np.longdouble, np.longdouble),
3009-
(np.dtype("O"), np.float64)]
3014+
]
30103015

30113016
@pytest.mark.parametrize(["input_dtype", "expected_dtype"], H_F_TYPE_CODES)
30123017
@pytest.mark.parametrize(["method", "expected"],
@@ -3566,6 +3571,7 @@ def test_quantile_monotonic(self, method):
35663571
quantile = np.quantile([0., 1., 2., 3.], p0, method=method)
35673572
assert_equal(np.sort(quantile), quantile)
35683573

3574+
@pytest.mark.skip(reason='no hypothesis')
35693575
@hypothesis.given(
35703576
arr=arrays(dtype=np.float64,
35713577
shape=st.integers(min_value=3, max_value=1000),
@@ -3584,6 +3590,7 @@ def test_quantile_scalar_nan(self):
35843590
assert_equal(np.quantile(a, 0.5), np.nan)
35853591

35863592

3593+
@pytest.mark.skip(reason='no hypothesis')
35873594
class TestLerp:
35883595
@hypothesis.given(t0=st.floats(allow_nan=False, allow_infinity=False,
35893596
min_value=0, max_value=1),

0 commit comments

Comments
 (0)