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

Make get_symbol(large_number) work in Python2 #48

Merged
merged 5 commits into from
Aug 23, 2018

Conversation

fritzo
Copy link
Contributor

@fritzo fritzo commented Aug 23, 2018

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, while opt_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

  • added a regression test
  • enabled previously skipped tests
  • tested in a Pyro application

Status

  • Ready to go

@dgasmith
Copy link
Owner

There are also tests here and here which can likely be fixed by these changes.

@codecov-io
Copy link

codecov-io commented Aug 23, 2018

Codecov Report

Merging #48 into master will decrease coverage by 0.08%.
The diff coverage is 92.3%.

@@ -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)
Copy link
Owner

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?

Copy link
Contributor Author

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.

Copy link
Owner

@dgasmith dgasmith left a 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))
Copy link
Owner

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?

Copy link
Contributor Author

@fritzo fritzo Aug 23, 2018

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.

@fritzo
Copy link
Contributor Author

fritzo commented Aug 23, 2018

@dgasmith Yes, I think this is ready to squash-and-merge.

@dgasmith dgasmith merged commit 57b27c0 into dgasmith:master Aug 23, 2018
dgasmith pushed a commit that referenced this pull request Aug 23, 2018
* Make get_symbol(large_number) work in Python2

* Enable fixed tests

* Simplify shim

* Enable more tests

* Avoid .format() in einsum_cache_wrap
@dgasmith
Copy link
Owner

@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.

@fritzo
Copy link
Contributor Author

fritzo commented Aug 24, 2018

@dgasmith Thanks for the speedy response!

@dgasmith dgasmith mentioned this pull request Aug 25, 2018
3 tasks
@dgasmith dgasmith added the bug label Aug 25, 2018
@dgasmith dgasmith added this to the v2.2 milestone Aug 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants