code: def test_random_RandomVariable(
      rv_op, dist_params, base_size, cdf_name, params_conv
  ):
      """The JAX samplers are not one-to-one with NumPy samplers so we
      need to use a statistical test to make sure that the transpilation
      is correct.
  
      Parameters
      ----------
      rv_op
          The transpiled `RandomVariable` `Op`.
      dist_params
          The parameters passed to the op.
  
      """
      if rv_op is ptr.integers:
          # Integers only accepts Generator, not RandomState
          rng = shared(np.random.default_rng(29402))
      else:
          rng = shared(np.random.RandomState(29402))
      g = rv_op(*dist_params, size=(10_000,) + base_size, rng=rng)
      g_fn = compile_random_function(dist_params, g, mode=jax_mode)
      samples = g_fn(
          *[
              i.tag.test_value
              for i in g_fn.maker.fgraph.inputs
              if not isinstance(i, (SharedVariable, Constant))
          ]
      )
  
      bcast_dist_args = np.broadcast_arrays(
          *[i.tag.test_value for i in dist_params]
      )
  
      for idx in np.ndindex(*base_size):
          cdf_params = params_conv(
              *tuple(arg[idx] for arg in bcast_dist_args)
          )
          test_res = stats.cramervonmises(
              samples[(Ellipsis,) + idx], cdf_name, args=cdf_params
          )
          assert not np.isnan(test_res.statistic)
          assert test_res.pvalue > 0.01
  
imports: import numpy
  import pytest
  import scipy.stats
  import pytensor
  import pytensor.tensor
  import pytensor.tensor.random.basic
  from pytensor.compile.function import function
  from pytensor.compile.sharedvalue import SharedVariable, shared
  from pytensor.graph.basic import Constant
  from pytensor.graph.fg import FunctionGraph
  from pytensor.tensor.random.basic import RandomVariable
  from pytensor.tensor.random.type import RandomType
  from pytensor.tensor.random.utils import RandomStream
  from tests.link.jax.test_basic import compare_jax_and_py, jax_mode, set_test_value
  from pytensor.link.jax.dispatch.random import numpyro_available
label_desc: Use image node_id 6 for calling a global function with example usage: test_random_RandomVariable(rv_op, dist_params, base_size, cdf_name, params_conv) without return types