Skip to content

Drop --> and ..: a pattern is its string, with einsum operands in a List - #63

Merged
AntonOresten merged 1 commit into
mainfrom
string-patterns
Oct 23, 2026
Merged

AntonOresten merged 1 commit into
mainfrom
string-patterns

Conversation

@AntonOresten

@AntonOresten AntonOresten commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Patterns are now only written as strings, einops"..." or the shorthand macros' strings. A pattern shows as the string that makes it:

julia> einops"a b()->a()b"
einops"a b () -> a () b"

julia> k = 2; einops"(h $k) (w $k) -> h w"
einops"(h 2) (w 2) -> h w"

--> and .. are gone, and with them the EllipsisNotation dependency. Internally ... is a vendored Einops.Ellipsis(). Einops.ArrowPattern{L,R}() can still be built from tuples by hand. The parse_shape fallback that warned about a tuple holding .. goes too, since nothing public can make one; parse_shape(x, einops"a b ...") covers it, and tuples of names and - still work.

Commas make a List of operands. In a pattern, a comma separates einsum operands, unlike the commas of a Julia tuple: "i, -> i" has two operands, the second 0-dimensional. Before, a tuple of tuples meant either operands or one array's groups, depending on how many arrays came with it (#61), so "i, j -> i j" and "(i) (j) -> i j" were the same value. Now commas make an internal List{((:i,), (:j,))}(), which iterates and indexes like the tuple it holds. It is a singleton carrying its operands as a parameter, since an instance holding Symbols can't be a type parameter.

  • einsum requires one array per operand: "The pattern has 2 operands, but 1 array was given".
  • The other operations reject a list.
  • Patterns without -> (parse_shape, pack/unpack) reject commas, since nothing takes several of them.
  • einsum(matrix, einops"i, j -> i j") used to read the two operands as one array's axes. It now throws; for one array, write "i j -> i j".

Tests: about 190 tuple patterns in the tests were rewritten by a script, which parsed each --> expression, generated the string, and checked that it reads back to the identical pattern. test/patterns.jl, which tests the parser itself, compares against explicit ArrowPattern{L,R}() types. New tests cover the display (every spelling reads back to the same pattern), List's interface and checks, and commas versus arity in einsum. The full suite passes on Julia 1.10 and 1.13, Zygote on 1.12, and Reactant on 1.13. Doctests and the docs build are clean.

🤖 Generated with Claude Code

… a List

Patterns are written as `einops"..."` and the shorthand macros' strings, and a
pattern now shows as the string that makes it. The tuple-building operator
`-->` and the re-exported `..` go, and with them EllipsisNotation: `...` is a
vendored `Ellipsis()`.

Commas separate einsum operands, unlike the commas of a Julia tuple: `"i, -> i"`
has two, the second 0-dimensional. They now make an internal `List` of operand
sides, iterable like the tuple it holds, where before a tuple of tuples meant
operands or one array's groups depending on how many arrays came with it. So
commas, not arity, decide: `einsum` requires one array per operand, the other
operations reject a list, and a pattern without `->` rejects commas. The
`parse_shape` fallback for a tuple holding `..` goes too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.43750% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 99.37%. Comparing base (1c8d0d7) to head (86b8c93).

Files with missing lines Patch % Lines
src/patterns/patterns.jl 95.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #63      +/-   ##
==========================================
- Coverage   99.49%   99.37%   -0.12%     
==========================================
  Files          15       15              
  Lines         793      802       +9     
==========================================
+ Hits          789      797       +8     
- Misses          4        5       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AntonOresten
AntonOresten merged commit c1ad145 into main Oct 23, 2026
5 of 7 checks passed
@AntonOresten
AntonOresten deleted the string-patterns branch October 29, 2026 12:34
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.

1 participant