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

Antoine Pitrou solipsis at pitrou.net
Fri Mar 14 12:54:47 CET 2014


On Fri, 14 Mar 2014 12:48:13 +0100
"M.-A. Lemburg" <mal at egenix.com> wrote:
> > 
> > Some more from real code:
> > 
> > RSR = R.dot(var_beta.dot(R.T))
> > RSR = R @ var_beta @ R.T
> > 
> > xx_inv.dot(xeps.dot(xx_inv))
> > xx_inv @ xeps @ xx_inv
> > 
> > dF2lower_dper.dot(F2lower.T) + F2lower.dot(dF2lower_dper.T) - 4/period*F2lower.dot(F2lower.T)
> > dF2lower_dper @ F2lower.T + F2lower @ dF2lower_dper.T - 4/period*(F2lower @ F2lower.T)
> > 
> > dFX_dper.dot(Gi.dot(FX2.T)) - FX.dot(Gi.dot(dG_dper.dot(Gi.dot(FX2.T)))) + FX.dot(Gi.dot(dFX2_dper.T))
> > (dFX_dper @ Gi @ FX2.T) - (FX @ Gi @ dG_dper @ Gi @ FX2.T) + (FX @ G @ dFX2_dper.T)
> > 
> > torient_inv.dot(tdof).dot(torient).dot(self.vertices[parent].meta['key']))
> > (((torient_inv @ tdof) @ torient) @ self.vertices[parent].meta['key']
> 
> This doesn't look very readable to me - the operator saves you
> a few parens in some situations, but as in the last example, it can
> also require adding new ones.

The parentheses mirror those necessary in the equivalent mathematical
formula, though, so they are "natural" in a sense.

I do find the "@" examples much more readable myself - except that I
don't understand what they are about, of course :-)

Regards

Antoine.




More information about the Python-ideas mailing list