[Pyrex] Subclassing Numeric arrays

khinsen at cea.fr khinsen at cea.fr
Wed May 11 15:11:15 CEST 2005


On May 9, 2005, at 11:46, George Sakkis wrote:

> array and delegates all calls to it. Unfortunately this was a 
> bottleneck
> for my real-time requirements, so I coded MyVector in Pyrex from 
> scratch
> (I need only a small fraction of the whole Numeric functionality).
> Although it's almost four time faster now, I have to convert 
> explicitly to
> Numeric arrays whenever a real array is expected. This is inelegant 
> apart

I did the same in the same situation - but it's not that much effort:

cdef class vector:

     cdef double xv, yv, zv

     property array:
         def __get__(self):
             return Numeric.array([self.xv, self.yv, self.zv])

That's three lines for the conversion, and since it's called rarely in 
my case, performance doesn't matter either.

BTW, I can confirm that Numeric arrays cannot be subclassed. The code 
was written for Python 1.4. Numarray provides subclassable arrays, but 
it has performance problems of its own for small arrays.

BTW, my Pyrex class for vectors is part of the ScientificPython 
distribution:
	http://dirac.cnrs-orleans.fr/ScientificPython/

Konrad.
--
---------------------------------------------------------------------
Konrad Hinsen
Laboratoire Léon Brillouin, CEA Saclay,
91191 Gif-sur-Yvette Cedex, France
Tel.: +33-1 69 08 79 25
Fax: +33-1 69 08 82 61
E-Mail: khinsen at cea.fr
---------------------------------------------------------------------




More information about the Pyrex mailing list