Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

22: Grouped sizes and shape aliases

E2201

Shape alias defined in terms of itself. A shape alias stands for a fixed list of axes, so it can’t contain itself, directly or through other aliases. Each alias in the cycle is reported.

dim Ping = [Pong n]
dim Pong = [Ping m]

Write the axes out in one of them. See Shape aliases.

E2202

Shape alias where its axes can’t be spliced. A shape alias stands for several axes, so it can be a type’s whole shape or among a shape’s axes, but not part of one axis: not inside a group, in arithmetic, or as an Index[V] size.

dim Images = [b 3 16gh 16gw]

fn f(x: [(Images 2)]) -> [b] = sum(x, over=b)

Put the alias among the axes, as in [Images 2], or write the group out. See Shape aliases.

E2203

Grouped size like 16gh outside an axis. A grouped size is one axis of a type or a pattern, the group (gh 16). It isn’t a size that arithmetic can use, a dim’s value, or an expression, and its name can’t be a keyword.

fn f(x: [b 16gh*2]) -> [b] = sum(x, over=b)

For the product as a size, write 16*gh; for a value, 16 * gh. See Grouped sizes.

H2201

16 gh, two axes, where 16gh was probably meant. In a function’s signature, a number greater than 1 directly followed by a name that isn’t a dim, is an axis of its own nowhere else in the signature, and is part of a group, other than a grouped size, somewhere in it. 16 gh is two axes; 16gh, without the space, is one, of size 16 × gh. This is a hint, not a warning: both are valid.

dim D = 768

fn patchify(img: [b 3 16 gh 16 gw]) -> [b (gh gw) D]:
    return img |> rearrange(b c p gh q gw -> b (gh gw) (p q c))
hint[H2201]: `16 gh` is two axes: did you mean `16gh`?

If two axes were meant, nothing needs to change. See Grouped sizes.