link numpy with openblas on Ubuntu 16.04

来源:互联网 发布:淘宝商标上传 编辑:程序博客网 时间:2024/06/06 01:55

最近在美帝搞了台台式机,总算有机会可以玩玩Ubuntu了,正好ST790的project需要用到TensorFlow,当然就要先配置一下Python,特别是numpy。

  1. 首先安装openblas

    sudo apt-get install libopenblas-base
  2. 切换blas库

    sudo update-alternatives --config libblas.so.3
  3. 安装numpy(pip或者apt-get均可)

  4. 测试

    我用了两段代码测试。

    import numpy as npa1 = np.random.rand(10000, 10000)a2 = np.random.rand(10000, 10000)np.dot(a1, a2)

    用时13s左右

import numpy as npimport numpy.random as nprimport time# --- Test 1N = 1n = 1000A = 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() - tprint("dotted two (%d,%d) matrices in %0.1f ms" % (n, n, 1e3*td/N))# --- Test 2N = 100n = 4000A = npr.randn(n)B = npr.randn(n)t = time.time()for i in range(N):    C = np.dot(A, B)td = time.time() - tprint("dotted two (%d) vectors in %0.2f us" % (n, 1e6*td/N))# --- Test 3m,n = (2000,1000)A = npr.randn(m,n)t = time.time()[U,s,V] = np.linalg.svd(A, full_matrices=False)td = time.time() - tprint("SVD of (%d,%d) matrix in %0.3f s" % (m, n, td))# --- Test 4n = 1500A = npr.randn(n,n)t = time.time()w, v = np.linalg.eig(A)td = time.time() - tprint("Eigendecomp of (%d,%d) matrix in %0.3f s" % (n, n, td))

输出为:

dotted two (1000,1000) matrices in 547.5 msdotted two (4000) vectors in 5.73 usSVD of (2000,1000) matrix in 6.938 sEigendecomp of (1500,1500) matrix in 16.114 s

跑程序的时候通过htop可见8核全开。

0 0
原创粉丝点击