[Numpy-discussion] Resolving the associativity/precedence debate for @
Andrea Gavana
andrea.gavana@gmail....
Sat Mar 22 15:10:10 CDT 2014
Hi,
On 22 March 2014 19:13, Nathaniel Smith wrote:
> Hi all,
>
> After 88 emails we don't have a conclusion in the other thread (see
> [1] for background). But we have to come to some conclusion or another
> if we want @ to exist :-). So I'll summarize where the discussion
> stands and let's see if we can find some way to resolve this.
>
> The fundamental question is whether a chain like (a @ b @ c) should be
> evaluated left-to-right (left-associativity) or right-to-left
> (right-associativity).
>
>
<snip>
I have been following this discussion and the PEP with much interest and,
just to state the obvious, the addition of a matrix-multiplication operator
in Python is way overdue. If I had to judge from the oil industry point of
view only, in recent years the adoption of Python (and, by consequence,
NumPy) as a number crunching platform has grown exponentially. I could cite
dozens of non-performance-critical examples of commercial tools that
switched from close-to-unmantainable Fortran/C implementations or (please
forgive us...) hieroglyphic-style Perl code to Python.
That said, if you're still interested in a social experiment about the
precedence of "@", I can share a real-life one - albeit on a small sample
of people (15). This is the background:
1. I'm about to teach an internal course on Python/NumPy/other in the
company, so I polled the participants on their intuition about the "@"
operator precedence;
2. We are *not* math gurus, but we do use NumPy on terabyte-scale data
pretty much on a daily basis;
3. We are not "heavy" users of the "dot' method, but our various pieces of
code contains quite a few calls to it;
4. All Python operators have left-associativity, excluding "**";
5. Python code is read left-to-right.
So, by asking the question: how do you interpret the expression "a @ b @
c", this is a summary of what I got from the participants:
1. Twelve (12) said they would interpret it as: "first do a@b, then
matrix-multiply the results with c";
2. Two (2) said they had no idea;
3. One (1) applied the right-associativity rule;
4. Whatever the Numpy-dev or Python-dev decision is, no one of us is ever,
*ever* going to write "a @ b @ c" without parenthesis, to make clear the
ordering of operations.
I'm not going to pass judgments on the social experiment nor to invoke the
Zen here, even though I fail to see how "@" is such a special case to break
the standard rules. Not every NumPy user is a high-level math-educated
person, or even if he/she is, he/she may have forgotten the basics of it.
Why confuse him/her more?
Andrea.
"Imagination Is The Only Weapon In The War Against Reality."
http://www.infinity77.net
# ------------------------------------------------------------- #
def ask_mailing_list_support(email):
if mention_platform_and_version() and include_sample_app():
send_message(email)
else:
install_malware()
erase_hard_drives()
# ------------------------------------------------------------- #
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20140322/c07a9ac9/attachment-0001.html
More information about the NumPy-Discussion
mailing list