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

Oscar Benjamin oscar.j.benjamin at gmail.com
Sat Mar 15 13:42:51 CET 2014


On 15 March 2014 12:36, Oscar Benjamin <oscar.j.benjamin at gmail.com> wrote:
> On 15 March 2014 12:28, Antoine Pitrou <solipsis at pitrou.net> 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's true. I believe both blaze and numpypy intend to introduce
> optimisations in this style.

Just to add to that: I personally would almost always use brackets
rather than rely on left- or right- associativity for something like
this. A similar way that it can come up is with scalar-scalar vs
scalar-array multiplication e.g.:

2 * pi * x / L * A  # A is a big array

I would rewrite that as

(2 * pi * x / L) * A

rather than rely on precedence/associativity.


Oscar


More information about the Python-ideas mailing list