[Numpy-discussion] numpy.complex* functions do not call the __complex__ method

jason-sage@creativetra... jason-sage@creativetra...
Thu Sep 25 15:28:50 CDT 2008

Neal Becker wrote:
> jason-sage@creativetrax.com wrote:
>> In creating an array of type numpy.complex128, I'm having problems
>> passing in Sage types that should be considered complex numbers since
>> they implement the standard __complex__ method.  However, numpy doesn't
>> recognize that.  Here's a minimal example:
> I had tried to add my own complex_int class (using c++ code).  Although partly successful, I was not able to get x.real to work.  The reason is that PyArray_ISCOMPLEX is used in various places, and this is a hard-coded macro.  There is no way to extend numpy's complex behavior to support user added types.  I wish there was.

Is there any possibility of redefining the macro to first call the 
Python function that converts to a python complex?  (I don't know much 
about the python C API, just throwing an idea out).  My example works if 
I do:


 but not if I do


Can we make the call to python's complex (or maybe numpy's copy of it) 



More information about the Numpy-discussion mailing list