gpt4 book ai didi

python - Numba python3 出错 [GPU ufunc 要求数组参数具有准确的类型。]

转载 作者:行者123 更新时间:2023-11-28 18:21:02 27 4
gpt4 key购买 nike

我正在尝试使用 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))

这是我得到的错误;

TypeError: No matching version.  GPU ufunc requires array arguments  
to have the exact types. This behaves like regular ufunc with casting='no'.

有人知道这是什么原因吗?

PS:我用这个视频来做我的剧本; https://youtu.be/jKV1m8APttU?t=388

编辑:感谢您的快速回答!

我在 np.matrix 中添加了 dtype='float32' 但现在出现此错误; 已知签名: * (float32, float32) -> float32 文件“”,第 5 行 [1] 期间:解析被调用者类型:Function( 签名=(float32, float32) -> float32>) [2] 期间:在 (5) 处输入调用

我也尝试在签名中使用 float32[:] 但它不起作用,在我关注的视频中他们没有这样做

最佳答案

矩阵的 dtype 将是 int32,这与 vector_diff_axis0 的签名不匹配,因为它需要 float32。您需要制作矩阵 float32,即在调用 np.matrix 时传递参数 dtype='float32'

关于python - Numba python3 出错 [GPU ufunc 要求数组参数具有准确的类型。],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44997860/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com