code: def wrap_method(method_name, unbound_method, cls_resolver):
      """Wraps `method` such that it enters name stack and runs method interceptors.
  
      Args:
        method_name: The name of the method (e.g. "__call__").
        unbound_method: An unbound method to wrap.
        cls_resolver: A callable the returns the Module subclass which defined this
          method.
  
      Returns:
        A function that runs the original method but in a context where parameters
        are reused and modules can be created.
      """
      if not getattr(unbound_method, _APPLY_NAME_SCOPE, True):
          return unbound_method
  
      @functools.wraps(unbound_method)
      def wrapped(self, *args, **kwargs):
          """Calls the original method with a group name set before and after."""
          if not base.frame_stack:
              raise ValueError(
                  "All `hk.Module`s must be initialized inside an `hk.transform`."
              )
  
          # Submodules are associated with this method. We allow users to associate
          # submodules with a different method than the one being called via
          # `@name_like("other_method")`. Interceptors and custom getters are still
          # provided the actual method name (e.g. "submodule_method_name" is only used
          # for naming submodules).
          submodule_method_name = getattr(
              unbound_method, _CUSTOM_NAME, method_name
          )
  
          frame = base.current_frame()
          state = base.ModuleState(
              module=self, method_name=submodule_method_name
          )
          with frame.module(state), _module_method_call(
              self, method_name
          ):
              # hk.Module enters the module name scope for all methods.
              module_name = getattr(self, "module_name", None)
              orig_class = cls_resolver()
              f = functools.partial(unbound_method, self)
              f = functools.partial(
                  run_interceptors, f, method_name, self, orig_class
              )
              if module_name:
                  local_module_name = module_name.split("/")[-1]
                  f = jax.named_call(f, name=local_module_name)
                  if method_name != "__call__":
                      f = jax.named_call(f, name=method_name)
  
              out = f(*args, **kwargs)
  
              # Module names are set in the constructor. If `f` is the constructor then
              # its name will only be set **after** `f` has run. For methods other
              # than `__init__` we need the name before running in order to wrap their
              # execution with `named_call`.
              if module_name is None:
                  module_name = getattr(self, "module_name", None)
  
              # Notify parent modules about our existence.
              if module_name is not None:
                  for module_state in frame.module_stack:
                      if module_state.module is not self:
                          module_state.module._submodules.add(
                              module_name
                          )  # pylint: disable=protected-access
          return out
  
      return wrapped
  
imports: from collections.abc import Mapping
  import contextlib
  import functools
  import inspect
  import re
  from typing import Any, Callable, ContextManager, NamedTuple, Optional, Protocol, TypeVar
  from haiku._src import base
  from haiku._src import config
  from haiku._src import data_structures
  from haiku._src import utils
  import jax
  import jax.numpy
label_desc: Use image node_id 6 for calling a global function with example usage: wrap_method(method_name, unbound_method, cls_resolver) and returns: wrapped, unbound_method, out