Skip to content

Macro-based interface #2

@AntonOresten

Description

@AntonOresten

Aside from the @einops_str macro for Python syntax, an @einops macro could be used to reduce colons and commas in the input expression—although without commas, (a b) won't work, so [a b] could be used instead.

@einops a b c d -> [a b] c d

This is parsed as:

julia> :(@einops a b c d -> [a b] c d)
:(#= REPL[5]:1 =# @einops a b c (d->begin
              #= REPL[5]:1 =#
              [a b]
          end) c d)

so anything adjacent to -> would require special parsing.

Alternatively (or additionally), the @einops macro could act on calls, e.g. @einops rearrange(x, "a b c d -> (a b) c d") but this isn't really better than rearrange(x, einops"a b c d -> (a b) c d").

Another option is @rearrange(x, "a b c d -> (a b) c d") for near perfect parity with Python implementation (just an extra @).

I don't want this becoming full of macros though, with 5 different ways of calling the same thing.

I would potentially consider just shortening einops"..." to ein"..." like they do in OMEinsum.jl, but there's the risk of clashing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions