From: Konrad H. <hi...@cn...> - 2001-08-29 10:06:47
|
> 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. Exactly. > 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. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hi...@cn... Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24 Rue Charles Sadron | Fax: +33-2.38.63.15.17 45071 Orleans Cedex 2 | Deutsch/Esperanto/English/ France | Nederlands/Francais ------------------------------------------------------------------------------- |