[Numpy-discussion] [help needed] associativity and precedence of '@'

Robert Kern robert.kern at gmail.com
Sat Mar 15 12:49:55 EDT 2014


On Sat, Mar 15, 2014 at 4:40 PM, Charles R Harris
<charlesr.harris at gmail.com> wrote:
>
> On Sat, Mar 15, 2014 at 9:58 AM, Robert Kern <robert.kern at gmail.com> wrote:
>>
>> On Sat, Mar 15, 2014 at 2:49 PM, Charles R Harris
>> <charlesr.harris at gmail.com> wrote:
>> >
>> > I favor the weak right option.
>> >
>> > 1) Giving '*' higher precedence than `@` makes it easier, to my mind, to
>> > parse out what is going to happen: all the element-wise multiplications,
>> > followed by the matrix operations. I'd probably still use parenthesis
>> > for
>> > clarity.
>>
>> It seems to me that 'tight' gives the same benefit. Any reasoning for
>> the preference of 'weak' over 'tight'?
>>
>
> Two other reasons come to mind. First, '*' is right associative, so I think
> it is nicer to first view the expression as parsed into blocks separated by
> '@', which act somewhat like parenthesis at that point, and then evaluate
> the blocks.

Again, I think tight does the same amount of separation, just with
blocks of matrix multiplication broken up by elementwise
multiplication; this is just an argument against 'same', not for
'weak' over 'tight'. As I mentioned elsewhere, my visual system seems
to break things up with @-tight anyways. Does it not for you?

> Second, and somewhat weaker, it might make it easier to track
> how arrays are broadcast.

I think this point is going to ultimately determine this, if we can
break down all the cases and if they actually do favor one choice over
another.

-- 
Robert Kern



More information about the NumPy-Discussion mailing list