微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在numba预编译函数中使用struct.unpack

如何解决如何在numba预编译函数中使用struct.unpack

我有一个用 numba 编写的函数来为 pcl_viewer 生成 3d 点云数据。为了将 rgb 值转换为 pcl_viewer 要求的编码浮点格式,我使用以下代码

@njit
def rgb2float(r,g,b):
    rgb_value = (int(r) << 16) + (int(g) << 8) + int(b)
    return struct.unpack('!f',struct.pack('!I',rgb_value))[0]

@njit(parallel=True)
def get_rgb_points(points,view_matrices,img_dict):
    for i in prange(len(points)):
        ... some code
        points[i][4] = rgb2float(color[0],color[1],color[2])
        
    return points

但是,当从我的主要 numba 优化函数调用函数时,出现以下错误

TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Failed in nopython mode pipeline (step: nopython frontend)
UnkNown attribute 'unpack' of type Module(<module 'struct' from '/usr/lib/python3.6/struct.py'>)

为了检查它是否是python版本问题,我检查了python3.6的struct.py,但我在那里找到了解包功能。所以我认为这不是python版本问题。我还尝试将“rgb2float”函数的“nopython”设置为True和False。

是否可以在 numba 函数中使用 struct.unpack?如果没有,我可以使用替代方法

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。