def testDescendantSize(self): arr = mt.random.rand(10, 10, chunk_size=4) arr2 = mt.random.rand(10, 10, chunk_size=4) arr_dot = arr.dot(arr2) graph = arr_dot.build_graph(fuse_enabled=False, tiled=True) analyzer = GraphAnalyzer(graph, {}) depths = analyzer.calc_depths() descendants = analyzer.calc_descendant_sizes() nodes = sorted(graph, key=lambda n: depths[n.op.key]) for idx in range(len(nodes) - 1): self.assertGreaterEqual(descendants[nodes[idx].op.key], descendants[nodes[idx + 1].op.key])
def testDepths(self): from mars.tensor.arithmetic import TensorAdd from mars.tensor.base import TensorSplit from mars.tensor.datasource import TensorOnes arr = mt.ones(12, chunk_size=4) arr_split = mt.split(arr, 2) arr_sum = arr_split[0] + arr_split[1] graph = arr_sum.build_graph(fuse_enabled=False, tiled=True) analyzer = GraphAnalyzer(graph, {}) depths = analyzer.calc_depths() for n in graph: if isinstance(n.op, TensorOnes): self.assertEqual(0, depths[n.op.key]) elif isinstance(n.op, TensorSplit): self.assertEqual(1, depths[n.op.key]) elif isinstance(n.op, TensorAdd): self.assertLessEqual(2, depths[n.op.key])