使用 Numba 求解 Python 中的最小二乘法
Solving least squares in Python using Numba
我在使用 Numba 求解 python 中的最小二乘法时遇到问题。
这是我的代码:
import numpy as np
from numba import jit
@jit(nopython=True)
def test(A, B):
alpha = np.linalg.lstsq(A,B,rcond=None)
return alpha
A = np.random.rand(10,3)
B = np.random.rand(10,1)
alpha = test(A,B)
print(alpha)
没有“@jit(nopython=True)”这一行就可以了。使用“@jit”我有以下错误:
Invalid use of Function(<function lstsq at 0x000001767E21E318>) with argument(s) of type(s): (array(float64, 2d, C), array(float64, 2d, C), rcond=none)
* parameterized
In definition 0:
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of ExternalFunction(numba_ez_gelsd) with argument(s) of type(s): (Literal[int](100), int64, int64, int64, ArrayCTypes(dtype=float64, ndim=2), int64, ArrayCT
ypes(dtype=float64, ndim=2), int64, ArrayCTypes(dtype=float64, ndim=1), none, ArrayCTypes(dtype=int32, ndim=1))
Known signatures:
* (int8, int64, int64, int64, float64*, int64, float64*, int64, float64*, float64, int32*) -> int32
In definition 0:
All templates rejected with literals.
In definition 1:
All templates rejected without literals.
This error is usually caused by passing an argument of a type that is unsupported by the named function.
[1] During: resolving callee type: ExternalFunction(numba_ez_gelsd)
[2] During: typing of call at C:\Users\owner\anaconda3\lib\site-packages\numba\targets\linalg.py (1645)
有什么建议吗?
删除 rcond=None 关键字,它将正常工作。
我在使用 Numba 求解 python 中的最小二乘法时遇到问题。 这是我的代码:
import numpy as np
from numba import jit
@jit(nopython=True)
def test(A, B):
alpha = np.linalg.lstsq(A,B,rcond=None)
return alpha
A = np.random.rand(10,3)
B = np.random.rand(10,1)
alpha = test(A,B)
print(alpha)
没有“@jit(nopython=True)”这一行就可以了。使用“@jit”我有以下错误:
Invalid use of Function(<function lstsq at 0x000001767E21E318>) with argument(s) of type(s): (array(float64, 2d, C), array(float64, 2d, C), rcond=none)
* parameterized
In definition 0:
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of ExternalFunction(numba_ez_gelsd) with argument(s) of type(s): (Literal[int](100), int64, int64, int64, ArrayCTypes(dtype=float64, ndim=2), int64, ArrayCT
ypes(dtype=float64, ndim=2), int64, ArrayCTypes(dtype=float64, ndim=1), none, ArrayCTypes(dtype=int32, ndim=1))
Known signatures:
* (int8, int64, int64, int64, float64*, int64, float64*, int64, float64*, float64, int32*) -> int32
In definition 0:
All templates rejected with literals.
In definition 1:
All templates rejected without literals.
This error is usually caused by passing an argument of a type that is unsupported by the named function.
[1] During: resolving callee type: ExternalFunction(numba_ez_gelsd)
[2] During: typing of call at C:\Users\owner\anaconda3\lib\site-packages\numba\targets\linalg.py (1645)
有什么建议吗?
删除 rcond=None 关键字,它将正常工作。