Questions tagged [numba]

Numba is an open source NumPy-aware optimizing compiler for Python.

Numba is an Open Source NumPy-aware optimizing compiler for Python sponsored by Continuum Analytics, Inc. It uses the remarkable LLVM compiler infrastructure to compile Python syntax to machine code.

It is aware of NumPy arrays as typed memory regions and so can speed-up code using NumPy arrays. Other, less well-typed code will be translated to Python C-API calls effectively removing the "interpreter" but not removing the dynamic indirection.

Numba is also not a tracing jit. It compiles your code before it gets run either using run-time type information or type information you provide in the decorator.

Numba is a mechanism for producing machine code from Python syntax and typed data structures such as those that exist in NumPy.

Source: README.rst of the Numba project (GitHub).

More informations about the package can be found on the Numba homepage and documentation.

2244 questions
17
votes
2 answers

Using python type hints with numba

From the numba website: from numba import jit @jit def f(x, y): # A somewhat trivial example return x + y Is there a way to have numba use python type hints (if provided)?
user308827
  • 21,227
  • 87
  • 254
  • 417
17
votes
1 answer

How to nest numba jitclass

I'm trying to understand how the @jitclass decorator works with nested classes. I have written two dummy classes: fifi and toto fifi has a toto attribute. Both classes have the @jitclass decorator but compilation fails. Here's the code: fifi.py from…
ma3oun
  • 3,681
  • 1
  • 21
  • 33
17
votes
5 answers

How to speed up multiple inner products in python

I have some simple code that does the following. It iterates over all possible length n lists F with +-1 entries. For each one, it iterates over all possible length 2n lists S with +-1 entries, where the first half of $S$ is simply a copy of the…
Simd
  • 19,447
  • 42
  • 136
  • 271
17
votes
5 answers

Speeding up element-wise array multiplication in python

I have been playing around with numba and numexpr trying to speed up a simple element-wise matrix multiplication. I have not been able to get better results, they both are basically (speedwise) equivalent to numpys multiply function. Has anyone had…
JEquihua
  • 1,217
  • 3
  • 20
  • 40
16
votes
1 answer

What is the difference between @jit and @vectorize in numba?

When should I use @vectorize? I tried @jit and show that part of the code below, from numba import jit @jit def kma(g,temp): k=np.exp(-(g+np.abs(g))/(2*temp)) return k but my code didn't accelerate the algorithm. Why?
kinder chen
  • 1,371
  • 5
  • 15
  • 25
16
votes
1 answer

Efficient way to process pandas DataFrame timeseries with Numba

I have a DataFrame with 1,500,000 rows. It's one-minute level stock market data that I bought from QuantQuote.com. (Open, High, Low, Close, Volume). I'm trying to run some home-made backtests of stockmarket trading strategies. Straight python code…
JasonEdinburgh
  • 669
  • 1
  • 10
  • 17
16
votes
2 answers

Numba and Cython aren't improving the performance compared to CPython significantly, maybe I am using it incorrectly?

BIG EDIT: ================ For the sake of clarity, I am removing the old results and replace it by the more recent results. The question is still the same: Am I using both Cython and Numba correctly, and what improvements to the code can be made?…
user2489252
15
votes
1 answer

Inconsistent behavior of jitted function

I have a very simple function like this one: import numpy as np from numba import jit import pandas as pd @jit def f_(n, x, y, z): for i in range(n): z[i] = x[i] * y[i] f_(df.shape[0], df["x"].values, df["y"].values,…
user10102398
15
votes
1 answer

Use numba to speed up for loop

From what I've read, numba can significantly speed up a python program. Could my program's time efficiency be increased using numba? import numpy as np def f_big(A, k, std_A, std_k, mean_A=10, mean_k=0.2, hh=100): return ( 1 / (std_A * std_k *…
kilojoules
  • 9,768
  • 18
  • 77
  • 149
15
votes
3 answers

Julia performance compared to Python+Numba LLVM/JIT-compiled code

The performance benchmarks for Julia I have seen so far, such as at http://julialang.org/, compare Julia to pure Python or Python+NumPy. Unlike NumPy, SciPy uses the BLAS and LAPACK libraries, where we get an optimum multi-threaded SIMD…
hiccup
  • 277
  • 2
  • 8
14
votes
2 answers

Can Numba be used with Tensorflow?

Can Numba be used to compile Python code which interfaces with Tensorflow? I.e. computations outside of the Tensorflow universe would run with Numba for speed. I have not found any resources on how to do this.
Ron Cohen
  • 2,815
  • 5
  • 30
  • 45
14
votes
2 answers

Comparing Python accelerators (Cython,Numba,f2py) to Numpy einsum

I'm comparing Python accelerators (Numba, Cython, f2py) to simple For loops and Numpy's einsum for a particular problem (see below). So far Numpy is the fastest for this problem (factor 6x faster), but I wanted some feedback if there are additional…
Michael
  • 486
  • 6
  • 19
13
votes
3 answers

Make GPU available again after numba.cuda.close()?

So when I run cuda.select_device(0) and then cuda.close(). Pytorch cannot access the GPU again, I know that there is way so that PyTorch can utilize the GPU again without having to restart the kernel. But I forgot how. Does anyone else know? from …
Janosch
  • 356
  • 2
  • 13
13
votes
2 answers

Python: can numba work with arrays of strings in nopython mode?

I am using pandas 0.16.2, numpy 1.9.2 and numba 0.20. Is there any way to get numba to support arrays of strings in nopython mode? Alternatively, could I somehow convert strings to numbers which numba would recognise? I have to run certain loops on…
Pythonista anonymous
  • 8,140
  • 20
  • 70
  • 112
12
votes
5 answers

How could I speed up my written python code: spheres contact detection (collision) using spatial searching

I am working on a spatial search case for spheres in which I want to find connected spheres. For this aim, I searched around each sphere for spheres that centers are in a (maximum sphere diameter) distance from the searching sphere’s center. At…
Ali_Sh
  • 2,667
  • 3
  • 43
  • 66