[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pypy-dev
Subject:    [pypy-dev] Issue #1777: Unable to create proper numpy array from cffi buffer (pypy/pypy)
From:       "Yichao Yu" <issues-reply () bitbucket ! org>
Date:       2014-05-25 23:42:15
Message-ID: 20140525234215.12252.49118 () app10 ! ash-private ! bitbucket ! org
[Download RAW message or body]

New issue 1777: Unable to create proper numpy array from cffi buffer
https://bitbucket.org/pypy/pypy/issue/1777/unable-to-create-proper-numpy-array-from

Yichao Yu:

I am writing something that need to convert a c buffer from cffi to a numpy array \
with arbitrary shape and strides. Besides the fact that \
[`as_strided`](https://bitbucket.org/pypy/numpy/issue/9/numpylibstride_tricksas_strided-is-not) \
is not really working, another problem is that the c buffer is maintained by the \
underlaying c/c++ library (OpenCL in this case). Therefore it is necessary to let the \
numpy ndarray hold a reference of the object which manage the memory.

In CPython, this is done by [setting the base on the \
ndarray](https://github.com/pyopencl/pyopencl/blob/master/src/wrapper/wrap_cl.hpp#L2718). \
However, there doesn't seem to be a way to do the same in (num)pypy.

In pypy, although I can pass the buffer to `np.frombuffer` and call `reshape` to get \
an array roughly correct, the array is only holding a reference to the buffer \
returned by cffi but not the (c++) object (or the python delegate of it) which \
manages the memory. Furthermore, the base property of the result array cannot be used \
to access the underlying object (which is currently a PyOpenCL API that I would love \
not to break.)

(The problem can probably be solved along with the [`as_strided` support \
bug](https://bitbucket.org/pypy/numpy/issue/9/numpylibstride_tricksas_strided-is-not) \
by allowing creating arrays from object with a proper array interface)



_______________________________________________
pypy-dev mailing list
pypy-dev@python.org
https://mail.python.org/mailman/listinfo/pypy-dev


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic