cython_capi | Where is __pyx_capi__? | Data Manipulation library
kandi X-RAY | cython_capi Summary
kandi X-RAY | cython_capi Summary
Demonstrates without using api keyword how __pyx_capi__ attribute is generated by Cython. How it requires pyx and pxd files to be in-place during build_ext step. Simple build_ext without packaging, in-place build_ext with packaging (see: setup_pkg_inplace.py). When build_ext is done with packaging using the Cython sources in some other directory (see setup_pkg.py). A Cython interface to a C++ class in Rectangle.cpp. Attempt to access a C++ bound method getArea. Modified api can export PyCapsules for regular Cython functions alone, not for bound methods in Cython classes. Pythran cannot have a struct type as an argument; thus Pythran fails to compile. A pyx file containing a function which adds 2 arrays / memory-views and another pyx file which adds integers. Also, Pythran file which includes similar add functions and a Pythran exported PyCapsule. PyCapsules exported using Cython (api) and Pythran is fed into the Pythran function. For integer type: Pythran calling Pythran-PyCapsule and Cython-PyCapsule. For array type: Pythran calling Pythran-PyCapsule. Direct Cython function calls. For array type: Pythran calling Cython-PyCapsule. Revisiting the Rectangle.cpp example, now with manually created PyCapsules through Cython. A cpdef function which works as a wrapper to access the getArea C++ bound method: only has int as argument and return types. Different kinds of twice functions of unbound cdef type and bound cpdef and static types. A cleaner version of the previous case, containing only "twice-functions". -ditto- and an attempt to write a C code with Python API to call the PyCapsule. Trying to use the Rectangle.cpp now with a bound-method with pointer arguments. Unable to manually generate PyCapsules. "Twice-functions" for an array of floats instead of a scalar int. Manually creating PyCapsules using make_PyCapsule function. Calling unbound and bound methods of cdef/cpdef/static types with memoryview/ndarray argument types from Pythran with the PyCapsules. Instead of Pythran, we try to call PyCapsules using scipy.LowLevelCallable feature. It extends the integrate.nquad example found in SciPy docs. We use Cython instead of ctypes to generate the LowLevelCallable for the same example. Cython function using double* argument. Cython function using a memoryview or numpy argument (Could be something related to SciPy internals, since scipy does a preliminary type checking using the PyCapsule's signature).
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Call a capsule .
- Add int caps to f
- Add a capsule to f
- Add a function to a function .
- Calculates the fractional capulus
- Apply func to a function .
- Get the area of the rectangle
cython_capi Key Features
cython_capi Examples and Code Snippets
Community Discussions
Trending Discussions on cython_capi
QUESTION
We would need to create a PyCapsule from a method of a class in Cython. We managed to write a code which compiles and even runs without error but the results are wrong.
A simple example is here: https://github.com/paugier/cython_capi/tree/master/using_cpython_pycapsule_class
The capsules are executed by Pythran (one needs to use the version on github https://github.com/serge-sans-paille/pythran).
The .pyx file:
...ANSWER
Answered 2017-Dec-04 at 21:39To follow up/expand on my comments:
The basic issue is that the Pythran is expecting a C function pointer with the signature int f(int)
to be contained within the PyCapsule. However, the signature of your methods is int(PyObject* self, int c)
. The 2
gets passed as self
(not causing disaster since it isn't actually used...) and some arbitrary bit of memory is used in place of the int c
. Unfortunately it isn't possible to use pure C code to create a C function pointer with "bound arguments" so Cython can't (and realistically won't be able to) do it.
Modification 1 is to get better compile-time type checking of what you're passing to your PyCapsules
by creating a function that accepts the correct types and casting in there, rather than just casting to blindly. This doesn't solve your problem but warns you at compile-time when it isn't going to work:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install cython_capi
You can use cython_capi like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page