Numba 键入错误:找不到用于签名的函数函数(<内部exception_match>)的实现



我面对的是TypingError,而我与numba工作。

我的功能没有@jit(nopython=True)工作良好,但有了它,它提高了TypingError

误差

TypingError: No implementation of function Function(<intrinsic exception_match>) found for signature:

exception_match(none, ValueError)

There are 2 candidate implementations:
- Of which 2 did not match due to:
Intrinsic in function 'exception_match': File: numbacoreunsafeeh.py: Line 47.
With argument(s): '(none, ValueError)':
Rejected as the implementation raised a specific error:
UnsupportedError: Exception matching is limited to <class 'Exception'>
raised from C:UsersAdminanaconda3envsenvlibsite-packagesnumbacoreunsafeeh.py:55
During: resolving callee type: Function(<intrinsic exception_match>)
During: typing of call at <ipython-input-19-6b44dd15c90f> (6)

import numpy as np
from math import factorial
from numba import jit
import pandas as pd
@jit(nopython=True)
def savitzky_golay(y, window_size, order, deriv=0, rate=1):
try:
window_size = np.abs(np.int(window_size))
order = np.abs(np.int(order))
except ValueError :
raise ValueError("window size & order have to be of type int")

if window_size % 2 != 1 or window_size < 1:
raise TypeError("window_size size must be a positive odd number")

if window_size < order + 2:
raise TypeError("window_size is too small for the polynomials order")

order_range = range(order+1)
half_window = (window_size -1) // 2
b = np.mat([[k**i for i in order_range] for k in range(-half_window, 
half_window+1)])
m = np.linalg.pinv(b).A[deriv] * rate**deriv * factorial(deriv)
firstvals = y[0] - np.abs( y[1:half_window+1][::-1] - y[0] )
lastvals = y[-1] + np.abs(y[-half_window-1:-1][::-1] - y[-1])
y = np.concatenate((firstvals, y, lastvals))
return np.convolve( m[::-1], y, mode='valid')

yaw = np.array(pd.read_csv('D:datasetsdf.csv')['yaw'])
sg_yaw = savitzky_golay(yaw , window_size =3 , order = 1, deriv=0, rate=1)

消息

UnsupportedError: Exception matching is limited to <class 'Exception'>

表示必须使用Exception,而不是它的一个派生类。

从文档中复制:

部分支持try .. except结构。支持以下形式的

  • 捕获所有异常的裸例外:

    try:
    ...
    except:
    ...
    
  • 完全使用except子句中的Exception类:

    try:
    ...
    except Exception:
    ...
    

相关内容

最新更新