Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何正确地为numba JIT函数指定签名?_Python_Algorithm_Performance_Numpy_Numba - Fatal编程技术网

Python 如何正确地为numba JIT函数指定签名?

Python 如何正确地为numba JIT函数指定签名?,python,algorithm,performance,numpy,numba,Python,Algorithm,Performance,Numpy,Numba,我创建了一个@jit编译函数,它应该比普通循环快。 但事实并非如此,因为即时编译需要几分钟的时间。我做错了什么 为该函数指定签名的最有效方法是什么 ''' reproducable sample data ''' import numpy as np, time, numba as nb LEN, Amount_Of_Elements = 10000,4000 temp = np.random.randint(Amount_Of_Elements*0.7,high=Amount_Of_Elem

我创建了一个
@jit
编译函数,它应该比普通循环快。 但事实并非如此,因为即时编译需要几分钟的时间。我做错了什么

为该函数指定签名的最有效方法是什么

''' reproducable sample data '''

import numpy as np, time, numba as nb
LEN, Amount_Of_Elements = 10000,4000
temp = np.random.randint(Amount_Of_Elements*0.7,high=Amount_Of_Elements, size=LEN) 
RatiosUp         = [np.random.uniform(size=rand) for rand in temp]
RatiosDown       = [np.random.uniform(size=rand) for rand in temp]
UpPointsSlices   = [np.random.uniform(size=rand) for rand in temp]
DownPointsSlices = [np.random.uniform(size=rand) for rand in temp]

''' function '''

@nb.jit
def filter(a,b):
    return a > b 

@nb.jit
def func(RatiosUp, RatiosDown, UpPointsSlices, DownPointsSlices, result):
    for i in range(len(RatiosUp)): 
   
        for j in range(RatiosUp[i].size): 

            if filter3(RatiosUp[i][j],RatiosDown[i][j]):
                result[i][j] = 1
            elif filter3(RatiosDown[i][j],RatiosUp[i][j]):
                result[i][j] = 0
            elif filter3(UpPointsSlices[i][j],DownPointsSlices[i][j]): 
                result[i][j] = 0
            else:                       
                result[i][j] = 1 

只需使用numpy数组。Numba有自己的列表类型,但这不是必需的,而且速度较慢。此外,不需要类型声明。我只能使用数组列表(而不是2d数组),因为子数组的大小不同:(我所说的签名是指@jit之后的声明。)