def pmap1(f, x, w = 3): n = x.shape[0] def local_apply(i): lower = __builtins__.max(i-w/2, 0) upper = __builtins__.min(i+w/2+1, n) elts = x[lower:upper] return f(elts) return imap(local_apply, n)
def pmap1(f, x, w=3): n = x.shape[0] def local_apply(i): lower = __builtins__.max(i - w / 2, 0) upper = __builtins__.min(i + w / 2 + 1, n) elts = x[lower:upper] return f(elts) return imap(local_apply, n)
def pmap2(f, x, width=(3, 3)): """ Patch-map where the function can accept both interior windows and smaller border windows """ width_x, width_y = width n_rows, n_cols = x.shape hx = width_x / 2 hy = width_y / 2 def local_apply((i, j)): lx = __builtins__.max(i - hx, 0) ux = __builtins__.min(i + hx + 1, n_rows) ly = __builtins__.max(j - hy, 0) uy = __builtins__.min(j + hy + 1, n_cols) return f(x[lx:ux, ly:uy]) return imap(local_apply, x.shape)
def pmap2(f, x, width = (3,3)): """ Patch-map where the function can accept both interior windows and smaller border windows """ width_x, width_y = width n_rows, n_cols = x.shape hx = width_x / 2 hy = width_y / 2 def local_apply((i,j)): lx = __builtins__.max(i-hx, 0) ux = __builtins__.min(i+hx+1, n_rows) ly = __builtins__.max(j-hy, 0) uy = __builtins__.min(j+hy+1, n_cols) return f(x[lx:ux, ly:uy]) return imap(local_apply, x.shape)
def ones(shape, dtype = float64): one = dtype(1) return imap(lambda _: one, shape)
def zeros(shape, dtype = float64): zero = dtype(0) return imap(lambda _: zero, shape)