[Numpy-discussion] Numpy and PEP 343

Paul F. Dubois paul at pfdubois.com
Tue Feb 28 17:20:16 CST 2006


You're reinventing C++ expression templates, although since Python is 
dynamically typed you don't need templates. The crucial feature in C++ 
that lets it all work is that you can override the action for assignment.

a = b*c + d*e

If we could realize we were at the "equals" sign we could evaluate the 
RHS, and assign it to a.

This is not possible in Python; to make is possible would require 
slowing down regular assignment, which is perhaps a definition of bad.

a[...] = RHS

could be overridden but it is ugly and 'naive' users will forget.

a := RHS

could be added to the language with the semantics that it tries to do 
a.__assignment__(RHS) but Guido told me no long ago. (:->. Also, you 
might forget the : in :=.

a.assign(RHS)

would also work but then the original statement would produce a strange 
object with surprising results.

David M. Cooke wrote:
> Tim Hochberg <tim.hochberg at cox.net> writes:
> 
>> <pie-in-the-sky>
>>
>> An idea that has popped up from time to time is delaying evalution of
>> a complicated expressions so that the result can be computed more
>> efficiently. For instance, the matrix expression:
>>
>> a = b*c + d*e
>>
>> results in the creation of two, potentially large, temporary matrices
>> and also does a couple of extra loops at the C level than the
>> equivalent expression implemented in C would.
>>
>> The general idea has been to construct some sort of psuedo-object,
>> when the numerical operations are indicated, then do the actual
<snip>




More information about the Numpy-discussion mailing list