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

Pierre GM pgmdevlist at gmail.com
Wed Jul 28 21:08:24 EDT 2010


On Jul 28, 2010, at 7:52 PM, Pauli Virtanen wrote:

> Wed, 28 Jul 2010 18:43:30 -0400, Pierre GM wrote:
> [clip]
>> Mmh. I did create a PyMappingMethod structure called MyArray_as_mapping,
>> and MyArray_as_mapping.mp_subscript points to the function that I want
>> to use. However, I'd like the MyArray_as_mapping.length and
>> MyArray.mp_ass_subscript to point to their PyArray equivalent. I was
>> hoping to do something like MyArray_as_mapping.length =
>> array_as_mapping.length but I don't know how to import array_as_mapping.
> 
> Maybe you can leave them NULL? I don't remember if they are inherited.

I gonna try that, good idea.

> 
>> I also tried to do
>> MyArray_as_mapping.length = &PyArray_Type->tp_as_mapping->length but it
>> doesn't work... And that's where I'm stuck...
> 
> How it fails?

 error: initializer element is not constant

> 
> Note that you probably need to call import_array() first before assigning 
> the function pointers.

Mmh, Not sure whether it's gonna be possible. The import_array() is in an import function called in yet another file... But thx for the pointer, I'll keep you posted

[a bit later...]
Well, setting MyArray_as_mapping.length to NULL does the trick indeed. Cool !!!





More information about the NumPy-Discussion mailing list