def __init__(self, py_func, identity=None, cache=False, targetoptions={}): self.py_func = py_func self.identity = parse_identity(identity) self.nb_func = jit(_target='npyufunc', cache=cache, **targetoptions)(py_func) self._sigs = [] self._cres = {}
def __init__(self, py_func, signature, identity=None, cache=False, targetoptions={}): self.py_func = py_func self.identity = parse_identity(identity) self.nb_func = jit(target='npyufunc', cache=cache)(py_func) self.signature = signature self.sin, self.sout = parse_signature(signature) self.targetoptions = targetoptions self.cache = cache self._sigs = [] self._cres = {}
for j in range(ny): if ((i * dx - 0.5)**2 + (j * dy - 0.5)**2 <= 0.1) and ((i * dx - 0.5)**2 + (j * dy - 0.5)**2 >= 0.05): ui[i, j] = 1 def diff_step(u, ui): for i in range(1, nx - 1): for j in range(1, ny - 1): uxx = (ui[i + 1, j] - 2 * ui[i, j] + ui[i - 1, j]) / (dx * dx) uyy = (ui[i, j + 1] - 2 * ui[i, j] + ui[i, j - 1]) / (dy * dy) u[i, j] = ui[i, j] + dt * a * (uxx + uyy) diff_step_numba = jit('void(f8[:,:], f8[:,:])')(diff_step) now = perf_counter() t = 0 worker = 'CPython' for m in range(timesteps): gr.clearws() start = now if t > 5: diff_step_numba(u, ui) worker = 'Numba' else: diff_step(u, ui)
a[1, i][1] *= -1 elif a[0, i][1] > 2 - size: a[0, i][1] = 2 - size a[1, i][1] *= -1 return a np.random.seed(0) a = np.empty([2, N, 2], dtype=np.float) a[0, :] = -0.5 + np.random.random((N, 2)) # positions a[1, :] = -0.5 + np.random.random((N, 2)) # velocities a[0, :] *= (4 - 2 * size) dt = 1. / 30 step_numba = jit('f8[:,:,:](f8, f8, f8[:,:,:])')(step) gr.setwindow(-2, 2, -2, 2) gr.setviewport(0, 1, 0, 1) gr.setmarkertype(gr.MARKERTYPE_SOLID_CIRCLE) gr.setmarkersize(1.0) start = time.time() t0 = start n = 0 t = 0 worker = 'CPython' while t < 6: