[Python-ideas] Fwd: [RFC] draft PEP: Dedicated infix operators for matrix multiplication and matrix power
Guido van Rossum
guido at python.org
Fri Mar 14 18:53:01 CET 2014
I have now read the PEP, and I think it's good. I think it's a waste of
time to keep bikeshedding on the choice of operator -- @ is the best
compromise. I do have a few specific notes:
- Right associativity is not unheard of in Python. E.g. **. If you
think that for other reasons @ should be right associative, don't
let Python's tradition stop you. But then you need to decide which
of * and @ binds more tightly -- e.g. does a*b at c mean a*(b at c) or
(a*b)@c? And if you choose the latter, it follows that a at b*c means
a@(b*c) -- is that okay? (And similar examples exist for the other
choice.)
- Did you consider a duck-typing (is that the word?) attribute?
E.g. a*b is elementwise multiplication; a.M*b must be used for
matrix multiplication. (Your use of .T as "transpose" made me think
of this.) Of course the question is, can you get those packages
that currently use * for matrix multiply to comply? (I don't consider
this a serious counter-proposal. But you list a bunch of rejected
alternatives; this could be in that list.
- Is @@ really necessary? It seems you are adding it mostly because
it's cute and because of the parallel with **, not because it is
actually important enough to add new syntax. And then later you use
it as an argument for @, which seems a bit circular. Also, if we
were to make @ right-associative, the parallel with ** is already
imperfect.
- For better counts of usages, perhaps Sourcegraph.com might help? It
is a source code query engine that has a Python parser and (limited)
type inference built in (also separately available as pysonar on
github IIRC). To be clear, I don't need more numbers to be convinced.
Once we've decided on associativity and @@, I'm ready to accept.
--
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140314/c888ea8b/attachment-0001.html>
More information about the Python-ideas
mailing list