[Numpy-discussion] Ransom Proposals
Tim Hochberg
tim.hochberg at cox.net
Mon Mar 27 17:53:14 CST 2006
Travis Oliphant wrote:
> Tim Hochberg wrote:
>
>>> Charles R Harris wrote:
>>>
>>> >>> l = list(a)
>>> >>> l
>>> [999, 1, 2, 3, 4, 5, 6, 7, 8]
>>> >>> a
>>> array([999, 1, 2, 3, 4, 5, 6, 7, 8])
>>> >>> l += a
>>> >>> l
>>> array([1998, 2, 4, 6, 8, 10, 12, 14, 16])
>>> >>> a
>>> array([999, 1, 2, 3, 4, 5, 6, 7, 8])
>>
>>
>>
>>
>> Let me add that I think that this is pretty dubious, so if this is a
>> new feature, perhaps we should revert it before it becomes entrenched.
>
>
>
> I don't think it's a new feature, but it's simply the result of
>
> l += a being translated to
>
> l = l + a # lists don't have in-place add's
>
> Numeric has this behavior as well.
That's what I would expect, but Charles claimed it was resulted in an
error of some sort, so I was wondering if it was new.
I was also wondering if we could disable it somehow by proper finagaling
of the various add and iadd ops, but I can't really see how. However, I
did stumble on this odd behaviour:
class reporter(object):
def __init__(self, name):
self.name = name
def __add__(self, other):
print "add called on", self.name, other.name
return NotImplemented
def __radd__(self, other):
print "radd called on", self.name, other.name
return NotImplemented
def __iadd__(self, other):
print "iadd called on", self.name, other.name
return NotImplemented
class reporter2(reporter):
pass
a = reporter("A")
b = reporter2("B")
a += b
print a
==>
iadd called on A B
add called on A B
radd called on B A
iadd called on A B
NotImplemented
Shouldn't that raise TypeError? Yes? No? I'll go enter it as a bug, but
I want to make sure I'm not missing something stupid.
-tim
More information about the Numpy-discussion
mailing list