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

Raise error in parse_einsum_input when output subscript is specified multiple times #222

Merged
merged 1 commit into from
May 5, 2024

Conversation

lgeiger
Copy link
Contributor

@lgeiger lgeiger commented Nov 24, 2023

Description

contract("ij->jij", [[0, 0], [0, 0]])
# ValueError: einstein sum subscripts string includes output subscript 'j' multiple times

currently relies on the backend to throw an error if an output subscript is specified multiple times. However

contract_path("ij->jij", [[0, 0], [0, 0]])

would still return an einsum path despite the wrong einsum equation. This might lead to subtle errors if a user ends up relying on this behaviour by accident. E.g. when using the jax backend no error is thrown but only an internal assertion fails.

This PR raises the error already in parse_einsum_input which ensures that contract_path matches the behaviour of np.einsum and all backends that might rely on opt_einsum for error handling will do so as well.

This PR also extends the unittests to test error handling for both contract_path and contract which is independent of the backend.

For reference I made a similar PR to numpy/numpy#25230 to fix the same issue for np.einsum_path.

Status

  • Ready to go

Copy link

codecov bot commented Nov 24, 2023

Codecov Report

Merging #222 (2e51e2b) into master (1a984b7) will increase coverage by 3.15%.
The diff coverage is 100.00%.

Additional details and impacted files

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.

Apologies for missing this, looks like a great change- especially in testing!

@dgasmith dgasmith merged commit 2824c9e into dgasmith:master May 5, 2024
@lgeiger lgeiger deleted the multi-output-error branch May 5, 2024 19:41
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

Successfully merging this pull request may close these issues.

2 participants