utils.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:WORLD4py 作者: yamachu 项目源码 文件源码
def cast_2d_list_to_2d_pointer(list_value_2d, c_type=ctypes.c_double):
    '''Cast Python 2d-list to 2d-pointer of c_types

    Args:
        list_value_2d (List[List[:object:]]): 2d-Python list
        c_type (ctypes, default: ctypes.c_double): target type

    Returns:
        POINTER(POINTER(c_type)): ctypes 2d-pointer
    '''
    inner_arr_type = c_type * len(list_value_2d[0])
    outer_arr_type = inner_arr_type * len(list_value_2d)
    tmp_buffer = outer_arr_type()

    pointer_2d = ctypes.cast(tmp_buffer, ctypes.POINTER(ctypes.POINTER(c_type)))
    outer_size = len(list_value_2d)

    for i in range(outer_size):
        pointer_2d[i] = ctypes.cast(inner_arr_type(*list_value_2d[i]), ctypes.POINTER(c_type))

    return pointer_2d
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号