Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
300 views
in Technique[技术] by (71.8m points)

python - How to use struct.unpack in numba precompiled function

I have a function written in numba to generate 3d point cloud data for pcl_viewer. In order to convert rgb values to encoded float format as required by pcl_viewer, I use the following code

@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

However, when calling this function from my main numba optimized function, I get the following error

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'>)

To check if its a python version issue I checked the struct.py of python3.6, but I found the unpack function there. So I assume it is not a python version issue. I also tried setting "nopython" to True and False for the "rgb2float" function.

Is it possible to use struct.unpack inside a numba function? If not is there an alternative that I can use.

question from:https://stackoverflow.com/questions/65896852/how-to-use-struct-unpack-in-numba-precompiled-function

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...