-
Notifications
You must be signed in to change notification settings - Fork 68
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
Make get_symbol(large_number) work in Python2 #48
Conversation
@@ -117,15 +117,14 @@ def test_drop_in_replacement(string): | |||
assert np.allclose(opt, np.einsum(string, *views)) | |||
|
|||
|
|||
@pytest.mark.skipif(sys.version_info[0] < 3, reason='requires python3') | |||
@pytest.mark.parametrize("string", tests) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I think there are two more in this file. I think this is good to go after those are patched?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, I believe this is good to go now. Looking forward to using this in Pyro.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM for squash and merge. Let me know if this is final.
@@ -129,7 +129,7 @@ def cached_einsum(*args, **kwargs): | |||
canonical = sorted(zip(inputs, map(id, operands)), key=lambda x: x[1]) | |||
canonical_ids = tuple(id_ for _, id_ in canonical) | |||
canonical_inputs = ','.join(input_ for input_, _ in canonical) | |||
canonical_equation = alpha_canonicalize('{}->{}'.format(canonical_inputs, output)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason to avoid format
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, 'blah {}'.format(u'\x80')
fails in Python 2. I couldn't figure out how to write a test for this, but it fixed my error in an application.
@dgasmith Yes, I think this is ready to squash-and-merge. |
* Make get_symbol(large_number) work in Python2 * Enable fixed tests * Simplify shim * Enable more tests * Avoid .format() in einsum_cache_wrap
@fritzo PyPI packages are up, works for me on Py2.7/3.6. Let me know if you have issues! Conda-forge packages will take a day or so. |
@dgasmith Thanks for the speedy response! |
Fixes #42
Description
This provides a compatibility shim for Python 2 so that
get_symbol(n)
can work for larger n.Note that Python 2's
numpy.einsum
still does not accept unicode. This means that, whileopt_einsum
can now work with arbitrarily large contractions in Python 2, it only works with contractions whose individual calls to Numpy involve fewer than 52 (I believe) characters.Tested
Status