On Tue, Jun 30, 2009 at 10:07 PM, Ondrej Certik<[email protected]> wrote:
>
> One more question. I am using ctypes because using it I can take a
> list of floats and create a C array of it:
>
> (c_float * len(ptr))(*ptr)
>
> from historical reasons (I am adapting some opengl example from
> pyglet, that used that approach --- since pyglet uses ctypes to wrap
> opengl).

You can even use the builtin array.array to convert a list of float to
an array of floats.. Of course. Next you will need to make some Python
C-API calls to get the pointer to the memory buffer. The second part
is what I'm currently doing in mpi4py, and it is working from Py2.3 to
Py3.1

>
>I use cython, so I think a better way is to use numpy?
>

If the numpy dependency is not a problem, perhaps this is the better way.

> opengl supports strides, but it's just one number, e.g. it has to be
> the same for all rows (as opposed to numpy). Is it safe to just copy
> the numpy array, to make sure it's contiguous and then just use the
> pointer to the .data member of ndarray? That's what I always do, but I
> don't know if this is the safe or best approach.
>

Well, not really sure what OpenGL wants... you can look at petsc4py
sources to the NumPy C-API calls I'm using (more specifically, the
flags I'm passing)... These NumPy C-API calls return a new
(contiguous) array by copying only if required.


-- 
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to