code: def test_local_Unique_second(
      x_val,
      unique_axis,
      new_shape,
      return_index,
      return_counts,
      return_inverse,
  ):
      x = as_tensor_variable(x_val).type()
      a = np.zeros(tuple(new_shape), dtype=x.dtype)
      y = unique(
          second(a, x),
          return_index=return_index,
          return_counts=return_counts,
          return_inverse=return_inverse,
          axis=unique_axis,
      )
  
      if isinstance(y, list):
          y, *_ = y
  
      # This approach allows us to directly confirm that `x` is in the result.
      y_fg = FunctionGraph(outputs=[y], copy_inputs=False)
      y_rewritten_fg = rewrite_graph(
          y_fg,
          clone=False,
          include=["canonicalize", "local_Unique_second_lift"],
          exclude=["local_Unique_scalar", "topo_constant_folding"],
      )
      y_rewritten = y_rewritten_fg.outputs[0]
      y_rewritten_start = y_rewritten
  
      assert isinstance(y_rewritten_start.owner.op, Unique)
  
      y_rewritten_start = y_rewritten_start.owner.inputs[0]
  
      if y_rewritten_start.owner and isinstance(
          y_rewritten_start.owner.op, DimShuffle
      ):
          y_rewritten_start = y_rewritten_start.owner.inputs[0]
  
      assert y_rewritten_start == x
      assert not any(
          isinstance(node.op.scalar_op, ps.Second)
          for node in y_rewritten_fg.apply_nodes
          if isinstance(node.op, Elemwise)
      )
  
      # The rewrite has already been applied to `y_rewritten`, so we can--and
      # should--exclude it from the compilation of both our reference, `y`, and
      # the rewritten result, `y_rewritten`.
      y_fn = function(
          [x], [y, y_rewritten], mode=Mode(optimizer=OPT_NONE)
      )
  
      # Make sure that the original `BroadcastTo` is used to compute the
      # reference `y` result
      assert any(
          isinstance(node.op.scalar_op, ps.Second)
          for node in y_fn.maker.fgraph.apply_nodes
          if isinstance(node.op, Elemwise)
      )
  
      y_exp_val, y_val = y_fn(x_val)
      assert np.array_equal(y_exp_val, y_val)
  
file_path: pytensor/tests/tensor/rewriting/test_extra_ops.py
imports: import numpy
  import pytest
  import pytensor.scalar
  from pytensor.compile.function import function
  from pytensor.compile.mode import OPT_NONE, Mode, get_default_mode
  from pytensor.graph.fg import FunctionGraph
  from pytensor.graph.rewriting.utils import rewrite_graph
  from pytensor.tensor.basic import Alloc, alloc, as_tensor_variable, second
  from pytensor.tensor.elemwise import DimShuffle, Elemwise
  from pytensor.tensor.extra_ops import Repeat, Unique, repeat, unique
  from pytensor.tensor.type import dscalar
label_desc: Use image node_id 4 for calling a global function with example usage: test_local_Unique_second(x_val, unique_axis, new_shape, return_index, return_counts, return_inverse) without return types