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
12
votes
1 answer

Python: How to profile code written with numba.njit() decorators

I have a fairly complex computational code that I'm trying to speed up and multi-thread. In order to optimize the code, I'm trying to work out which functions are taking the longest or being called the most. I haven't really profiled code before, so…
Yoshi
  • 671
  • 8
  • 20
12
votes
1 answer

Using line_profiler with numba jitted functions

Is it possible to use line_profiler with Numba? Calling %lprun on a function decorated with @numba.jit returns an empty profile: Timer unit: 1e-06 s Total time: 0 s File: Function: conv at line 1 Line # Hits …
sudo
  • 503
  • 4
  • 12
12
votes
2 answers

How to pass additional parameters to numba cfunc passed as LowLevelCallable to scipy.integrate.quad

The documentation discusses using numba's cfuncs as LowLevelCallable argument of scipy.integrate.quad. I need the same thing with additional parameter. I'm basically trying to do something like this: import numpy as np from numba import cfunc import…
Ilya V. Schurov
  • 7,687
  • 2
  • 40
  • 78
12
votes
1 answer

Numba: calling jit with explicit signature using arguments with default values

I'm using numba to make some functions containing cycles on numpy arrays. Everything is fine and dandy, I can use jit and I learned how to define the signature. Now I tried using jit on a function with optional arguments, e.g.: from numba import…
gionni
  • 1,284
  • 1
  • 12
  • 32
12
votes
3 answers

Create multiple columns in Pandas Dataframe from one function

I'm a python newbie, so I hope my two questions are clear and complete. I posted the actual code and a test data set in csv format below. I've been able to construct the following code (mostly with the help from the StackOverflow contributors) to…
vlmercado
  • 1,848
  • 2
  • 17
  • 19
12
votes
2 answers

Using Numba with scikit-learn

Has anyone succeeded in speeding up scikit-learn models using numba and jit compilaition. The specific models I am looking at are regression models such as Logistic Regressions. I am able to use numba to optimize the functions I write using sklearn…
mzm
  • 373
  • 1
  • 6
  • 16
12
votes
2 answers

Retrieve generated LLVM from Numba

After compiling a Python function with Numba such as: from numba import jit @jit def sum(x, y): return x + y how can I retrieve the generated LLVM code (as a string) of the compiled function? It looks as though this was available in a previous…
InSilico
  • 213
  • 2
  • 7
11
votes
1 answer

Solving Linear Equations on the GPU with NumPy and PyTorch

I am trying to solve a lot of linear equations as fast as possible. To find out the fastest way I benchmarked NumPy and PyTorch, each on the CPU and on my GeForce 1080 GPU (using Numba for NumPy). The results really confused me. This is the code I…
wehnsdaefflae
  • 826
  • 2
  • 12
  • 27
11
votes
1 answer

CUDA GPU processing: TypeError: compile_kernel() got an unexpected keyword argument 'boundscheck'

Today I started working with CUDA and GPU processing. I found this tutorial: https://www.geeksforgeeks.org/running-python-script-on-gpu/ Unfortunately my first attempt to run gpu code failed: from numba import jit, cuda import numpy as np # to…
Artur Müller Romanov
  • 4,417
  • 10
  • 73
  • 132
11
votes
5 answers

convert float to string numba python numpy array

I am running a @nb.njit function within which I am trying to put an integer within a string array. import numpy as np import numba as nb @nb.njit(nogil=True) def func(): my_array = np.empty(6, dtype=np.dtype("U20")) my_array[0] =…
Chapo
  • 2,563
  • 3
  • 30
  • 60
11
votes
1 answer

Numba jit warnings interpretation in python

I have defined the following recursive array generator and am using Numba jit to try and accelerate the processing (based on this SO answer) @jit("float32[:](float32,float32,intp)", nopython=False, nogil=True) def calc_func(a, b, n): res =…
Chapo
  • 2,563
  • 3
  • 30
  • 60
11
votes
2 answers

Numba jit with scipy

So I wanted to speed up a program I wrote with the help of numba jit. However jit seems to be not compatible with many scipy functions because they use try ... except ... structures that jit cannot handle (Am I right with this point?) A relatively…
Katermickie
  • 213
  • 1
  • 2
  • 5
11
votes
1 answer

How to determine if numba's prange actually works correctly?

In another Q+A (Can I perform dynamic cumsum of rows in pandas?) I made a comment regarding the correctness of using prange about this code (of this answer): from numba import njit, prange @njit def dynamic_cumsum(seq, index, max_value): cumsum…
MSeifert
  • 145,886
  • 38
  • 333
  • 352
11
votes
1 answer

Using numpy.vstack in numba

So I have been trying to optimize some code that calculates a statistical error metric from some array data. The metric is called the Continuous Rank Probability Score (CRPS). I have been using Numba to try to speed up the double for loop required…
pythonweb
  • 1,024
  • 2
  • 11
  • 26
11
votes
1 answer

Running nested functions using numba

I am trying to use numba recently to speedup parts of my code in python. I was trying to run function 1 from inside function 2 while they are both compiled with numba but it is not working. Here is my code: import numba as nb from math import…
user1751189
  • 113
  • 1
  • 5