class_docstr: Class containing tests for InternalTorchIR optimization passes.
      
class_docstr_tok: ["Class","containing","tests","for","InternalTorchIR","optimization","passes","."]
code: def test_transform_inplace_ops_if(self):
      # The test graph is:
      #    graph(
      #        %x : Tensor[1],
      #    ):
      #      %1 = constant[value=True]()
      #      %2 = constant[value=0]()
      #      %3 = constant[value=1]()
      #      %4 = listconstruct[](%2)
      #       = if[](%1)
      #        block0():
      #          %5 = append[](%4, %3)
      #        return ()
      #        block1():
      #          %6 = append[](%4, %2)
      #        return ()
      #    return (%4)
      graph_params = {}
      graph_inputs = OrderedDict()
      graph_inputs["x"] = torch.rand(1)
      if_true_block = InternalTorchIRBlock(
          inputs=[],
          outputs=[],
          nodes=[
              InternalTorchIRNode(
                  inputs=["4", "3"],
                  outputs=["5"],
                  kind="append",
              ),
          ],
      )
      if_true_block.nodes[0].parent = if_true_block
      if_false_block = InternalTorchIRBlock(
          inputs=[],
          outputs=[],
          nodes=[
              InternalTorchIRNode(
                  inputs=["4", "2"],
                  outputs=["6"],
                  kind="append",
              ),
          ],
      )
      if_false_block.nodes[0].parent = if_false_block
      if_node = InternalTorchIRNode(
          inputs=["1"],
          outputs=[],
          kind="if",
          blocks=[if_true_block, if_false_block],
      )
      if_true_block.parent = if_node
      if_false_block.parent = if_node
      graph_nodes = [
          InternalTorchIRNode(
              inputs=[],
              attr={"value": True},
              outputs=["1"],
              kind="constant",
          ),
          InternalTorchIRNode(
              inputs=[],
              attr={"value": 0},
              outputs=["2"],
              kind="constant",
          ),
          InternalTorchIRNode(
              inputs=[],
              attr={"value": 1},
              outputs=["3"],
              kind="constant",
          ),
          InternalTorchIRNode(
              inputs=["2"],
              outputs=["4"],
              kind="listconstruct",
          ),
          if_node,
      ]
      graph_outputs = ["4"]
      graph = InternalTorchIRGraph(
          nodes=graph_nodes,
          params=graph_params,
          inputs=graph_inputs,
          outputs=graph_outputs,
      )
      for node in graph.nodes:
          node.parent = graph
  
      transform_inplace_ops(graph)
  
      # The true block should now have an output.
      np.testing.assert_equal(len(if_true_block.outputs), 1)
      # The true block should output the result of the append op.
      np.testing.assert_equal(
          if_true_block.outputs[0], if_true_block.nodes[0].outputs[0]
      )
      # The false block should now have an output.
      np.testing.assert_equal(len(if_false_block.outputs), 1)
      # The false block should output the result of the append op.
      np.testing.assert_equal(
          if_false_block.outputs[0], if_false_block.nodes[0].outputs[0]
      )
      # The if op should have an additional output.
      np.testing.assert_equal(len(if_node.outputs), 1)
      # The if's name should now be the name of its output.
      np.testing.assert_equal(if_node.name, if_node.outputs[0])
      # The graph output should be the if op output.
      np.testing.assert_equal(if_node.outputs[0], graph.outputs[0])
  
file_path: turicreate/src/external/coremltools_wrap/coremltools/coremltools/converters/mil/frontend/torch/test/test_passes.py
imports: import itertools
  import numpy
  import pytest
  import torch
  from ..internal_graph import *
  from ..torchir_passes import *
label_desc: Use image node_id 6 for calling the TestTorchPasses obj's underlying member method code with example usage: obj.test_transform_inplace_ops_if() without return types