Created
February 24, 2015 03:58
-
-
Save matpalm/7b519c93ca6fb732dd17 to your computer and use it in GitHub Desktop.
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 | |
import time | |
np.random.seed(123) | |
# square matrices will do for a demo | |
m = np.random.randn(1000, 1000).astype('float32') | |
x = np.random.randn(1000, 1000).astype('float32') | |
b = np.random.randn(1000, 1000).astype('float32') | |
start = time.time() | |
for i in range(500): | |
y = np.add(np.dot(m, x), b) | |
print "numpy", time.time()-start, "sec" |
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 | |
import time | |
import theano | |
import theano.tensor as T | |
# define data | |
np.random.seed(123) | |
m = np.random.randn(1000, 1000).astype('float32') | |
x = np.random.randn(1000, 1000).astype('float32') | |
b = np.random.randn(1000, 1000).astype('float32') | |
# define a symbolic expression of the equations in theano | |
tm = T.matrix("m") | |
tx = T.matrix("x") | |
tb = T.matrix("b") | |
ty = T.add(T.dot(tm, tx), tb) | |
# and compile it | |
line = theano.function(inputs=[tx, tm, tb], outputs=[ty]) | |
print theano.printing.debugprint(line) | |
print theano.printing.pydotprint(line) | |
# then run same loop as before | |
start = time.time() | |
for i in range(500): | |
y, = line(m, x, b) | |
print "theano", time.time()-start, "sec" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment