Comments (7)
Cython and numba:
- https://stackoverflow.com/questions/43016076/calling-cython-functions-from-numba-jitted-code
- https://numba.pydata.org/numba-doc/latest/extending/high-level.html#importing-cython-functions
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__.py
from 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
- empty
src2/__init__.pyd
$ cythonize -X language_level=3 -f -a -i myfilea.pyx src2/myfile2.pyx
from eko.
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.
Moreover, providing the C library for external users was the goal since the beginning. If EKO consumes the same one, at least during the transition, it's not bad (eventually, when the top-level infrastructure will move out of Numba, we could also consume a different kind of API). In any case, we aim to drop Numba.
from eko.
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 ...
from eko.
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 ctypes
).
from eko.
Cython is the minimal effort in rewriting
well, we would still need to rewrite everything from scratch (using C/Rust syntax)
from eko.
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...
(and doing it incrementally should make this a fully negligible concern)
from eko.
closed in favour of #189
from eko.
Related Issues (20)
- Improve tutorials HOT 2
- Consistently adopt `EvolutionPoint` HOT 2
- Hash computation seems not unique (across systems?) HOT 2
- Gluonic NNLO polarized matching in `M scheme` HOT 2
- `Atlas` do not infer correct values from `np.array` HOT 9
- In legacy runcards `nf0` is not correctly determined
- QED effects in polarized evolution
- Fix `apply_pdf` so that `(Q, nf)` does not overwrite `(Q, nf-1)`.
- Typo in docs HOT 2
- `evolve_pdfs` doesn't produce correct LHAPDF grids
- Is `matching_order` correctly determined? HOT 8
- On the backwards-compatibility or future-proofing of ekos HOT 15
- Remove photon and top from LHAPDF grid if they are not active HOT 5
- seemingly infinite error loop when running evolve_pdfs
- infinite error loop running evolve_pdfs HOT 5
- Packaging for rust
- Release for py 3.12 HOT 1
- Update `eko.io.dictlike` HOT 2
- Add a_Qg^3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eko.