您的位置:首页 > 运维架构

link numpy with openblas on Ubuntu 16.04

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

首先安装openblas

sudo apt-get install libopenblas-base


切换blas库

sudo update-alternatives --config libblas.so.3


安装numpy(pip或者apt-get均可)

测试

我用了两段代码测试。

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


用时13s左右

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))


输出为:

dotted two (1000,1000) matrices in 547.5 ms
dotted two (4000) vectors in 5.73 us
SVD of (2000,1000) matrix in 6.938 s
Eigendecomp of (1500,1500) matrix in 16.114 s


跑程序的时候通过htop可见8核全开。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: