Skip to content

Instantly share code, notes, and snippets.

@Sentient07
Created October 17, 2016 11:55
Show Gist options
  • Save Sentient07/a4b69b9a3ca9b2568ba7d70f872c1af3 to your computer and use it in GitHub Desktop.
Save Sentient07/a4b69b9a3ca9b2568ba7d70f872c1af3 to your computer and use it in GitHub Desktop.
import numpy as np
import theano
import theano.tensor as T
import resource
def random_matrix_mult():
mat1 = T.fmatrix('mat1')
mat2 = T.fmatrix('mat2')
col_index = np.arange(0, 150000, 5000)
row_index = np.arange(10000)
first_matrix = col_index[:,np.newaxis] + row_index[np.newaxis, :]
second_matrix = np.random.random((20, 10000))
dot_output = T.dot(mat1, mat2.T)
dot_func = theano.function([mat1, mat2], dot_output, allow_input_downcast=True)
prior = resource.getrusage(resource.RUSAGE_SELF)
output = dot_func(first_matrix, second_matrix)
post = resource.getrusage(resource.RUSAGE_SELF)
print("User time for matrix theano: " + str(post.ru_utime - prior.ru_utime))
if __name__ == '__main__':
for i in range(2):
random_matrix_mult()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment