[Numpy-discussion] Subclassing ndarray in C: getitem ?

Travis Oliphant oliphant@enthought....
Wed Jul 28 16:52:46 CDT 2010

On Jul 26, 2010, at 11:58 AM, Pierre GM wrote:

> All,
> I'm teaching myself how to subclass ndarrays in C (not in Cython, just plain C). It's slowly coming together, but I'm now running into a problem: I need to overwrite __getitem__ and I'm not sure how to do it. I was thinking about using my own function instead of array_as_mapping.mp_subscript, but how do I import array_as_mapping in the first place ? And is it really the way to go ?
> Any pointer appreciated...

To subtype in C, you have to populate the function pointer tables.  To "over-ride" __getitem__ you have to replace the function pointer, which in the case of mp_subscript is in the array_as_mapping table --- which you have to create as a static pointer table that contains the functions you want and then point the TypeObject structure to it some-time during initialization. 

I hope that helps a little bit.  


More information about the NumPy-Discussion mailing list