numba

function types in numba

柔情痞子 提交于 2019-12-07 11:08:57
问题 What is currently the best way of dealing with higher order functions in numba? I implemented the secant method: def secant_method_curried (f): def inner (x_minus1, x_0, consecutive_tolerance): x_new = x_0 x_old = x_minus1 x_oldest = None while abs(x_new - x_old) > consecutive_tolerance: x_oldest = x_old x_old = x_new x_new = x_old - f(x_old)*((x_old-x_oldest)/(f(x_old)-f(x_oldest))) return x_new return numba.jit(nopython=False)(inner) The issue is that there's no way to tell numba that f is

Coroutines in numba

夙愿已清 提交于 2019-12-07 10:39:24
问题 I'm working on something that requires fast coroutines and I believe numba could speed up my code. Here's a silly example: a function that squares its input, and adds to it the number of times its been called. def make_square_plus_count(): i = 0 def square_plus_count(x): nonlocal i i += 1 return x**2 + i return square_plus_count You can't even nopython=False JIT this, presumably due to the nonlocal keyword. But you don't need nonlocal if you use a class instead: def make_square_plus_count():

Why doesn't Numba improve this iteration …?

风格不统一 提交于 2019-12-06 11:47:40
问题 I am trying out Numba in speeding up a function that computes a minimum conditional probability of joint occurrence. import numpy as np from numba import double from numba.decorators import jit, autojit X = np.random.random((100,2)) def cooccurance_probability(X): P = X.shape[1] CS = np.sum(X, axis=0) #Column Sums D = np.empty((P, P), dtype=np.float) #Return Matrix for i in range(P): for j in range(P): D[i, j] = (X[:,i] * X[:,j]).sum() / max(CS[i], CS[j]) return D cooccurance_probability

Usage of parallel option in numba.jit decoratior makes function give wrong result

旧街凉风 提交于 2019-12-06 09:20:00
Given two opposite corners of a rectangle (x1, y1) and (x2, y2) and two radii r1 and r2 , find the ratio of points that lie between the circles defined by the radii r1 and r2 to the total number of points in the rectangle. Simple NumPy approach: def func_1(x1,y1,x2,y2,r1,r2,n): x11,y11 = np.meshgrid(np.linspace(x1,x2,n),np.linspace(y1,y2,n)) z1 = np.sqrt(x11**2+y11**2) a = np.where((z1>(r1)) & (z1<(r2))) fill_factor = len(a[0])/(n*n) return fill_factor Next I tried to optimize this function with the jit decorator from numba. When I use: nopython = True The function is faster and gives the

Why this python class is not working with numba jitclass?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 08:46:24
I have written the following code with the help of numpy and I want to improve the performance with numba. I am not sure why it is not working as I have set all the variables as per numba system. I am trying to speed up this code as I would be working with large data sets in the future. import numpy as np import math from numba import jitclass from numba import float64,int64 spec =[ ('spacing',float64), ('n_iterations',int64), ('np_emptyhouses',float64[:,:]), ('np_agenthouses',float64[:,:]), ('similarity_threshhold',float64), ('n_changes',int64) ] @jitclass(spec) class geo_schelling_update:

Numba and guvectorize for CUDA target: Code running slower than expected

家住魔仙堡 提交于 2019-12-06 08:33:02
Notable details Large datasets (10 million x 5), (200 x 10 million x 5) Numpy mostly Takes longer after every run Using Spyder3 Windows 10 First thing is attempting to use guvectorize with the following function. I am passing in a bunch of numpy arrays and attempting to use them to multiply across two of the arrays. This works if run with a target other than cuda. However, when switched to cuda it results in an unknown error being: File "C:\ProgramData\Anaconda3\lib\site-packages\numba\cuda\decorators.py", >line 82, in jitwrapper debug=debug) TypeError: init () got an unexpected keyword

Numba: calling jit with explicit signature using arguments with default values

我只是一个虾纸丫 提交于 2019-12-06 04:40:50
问题 I'm using numba to make some functions containing cycles on numpy arrays. Everything is fine and dandy, I can use jit and I learned how to define the signature. Now I tried using jit on a function with optional arguments, e.g.: from numba import jit import numpy as np @jit(['float64(float64, float64)', 'float64(float64, optional(float))']) def fun(a, b=3): return a + b This works, but if instead of optional(float) I use optional(float64) it doesn't (same thing with int or int64 ). I lost 1

Install numba 0.30.1 on ubuntu 16.04 lts

我们两清 提交于 2019-12-06 04:33:48
How do I install the current version (0.30.1) of numba for Python 3 on Ubuntu 16.04 LTS? My version of Python is 3.5.2, and I have a barebones install of Ubuntu (server edition I think) Okay so after a couple of hours of figuring things out, I've decided that this is painful enough to share and not let others figure out. First, set up the basics: install Python 3, Git and g++ sudo apt install python3 git g++ Then get python3 packages PyPI (aka pip) and NumPy sudo apt python3-pip pip3 install numpy Before we start, decide now if you want Anaconda now: it makes it a LOT easier, and you DO get

Optimizing dict of set of tuple of ints with Numba?

喜欢而已 提交于 2019-12-06 03:17:38
问题 I am learning how to use Numba (while I am already fairly familiar with Cython). How should I go about speeding up this code? Notice the function returns a dict of sets of two-tuples of ints. I am using IPython notebook. I would prefer Numba over Cython. @autojit def generateadj(width,height): adj = {} for y in range(height): for x in range(width): s = set() if x>0: s.add((x-1,y)) if x<width-1: s.add((x+1,y)) if y>0: s.add((x,y-1)) if y<height-1: s.add((x,y+1)) adj[x,y] = s return adj I

When does a numba function compile?

江枫思渺然 提交于 2019-12-06 02:15:16
问题 I'm working off this example: http://numba.pydata.org/numba-doc/0.15.1/examples.html#multi-threading and it states that: You should make sure inner_func is compiled at this point, because the compilation must happen on the main thread. This is the case in this example because we use jit(). It seems in the example that calling jit on a function ensures compilation at that time. Would the multithreaded example work if instead of calling jit on the function we had used jit with argument types