Skip to content

Commit 173bba6

Browse files
committed
Just delete tests which aren't even interesting to keep skip
1 parent 581917b commit 173bba6

File tree

1 file changed

+0
-319
lines changed

1 file changed

+0
-319
lines changed

torch_np/tests/numpy_tests/core/test_indexing.py

Lines changed: 0 additions & 319 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,6 @@ def test_empty_tuple_index(self):
122122
)
123123
assert_(isinstance(a[()], np.int_))
124124

125-
@pytest.mark.skip(reason="torch does not have an equivalent to np.void")
126-
def test_void_scalar_empty_tuple(self):
127-
s = np.zeros((), dtype='V4')
128-
assert_equal(s[()].dtype, s.dtype)
129-
assert_equal(s[()], s)
130-
assert_equal(type(s[...]), np.ndarray)
131-
132125
def test_same_kind_index_casting(self):
133126
# Indexes should be cast with same-kind and not safe, even if that
134127
# is somewhat unsafe. So test various different code paths.
@@ -248,21 +241,6 @@ def f(a, v):
248241
assert_raises((ValueError, RuntimeError), f, a, [1, 2, 3])
249242
assert_raises((ValueError, RuntimeError), f, a[:1], [1, 2, 3])
250243

251-
@pytest.mark.skip(reason="torch does not support object dtype")
252-
def test_boolean_assignment_needs_api(self):
253-
# See also gh-7666
254-
# This caused a segfault on Python 2 due to the GIL not being
255-
# held when the iterator does not need it, but the transfer function
256-
# does
257-
arr = np.zeros(1000)
258-
indx = np.zeros(1000, dtype=bool)
259-
indx[:100] = True
260-
arr[indx] = np.ones(100, dtype=object)
261-
262-
expected = np.zeros(1000)
263-
expected[:100] = 1
264-
assert_array_equal(arr, expected)
265-
266244
def test_boolean_indexing_twodim(self):
267245
# Indexing a 2-dimensional array with
268246
# 2-dimensional boolean array
@@ -388,43 +366,6 @@ def test_trivial_fancy_not_possible(self):
388366
res[3] = -1
389367
assert_array_equal(a, res)
390368

