code: def test_simplify_consecutive_cast():
      x = relay.var("x", shape=(3, 4, 5), dtype="int8")
      y = relay.var("y", shape=(3, 4), dtype="int64")
      z = relay.var("z", shape=(3,), dtype="float32")
  
      expr1 = relay.cast(x, "int16")
      expr2 = relay.cast(expr1, "int32")
      expr3 = relay.cast_like(expr2, y)
      expr4 = relay.cast_like(expr3, z)
  
      actual1 = run_opt_pass(expr2, relay.transform.SimplifyExpr())
      expected = run_infer_type(relay.cast(x, "int32"))
      assert tvm.ir.structural_equal(actual1, expected)
      actual2 = run_opt_pass(expr3, relay.transform.SimplifyExpr())
      expected = run_infer_type(relay.cast(x, "int64"))
      assert tvm.ir.structural_equal(actual2, expected)
      actual3 = run_opt_pass(expr4, relay.transform.SimplifyExpr())
      expected = run_infer_type(relay.cast(x, "float32"))
      assert tvm.ir.structural_equal(actual3, expected)
  
      # cannot simplify the narrow cast
      x = relay.var("x", shape=(3, 4, 5), dtype="float32")
      y = relay.var("y", shape=(3, 4), dtype="float32")
      expr1 = relay.cast(x, "int32")
      expr2 = relay.cast_like(expr1, y)
      actual = run_opt_pass(expr2, relay.transform.SimplifyExpr())
      expected = run_infer_type(relay.cast(expr1, "float32"))
      assert tvm.ir.structural_equal(actual, expected)
  
      x = relay.var("x", shape=(3, 4), dtype="int64")
      expr1 = relay.cast(x, "bool")
      expr2 = relay.cast(expr1, "int32")
      actual = run_opt_pass(expr2, relay.transform.SimplifyExpr())
      expected = run_infer_type(expr2)
      assert tvm.ir.structural_equal(actual, expected)
  
imports: from math import sqrt
  import pytest
  import tvm
  from tvm import relay
  from tvm.relay import transform
  from tvm.relay.testing import run_opt_pass, run_infer_type
  import numpy
label_desc: Use image node_id 6 for calling a global function with example usage: test_simplify_consecutive_cast() without return types