sometype.__new__ and C subclasses

2010-05-02 Thread James Porter
I've been trying to write a Python C extension module that uses NumPy and has a subtype of numpy.ndarray written in C. However, I've run into a snag: calling numpy.ndarray.__new__(mysubtype, ...) triggers an exception in the bowels of Python (this is necessary for a handful of NumPy features).

Re: sometype.__new__ and C subclasses

2010-05-02 Thread James Porter
On 5/2/2010 4:34 AM, Carl Banks wrote: Why don't you use mysubtype.__new__(mysubtype,...)? If you wrote mysubtype in C, and defined a different tp_new than ndarray, then this exception will trigger. And it ought to; you don't want to use ndarray's tp_new to create an object of your subclass,

Re: sometype.__new__ and C subclasses

2010-05-02 Thread James Porter
On 5/2/2010 1:43 PM, Robert Kern wrote: Perhaps things would be clearer if you could post the C code that you've written that fails. So far, you've only alluded at what you are doing using Python-syntax examples. I'm not sure how much this will help, but here you go. The actual C code

Re: sometype.__new__ and C subclasses

2010-05-02 Thread James Porter
On 5/2/2010 3:58 PM, Robert Kern wrote: Well, I think we can change zeros_like() and the rest to work around this issue. Can you bring it up on the numpy mailing list? def zeros_like(a): if isinstance(a, ndarray): res = numpy.empty(a.shape, a.dtype, order=a.flags.fnc) res.fill(0) res =