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
评论列表
文章目录