code: def test_change_rv_size():
      loc = pt.as_tensor_variable([1, 2])
      rng = pytensor.shared(np.random.default_rng())
      rv = normal(loc=loc, rng=rng)
      assert rv.ndim == 1
      assert tuple(rv.shape.eval()) == (2,)
  
      with pytest.raises(ShapeError, match="must be ≤1-dimensional"):
          change_dist_size(rv, new_size=[[2, 3]])
      with pytest.raises(ShapeError, match="must be ≤1-dimensional"):
          change_dist_size(
              rv, new_size=pt.as_tensor_variable([[2, 3], [4, 5]])
          )
  
      rv_new = change_dist_size(rv, new_size=(3,), expand=True)
      assert rv_new.ndim == 2
      assert tuple(rv_new.shape.eval()) == (3, 2)
  
      # Make sure that the shape used to determine the expanded size doesn't
      # depend on the old `RandomVariable`.
      rv_new_ancestors = set(ancestors((rv_new,)))
      assert loc in rv_new_ancestors
      assert rv not in rv_new_ancestors
  
      # Check that the old rng is not reused
      assert rv_new.owner.inputs[0] is not rng
  
      rv_newer = change_dist_size(rv_new, new_size=(4,), expand=True)
      assert rv_newer.ndim == 3
      assert tuple(rv_newer.shape.eval()) == (4, 3, 2)
  
      # Make sure we avoid introducing a `Cast` by converting the new size before
      # constructing the new `RandomVariable`
      rv = normal(0, 1)
      new_size = np.array([4, 3], dtype="int32")
      rv_newer = change_dist_size(rv, new_size=new_size, expand=False)
      assert rv_newer.ndim == 2
      assert isinstance(rv_newer.owner.inputs[1], Constant)
      assert tuple(rv_newer.shape.eval()) == (4, 3)
  
      rv = normal(0, 1)
      new_size = pt.as_tensor(np.array([4, 3], dtype="int32"))
      rv_newer = change_dist_size(rv, new_size=new_size, expand=True)
      assert rv_newer.ndim == 2
      assert tuple(rv_newer.shape.eval()) == (4, 3)
  
      rv = normal(0, 1)
      new_size = pt.as_tensor(2, dtype="int32")
      rv_newer = change_dist_size(rv, new_size=new_size, expand=True)
      assert rv_newer.ndim == 1
      assert tuple(rv_newer.shape.eval()) == (2,)
  
imports: import re
  import warnings
  import numpy
  import pytensor
  import pytest
  from pytensor import tensor
  from pytensor.compile.mode import Mode
  from pytensor.graph import Constant, ancestors
  from pytensor.tensor import TensorVariable
  from pytensor.tensor.random import normal
  from pytensor.tensor.shape import SpecifyShape
  import pymc
  from pymc import ShapeError
  from pymc.distributions.shape_utils import broadcast_dist_samples_shape, change_dist_size, convert_dims, convert_shape, convert_size, get_support_shape, get_support_shape_1d, rv_size_is_none, to_tuple
  from pymc.model import Model
label_desc: Use image node_id 5 for calling a global function with example usage: test_change_rv_size() without return types