-
Notifications
You must be signed in to change notification settings - Fork 0
/
svdtimer.py
29 lines (24 loc) · 695 Bytes
/
svdtimer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""
This is just a script to test the svd speed.
Reasonable inputs are n=450 p=10000.
"""
import time
import sys
import numpy as np
def main():
usage = 'Usage: ' + sys.argv[0] + ' <n> <p>'
if len(sys.argv) != 3:
print usage
return
script_name, nrows_string, ncols_string = sys.argv
n, p = int(nrows_string), int(ncols_string)
print 'create a', n, 'by', p, 'matrix:'
start_time = time.time()
X = np.random.random((n, p))
print time.time() - start_time
print 'take the svd of the matrix:'
start_time = time.time()
U, S, VT = np.linalg.svd(X, full_matrices=0)
print time.time() - start_time
if __name__ == '__main__':
main()