Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test that Tuple.reduce can't remove any indices #83

Open
asmeurer opened this issue Sep 17, 2020 · 2 comments
Open

Test that Tuple.reduce can't remove any indices #83

asmeurer opened this issue Sep 17, 2020 · 2 comments

Comments

@asmeurer
Copy link
Member

We can't guarantee that Tuple.reduce is fully canonical like with slices #82, because there are too many combinations. But we can test that it removes any redundant terms. Something like

diff --git a/ndindex/tests/test_tuple.py b/ndindex/tests/test_tuple.py
index c8a53a4..3a02961 100644
--- a/ndindex/tests/test_tuple.py
+++ b/ndindex/tests/test_tuple.py
@@ -10,7 +10,7 @@ from pytest import raises
 from ..ndindex import ndindex
 from ..tuple import Tuple
 from ..integer import Integer
-from .helpers import check_same, Tuples, prod, short_shapes, iterslice
+from .helpers import assert_equal, check_same, Tuples, prod, short_shapes, iterslice

 def test_tuple_constructor():
     # Test things in the Tuple constructor that are not tested by the other
@@ -131,6 +131,12 @@ def test_tuple_reduce_hypothesis(t, shape):
         if isinstance(reduced, Tuple):
             assert len(reduced.args) != 1
             assert reduced == () or reduced.args[-1] != ...
+            args = reduced.args
+            for i in range(len(args)):
+                a_index = a[index.raw]
+                idx = Tuple(*(args[0:i] + args[i+1:]))
+                # Is there a better way to do assert not equal?
+                raises((IndexError, AssertionError), lambda: assert_equal(a_index, a[idx.raw]))
         # TODO: Check the other properties from the Tuple.reduce docstring.

 def test_tuple_reduce_explicit():

The problem is that this leads to some odd cases which aren't straightforward to match, for example, (..., False) and False are equivalent for shape (0,) because the added 0 to the shape from the False is the same on the left or right. Similarly for (..., None) and None for shape (1,).

@asmeurer
Copy link
Member Author

It's not just the ellipsis. There's the same problem for (slice(None), False) and (slice(None), None).

@asmeurer
Copy link
Member Author

And for something like shape (2, 1), (..., None) and (slice(None), None) are equivalent, but not just None. So there's the question of which is better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant