Pyrex and numarray

Marco Bubke marco at
Mon Jan 19 19:33:28 CET 2004


I have tried to include numarray in Pyrex but I get allways 
this error:

Traceback (most recent call last):
  File "", 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

The code is:

cdef extern from "numarray/numarray.h":
  struct PyArray_Descr: 
    int type_num, elsize 
    char type 

  ctypedef class numarray.NumArray [object PyArrayObject]: 
    cdef char *data 
    cdef int nd 
    cdef int *dimensions, *strides 
    cdef object base 
    cdef PyArray_Descr *descr 
    cdef int flags
    cdef object _data
    cdef object _shadows
    cdef long int nstrides
    cdef long byteoffset
    cdef long bytestride
    cdef long itemsize
    cdef char byteorder
    cdef char _aligned
    cdef char _contiguous
    cdef char *wptr

def materialfv(GLenum face, GLenum pname, NumArray params):
  Set the material.
  materialfv(enum face, enum pname, params)
  params - should be a tuple
  assert (len(params) == 4 and pname in \
    or (len(params) == 1 and pname == SHININESS) \
    or (len(param) == 1 and pname == COLOR_INDEXES),\
    "arguments are not right"
  str_params = params.tostring()
  print str_params
  cdef float* flat_params
  flat_params = <float*>str_params
  glMaterialfv(face, pname, flat_params)

I write a little OpenGL wrapper of my own(I know PyOpenGL but it doesn't fit
to me). Now I try to get the numarray to this function and cast it to a
float pointer(ugly hack, will be cleaned later).



More information about the Python-list mailing list