def test_hyper_map_polymorphic_2(c, xs, ys): def square(x): return x * x def double(x): return x + x def picker(c): if c: return square else: return double f = picker(c) return hyper_map(f, xs), hyper_map(f, ys)
def test_hypermap(): # Normal assert hyper_map(scalar_add, 10, 20) == 30 assert hyper_map(scalar_add, (1, 2), (10, 20)) == (11, 22) assert hyper_map(scalar_add, [1, 2, 3], [3, 2, 1]) == [4, 4, 4] assert (hyper_map(scalar_add, numpy.ones((2, 2)), numpy.ones((2, 2))) == 2 * numpy.ones((2, 2))).all() # Broadcast assert hyper_map(scalar_add, [1, 2, 3], 10) == [11, 12, 13] assert hyper_map(scalar_add, Point([1, 2], (3, 4)), Point(10, 100)) \ == Point([11, 12], (103, 104)) assert (hyper_map(scalar_add, numpy.ones((2, 2)), 9) == 10 * numpy.ones((2, 2))).all() # Provide fn_leaf adder = HyperMap(fn_leaf=scalar_add) assert adder((1, 2), (10, 20)) == (11, 22) assert (adder(numpy.ones((2, 2)), numpy.ones((2, 2))) == 2 * numpy.ones((2, 2))).all()
def mod_sub(self, x): """Hypermap subtraction (used for subtracting modules during update).""" return hyper_map(operations.sub, self, x)
def test_hyper_map_polymorphic(xs, ys): def square(x): return x * x return hyper_map(square, xs), hyper_map(square, ys)
def test_hyper_map(xs): def square(x): return x * x return hyper_map(square, xs)
def test_hyper_map(x, y): return hyper_map(scalar_add, x, y)
def test_hypermap_tree(t): return hyper_map(scalar_add, t, t)
def test_hyper_map_ct(x): return hyper_map(scalar_add, x, 1)