TorchLean API

NN.Tensor.Internal.Syntax.Ast

Lossless einops syntax trees #

The AST preserves grouping, unit axes, anonymous-axis occurrences, and source locations. This is more informative than the reference implementation's internal ParsedExpression, which erases unit axes while parsing.

An elementary axis in a transformation expression.

Anonymous axes carry an occurrence number because two textual occurrences of the same numeral denote distinct axes in einops.

  • named (name : String) : Axis

    A logical axis identified by the user's name.

  • anonymous (value occurrence : Nat) : Axis

    A numeric axis, distinguished by its occurrence in the source pattern.

  • unit : Axis

    A length-one axis written as 1.

  • ellipsis : Axis

    The ... axis that stands for zero or more physical dimensions.

Instances For

    One top-level axis or parenthesized composition.

    • axes : List (Located Axis)

      Elementary axes written in this top-level component.

    • parenthesized : Bool

      Whether the component was explicitly enclosed in parentheses.

    • span : Span

      Source range covering the complete component.

    Instances For

      Unit axes disappear from the elementary-axis sequence.

      Instances For

        Whether this composition contains an ellipsis.

        Instances For

          One side of a transformation or einsum pattern.

          • Top-level physical axes in source order.

          • span : Span

            Source range covering the complete expression.

          Instances For

            Elementary axes after removing syntactic unit axes.

            Instances For

              Named axes in source order, including repeated occurrences when allowed.

              Instances For

                The number of ellipses in an expression.

                Instances For

                  Whether an ellipsis occurs inside parentheses.

                  Instances For

                    Whether an expression contains a genuine composite axis.

                    Instances For

                      The shared syntax of rearrange, repeat, and reduce.

                      • left : Expression

                        Input-side expression.

                      • arrow : Span

                        Source range of the -> token.

                      • right : Expression

                        Output-side expression.

                      • span : Span

                        Source range covering the complete transformation pattern.

                      Instances For

                        The separate grammar used by pack and unpack.

                        • before : List (Located String)

                          Fixed named axes before the packed * region.

                        • packed : Span

                          Source range of the unique * token.

                        • after : List (Located String)

                          Fixed named axes after the packed * region.

                        • span : Span

                          Source range covering the complete packing pattern.

                        Instances For

                          The multi-input grammar used by einsum.

                          • inputs : List Expression

                            Comma-separated operand expressions in source order.

                          • arrow : Span

                            Source range of the -> token.

                          • output : Expression

                            Output expression following the arrow.

                          • span : Span

                            Source range covering the complete einsum pattern.

                          Instances For