NUMBA @jit装饰器以对象模式而不是nopython模式编译代码我该如何解决?

问题描述

在以下代码中将@jit装饰器添加功能distanceMatrix中时,NUMBA以对象模式而不是nopython模式编译该代码。如何使用@jit装饰器更正我的代码以使其加速? distanceMatrix正在计算的数据是地理坐标点的数组。目前,我收到的错误消息告诉我,函数len正在应用于不兼容的类型。但是,我知道不是。

import geopandas as gpd 
import numpy as np
from numba import jit
import time 

t0 = time.time()

# Import Shapefile
labs = r"G:\MAX-Filer\Collab\Labs-kbuzard-S18\Admin\Block Level Analysis\CA_Lab_Data.shp"

points = gpd.read_file(labs).filter(['REF_ID','SIC','geometry'],axis = 1)

# Pull X and Y Coordinates from pointFeatures [Observed Point Shapefile]
points["X"] = points.geometry.x
points["Y"] = points.geometry.y

# To NUMPY ARRAY
array = points.loc[:,["X","Y"]].values

@jit('float64(float64,float64)',target = 'cpu')
def distanceMatrix(locsA,locsB):
    """ Calculates distance matrix (in miles) between the locations in locsA to locations in 
    locsB. Assumes that both locsA/locsB are numpy arrays.
    First column of locsA/locsB must be X or LON; second column must be Y or LAT. Measures 
    all pairwise distances. 
    Returns the full distance matrix in numpy matrix form (dist). """

    # Empty Container Matrix for distances
    dist = np.zeros((len(locsA),len(locsB)))
    dist = np.sqrt((69.1 * (locsB[:,0][:,np.newaxis] - locsA[:,0]) * 
    np.cos(locsA[:,1]/57.3))**2 + (69.1 * (locsB[:,1][:,1]))**2)

    return dist


hold = distanceMatrix(array,array)
t1 = time.time()
print(str(t1-t0) + "Seconds")

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)