391-
@pytest.mark.skip(reason="torch does not support subclassing")
392-
def test_nonbaseclass_values(self):
393-
class SubClass(np.ndarray):
394-
def __array_finalize__(self, old):
395-
# Have array finalize do funny things
396-
self.fill(99)
397-
398-
a = np.zeros((5, 5))
399-
s = a.copy().view(type=SubClass)
400-
s.fill(1)
401-
402-
a[[0, 1, 2, 3, 4], :] = s
403-
assert_((a == 1).all())
404-
405-
# Subspace is last, so transposing might want to finalize
406-
a[:, [0, 1, 2, 3, 4]] = s
407-
assert_((a == 1).all())
408-
409-
a.fill(0)
410-
a[...] = s
411-
assert_((a == 1).all())
412-
413-
@pytest.mark.skip(reason="torch does not support subclassing")
414-
def test_array_like_values(self):
415-
# Similar to the above test, but use a memoryview instead
416-
a = np.zeros((5, 5))
417-
s = np.arange(25, dtype=np.float64).reshape(5, 5)
418-
419-
a[[0, 1, 2, 3, 4], :] = memoryview(s)
420-
assert_array_equal(a, s)
421-
422-
a[:, [0, 1, 2, 3, 4]] = memoryview(s)
423-
assert_array_equal(a, s)
424-
425-
a[...] = memoryview(s)
426-
assert_array_equal(a, s)
427-
428369
@pytest.mark.xfail(reason="XXX: recarray stuff is TBD")
429370
def test_subclass_writeable(self):
430371
d = np.rec.array([('NGC1001', 11), ('NGC1002', 1.), ('NGC1003', 1.)],
@@ -448,41 +389,6 @@ def test_memory_order(self):
448389
a = a.reshape(-1, 1)
449390
assert_(a[b, 0].flags.f_contiguous)
450391

451-
@pytest.mark.skip(reason="torch has no type distinct from a 0-d array")
452-
def test_scalar_return_type(self):
453-
# Full scalar indices should return scalars and object
454-
# arrays should not call PyArray_Return on their items
455-
class Zero:
456-
# The most basic valid indexing
457-
def __index__(self):
458-
return 0
459-
460-
z = Zero()
461-
462-
class ArrayLike:
463-
# Simple array, should behave like the array
464-
def __array__(self):
465-
return np.array(0)
466-
467-
a = np.zeros(())
468-
assert_(isinstance(a[()], np.float_))
469-
a = np.zeros(1)
470-
assert_(isinstance(a[z], np.float_))
471-
a = np.zeros((1, 1))
472-
assert_(isinstance(a[z, np.array(0)], np.float_))
473-
assert_(isinstance(a[z, ArrayLike()], np.float_))
474-
475-
# And object arrays do not call it too often:
476-
b = np.array(0)
477-
a = np.array(0, dtype=object)
478-
a[()] = b
479-
assert_(isinstance(a[()], np.ndarray))
480-
a = np.array([b, None])
481-
assert_(isinstance(a[z], np.ndarray))
482-
a = np.array([[b, None]])
483-
assert_(isinstance(a[z, np.array(0)], np.ndarray))
484-
assert_(isinstance(a[z, ArrayLike()], np.ndarray))
485-
486392
def test_small_regressions(self):
487393
# Reference count of intp for index checks
488394
a = np.array([0])
@@ -499,29 +405,6 @@ def test_small_regressions(self):
499405
if HAS_REFCOUNT:
500406
assert_equal(sys.getrefcount(np.dtype(np.intp)), refcount)
501407

502-
@pytest.mark.skip(reason="torch does not support subclassing")
503-
def test_unaligned(self):
504-
v = (np.zeros(64, dtype=np.int8) + ord('a'))[1:-7]
505-
d = v.view(np.dtype("S8"))
506-
# unaligned source
507-
x = (np.zeros(16, dtype=np.int8) + ord('a'))[1:-7]
508-
x = x.view(np.dtype("S8"))
509-
x[...] = np.array("b" * 8, dtype="S")
510-
b = np.arange(d.size)
511-
#trivial
512-
assert_equal(d[b], d)
513-
d[b] = x
514-
# nontrivial
515-
# unaligned index array
516-
b = np.zeros(d.size + 1).view(np.int8)[1:-(np.intp(0).itemsize - 1)]
517-
b = b.view(np.intp)[:d.size]
518-
b[...] = np.arange(d.size)
519-
assert_equal(d[b.astype(np.int16)], d)
520-
d[b.astype(np.int16)] = x
521-
# boolean
522-
d[b % 2 == 0]
523-
d[b % 2 == 0] = x[::2]
524-
525408
def test_tuple_subclass(self):
526409
arr = np.ones((5, 5))
527410

@@ -585,16 +468,6 @@ def test_indexing_array_negative_strides(self):
585468
arr[slices] = 10
586469
assert_array_equal(arr, 10.)
587470

588-
@pytest.mark.skip(reason="torch does not support character/string dtypes")
589-
def test_character_assignment(self):
590-
# This is an example a function going through CopyObject which
591-
# used to have an untested special path for scalars
592-
# (the character special dtype case, should be deprecated probably)
593-
arr = np.zeros((1, 5), dtype="c")
594-
arr[0] = np.str_("asdfg") # must assign as a sequence
595-
assert_array_equal(arr[0], np.array("asdfg", dtype="c"))
596-
assert arr[0, 1] == b"s" # make sure not all were set to "a" for both
597-
598471
@pytest.mark.parametrize("index",
599472
[True, False, np.array([0])])
600473
@pytest.mark.parametrize("num", [32, 40])
@@ -613,32 +486,6 @@ def test_too_many_advanced_indices(self, index, num, original_ndim):
613486
arr[(index,) * num] = 1.
614487

615488

616-
@pytest.mark.skip(reason="torch does not support subclassing")
617-
@pytest.mark.skipif(IS_WASM, reason="no threading")
618-
def test_structured_advanced_indexing(self):
619-
# Test that copyswap(n) used by integer array indexing is threadsafe
620-
# for structured datatypes, see gh-15387. This test can behave randomly.
621-
from concurrent.futures import ThreadPoolExecutor
622-
623-
# Create a deeply nested dtype to make a failure more likely:
624-
dt = np.dtype([("", "f8")])
625-
dt = np.dtype([("", dt)] * 2)
626-
dt = np.dtype([("", dt)] * 2)
627-
# The array should be large enough to likely run into threading issues
628-
arr = np.random.uniform(size=(6000, 8)).view(dt)[:, 0]
629-
630-
rng = np.random.default_rng()
631-
def func(arr):
632-
indx = rng.integers(0, len(arr), size=6000, dtype=np.intp)
633-
arr[indx]
634-
635-
tpe = ThreadPoolExecutor(max_workers=8)
636-
futures = [tpe.submit(func, arr) for _ in range(10)]
637-
for f in futures:
638-
f.result()
639-
640-
assert arr.dtype is dt
641-
642489
def test_nontuple_ndindex(self):
643490
a = np.arange(25).reshape((5, 5))
644491
assert_equal(a[[0, 1]], np.array([a[0], a[1]]))
@@ -652,16 +499,6 @@ def test_nontuple_ndindex(self):
652499
assert_raises(IndexError, a.__getitem__, [slice(None)])
653500

654501

655-
class TestFieldIndexing:
656-
@pytest.mark.skip(reason="torch has no type distinct from a 0-d array")
657-
def test_scalar_return_type(self):
658-
# Field access on an array should return an array, even if it
659-
# is 0-d.
660-
a = np.zeros((), [('a','f8')])
661-
assert_(isinstance(a['a'], np.ndarray))
662-
assert_(isinstance(a[['a']], np.ndarray))
663-
664-
665502
class TestBroadcastedAssignments:
666503
def assign(self, a, ind, val):
667504
a[ind] = val
@@ -732,71 +569,6 @@ def test_broadcast_subspace(self):
732569
assert_((a[::-1] == v).all())
733570

734571

735-
@pytest.mark.skip(reason="torch does not support subclassing")
736-
class TestSubclasses:
737-
def test_basic(self):
738-
# Test that indexing in various ways produces SubClass instances,
739-
# and that the base is set up correctly: the original subclass
740-
# instance for views, and a new ndarray for advanced/boolean indexing
741-
# where a copy was made (latter a regression test for gh-11983).
742-
class SubClass(np.ndarray):
743-
pass
744-
745-
a = np.arange(5)
746-
s = a.view(SubClass)
747-
s_slice = s[:3]
748-
assert_(type(s_slice) is SubClass)
749-
assert_(s_slice.base is s)
750-
assert_array_equal(s_slice, a[:3])
751-
752-
s_fancy = s[[0, 1, 2]]
753-
assert_(type(s_fancy) is SubClass)
754-
assert_(s_fancy.base is not s)
755-
assert_(type(s_fancy.base) is np.ndarray)
756-
assert_array_equal(s_fancy, a[[0, 1, 2]])
757-
assert_array_equal(s_fancy.base, a[[0, 1, 2]])
758-
759-
s_bool = s[s > 0]
760-
assert_(type(s_bool) is SubClass)
761-
assert_(s_bool.base is not s)
762-
assert_(type(s_bool.base) is np.ndarray)
763-
assert_array_equal(s_bool, a[a > 0])
764-
assert_array_equal(s_bool.base, a[a > 0])
765-
766-
def test_fancy_on_read_only(self):
767-
# Test that fancy indexing on read-only SubClass does not make a
768-
# read-only copy (gh-14132)
769-
class SubClass(np.ndarray):
770-
pass
771-
772-
a = np.arange(5)
773-
s = a.view(SubClass)
774-
s.flags.writeable = False
775-
s_fancy = s[[0, 1, 2]]
776-
assert_(s_fancy.flags.writeable)
777-
778-
779-
def test_finalize_gets_full_info(self):
780-
# Array finalize should be called on the filled array.
781-
class SubClass(np.ndarray):
782-
def __array_finalize__(self, old):
783-
self.finalize_status = np.array(self)
784-
self.old = old
785-
786-
s = np.arange(10).view(SubClass)
787-
new_s = s[:3]
788-
assert_array_equal(new_s.finalize_status, new_s)
789-
assert_array_equal(new_s.old, s)
790-
791-
new_s = s[[0,1,2,3]]
792-
assert_array_equal(new_s.finalize_status, new_s)
793-
assert_array_equal(new_s.old, s)
794-
795-
new_s = s[s > 0]
796-
assert_array_equal(new_s.finalize_status, new_s)
797-
assert_array_equal(new_s.old, s)
798-
799-
800572
class TestFancyIndexingCast:
801573
@pytest.mark.xfail(
802574
reason="XXX: low-prio to support assigning complex values on floating arrays"
@@ -822,56 +594,6 @@ def test_boolean_index_cast_assign(self):
822594
zero_array.__setitem__, bool_index, np.array([1j]))
823595
assert_equal(zero_array[0, 1], 0)
824596

825-
class TestFancyIndexingEquivalence:
826-
@pytest.mark.skip(reason="torch does not support object dtype")
827-
def test_object_assign(self):
828-
# Check that the field and object special case using copyto is active.
829-
# The right hand side cannot be converted to an array here.
830-
a = np.arange(5, dtype=object)
831-
b = a.copy()
832-
a[:3] = [1, (1,2), 3]
833-
b[[0, 1, 2]] = [1, (1,2), 3]
834-
assert_array_equal(a, b)
835-
836-
# test same for subspace fancy indexing
837-
b = np.arange(5, dtype=object)[None, :]
838-
b[[0], :3] = [[1, (1,2), 3]]
839-
assert_array_equal(a, b[0])
840-
841-
# Check that swapping of axes works.
842-
# There was a bug that made the later assignment throw a ValueError
843-
# do to an incorrectly transposed temporary right hand side (gh-5714)
844-
b = b.T
845-
b[:3, [0]] = [[1], [(1,2)], [3]]
846-
assert_array_equal(a, b[:, 0])
847-
848-
# Another test for the memory order of the subspace
849-
arr = np.ones((3, 4, 5), dtype=object)
850-
# Equivalent slicing assignment for comparison
851-
cmp_arr = arr.copy()
852-
cmp_arr[:1, ...] = [[[1], [2], [3], [4]]]
853-
arr[[0], ...] = [[[1], [2], [3], [4]]]
854-
assert_array_equal(arr, cmp_arr)
855-
arr = arr.copy('F')
856-
arr[[0], ...] = [[[1], [2], [3], [4]]]
857-
assert_array_equal(arr, cmp_arr)
858-
859-
@pytest.mark.skip(reason="torch does not support character/string dtypes")
860-
def test_cast_equivalence(self):
861-
# Yes, normal slicing uses unsafe casting.
862-
a = np.arange(5)
863-
b = a.copy()
864-
865-
a[:3] = np.array(['2', '-3', '-1'])
866-
b[[0, 2, 1]] = np.array(['2', '-1', '-3'])
867-
assert_array_equal(a, b)
868-
869-
# test the same for subspace fancy indexing
870-
b = np.arange(5)[None, :]
871-
b[[0], :3] = np.array([['2', '-3', '-1']])
872-
assert_array_equal(a, b[0])
873-
874-
875597
@pytest.mark.xfail(reason="XXX: requires broadcast() and broadcast_to()")
876598
class TestMultiIndexingAutomated:
877599
"""
@@ -1468,44 +1190,3 @@ def test_basic(self):
14681190
assert_raises(IndexError, lambda: a[..., ...])
14691191
assert_raises(IndexError, a.__getitem__, ((Ellipsis,) * 2,))
14701192
assert_raises(IndexError, a.__getitem__, ((Ellipsis,) * 3,))
1471-
1472-
1473-
class TestCApiAccess:
1474-
@pytest.mark.skip("no array_indexing() function")
1475-
def test_getitem(self):
1476-
subscript = functools.partial(array_indexing, 0)
1477-
1478-
# 0-d arrays don't work:
1479-
assert_raises(IndexError, subscript, np.ones(()), 0)
1480-
# Out of bound values:
1481-
assert_raises(IndexError, subscript, np.ones(10), 11)
1482-
assert_raises(IndexError, subscript, np.ones(10), -11)
1483-
assert_raises(IndexError, subscript, np.ones((10, 10)), 11)
1484-
assert_raises(IndexError, subscript, np.ones((10, 10)), -11)
1485-
1486-
a = np.arange(10)
1487-
assert_array_equal(a[4], subscript(a, 4))
1488-
a = a.reshape(5, 2)
1489-
assert_array_equal(a[-4], subscript(a, -4))
1490-
1491-
@pytest.mark.skip("no array_indexing() function")
1492-
def test_setitem(self):
1493-
assign = functools.partial(array_indexing, 1)
1494-
1495-
# Deletion is impossible:
1496-
assert_raises(ValueError, assign, np.ones(10), 0)
1497-
# 0-d arrays don't work:
1498-
assert_raises(IndexError, assign, np.ones(()), 0, 0)
1499-
# Out of bound values:
1500-
assert_raises(IndexError, assign, np.ones(10), 11, 0)
1501-
assert_raises(IndexError, assign, np.ones(10), -11, 0)
1502-
assert_raises(IndexError, assign, np.ones((10, 10)), 11, 0)
1503-
assert_raises(IndexError, assign, np.ones((10, 10)), -11, 0)
1504-
1505-
a = np.arange(10)
1506-
assign(a, 4, 10)
1507-
assert_(a[4] == 10)
1508-
1509-
a = a.reshape(5, 2)
1510-
assign(a, 4, 10)
1511-
assert_array_equal(a[-1], [10, 10])

0 commit comments

Comments
 (0)