Documentation

RoleFlow.Flow.PermS

Permutations as data #

A permutation of the entries of a vector of length n is a sequence of steps (PermS), each a numpy operation on the vector reshaped, row-major, to a shape dims with n entries:

stepnumpy
tr dims axesx.reshape(dims).transpose(axes).reshape(-1)
flip dims kjnp.flip(x.reshape(dims), k).reshape(-1)
roll dims k sjnp.roll(x.reshape(dims), s, axis=k).reshape(-1)

The steps apply in order. Each acts as a gather: output position i reads input position idx i, so the sequence [p₁, p₂, …] reads p₁.idx (p₂.idx (… i)) (PermS.idx). The squeezes and patchings of the models are transposes, their channel and token reversals flips, and their rotations rolls.

Nothing here uses Mathlib: the flow signature (Flow.Basic) reads PermS.idx as an Equiv.Perm, and the printer (Flow.Print) prints the steps.

One step of a permutation, on the vector reshaped to dims.

  • tr (dims axes : List Nat) : PermStep

    Permute the axes: output axis j is input axis axes[j].

  • flip (dims : List Nat) (k : Nat) : PermStep

    Reverse axis k.

  • roll (dims : List Nat) (k s : Nat) : PermStep

    Rotate axis k by s: output index j reads j - s (mod the axis length).

Instances For
    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      @[reducible, inline]

      A permutation: its steps, applied in order.

      Equations
      Instances For

        The row-major digits of i in the shape dims.

        Equations
        Instances For

          The position of the digits ds in the shape dims.

          Equations
          Instances For

            The input position that output position i reads.

            Equations
            • One or more equations did not get rendered due to their size.
            Instances For

              The step that undoes this one.

              Equations
              Instances For

                The step is well formed on vectors of length n: its shape has n entries, axes is a permutation of the axes, and k is an axis.

                Equations
                Instances For

                  The step on the middle of the shape [outer] ++ dims ++ [inner] (an axis of length 1 is left out).

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For

                    The step does nothing: a transpose with the axes in order, a flip of an axis of length at most 1, a roll by a multiple of the axis length.

                    Equations
                    Instances For

                      The step in the surface syntax of the webapp, before its argument: tr<[2, 3], [1, 0]>.

                      Equations
                      Instances For

                        The steps applied to x, in the surface syntax of the webapp.

                        Equations
                        Instances For

                          The input position that output position i reads.

                          Equations
                          Instances For

                            The steps that undo ps.

                            Equations
                            Instances For

                              Every step is well formed on vectors of length n.

                              Equations
                              Instances For

                                The index list [idx 0, …, idx (n - 1)].

                                Equations
                                Instances For

                                  ps is a permutation of 0, …, n - 1: well formed, and its index list is one.

                                  Equations
                                  • One or more equations did not get rendered due to their size.
                                  Instances For