ire*_*ire 5 python numpy python-3.x numba
我正在尝试使用 numba 在我的 GPU 上执行 np.diff。
这是我使用的脚本;
import numpy as np
import numba
@numba.vectorize(["float32(float32, float32)"], target='cuda')
def vector_diff_axis0(a, b):
return a + b
def my_diff(A, axis=0):
if (axis == 0):
return vector_diff_axis0(A[1:], A[:-1])
if (axis == 1):
return vector_diff_axis0(A[:,1:], A[:,:-1])
A = np.matrix([
[0, 1, 2, 3, 4],
[5, 6, 7, 8, 9],
[9, 8, 7, 6, 5],
[4, 3, 2, 1, 0],
[0, 2, 4, 6, 8]
], dtype='float32')
C = my_diff(A, axis=1)
print (str(C))
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误;
TypeError: No matching version. GPU ufunc requires array arguments
to have the exact types. This behaves like regular ufunc with casting='no'.
Run Code Online (Sandbox Code Playgroud)
有人知道这是什么原因吗?
PS:我用这个视频来做我的脚本; https://youtu.be/jKV1m8APttU?t=388
编辑:感谢您的快速回答!
我在 np.matrix 中添加了 dtype='float32' 但现在我有这个错误;已知签名: * (float32, float32) -> float32 File "", line 5 [1] 期间:解析被调用者类型:Function( signature=(float32, float32) -> float32>) [2] 期间:调用 at (5)
我也尝试在签名中使用 float32[:] 但它不起作用,在我跟随的视频中他们没有这样做
矩阵的 dtype 将为int32,它与 的签名不匹配,vector_diff_axis0因为它需要float32。您需要制作矩阵,即在调用时float32传递参数。dtype='float32'np.matrix
| 归档时间: |
|
| 查看次数: |
1898 次 |
| 最近记录: |