-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Cython as numba alternative #266
Comments
Cython and numba:
Cython submodules: myfilea.pyx# cython: language_level=3
from src2.myfile2 import f2
cpdef api double foo(double x):
return x * f2(x) src2/myfile2.pyx# cython: language_level=3
def f2(x):
return 2.*x*x pkgcy/__init__.pyfrom scipy.integrate import quad
import os
# if os.environ.get("BUILD_WHEEL",False):
# pass
# else:
# import pyximport; pyximport.install()
# from myfilea import f3a as g
# # import myfile
import numba as nb
import ctypes
from numba.extending import get_cython_function_address
addr = get_cython_function_address("myfilea", "foo")
functype = ctypes.CFUNCTYPE(ctypes.c_double, ctypes.c_double)
myexp = functype(addr)
@nb.njit
def f(x):
return x * myexp(x)
def run():
# print(myfile.__pyx_capi__)
# return f(10.)
return quad(f, 0.,1.) and
|
We can call more or less in the same way any C library from Numba: https://numba.readthedocs.io/en/stable/user/cfunc.html#calling-c-code-from-numba At that point, I'd write the code directly in C/C++, or in Rust and providing a C API. |
yes, but the main advantage of using Cython is the minimal effort in rewriting, because I'm still afraid of doing all in one gigantic step ... this way we could, maybe, do step by step, though I'm not sure still ... |
This is exactly what I was pointing out: the same feature that allows Cython to be introduced one step at a time could be used with whatever C library (because it's based on |
well, we would still need to rewrite everything from scratch (using C/Rust syntax) |
For as long as it's just math, the C/Rust syntax is mostly Python syntax. It was Fortran in the first place... |
closed in favour of #189 |
related to #185 - for the moment I use this issue to save my work on a different place than just my computer ... eventually, I think, I can turn this into an PR.
at the moment it seems doing just
poetry build
is not enough, but doing just before acythonize -X language_level=3 -a -i myfile.pyx
seems to be sufficientcc @scarrazza
Resources
Files
`pyproject.toml`
`pkgcy/__init__.py`
`mybuild.py`
`myfile.pyx`
The text was updated successfully, but these errors were encountered: