Skip to content

Instantly share code, notes, and snippets.

@anyuzx
Created March 21, 2016 03:14
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 anyuzx/68f75d7c653ba4298f22 to your computer and use it in GitHub Desktop.
Save anyuzx/68f75d7c653ba4298f22 to your computer and use it in GitHub Desktop.
test script for numpy BLAS linkage
import numpy
from numpy.distutils.system_info import get_info
import sys
import timeit
print("version: %s" % numpy.__version__)
print("maxint: %i\n" % sys.maxsize)
info = get_info('blas_opt')
print('BLAS info:')
for kk, vv in info.items():
print(' * ' + kk + ' ' + str(vv))
setup = "import numpy; x = numpy.random.random((1000, 1000))"
count = 10
t = timeit.Timer("numpy.dot(x, x.T)", setup=setup)
print("\ndot: %f sec" % (t.timeit(count) / count))
import numpy as np
import numpy.random as npr
import time
# --- Test 1
N = 1
n = 1000
A = npr.randn(n, n)
B = npr.randn(n, n)
t = time.time()
for i in range(N):
C = np.dot(A, B)
td = time.time() - t
print("dotted two (%d,%d) matrices in %0.1f ms" % (n, n, 1e3*td/N))
# --- Test 2
N = 100
n = 4000
A = npr.randn(n)
B = npr.randn(n)
t = time.time()
for i in range(N):
C = np.dot(A, B)
td = time.time() - t
print("dotted two (%d) vectors in %0.2f us" % (n, 1e6*td/N))
# --- Test 3
m,n = (2000,1000)
A = npr.randn(m,n)
t = time.time()
[U,s,V] = np.linalg.svd(A, full_matrices=False)
td = time.time() - t
print("SVD of (%d,%d) matrix in %0.3f s" % (m,n,td))
# --- Test 4
n = 1500
A = npr.randn(n,n)
t = time.time()
w, v = np.linalg.eig(A)
td = time.time() - t
print("Eigendecomp of (%d,%d) matrix in %0.3f s" % (n,n,td))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment