Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. # !/usr/bin/env python
  2. import sys
  3. import numpy as np
  4. import numpy.random as npr
  5. from numpy.distutils.system_info import get_info
  6. import time
  7.  
  8.  
  9. if __name__ == '__main__':
  10.  
  11. # Run diagnostics
  12.  
  13. print("NumPy Version: %s" % np.__version__)
  14. print("Max int: %i\n" % sys.maxsize)
  15.  
  16. info = get_info('blas_opt')
  17. print('BLAS info:')
  18. for kk, vv in info.items():
  19. print(' * ' + kk + ' ' + str(vv))
  20.  
  21. print("\n")
  22.  
  23. # Run Test 1
  24. N = 1
  25. n = 1000
  26.  
  27. A = npr.randn(n, n)
  28. B = npr.randn(n, n)
  29.  
  30. t = time.time()
  31.  
  32. for i in range(N):
  33. C = np.dot(A, B)
  34.  
  35. td = time.time() - t
  36.  
  37. print("Dot product of two (%d,%d) matrices took %0.1f ms" % (n, n, 1e3 * td / N))
  38.  
  39. # Run Test 2
  40. N = 100
  41. n = 2000
  42.  
  43. A = npr.randn(n)
  44. B = npr.randn(n)
  45.  
  46. t = time.time()
  47.  
  48. for i in range(N):
  49. C = np.dot(A, B)
  50.  
  51. td = time.time() - t
  52.  
  53. print("Dot product of two (%d) d vectors took %0.2f us" % (n, 1e6 * td / N))
  54.  
  55. # Run Test 3
  56. m, n = (1000, 2000)
  57.  
  58. A = npr.randn(m, n)
  59.  
  60. t = time.time()
  61. [U, s, V] = np.linalg.svd(A, full_matrices=False)
  62. td = time.time() - t
  63. print("SVD of (%d,%d) matrix took %0.3f s" % (m, n, td))
  64.  
  65. # Run Test 4
  66. n = 1000
  67. A = npr.randn(n, n)
  68.  
  69. t = time.time()
  70. w, v = np.linalg.eig(A)
  71. td = time.time() - t
  72. print("Eigen decomposion of (%d,%d) matrix took %0.3f s" % (n, n, td))
  73.  
  74. print("\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement