[Numpy-discussion] Curious behavior of __radd__

2012-02-01 Thread Andreas Kloeckner
Hi all, here's something I don't understand. Consider the following code snippet: --- class A(object): def __radd__(self, other): print(type(other)) import numpy as np np.complex64(1j) + A()

Re: [Numpy-discussion] Curious behavior of __radd__

2012-02-01 Thread Charles R Harris
On Wed, Feb 1, 2012 at 12:26 PM, Andreas Kloeckner li...@informa.tiker.netwrote: Hi all, here's something I don't understand. Consider the following code snippet: --- class A(object): def __radd__(self, other): print(type(other))

Re: [Numpy-discussion] Curious behavior of __radd__

2012-02-01 Thread Travis Oliphant
This seems odd to me. Unraveling what is going on (so far): Let a = np.complex64(1j) and b = A() * np.complex64.__add__ is calling np.add * np.add(a, b) needs to search for an add loop that matches the input types and it finds one with signature

Re: [Numpy-discussion] Curious behavior of __radd__

2012-02-01 Thread Travis Oliphant
Hey Andreas, As previously described: what changes the type of np.complex64(1j) during the A() call is that when a is an array scalar it is converted to an object array because that is the only signature that matches. During this conversion, what is extracted from the object array is piped