[Python-ideas] Infix matrix-multiply, but not general infix operators?
Nick Coghlan
ncoghlan at gmail.com
Thu Mar 20 09:02:54 CET 2014
More information about the Python-ideas mailing list
Thu Mar 20 09:02:54 CET 2014
- Previous message: [Python-ideas] Infix matrix-multiply, but not general infix operators?
- Next message: [Python-ideas] Infix matrix-multiply, but not general infix operators?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 20 March 2014 17:41, Jared Grubb <jared.grubb at gmail.com> wrote: > A couple months back, Andrew Barnet brought up the idea of adding a way to apply functions in an infix style. It really didnt gain much traction. (Subject line "Infix Functions") > > Nathaniel Smith has just proposed a PEP to add an infix matrix multiply operator, and everyone seems to love it. > > I honestly am surprised at the difference in reaction. Why are we so quick to add a single-purpose punctuation mark, but reject a named infix operator that works for many general cases? Is the matrix-multiply use case so special? Yes, basically - a large portion of the PEP is about pointing out that matrix multiplication really is that special. All past attempts at getting syntax for it *have* been generalised along that lines of this suggestion from Andrew, and have ended up failing on the grounds of "just use a method or function instead". Nathaniel's PEP is about looking at those past proposals and the experience of the numeric computing community and asking "Which operator have we *really* missed?". And they realised that it was only one: a way to spell matrix multiplication, since "*" has already been claimed for element-wise multiplication. The generalised proposals failed because they were still clumsy for the matrix multiplication use case, and there wasn't a compelling justification for the extra complexity that came with the generalisation. By contrast, Nathaniel's latest PEP looked at solving the *exact* problem the numeric community has: a clean and concise way to spell matrix multiplication. It hit the sweet spot of design proposals: a clean targeted solution that is as simple as it can possibly be, while still solving the problem that needs to be solved. It may have *looked* deceptively fast in terms of core devs saying "yes, that's a good idea", but the speed makes more sense if you start the timer from some of the earlier PEPs referenced from Nathaniel's one - the "matrix multiplication is clumsy compared to MATLAB" problem has been around for as long as people have been doing numeric computing in Python. Cheers, Nick. > > I dont oppose the PEP, and I dont mean to derail it. And I know there was quite a bit of discussion on Andrew's email. But I cant help feel that Andrew's idea didnt get the appreciation it should. (But hey, I'm biased because I like the idea :)) > > Jared > > QUICK SUMMARY OF ANDREW'S EMAIL: > (Not a proposal for syntax or naming) > > m `cross` n > m `dot` n > > a `Pair` b > a `Tree` (b `Tree` c `Tree` d) `Tree` e > > And of course the matrix multiply (and matrix div that was briefly discussed) are implementable too: > > m `mmul` n > m `mdiv` n > > _______________________________________________ > Python-ideas mailing list > Python-ideas at python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ -- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
- Previous message: [Python-ideas] Infix matrix-multiply, but not general infix operators?
- Next message: [Python-ideas] Infix matrix-multiply, but not general infix operators?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-ideas mailing list