Last active
August 29, 2015 14:19
-
-
Save natemurthy/c919ece7f3df7e8addd5 to your computer and use it in GitHub Desktop.
linear algebra benchmarks
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
from numpy import linalg | |
import numpy as np | |
import time | |
""" This will generate a random NxN invertible matrix [1] """ | |
def generate_mat(n): | |
mat = list() | |
for k in range(n): | |
rv = np.linspace(1,1,n) | |
rv = rv*np.random.random(n) | |
rv[k] = rv[k]*(k+1) | |
mat.append(rv) | |
return np.array(mat) | |
""" Some benchmarks worth trying out """ | |
N = 2000 | |
# Time to construct matrix A | |
s=time.time(); A=generate_mat(N); e=time.time(); print (e-s) # my machine: 0.184283971 sec | |
# Time to compute inverse of A | |
s=time.time(); result=linalg.inv(A); e=time.time(); print (e-s) # my machine: 2.667845010 sec | |
# Time to compute eigen[values/vectors] of A | |
s=time.time(); result=linalg.eig(A); e=time.time(); print (e-s) # my machine: 29.871132135 sec | |
# Time to compute Singular Value Decomposition of A | |
s=time.time(); result=linalg.svd(A); e=time.time(); print (e-s) # my machine: 15.854166984 sec | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
CPU starts to choke on my machine (Ubuntu 14.04 on virtualized Intel Core i7-3687U with 12 GB RAM running Python 2.7.6) when N >= 2000
References:
[1] https://matthewhr.wordpress.com/2013/09/01/how-to-construct-an-invertible-matrix-just-choose-large-diagonals/