{"id":16027061,"url":"https://github.com/ashwinvis/cython_capi","last_synced_at":"2025-03-18T03:32:05.598Z","repository":{"id":95790113,"uuid":"112202679","full_name":"ashwinvis/cython_capi","owner":"ashwinvis","description":"Where is __pyx_capi__?","archived":false,"fork":false,"pushed_at":"2018-02-15T16:57:16.000Z","size":49,"stargazers_count":14,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-15T04:55:19.860Z","etag":null,"topics":["c","cython","python","pythran"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ashwinvis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-27T13:56:45.000Z","updated_at":"2024-08-09T05:48:27.000Z","dependencies_parsed_at":"2023-04-26T20:01:55.382Z","dependency_job_id":null,"html_url":"https://github.com/ashwinvis/cython_capi","commit_stats":{"total_commits":33,"total_committers":3,"mean_commits":11.0,"dds":"0.21212121212121215","last_synced_commit":"db86651b4fac4452ce5b9f99186b32b4b3c0cc4a"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashwinvis%2Fcython_capi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashwinvis%2Fcython_capi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashwinvis%2Fcython_capi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashwinvis%2Fcython_capi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ashwinvis","download_url":"https://codeload.github.com/ashwinvis/cython_capi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243901031,"owners_count":20366251,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","cython","python","pythran"],"created_at":"2024-10-08T20:04:48.752Z","updated_at":"2025-03-18T03:32:05.590Z","avatar_url":"https://github.com/ashwinvis.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Experiments with Cython C API and PyCapsules\n\nExploring different methods to activate the elusive `__pyx_capi__` attribute in\nCython modules.\n\nWhile using pxd, it is important that:\n\n 1. the `.pyx` and `.pxd` files are built in-place, i.e. the source files are\n    present where the `.so` file will appear.\n\n 2. `.pyx`, `.pxd` and `.so` files - all of them share the same name\n\nSee the differences by building and testing `using_pxd/pkg` and\n`using_pxd/pkg_inplace` by running `make all_pkg` and `make all_pkg_inplace`\nrespectively.\n\n## Summary of the different attempts in this repo\n\n| Directory | Description | What works | What does not work |\n|-----------|-------------|------------|--------------------|\n| `using_pxd` | 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`). |\n| `using_api_cpp_classes` | 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. |\n| `using_api_keyword` | 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 |\n| `using_cpython_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. | -no issues- |\n| `using_cpython_pycapsule_class` | A cleaner version of the previous case, containing only \"twice-functions\" | -ditto- | -ditto- and an attempt to write a C code with Python API to call the PyCapsule. |\n| `using_cpython_pycapsule_pointers` | Trying to use the `Rectangle.cpp` now with a bound-method with pointer arguments | -nothing works- | Unable to manually generate PyCapsules |\n| `using_cpython_pycapsule_class_array` | \"Twice-functions\" for an `array` of `float`s 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 |\n| `using_scipy_lowlevelcallable` | Instead of Pythran, we try to call PyCapsules using `scipy.LowLevelCallable` feature. It extends [the `integrate.nquad` example](https://docs.scipy.org/doc/scipy/reference/tutorial/integrate.html#quad-callbacks) 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). |\n\n## Similar Cython experiments by the community\n * https://github.com/pelson/calling_publicly_declared_cython_from_c\n * https://gist.github.com/insertinterestingnamehere/df7894b414a94a4456c5\n\n## References\n * [SciPy 2015](https://github.com/scipy-conference/scipy_proceedings_2015/blob/master/papers/ian_henriksen/cython_blas_lapack_api.rst) | [PDF](http://conference.scipy.org/proceedings/scipy2015/pdfs/proceedings.pdf)\n * [serge-sans-paille/pythran#743](https://github.com/serge-sans-paille/pythran/issues/743) and [serge-sans-paille/pythran#746](https://github.com/serge-sans-paille/pythran/issues/746)\n * [cython/cython#2027](https://github.com/cython/cython/issues/2027)\n * [cython-devel mail, 2012 Feb](https://mail.python.org/pipermail/cython-devel/2012-February/001864.html)\n * [cython-users mail, 2012 Dec](http://grokbase.com/t/gg/cython-users/12cmf6zzm9/how-to-make-cython-generate-pyx-capi)\n * [stackexchange](https://stackoverflow.com/questions/40572073/how-to-create-a-public-cython-function-that-can-receive-c-struct-instance-or-p#40691577)\n * [cython-docs](http://docs.cython.org/en/latest/src/userguide/extension_types.html#name-specification-clause)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashwinvis%2Fcython_capi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fashwinvis%2Fcython_capi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashwinvis%2Fcython_capi/lists"}