You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, there are no brackets that allow grouping subexpressions without also including additional semantics.
Axis composition (a b) groups axes a and b, but also says that they are to be read as a single composed axis.
Brackets [a b] group axes a and b, but also say that the operation should be applied to these axes.
A new kind of grouping bracket, e.g. {a b}, would group the axes a and b without including additional meaning, i.e. it would be equivalent to just writing a b.
Some examples where this would be useful:
Example 1: Apply an ellipsis to a group
In the following expression, a and b are grouped in (a b), and the ellipsis therefore applies to the entire group:
"(a b)... -> a... b..."
# expands to (assuming the ellipsis is expanded to 2 repetitions)
"(a.0 b.0) (a.1 b.1) -> a.0 a.1 b.0 b.1"
If I don't want to compose a and b into a single new axis though, I could use grouping brackets instead:
"{a b}... -> a... b..."
# expands to (assuming the ellipsis is expanded to 2 repetitions)
"{a.0 b.0} {a.1 b.1} -> a.0 a.1 b.0 b.1"
# same as (grouping brackets add no semantics)
"a.0 b.0 a.1 b.1 -> a.0 a.1 b.0 b.1"
Example 2: Composability of -> and ,
The composability of expressions in einx also allows composing grouping brackets with -> and ,. This is useful for example to specify batch dimensions for all input and output tensors in an operation jointly:
einx.dot("... {a [b], [b] c -> a c}", ...) # specifiy batch dimensions jointly for all arguments
# is resolved to
einx.dot("... {a [b]}, ... {[b] c} -> ... {a c}", ...)
# same as
einx.dot("... a [b], ... [b] c -> ... a c", ...)
Using e.g. axis composition here changes the semantics of the expression:
einx.dot("... (a [b], [b] c -> a c)", ...)
# is resolved to
einx.dot("... (a [b]), ... ([b] c) -> ... (a c)", ...) # this is not what we wanted to express
Using brackets also changes the semantics:
einx.dot("... [a [b], [b] c -> a c]", ...)
# is resolved to
"einx.dot("... [a [b]], ... [[b] c] -> ... [a c]", ...)
# same as (brackets are idempotent)
"einx.dot("... [a b], ... [b c] -> ... [a c]", ...) # this is not what we wanted to express
Good:
Allows writing some expressions more concisely.
Probably easy to implement.
Bad:
Adds another type of delimiter (e.g. braces {} as in the examples above) in addition to axis composition () and operation axes [], which adds to the complexity of einx expressions. This makes the notation more difficult to read/ learn and less intuitive.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently, there are no brackets that allow grouping subexpressions without also including additional semantics.
(a b)groups axesaandb, but also says that they are to be read as a single composed axis.[a b]group axesaandb, but also say that the operation should be applied to these axes.{a b}, would group the axesaandbwithout including additional meaning, i.e. it would be equivalent to just writinga b.Some examples where this would be useful:
Example 1: Apply an ellipsis to a group
In the following expression,
aandbare grouped in(a b), and the ellipsis therefore applies to the entire group:If I don't want to compose
aandbinto a single new axis though, I could use grouping brackets instead:Example 2: Composability of
->and,The composability of expressions in einx also allows composing grouping brackets with
->and,. This is useful for example to specify batch dimensions for all input and output tensors in an operation jointly:Using e.g. axis composition here changes the semantics of the expression:
Using brackets also changes the semantics:
Good:
Bad:
{}as in the examples above) in addition to axis composition()and operation axes[], which adds to the complexity of einx expressions. This makes the notation more difficult to read/ learn and less intuitive.Beta Was this translation helpful? Give feedback.
All reactions