[Pyrex] Numeric and Pyrex: you may need to call import_array()

Lukasz Pankowski lukpank at o2.pl
Mon Sep 19 23:38:49 CEST 2005


Nitin Madnani <nmadnani at wam.umd.edu> writes:

> cdef extern from "/nfshomes/nmadnani/local/include/python2.4/Numeric/ 
> arrayobject.h":
>
>     ctypedef struct PyArray_Descr:
>         int type_num, elsize
>         char type
>
>     ctypedef struct PyArrayObject:
>         char *data
>         int nd
>         int *dimensions, *strides
>         object base
>         PyArray_Descr *descr
>         int flags
>
>     PyObject* PyArray_FromDims(int n_dimensions, int dimensions 
> [n_dimensions], int type_num)

If you decide to use PyArray_FromDims or other PyArray_* functions in your
Pyrex module you may also add:

#-----
cdef extern from "Numeric/arrayobject.h":
    void import_array() except *

# Needed for arrayobject.h functions to work
import_array()
#-----

or first call to PyArray_* function will crash your module, as
explained Chapter 12. (Writing a C extension to NumPy) of "Numerical
Python".

-- 

=*= Lukasz Pankowski =*=



More information about the Pyrex mailing list