numba无法编译光线投射功能

时间:2019-06-01 21:46:49

标签: python numba

我依靠numba JIT编译的功能来执行射线投射操作。该功能在大约99%的情况下都能可靠地执行,但我发现它无法正常工作。

可重现的示例是:

from numba import vectorize, bool_, float64
import numpy as np

# Define points to clip
x_vec = [468559.33, 468559.99]
y_vec = [5016610.22, 5016609.12]

bad_poly = np.array([[468560.495, 5016609.98611111],
                [468560.495, 5016607.625],
                [468558.245, 5016609.875],
                [468557.97700443, 5016610.41099114],
                [468558.13454149, 5016610.51065745],
                [468560.495, 5016609.98611111]])

good_poly = np.array([[468560.495, 5016609.98611111],
                     [468560.495, 5016607.625],
                     [468558.245, 5016609.875],
                     [468558.13454149, 5016610.51065745],
                     [468560.495, 5016609.98611111]])

poly = bad_poly

@vectorize([bool_(float64, float64)])
def ray(x, y):
    n = len(poly)
    inside = False
    p2x = 0.0
    p2y = 0.0
    xints = 0.0
    p1x, p1y = poly[0]
    for i in range(n + 1):
        p2x, p2y = poly[i % n]
        if y > min(p1y, p2y):
            if y <= max(p1y, p2y):
                if x <= max(p1x, p2x):
                    if p1y != p2y:
                        xints = (y - p1y) * (p2x - p1x) / (p2y - p1y) + p1x
                    if p1x == p2x or x <= xints:
                        inside = not inside
        p1x, p1y = p2x, p2y
    return inside

如果poly=bad_poly,则该函数无法编译,并产生以下错误

python: /tmp/build/80754af9/llvmdev_1546540969021/work/include/llvm/ADT/APInt.h:1124: bool llvm::APInt::operator==(const llvm::APInt&) const: Assertion `BitWidth == RHS.BitWidth && "Comparison requires equal bit widths"' failed.

如果poly=good_poly,则函数进行编译。似乎删除一个或一些坐标可以使函数编译。

0 个答案:

没有答案