***numba.errors.TypingError:在nopython模式管道中失败(步骤:nopython前端)
我对***numba.errors.TypingError:在nopython模式管道中失败(步骤:nopython前端),python,numba,Python,Numba,我对UMAP(…).transform()有问题。。我用trans=pickle.load()加载了模型 由于UMAP使用numba包,我在解析类型时遇到了问题。下面是显示的错误 ipdb> trans.transform(X_test.reshape(X_test.shape[0], -1)) *** numba.errors
UMAP(…).transform()有问题。
。我用trans=pickle.load()
加载了模型
由于UMAP使用numba
包,我在解析类型时遇到了问题。下面是显示的错误
ipdb> trans.transform(X_test.reshape(X_test.shape[0], -1))
*** numba.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of type(CPUDispatcher(<function rdist at 0x7f36c7ce4e18>)) with parameters (array(float32, 1d, C), array(float64, 1d, C))
Known signatures:
* (array(float32, 1d, A), array(float32, 1d, A)) -> float32
* parameterized
[1] During: resolving callee type: type(CPUDispatcher(<function rdist at 0x7f36c7ce4e18>))
[2] During: typing of call at /home/infinity/anaconda3/envs/HFT/lib/python3.6/site-packages/umap/umap_.py (776)
File "../../../anaconda3/envs/HFT/lib/python3.6/site-packages/umap/umap_.py", line 776:
def optimize_layout(
<source elided>
dist_squared = rdist(current, other)
^
This is not usually a problem with Numba itself but instead often caused by
the use of unsupported features or an issue in resolving types.
To see Python/NumPy features supported by the latest release of Numba visit:
http://numba.pydata.org/numba-doc/dev/reference/pysupported.html
and
http://numba.pydata.org/numba-doc/dev/reference/numpysupported.html
For more information about typing errors and how to debug them visit:
http://numba.pydata.org/numba-doc/latest/user/troubleshoot.html#my-code-doesn-t-compile
If you think your code should work with Numba, please report the error message
and traceback, along with a minimal reproducer at:
https://github.com/numba/numba/issues/new
形状是(5839,45,41)
如何修复该类型错误
更新
我通知说问题出在
@numba.njit("f4(f4[:],f4[:])", fastmath=True)
def rdist(x, y):
"""Reduced Euclidean distance.
Parameters
----------
x: array of shape (embedding_dim,)
y: array of shape (embedding_dim,)
Returns
-------
The squared euclidean distance between x and y
"""
result = 0.0
for i in range(x.shape[0]):
result += (x[i] - y[i]) ** 2
return result
x = [-4.3200183, 0.2443985, 0.24419938]
y = [-3.7033827, 0.91038215, 4.292648 ]
test = rdist(x,y)
但是,我没有资格解决这个问题
如果我运行上面的代码,我会得到以下错误
TypeError:reflectedlist(float64)参数类型没有匹配的定义,reflectedlist(float64)
输入数据的真实示例是什么?您正在向函数传递一个列表,但是您声明了两个1d float32数组作为输入。除此之外,如果您的阵列较大,则可以改进算法。
array([[[-7.84867750e-05, -3.92410776e-05, -1.17713994e-04, ...,
0.00000000e+00, 0.00000000e+00, -5.88910810e-05],
[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
3.22361913e+01, 3.36224857e+01, 0.00000000e+00],
[-1.17741714e-04, -1.56979711e-04, 0.00000000e+00, ...,
-3.22361913e+01, -3.36224857e+01, -2.35599012e-04],
...,
[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
0.00000000e+00, 0.00000000e+00, 3.92395378e-05],
[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00],
[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00]],
[[ 0.00000000e+00, 0.00000000e+00, 7.98615775e-04, ...,
0.00000000e+00, 0.00000000e+00, -2.66778461e-04],
[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00],
[ 1.10377388e-03, 1.86421709e-03, 3.04066897e-04, ...,
0.00000000e+00, 0.00000000e+00, 5.52533571e-04],
...,
[ 0.00000000e+00, 1.14074947e-04, 3.80220908e-05, ...,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00],
[-1.36996749e-03, -4.18338442e-04, -4.18322533e-04, ...,
0.00000000e+00, 0.00000000e+00, -1.21918711e-03],
[-3.80814562e-05, -1.10373187e-03, -3.80380000e-05, ...,
0.00000000e+00, 0.00000000e+00, -1.90615976e-05]]])
@numba.njit("f4(f4[:],f4[:])", fastmath=True)
def rdist(x, y):
"""Reduced Euclidean distance.
Parameters
----------
x: array of shape (embedding_dim,)
y: array of shape (embedding_dim,)
Returns
-------
The squared euclidean distance between x and y
"""
result = 0.0
for i in range(x.shape[0]):
result += (x[i] - y[i]) ** 2
return result
x = [-4.3200183, 0.2443985, 0.24419938]
y = [-3.7033827, 0.91038215, 4.292648 ]
test = rdist(x,y)