Created
May 26, 2018 08:57
-
-
Save dakami/5b0cb0bc53927a1a7fc8fa3c081078c1 to your computer and use it in GitHub Desktop.
Naive Numba Demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
#### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.