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 }}
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.
JanisGailis edited this page Apr 12, 2016
·
2 revisions
Numba
Numba gives you the power to speed up your applications with high performance functions written directly in Python. With a few annotations, array-oriented and math-heavy Python code can be just-in-time compiled to native machine instructions, similar in performance to C, C++ and Fortran, without having to switch languages or Python interpreters.
Numba works by generating optimized machine code using the LLVM compiler infrastructure at import time, runtime, or statically (using the included pycc tool). Numba supports compilation of Python to run on either CPU or GPU hardware, and is designed to integrate with the Python scientific software stack.
fromnumbaimportjitfromnumpyimportarange# jit decorator tells Numba to compile this function.# The argument types will be inferred by Numba when function is called.@jitdefsum2d(arr):
M, N=arr.shaperesult=0.0foriinrange(M):
forjinrange(N):
result+=arr[i,j]
returnresulta=arange(9).reshape(3,3)
print(sum2d(a))
See also this article on using Cython vs Numba for speeding up one's code.