code: def test_memoize_sample(check_sample):
      if get_backend() == "jax":
          from funsor.jax.distributions import Normal
      else:
          from funsor.torch.distributions import Normal
  
      rng_keys = (
          (None, None, None)
          if get_backend() == "torch"
          else np.array([[0, 1], [0, 2], [0, 3]], dtype=np.uint32)
      )
  
      with memoize():
          m, s = numeric_array(0.0), numeric_array(1.0)
          j1 = Normal(m, s, "x")
          j2 = Normal(m, s, "x")
          x1 = j1.sample(frozenset({"x"}), rng_key=rng_keys[0])
          x12 = j1.sample(frozenset({"x"}), rng_key=rng_keys[1])
          x2 = j2.sample(frozenset({"x"}), rng_key=rng_keys[2])
  
      # this assertion now passes
      assert j1 is j2
  
      # these assertions fail because sample is not memoized
      if check_sample:
          assert x1 is x12
          assert x1 is x2
  
file_path: funsor/test/test_memoize.py
imports: import numpy
  import pytest
  import funsor.ops
  from funsor.cnf import BACKEND_TO_EINSUM_BACKEND, BACKEND_TO_LOGSUMEXP_BACKEND
  from funsor.einsum import einsum, naive_plated_einsum
  from funsor.interpretations import memoize
  from funsor.interpreter import reinterpret
  from funsor.tensor import numeric_array
  from funsor.terms import reflect
  from funsor.testing import excludes_backend, make_einsum_example, xfail_param
  from funsor.util import get_backend
label_desc: Use image node_id 4 for calling a global function with example usage: test_memoize_sample(check_sample) without return types