[Python-ideas] [RFC] draft PEP: Dedicated infix operators for matrix multiplication and matrix power

Steven D'Aprano steve at pearwood.info
Sat Mar 15 15:04:51 CET 2014


On Sat, Mar 15, 2014 at 01:28:11PM +0100, Antoine Pitrou wrote:
> On Sat, 15 Mar 2014 12:20:42 +0000
> Oscar Benjamin
> <oscar.j.benjamin at gmail.com> wrote:
> > 
> > I don't think it's a premature optimisation. It's a significant
> > algorithmic optimisation.
> 
> You could also make the multiplications lazy (and enforce the optimal
> order when computing the final result) rather than enforce that
> optimization at the language parsing level. It would be more flexible,
> and would also avoid potentially pessimizing other use cases.

That sounds to me that you are suggesting that every single 
implementation of a matrix type that supports matrix multiplication 
needs to spend the considerable extra effort to make the multiplication 
lazy, in order to "potentially" avoid hurting hypothetical use-cases 
which don't exist now and may never exist.

That's as clear a case of YAGNI as I've seen for a long time.

We have one solid use-case for a matrix multiplication operator, and 
that's matrix multiplication. If matrix multiplication is most usefully 
treated as right-associative, then we ought to make it right- 
associative, and not burden the matrix multiplication operator with 
restrictions for the sake of hypothetical non-matrix-mult uses.

In the same way that there is one good use-case for the numeric 
exponentiation operator ** , namely numeric exponentiation, and 
consequently it is right-associative because that's how the operator is 
most usefully treated.


-- 
Steven


More information about the Python-ideas mailing list