Skip to content

Instantly share code, notes, and snippets.

@diyan
Last active January 3, 2016 12:19
Show Gist options
  • Save diyan/8461724 to your computer and use it in GitHub Desktop.
Save diyan/8461724 to your computer and use it in GitHub Desktop.

How to install Numba on Ubuntu 13.10

  • separate calls of "pip install" is a must
  • v0.11.0 was failed to install from PyPI, so I've used version from GitHub
$ sudo apt-get install python-dev llvm-dev
$ virtualenv numba && cd $_ && . bin/activate
$ pip install ipython cython numpy llvmpy
$ pip install llvmmath
$ pip install https://github.com/numba/numba/archive/0.11_maintenance.zip 
# Save this code into jake_bench.py file
import numpy as np
from numba import double
from numba import jit
from numba import autojit


def pairwise_python(X, D):
    M = X.shape[0]
    N = X.shape[1]
    for i in range(M):
        for j in range(M):
            d = 0.0
            for k in range(N):
                tmp = X[i, k] - X[j, k]
                d += tmp * tmp
            D[i, j] = np.sqrt(d)


@autojit
def pairwise_numba_autojit(X, D):
    M = X.shape[0]
    N = X.shape[1]
    for i in range(M):
        for j in range(M):
            d = 0.0
            for k in range(N):
                tmp = X[i, k] - X[j, k]
                d += tmp * tmp
            D[i, j] = np.sqrt(d)

"""
# NOTE jit decorator did not worked on my workstation
@jit(arg_types=[double[:,:], double[:,:]])
def pairwise_numba_jit(X, D):
    M = X.shape[0]
    N = X.shape[1]
    for i in range(M):
        for j in range(M):
            d = 0.0
            for k in range(N):
                tmp = X[i, k] - X[j, k]
                d += tmp * tmp
            D[i, j] = np.sqrt(d)
"""

X = np.random.random((1000, 3))
D = np.empty((1000, 1000))


def pairwise_python_bench():
    pairwise_python(X, D)


def pairwise_numba_autojit_bench():
    pairwise_numba_autojit(X, D)


"""
def pairwise_numba_jit_bench():
    pairwise_numba_jit(X, D)
"""

Results on Core i7 3517U 1900 Mhz / Ubuntu 13.10 64 bit / Python 2.7.5 64 bit:

In [1]: from jake_bench import *

In [2]: %timeit pairwise_python_bench()
1 loops, best of 3: 6.11 s per loop

In [3]: %timeit pairwise_numba_autojit_bench()
1 loops, best of 3: 5.47 ms per loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment