    def test_multiple_dst_ops(self):
        """
        Given

          x0 -> reshape -> x1 -> unsqueeze -> ...
                            |--> ...

        We cannot eliminate x1 since it has a non-view-op destination, but we
        can still merge the reshape and unsqueeze operators.
        """
        dtype = "float"
        x0_shape = [2, 4, 8]
        y0_shape = [8]
        y1_shape = [8, 8]

        x0 = Tensor(
            shape=x0_shape,
            dtype=dtype,
            name="x0",
            is_input=True,
        )
        x1 = ops.reshape()(x0, [8, 8])
        x2 = ops.unsqueeze(dim=1)(x1)

        y0 = ops.reduce_sum(dim=1)(x1)
        y0._attrs["name"] = "y0"
        y0._attrs["is_output"] = True

        y1 = ops.reduce_sum(dim=1)(x2)
        y1._attrs["name"] = "y1"
        y1._attrs["is_output"] = True

        x0_pt = get_random_torch_tensor(x0_shape, dtype)
        y0_pt = get_torch_empty_tensor(y0_shape, dtype)
        y1_pt = get_torch_empty_tensor(y1_shape, dtype)

        target = detect_target()
        module = compile_model(
            [y0, y1],
            target,
            "./tmp",
            "test_multiple_dst_ops",
        )
        result_graph = module.debug_sorted_graph
        module.run_with_tensors({"x0": x0_pt}, {"y0": y0_pt, "y1": y1_pt})

        self.assertEqual(len(result_graph), 5)
        self.assertFalse(graph_has_op(result_graph, "unsqueeze"))
        sorted_ops = graph_utils.get_sorted_ops(result_graph)
        self.assertEqual(count_ops(sorted_ops, "reshape"), 2)

        y0_expected = torch.sum(torch.reshape(x0_pt, [8, 8]), 1)
        y1_expected = torch.reshape(x0_pt, y1_shape)
        torch.testing.assert_close(y0_expected, y0_pt, atol=5e-2, rtol=5e-2)
        torch.testing.assert_close(y1_expected, y1_pt, atol=5e-2, rtol=5e-2)
Given

x0 -> reshape -> x1 -> unsqueeze -> ...
|--> ...

We cannot eliminate x1 since it has a non-view-op destination, but we
can still merge the reshape and unsqueeze operators.
tests/unittest/compiler/test_merge_view_ops.py