code: def change_rv_size(op, rv, new_size, expand) -> TensorVariable:
      # Extract the RV node that is to be resized
      rv_node = rv.owner
      old_rng, old_size, dtype, *dist_params = rv_node.inputs
  
      if expand:
          shape = tuple(rv_node.op._infer_shape(old_size, dist_params))
          old_size = shape[: len(shape) - rv_node.op.ndim_supp]
          new_size = tuple(new_size) + tuple(old_size)
  
      # Make sure the new size is a tensor. This dtype-aware conversion helps
      # to not unnecessarily pick up a `Cast` in some cases (see #4652).
      new_size = pt.as_tensor(new_size, ndim=1, dtype="int64")
  
      new_rv = rv_node.op(*dist_params, size=new_size, dtype=dtype)
  
      # Replicate "traditional" rng default_update, if that was set for old_rng
      default_update = getattr(old_rng, "default_update", None)
      if default_update is not None:
          if default_update is rv_node.outputs[0]:
              new_rv.owner.inputs[
                  0
              ].default_update = new_rv.owner.outputs[0]
          else:
              warnings.warn(
                  f"Update expression of {rv} RNG could not be replicated in resized variable",
                  UserWarning,
              )
  
      return new_rv
  
imports: import warnings
  from functools import singledispatch
  from typing import Any, Optional, Sequence, Tuple, Union, cast
  import numpy
  from pytensor import config
  from pytensor import tensor
  from pytensor.graph.basic import Variable
  from pytensor.graph.op import Op, compute_test_value
  from pytensor.raise_op import Assert
  from pytensor.tensor.random.op import RandomVariable
  from pytensor.tensor.shape import SpecifyShape
  from pytensor.tensor.variable import TensorVariable
  from typing_extensions import TypeAlias
  from pymc.model import modelcontext
  from pymc.pytensorf import convert_observed_data
  from pymc.exceptions import ShapeError
  from pymc.pytensorf import PotentialShapeType
  from pymc.util import _add_future_warning_tag
label_desc: Use image node_id 12 for calling a global function with example usage: change_rv_size(op, rv, new_size, expand) and returns: new_rv