[Pyrex] Numeric and Pyrex
Nitin Madnani
nmadnani at wam.umd.edu
Mon Sep 19 18:08:03 CEST 2005
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
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 !
Nitin
On Sep 19, 2005, at 10:39 AM, Nitin Madnani wrote:
> Hmm, I see. So I can call Numeric pythonically to create the array
> and then use the external type code as demonstrated in your example
> to fill it ? And I can do both of these things in the same pyrex
> module?
>
> Did I get that right? Awesome !
> Nitin
>
> On Sep 19, 2005, at 3:29 AM, Greg Ewing wrote:
>
>
>> Nitin Madnani wrote:
>>
>>
>>
>>> I need to be able to create Numeric arrays inside my pyrex
>>> function and be able to return that created Numeric array as the
>>> result of my function.
>>>
>>>
>>
>> The easiest way to create a Numeric array in Pyrex is
>> the same way you would do it in Python, i.e. by
>> calling its constructor, or one of the functions in the
>> Numeric module that constructs arrays.
>>
>> If you declare the Numeric array type as an external
>> extension type, then once you've created it, you can
>> access its C internals to put data into it. One of the
>> demos that comes with Pyrex shows the declarations
>> you need.
>>
>> Greg
>>
>>
>
>
> _______________________________________________
> Pyrex mailing list
> Pyrex at lists.copyleft.no
> http://lists.copyleft.no/mailman/listinfo/pyrex
>
More information about the Pyrex
mailing list