Skip to content

Instantly share code, notes, and snippets.

@dakami
Created May 26, 2018 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dakami/5b0cb0bc53927a1a7fc8fa3c081078c1 to your computer and use it in GitHub Desktop.
Save dakami/5b0cb0bc53927a1a7fc8fa3c081078c1 to your computer and use it in GitHub Desktop.
Naive Numba Demo
import numpy as np
from numba import jit
X = (np.random.random((256,256))*16).astype(int)
Y = (np.random.random((256,256))*16).astype(int)
@jit
def naive():
result = np.zeros((256,256))
for i in range(len(X)):
for j in range(len(Y[0])):
for k in range(len(Y)):
result[i][j] += X[i][k] * Y[k][j]
return result
result=naive()
print(result[1])
#####
#$ time python3 naive.py
#real 0m1.114s
#user 0m3.006s
#sys 0m6.170s
#(commenting out @jit )
#$ time python3 naive.py
#real 0m19.950s
#user 0m21.928s
#sys 0m6.083s
####
@dakami
Copy link
Author

dakami commented May 26, 2018

Note this is super naive, not using @jit with nopython=true or target='gpu' or type declaration or or or. But seriously, numba is all kinds of baller. LLVM loves you and wants you to be happy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment