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

Filtering (reducing) a NumPy Array

Suppose I have a NumPy array arr that I want to element-wise filter (reduce) depending on the truth value of a (broadcastable) function, e.g. I want to get only values below a certain threshold value k: def cond(x): return x < k There are a…
norok2
  • 25,683
  • 4
  • 73
  • 99
55
votes
2 answers

How do I use numba on a member function of a class?

I'm using the stable version of Numba 0.30.1. I can do this: import numba as nb @nb.jit("void(f8[:])",nopython=True) def complicated(x): for a in x: b = a**2.+a**3. as a…
dbrane
  • 887
  • 1
  • 7
  • 19
50
votes
3 answers

Improve Pandas Merge performance

I specifically dont have performace issue with Pands Merge, as other posts suggest, but I've a class in which there are lot of methods, which does a lot of merge on datasets. The class has around 10 group by and around 15 merge. While groupby is…
Debasish Kanhar
  • 1,123
  • 2
  • 15
  • 27
49
votes
3 answers

Python numpy: cannot convert datetime64[ns] to datetime64[D] (to use with Numba)

I want to pass a datetime array to a Numba function (which cannot be vectorised and would otherwise be very slow). I understand Numba supports numpy.datetime64. However, it seems it supports datetime64[D] (day precision) but not datetime64[ns]…
Pythonista anonymous
  • 8,140
  • 20
  • 70
  • 112
49
votes
2 answers

Multiple output and numba signatures

Maybe it is trivial, but I was wondering how to write signatures in the jit decorator when there are several outputs. For instance : import numba as nb @nb.jit(['???(int32, int32, float(:,:), float(:,:))'], nopython=True) def foo(nx, ny, a, b): …
Ipse Lium
  • 970
  • 1
  • 6
  • 19
46
votes
2 answers

Why is np.dot so much faster than np.sum?

Why is np.dot so much faster than np.sum? Following this answer we know that np.sum is slow and has faster alternatives. For example: In [20]: A = np.random.rand(1000) In [21]: B = np.random.rand(1000) In [22]: %timeit np.sum(A) 3.21 µs ± 270 ns…
Simd
  • 19,447
  • 42
  • 136
  • 271
39
votes
8 answers

Matrix inversion without Numpy

I want to invert a matrix without using numpy.linalg.inv. The reason is that I am using Numba to speed up the code, but numpy.linalg.inv is not supported, so I am wondering if I can invert a matrix with 'classic' Python code. With numpy.linalg.inv…
32
votes
1 answer

Performance of various numpy fancy indexing methods, also with numba

Since for my program fast indexing of Numpy arrays is quite necessary and fancy indexing doesn't have a good reputation considering performance, I decided to make a few tests. Especially since Numba is developing quite fast, I tried which methods…
JE_Muc
  • 5,403
  • 2
  • 26
  • 41
32
votes
4 answers

Why is numba faster than numpy here?

I can't figure out why numba is beating numpy here (over 3x). Did I make some fundamental error in how I am benchmarking here? Seems like the perfect situation for numpy, no? Note that as a check, I also ran a variation combining numba and numpy…
JohnE
  • 29,156
  • 8
  • 79
  • 109
27
votes
9 answers

Cuda: library nvvm not found

I am trying to run the code below but an error is reported: NvvmSupportError: libNVVM cannot be found. Do conda install cudatoolkit: library nvvm not found My development environment is: Ubuntu 17.04, Spyder/Python3.5 and I have installed via conda…
Helton Maia
  • 271
  • 1
  • 4
  • 5
27
votes
4 answers

Comparing Python, Numpy, Numba and C++ for matrix multiplication

In a program I am working on, I need to multiply two matrices repeatedly. Because of the size of one of the matrices, this operation takes some time and I wanted to see which method would be the most efficient. The matrices have dimensions (m x…
JD80121
  • 591
  • 1
  • 6
  • 13
26
votes
2 answers

numba - TypingError: cannot determine Numba type of

I have a simple function to rank poker hands (the hands are strings). I call it with rA,rB = rank(a),rank(b) and here is my implementation. Works well without @jit(nopython=True), but with it, it fails: File "...poker.py", line 190, in
CIsForCookies
  • 12,097
  • 11
  • 59
  • 124
26
votes
5 answers

Python: rewrite a looping numpy math function to run on GPU

Can someone help me rewrite this one function (the doTheMath function) to do the calculations on the GPU? I used a few good days now trying to get my head around it but to no result. I wonder maybe somebody can help me rewrite this function in…
RaduS
  • 2,465
  • 9
  • 44
  • 65
26
votes
10 answers

Getting python Numba working on Ubuntu 14.10 or Fedora 21 with python 2.7

Recently, I have had a frustrating time to get python Numba working on Ubuntu or Fedora Linux. The main problem has been with the compilation of llvmlite. What do I need to install for these to compile properly?
mettw
  • 439
  • 5
  • 10
25
votes
2 answers

How to parallelize this Python for loop when using Numba

I'm using the Anaconda distribution of Python, together with Numba, and I've written the following Python function that multiplies a sparse matrix A (stored in a CSR format) by a dense vector x: @jit def csrMult( x, Adata, Aindices, Aindptr, Ashape…
littleO
  • 942
  • 1
  • 11
  • 26
1
2 3
99 100