[Numpy-discussion] one-offset arrays

Konrad Hinsen hinsen at cnrs-orleans.fr
Wed Aug 29 06:06:25 EDT 2001

> This led me to some thinking about why UserArrays are not more often used.
> I think one of the biggest reasons is that most of the functions can
> take UserArrays but returned the basic array type upon completion.
> So, you end up having to continually construct your UserArrays.


> Are there other reasons people have thought of?

Performance, in some cases. Or passing objects to C routines that expect
plain arrays. But the function issue is certainly the major one.

> So, here's a suggestion:
> Why don't we modify PyArray_Return to return an object of the same class as 
> one of the arguments which was passed if the class defines an __array__ 
> method. 

I don't think it can be done at the level of PyArray_Return, it cannot
know what the classes of the arguments were. We *could* achieve the
same goal by making appropriate modifications to all the C functions
in Numeric.

> Which argument to pick and how this would be implemented without
> changing old code is an interesting question.

No idea about the first issue, but compatibility can be assured (well,
in most cases) by picking some attribute name (__array__) that is not
used in the current UserArray class. We'd then have some other class
derived from UserArray which sets that attribute.

Konrad Hinsen                            | E-Mail: hinsen at cnrs-orleans.fr
Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-
Rue Charles Sadron                       | Fax:  +33-
45071 Orleans Cedex 2                    | Deutsch/Esperanto/English/
France                                   | Nederlands/Francais

More information about the NumPy-Discussion mailing list