[Pyrex] Numeric and Pyrex

len-l at telus.net len-l at telus.net
Mon Sep 19 19:51:32 CEST 2005


On 19 Sep 2005 at 12:08, Nitin Madnani wrote:

> Hmm ... here's what I tried:
> 
> import Numeric
> 
> cdef extern from "/nfshomes/nmadnani/local/include/python2.4/Numeric/ 
> arrayobject.h":
> 
>      struct PyArray_Descr:
>          int type_num, elsize
>          char type
> 
>      ctypedef class Numeric.ArrayType [object PyArrayObject]:
>          cdef char *data
>          cdef int nd
>          cdef int *dimensions, *strides
>          cdef object base
>          cdef PyArray_Descr *descr
>          cdef int flags
> 
> def estimate_future_costs(phrase_dict, sent):
>      cdef int i,j
>      cdef float* elems

     cdef ArrayType m

>      m = Numeric.zeros((3, 3), Numeric.Float)
> 
> So my question is that now that I have an Numeric array that I have  
> created, how do I access its C internals since 'm' is now a python  
> object right? Things like 'm.data' etc. don't seem to work. I would  
> really appreciate an example !!
> 
> Thanks !

Declaring m as ArrayType lets Pyrex ensure m is of the right type before allowing its 
C fields to be accessed directly. This is explained more fully in the Attributes section 
of the extension types page of the Pyrex documentation.

Lenard Lindstrom
<len-l at telus.net>




More information about the Pyrex mailing list