在我的代码中执行 njit 函数时:
from numba import njit
@njit(fastmath=True)
def project(vertices, camera_matrix, projection_matrix, to_screen_matrix):
vertices = vertices @ camera_matrix
vertices = vertices @ projection_matrix
vertices[vertices[:, 2] < 0] = 0
vertices /= vertices[:, -1].reshape(-1, 1)
vertices = vertices @ to_screen_matrix
return vertices[:, :2]
抛出错误:
类型错误:reshape() 仅支持连续数组
这是顶点变量:
vertices = [
(-1.5, -1.5, -1.5, 1),
(-1.5, -1.5, 1.5, 1),
(-1.5, 1.5, -1.5, 1),
(-1.5, 1.5, 1.5, 1),
(1.5, -1.5, -1.5, 1),
(1.5, -1.5, 1.5, 1),
(1.5, 1.5, -1.5, 1),
(1.5, 1.5, 1.5, 1)
]
如何修复它?
如果
reshape您之前执行此操作copy,它似乎可以在您的函数的精简版本上运行,但是如果没有copy此函数,它会崩溃并出现与您相同的错误。我必须制作一个缩短的版本,因为我不知道其余变量的值,所以我不得不将它们从函数中扔掉。但情况是在没有它们的情况下模拟的。该建议可以在此错误报告中看到。