我想评估 python (2.7) 中 numexpr 模块的性能。为此,我创建了一个大小为 (10^5, 10^5) 的随机稀疏矩阵。但是,下面的脚本已经在表达式求值步骤中抛出了一个错误,说它不能识别对象类型。
我究竟做错了什么?
代码:
import timeit
import scipy.sparse as sps
import numpy as np
import numexpr as ne
test_matrix = sps.rand(1e4, 1e4, density=0.01, format='coo', dtype = np.float32)
ne.evaluate('sum(test_matrix, axis = 1)')
setup = 'import numexpr as ne; import numpy as np'
print min(timeit.Timer('ne.evaluate(sum(test_matrix, axis = 1))', setup=setup).repeat(7, 1000))
错误:
回溯(最近一次通话最后):
File "benchmark_expressmath.py", line 19, in <module>
ne.evaluate('sum(test_matrix, axis = 1)')
File "C:\Users\blahblah\AppData\Local\Continuum\Anaconda\lib\site-packages\numexpr\necompiler.py", line 756, in evaluate
signature = [(name, getType(arg)) for (name, arg) in zip(names, arguments)]
File "C:\Users\blahblah\AppData\Local\Continuum\Anaconda\lib\site-packages\numexpr\necompiler.py", line 654, in getType
raise ValueError("unknown type %s" % a.dtype.name)
ValueError: unknown type object