Esempio n. 1
0
    def test_simple(self):
        # Test a simple graph
        r1, r2, r5 = MyVariable(1), MyVariable(2), MyVariable(5)
        o = MyOp(r1, r2)
        o.name = "o1"
        o2 = MyOp(o, r5)
        o2.name = "o2"

        clients = {}
        res = general_toposort([o2], prenode, clients=clients)

        assert clients == {
            o2.owner: [o2],
            o: [o2.owner],
            r5: [o2.owner],
            o.owner: [o],
            r1: [o.owner],
            r2: [o.owner],
        }
        assert res == [r5, r2, r1, o.owner, o, o2.owner, o2]

        with pytest.raises(ValueError):
            general_toposort(
                [o2], prenode, compute_deps_cache=lambda x: None, deps_cache=None
            )

        res = io_toposort([r5], [o2])
        assert res == [o.owner, o2.owner]
Esempio n. 2
0
 def test_double_dependencies(self):
     # Test a graph with double dependencies
     r1, r5 = MyVariable(1), MyVariable(5)
     o = MyOp.make_node(r1, r1)
     o2 = MyOp.make_node(o.outputs[0], r5)
     all = general_toposort(o2.outputs, prenode)
     assert all == [r5, r1, o, o.outputs[0], o2, o2.outputs[0]]