def f(xs, ys): z = 1 + 1 def add(x, y): return x + y + z return array_map(add, xs, ys)
def after(xs, ys, z): def g(x): return x * x * x def f(x, y): return (x * x * x) + (y * y * y) return array_map(f, xs, ys), g(z + 1), g(z + 2)
def before(xs, ys, z): def f(x, y): def g(x): return x * y return g(x) return array_map(f, xs, ys)
def before(xs, ys, z): def g(x): return x * x * x def f(x, y): return g(x) + g(y) return array_map(f, xs, ys), g(z + 1), g(z + 2)
def test_prim_array_map(): v = np.zeros((2, 3)) def f(a): return a + 1 v2 = array_map(f, v) assert (v == 0).all() assert (v2 == 1).all()
def test_prim_array_map2(): v1 = np.ones((2, 3)) v2 = np.ones((2, 3)) def f(a, b): return a + b vres = array_map(f, v1, v2) assert (v1 == 1).all() assert (v2 == 1).all() assert (vres == 2).all()
def f(x): def add1(x): return x + 1 return array_map(add1, x)
def helper(fn): return array_map(fn, xs), array_map(fn, ys)
def test_array_map_polymorphic(xs, ys): def square(x): return x * x return array_map(square, xs), array_map(square, ys)
def test_array_map(xs): def square(x): return x * x return array_map(square, xs)
def test_array_operations_distribute(x, y): xs = distribute(scalar_to_array(x, AA), (4, 3)) ys = distribute(scalar_to_array(y, AA), (4, 3)) div = array_map(scalar_div, xs, ys) sm = array_reduce(scalar_add, div, ()) return array_to_scalar(sm)
def before(xs): def f(x): return 3 return array_map(f, xs)
def before(xs, ys): def f(x, y): return x * x + y * y return array_map(f, xs, ys)
def after(xs, ys): return array_map(scalar_add, ys, xs)
def before(xs, ys): def f(x, y): return scalar_add(y, x) return array_map(f, xs, ys)
def f(xs, ys): def add(x, y): return x + y return array_map(add, xs, ys)
def f(xs): return array_map(scalar_usub, xs)
def before(x): def p1(x): return x + 1 return array_map(p1, x)
def test_array_operations(xs, ys): div = array_map(scalar_div, xs, ys) sm = array_reduce(scalar_add, div, ()) return array_to_scalar(sm)
def up1(x2): return array_map( scalar_add, x2, distribute(scalar_to_array(1, typeof(x)), shape(x)), )
def test_array_operations_reshape(xs, ys): xs = reshape(xs, (6, )) ys = reshape(ys, (6, )) div = array_map(scalar_div, xs, ys) sm = array_reduce(scalar_add, div, ()) return array_to_scalar(sm)
def f(xs, ys): return array_map(inl, xs, ys)