def test_list(): expected = 13 with pm.Node() as graph: a = pm.parameter(default=expected) b = pm.identity([a, a]) actual, _ = graph(b) assert actual is expected, "expected %s but got %s" % (expected, actual)
def test_dict(): expected = 13 with pm.Node() as graph: a = pm.parameter(default=expected) b = pm.identity({'foo': a}) actual = graph(b)['foo'] assert actual is expected, "expected %s but got %s" % (expected, actual)
def test_try_callback(): with pm.Node() as graph: a = pm.placeholder('a') b = pm.assert_((a > 0).set_name('condition'), val=a, name='b') c = pm.try_( b, [(AssertionError, (pm.identity(41, name='41') + 1).set_name('alternative'))]) tracer = pm.Profiler() graph(c, {a: 3}, callback=tracer) == 3 assert len(tracer.times) == 4 graph(c, {a: -2}, callback=tracer) == 42 assert len(tracer.times) == 6
def test_call(): class Adder: def __init__(self, a, b): self.a = a self.b = b def compute(self): return self.a + self.b def __call__(self): return self.compute() with pm.Node() as graph: adder = pm.identity(Adder(3, 7)) op1 = adder() op2 = adder.compute() assert graph([op1, op2]) == (10, 10)