Numexpr 无法识别浮点类型(稀疏矩阵)
Numexpr doesn't recognize float type (sparse matrix)
我想评估 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
numexpr
期望变量是 numpy 数组。它不处理 scipy 的稀疏矩阵。 (例如,请参阅此电子邮件线程:http://numpy-discussion.10968.n7.nabble.com/ANN-numexpr-2-3-final-released-td36154.html)
我想评估 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
numexpr
期望变量是 numpy 数组。它不处理 scipy 的稀疏矩阵。 (例如,请参阅此电子邮件线程:http://numpy-discussion.10968.n7.nabble.com/ANN-numexpr-2-3-final-released-td36154.html)