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_loop(self):
      # The test graph is:
      #    graph(
      #        %x : Tensor[1],
      #    ):
      #      %1 = constant[value=True]()
      #      %2 = constant[value=-1]()
      #      %3 = constant[value=10]()
      #      %4 = listconstruct[](%2)
      #       = loop[](%3, %1)
      #        block(%i.1):
      #          %6 = append[](%4, %i.1)
      #        return (%1)
      #    return (%4)
      graph_params = {}
      graph_inputs = OrderedDict()
      graph_inputs["x"] = torch.rand(1)
      loop_block = InternalTorchIRBlock(
          inputs=["i.1"],
          outputs=["1"],
          nodes=[
              InternalTorchIRNode(
                  inputs=["4", "i.1"],
                  outputs=["6"],
                  kind="append",
              ),
          ],
      )
      loop_block.nodes[0].parent = loop_block
      loop_node = InternalTorchIRNode(
          inputs=["3", "1"],
          outputs=[],
          kind="loop",
          blocks=[loop_block],
      )
      loop_block.parent = loop_node
      graph_nodes = [
          InternalTorchIRNode(
              inputs=[],
              attr={"value": True},
              outputs=["1"],
              kind="constant",
          ),
          InternalTorchIRNode(
              inputs=[],
              attr={"value": -1},
              outputs=["2"],
              kind="constant",
          ),
          InternalTorchIRNode(
              inputs=[],
              attr={"value": 10},
              outputs=["3"],
              kind="constant",
          ),
          InternalTorchIRNode(
              inputs=["2"],
              outputs=["4"],
              kind="listconstruct",
          ),
          loop_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)
  
      # There should be an additional input to the loop.
      np.testing.assert_equal(len(loop_node.inputs), 3)
      # That input should be the output of the previous op.
      np.testing.assert_equal(
          loop_node.inputs[2], graph.nodes[3].outputs[0]
      )
      # The loop block should have an additional input.
      np.testing.assert_equal(len(loop_block.inputs), 2)
      # The loop block's new input should be the input to append.
      np.testing.assert_equal(
          loop_block.inputs[1], loop_block.nodes[0].inputs[0]
      )
      # The loop block should have an additional output.
      np.testing.assert_equal(len(loop_block.outputs), 2)
      # Append's output should be returned from the loop block.
      np.testing.assert_equal(
          loop_block.outputs[1], loop_block.nodes[0].outputs[0]
      )
      # The loop should now have an output.
      np.testing.assert_equal(len(loop_node.outputs), 1)
      # The loop's name should now be the name of its output.
      np.testing.assert_equal(loop_node.name, loop_node.outputs[0])
      # That graph output should now be the output of the graph.
      np.testing.assert_equal(loop_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 5 for calling the TestTorchPasses obj's underlying member method code with example usage: obj.test_transform_inplace_ops_loop() without return types