You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
suggest add numpy to dependance of codon-jit so that it can be installed automatically #808
import codon
from time import time
@codon.jit(debug=True)
def codon_numpy_sum(n: int) -> float:
import numpy as np
arr = np.arange(n, dtype=np.float64)
return ((arr * 2.0) + 1.0).sum()
def main() -> None:
n = 1_000_000
t0 = time()
ans = codon_numpy_sum(n)
t1 = time()
print(f"[codon numpy only] result={ans:.1f} time={t1 - t0:.6f}s")
if __name__ == "__main__":
main()
Result
After uninstalling CPython NumPy:
$ python3 -m pip uninstall numpy
Found existing installation: numpy 2.4.4
Uninstalling numpy-2.4.4:
Would remove:
/home/swchoi/.venvs/codon311/bin/f2py
/home/swchoi/.venvs/codon311/bin/numpy-config
/home/swchoi/.venvs/codon311/lib/python3.11/site-packages/numpy-2.4.4.dist-info/*
/home/swchoi/.venvs/codon311/lib/python3.11/site-packages/numpy.libs/libgfortran-040039e1-0352e75f.so.5.0.0
/home/swchoi/.venvs/codon311/lib/python3.11/site-packages/numpy.libs/libquadmath-96973f99-934c22de.so.0.0.0
/home/swchoi/.venvs/codon311/lib/python3.11/site-packages/numpy.libs/libscipy_openblas64_-32a4b2a6.so
/home/swchoi/.venvs/codon311/lib/python3.11/site-packages/numpy/*
Proceed (Y/n)? Y
Successfully uninstalled numpy-2.4.4
Running the MRE fails before the Codon-compiled function body is actually used:
$ python3 codon_numpy_only_demo.py
Traceback (most recent call last):
File "/home/swchoi/src/test_code/python_codon_dsl/codon_numpy_only_demo.py", line 7, in <module>
import codon
File "/home/swchoi/src/codon/install/python/codon/__init__.py", line 7, in <module>
from .decorator import jit, convert, execute, JITError, JITWrapper, _jit_register_fn, _jit_callback_fn, _jit
File "/home/swchoi/src/codon/install/python/codon/decorator.py", line 13, in <module>
import numpy as np
ModuleNotFoundError: No module named 'numpy'
(codon311) swchoi@swc-WIN:~/src/test_code/python_codon_dsl$ ```
Running the MRE fails before the Codon-compiled function body is actually used:
Root Cause
This failure happens even when the user code only intends to use Codon's native NumPy support inside the JIT-compiled function, not CPython's NumPy module directly.
Looking at codon/install/python/codon/decorator.py, the decorator currently refers to CPython NumPy scalar types:
Because of this, importing codon through the Python JIT path implicitly depends on the CPython NumPy package being installed,
even if Codon Native NumPy is only imported inside the Codon-compiled function body.
My understanding is that these entries are used to map Python / NumPy scalar types to Codon's statically typed representation.
Since Python's builtin numeric types do not always encode the exact fixed-width type information needed here, NumPy scalar types are being used as convenient concrete type markers.
A possible direction may be to avoid requiring CPython NumPy at module import time by using another internal/builtin representation for fixed-width scalar type markers.
Alternatively, if this dependency is intentional, it may be worth documenting that codon-jit currently requires CPython NumPy for NumPy scalar type conversion support, or just add module dependency,
even when the compiled function body uses Codon's native NumPy implementation.
Activity
BI71317 commentedon May 15, 2026
MRE
Result
After uninstalling CPython NumPy:
Running the MRE fails before the Codon-compiled function body is actually used:
Root Cause
This failure happens even when the user code only intends to use
Codon's native NumPysupport inside the JIT-compiled function, notCPython's NumPymodule directly.Looking at
codon/install/python/codon/decorator.py, the decorator currently refers toCPython NumPyscalar types:Because of this, importing codon through the Python JIT path implicitly depends on the
CPython NumPypackage being installed,even if
Codon Native NumPyis only imported inside the Codon-compiled function body.My understanding is that these entries are used to map Python / NumPy scalar types to Codon's statically typed representation.
Since Python's builtin numeric types do not always encode the exact fixed-width type information needed here, NumPy scalar types are being used as convenient concrete type markers.
A possible direction may be to avoid requiring CPython NumPy at module import time by
using another internal/builtin representation for fixed-width scalar type markers.Alternatively, if this dependency is intentional, it may be worth documenting that codon-jit currently requires CPython NumPy for NumPy scalar type conversion support, or just add module dependency,
even when the compiled function body uses Codon's native NumPy implementation.