Pyrex and numarray

Simon Burton simonb at NOTTHISBIT.webone.com.au
Tue Jan 20 01:09:20 CET 2004


On Mon, 19 Jan 2004 19:33:28 +0100, Marco Bubke wrote:

> Hi
> 
> I have tried to include numarray in Pyrex but I get allways this error:
> 
> Traceback (most recent call last):
>   File "gears.py", line 9, in ?
>     import gl
>   File "/home/marco/projects/test_pyrex/gl.pyx", line 40, in gl
>     ctypedef class numarray.NumArray [object PyArrayObject]:
> ValueError: numarray.NumArray does not appear to be the correct type
> object
> 

Yes, i had that problem. Here is what I'm using now:

  ctypedef class numarray._numarray._numarray [object PyArrayObject]:
    # Compatibility with Numeric
    cdef char *data
    cdef int nd
    #cdef int dimensions[MAXDIM], strides[MAXDIM]
    cdef int *dimensions, *strides
    cdef object base
    cdef PyArray_Descr *descr
    cdef int flags
    # New attributes for numarray objects
    cdef object _data         # object must meet buffer API
    cdef object _shadows      # ill-behaved original array.
    cdef int    nstrides      # elements in strides array
    cdef long   byteoffset    # offset into buffer where array data begins
    cdef long   bytestride    # basic seperation of elements in bytes
    cdef long   itemsize      # length of 1 element in bytes
    cdef char   byteorder     # NUM_BIG_ENDIAN, NUM_LITTLE_ENDIAN
    cdef char   _aligned      # test override flag
    cdef char   _contiguous   # test override flag

cdef extern from "numarray/libnumarray.h":
  void import_libnumarray()
  object NA_NewAll(
    int ndim, maybelong* shape, NumarrayType type, void* buffer,
    maybelong byteoffset, maybelong bytestride, int byteorder, int aligned, int writeable )
  object NA_NewAllStrides(
    int ndim, maybelong* shape, maybelong* strides, NumarrayType type, void* buffer,
    int byteorder, int byteoffset, int aligned, int writeable )
  object NA_New( void* buffer, NumarrayType type, int ndim,... )
  object NA_Empty( int ndim, maybelong* shape, NumarrayType type )
  object NA_NewArray( void* buffer, NumarrayType type, int ndim, ... )
  object NA_vNewArray( void* buffer, NumarrayType type, int ndim, maybelong *shape )

  object NA_InputArray (object, NumarrayType, int)
  object NA_OutputArray (object, NumarrayType, int)
  object NA_IoArray (object, NumarrayType, int)
  object PyArray_FromDims(int nd, int *d, int type)
  object NA_updateDataPtr(object)
  object NA_getPythonScalar(object, long)
  object NA_setFromPythonScalar(object, int, object)
  #object NA_getPythonScalar(PyArrayObject, long)
  #object NA_setFromPythonScalar(PyArrayObject, int, PyArrayObject)

  object PyArray_ContiguousFromObject(object op, int type,
                                      int min_dim, int max_dim)
  #cdef void*NA_OFFSETDATA(object)
  void*NA_OFFSETDATA(_numarray)
  int  NA_nameToTypeNo  (char*)


Simon.

-- 
Simon Burton, B.Sc.
Licensed PO Box A66
ANU Canberra 2601
Australia
Ph. 02 6249 6940
http://arrowtheory.com 






More information about the Python-list mailing list