CINXE.COM
Numba: A High Performance Python Compiler
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="description" content=""> <meta name="author" content=""> <link rel="icon" href="_static/numba-blue-icon-rgb.svg"> <title>Numba: A High Performance Python Compiler</title> <!-- Bootstrap core CSS --> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"> <link rel="stylesheet" href="_static/prism-duotone-light.css"> <!-- Custom styles for this template --> <link href="_static/main-page.css" rel="stylesheet"> <!-- Mastodon account verification --> <link rel="me" href="https://fosstodon.org/@numba" /> </head> <body> <header> <nav class="navbar navbar-expand-lg"> <div class="navbar-brand"> <img src="_static/numba-blue-icon-rgb.svg" style="height: 2rem;" alt="Numba logo"> </div> <div class="navbar-light bg-light"> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> </div> <div class="collapse navbar-collapse" id="navbarNavDropdown"> <ul class="navbar-nav"> <li class="navbar-item"><a class="nav-link" href="https://numba.readthedocs.io/en/stable/user/5minguide.html">Learn Numba in 5 minutes</a></li> <li class="nav-item dropdown"> <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> Documentation </a> <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink"> <a class="dropdown-item" href="https://numba.readthedocs.io/en/stable/index.html">Overview</a> <a class="dropdown-item" href="https://numba.readthedocs.io/en/stable/user/index.html">User Manual</a> <a class="dropdown-item" href="https://numba.readthedocs.io/en/stable/reference/index.html">Reference Manual</a> <a class="dropdown-item" href="https://numba.readthedocs.io/en/stable/cuda/index.html">NVIDIA CUDA GPU Programming</a> <a class="dropdown-item" href="https://numba.readthedocs.io/en/stable/developer/index.html">Developer Manual</a> <a class="dropdown-item" href="https://numba.readthedocs.io/en/stable/release-notes-overview.html">Release Notes</a> </div> </li> <li class="navbar-item"><a class="nav-link" href="https://numba.readthedocs.io/en/stable/user/installing.html">Install</a></li> <li class="navbar-item"><a class="nav-link" href="https://numba.pydata.org/numba-examples/">Examples</a></li> <li class="navbar-item"><a class="nav-link" href="https://numba.readthedocs.io/en/stable/user/talks.html">Talks/Tutorials</a></li> <li class="nav-item dropdown"> <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink2" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> Community </a> <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink2"> <a class="dropdown-item" href="https://github.com/numba/numba">Github</a> <a class="dropdown-item" href="https://pypi.org/project/numba/">PyPI</a> <a class="dropdown-item" href="https://anaconda.org/numba/">anaconda.org</a> <a class="dropdown-item" href="https://gitter.im/numba/numba">Gitter Chat</a> <a class="dropdown-item" href="https://numba.discourse.group/">Discourse Forum</a> </div> </li> </ul> </div> </nav> <div class="hero position-relative overflow-hidden p-3 text-center text-dark"> <div class="col-md-5 p-lg-1 mx-auto my-5"> <img src="_static/numba-blue-horizontal-rgb.svg" style="max-width: 30rem;" alt="Numba logo"> <p class="lead font-weight-normal"> Numba makes Python code fast </p> <p class="lead "> Numba is an open source JIT compiler that translates a subset of Python and NumPy code into fast machine code. </p> <a class="btn outline-numba btn-lg" href="https://numba.readthedocs.io/en/stable/user/5minguide.html">Learn More</a> <a class="btn filled-numba btn-lg" href="https://mybinder.org/v2/gh/numba/numba-examples/master?filepath=notebooks" role="button">Try Numba »</a> </div> <div class="product-device box-shadow d-none d-md-block"></div> <div class="product-device product-device-2 box-shadow d-none d-md-block"></div> </div> </header> <main role="main"> <!-- Wrap the rest of the page in another container to center all the content. --> <div class="container marketing p-md-5"> <div class="row featurette"> <div class="col-md-7"> <h2 class="featurette-heading">Accelerate Python Functions</h2> <p class="lead">Numba translates Python functions to optimized machine code at runtime using the industry-standard <a href="https://llvm.org/">LLVM</a> compiler library. Numba-compiled numerical algorithms in Python can approach the speeds of C or FORTRAN.</p> <p class="lead">You don't need to replace the Python interpreter, run a separate compilation step, or even have a C/C++ compiler installed. Just apply one of the Numba decorators to your Python function, and Numba does the rest. </p> <a class="btn btn-outline-secondary" href="https://numba.readthedocs.io/en/stable/user/jit.html" role="button">Learn More »</a> <a class="btn btn-secondary" href="https://mybinder.org/v2/gh/numba/numba-examples/master?filepath=notebooks%2Fbasics.ipynb" role="button">Try Now »</a> </div> <div class="col-md-5 code-block"> <pre><code class="language-python">from numba import njit import random @njit def monte_carlo_pi(nsamples): acc = 0 for i in range(nsamples): x = random.random() y = random.random() if (x ** 2 + y ** 2) < 1.0: acc += 1 return 4.0 * acc / nsamples</code></pre> </div> </div> <hr class="featurette-divider"> <div class="row featurette"> <div class="col-md-7"> <h2 class="featurette-heading">Built for Scientific Computing</h2> <p class="lead">Numba is designed to be used with NumPy arrays and functions. Numba generates specialized code for different array data types and layouts to optimize performance. Special decorators can create <a href="https://docs.scipy.org/doc/numpy/reference/ufuncs.html">universal functions</a> that broadcast over NumPy arrays just like NumPy functions do.</p> <p class="lead">Numba also works great with Jupyter notebooks for interactive computing, and with distributed execution frameworks, like Dask and Spark.</p> <a class="btn btn-outline-secondary" href="https://numba.readthedocs.io/en/stable/reference/numpysupported.html" role="button">Learn More »</a> <a class="btn btn-secondary" href="https://mybinder.org/v2/gh/numba/numba-examples/master?filepath=notebooks%2Fnumpy.ipynb" role="button">Try Now »</a> </div> <div class="col-md-5 code-block"> <pre><code class="language-python">@njit(parallel=True) def logistic_regression(Y, X, w, iterations): for i in range(iterations): w -= np.dot(((1.0 / (1.0 + np.exp(-Y * np.dot(X, w))) - 1.0) * Y), X) return w</code></pre> </div> </div> <hr class="featurette-divider"> <div class="row featurette"> <h2 class="featurette-heading">Parallelize Your Algorithms</h2> <p>Numba offers a range of options for parallelizing your code for CPUs and GPUs, often with only minor code changes.</p> <div class="row"> <div class="col-lg-4"> <h2 class="mt-3">Simplified Threading</h2> <pre><code class="language-python">@njit(parallel=True) def simulator(out): # iterate loop in parallel for i in prange(out.shape[0]): out[i] = run_sim()</code></pre> <p>Numba can automatically execute NumPy array expressions on multiple CPU cores and makes it easy to write parallel loops.</p> <p> <a class="btn btn-outline-secondary" href="https://numba.readthedocs.io/en/stable/user/parallel.html" role="button">Learn More »</a> <a class="btn btn-secondary" href="https://mybinder.org/v2/gh/numba/numba-examples/master?filepath=notebooks%2Fthreads.ipynb" role="button">Try Now »</a> </p> </div><!-- /.col-lg-4 --> <div class="col-lg-4"> <h2 class="mt-3">SIMD Vectorization</h2> <pre><code class="language-nasm">LBB0_8: vmovups (%rax,%rdx,4), %ymm0 vmovups (%rcx,%rdx,4), %ymm1 vsubps %ymm1, %ymm0, %ymm2 vaddps %ymm2, %ymm2, %ymm2</code></pre> <p>Numba can automatically translate some loops into vector instructions for 2-4x speed improvements. Numba adapts to your CPU capabilities, whether your CPU supports SSE, AVX, or AVX-512.</p> <p> <a class="btn btn-outline-secondary" href="https://numba.readthedocs.io/en/stable/user/performance-tips.html" role="button">Learn More »</a> <a class="btn btn-secondary" href="https://mybinder.org/v2/gh/numba/numba-examples/master?filepath=notebooks%2Fsimd.ipynb" role="button">Try Now »</a> </p> </div><!-- /.col-lg-4 --> <div class="col-lg-4"> <h2 class="mt-3">GPU Acceleration</h2> <img src="_static/nvidia_cuda.jpg" class="top-image" alt="NVIDIA CUDA logo"> <p>With support for NVIDIA CUDA, Numba lets you write parallel GPU algorithms entirely from Python.</p> <p> <a class="btn btn-outline-secondary" href="https://numba.readthedocs.io/en/stable/cuda/index.html" role="button">Numba CUDA »</a> </p> </div><!-- /.col-lg-4 --> </div><!-- /.row --> </div> <hr class="featurette-divider"> <div class="row featurette"> <div class="col-md-12"> <h2 class="featurette-heading">Portable Compilation</h2> <p class="lead">Ship high performance Python applications without the headache of binary compilation and packaging. Your source code remains pure Python while Numba handles the compilation at runtime. We test Numba continuously in more than 200 different platform configurations.</p> <p class="lead">Numba supports Intel and AMD x86, POWER8/9, and ARM CPUs (including Apple M1), NVIDIA GPUs, Python 3.9-3.12, as well as Windows/macOS/Linux. Precompiled Numba binaries for most systems are available as conda packages and pip-installable wheels.</p> <a class="btn btn-outline-secondary" href="https://numba.readthedocs.io/en/stable/user/installing.html" role="button">Learn More »</a> </div> </div> </div> <hr class="featurette-divider"> <section id="supporters"> <div class="container supporters"> <h2>Acknowledgements</h2> <p>Numba development is made possible through the current and/or past support of a number of organizations:<p> <div class="row"> <div class="col supporter"> <a href="https://anaconda.com"><img src="_static/anaconda_logo.png" alt="Anaconda logo"></a> </div> <div class="col supporter"> <a href="https://www.darpa.mil"><img src="_static/darpa_logo.png" alt="DARPA logo"></a> </div> <div class="col supporter"> <a href="https://www.moore.org/grant-detail?grantId=GBMF5423"><img src="_static/moore_logo.png" alt="Moore foundation logo"></a> </div> </div> <div class="row"> <div class="col supporter"> <a href="https://www.intel.com"><img src="_static/intel_logo.png" alt="Intel logo"></a> </div> <div class="col supporter"> <a href="https://www.nvidia.com/"><img src="_static/nvidia_logo.png" alt="NVIDIA logo"></a> </div> <div class="col supporter"> <a href="https://www.amd.com"><img src="_static/amd_logo.png" alt="AMD logo"></a> </div> </div> </div> </section> <!-- /END THE FEATURETTES --> <!-- FOOTER --> <footer class="container"> <p>© 2018 Anaconda</p> <p><i>HTML layout adapted from the <a href="http://dask.pydata.org/">Dask</a> homepage.</i></p> </footer> </main> <!-- Bootstrap core JavaScript ================================================== --> <!-- Placed at the end of the document so the pages load faster --> <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script> <!-- Code highlighting --> <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.6.0/prism.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.6.0/components/prism-python.min.js"></script> </body> </html>