Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • pypy pypy
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 668
    • Issues 668
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 15
    • Merge requests 15
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar

Mercurial Paris conference scheduled ! Main event : 2022-09-22. Call for papers deadline: 2022-06-17.

  • PyPy
  • pypypypy
  • Issues
  • #1777

Closed
Open
Created May 25, 2014 by Bitbucket Importer@bitbucket_importerMaintainer

Unable to create proper numpy array from cffi buffer

Created originally on Bitbucket by yuyichao (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 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. 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 by allowing creating arrays from object with a proper array interface)

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking