code: def finalise_eval_jaxpr(jaxpr: jax.core.Jaxpr, consts, *args):
      """As jax.core.eval_jaxpr, but finalises (typically by calling `impl` rather than
      `bind` for custom primitives).
      """
  
      def read(v: jax.core.Atom) -> Any:
          return v.val if isinstance(v, jax.core.Literal) else env[v]
  
      def write(v: jax.core.Var, val: Any) -> None:
          env[v] = val
  
      env: dict[jax.core.Var, Any] = {}
      _safe_map(write, jaxpr.constvars, consts)
      _safe_map(write, jaxpr.invars, args)
      for eqn in jaxpr.eqns:
          params = _finalise_jaxprs_in_params(eqn.params)
          subfuns, bind_params = eqn.primitive.get_bind_params(params)
          try:
              call = primitive_finalisations[eqn.primitive]
          except KeyError:
              call = ft.partial(_default_finalisation, eqn.primitive)
          ans = call(
              *subfuns, *_safe_map(read, eqn.invars), **bind_params
          )
          if eqn.primitive.multiple_results:
              _safe_map(write, eqn.outvars, ans)
          else:
              write(eqn.outvars[0], ans)
      return _safe_map(read, jaxpr.outvars)
  
imports: import functools
  from collections.abc import Callable
  from typing import Any, cast, Literal, overload, Union
  import jax
  import jax.core
  import jax.custom_derivatives
  import jax.tree_util
  from jaxtyping import PyTree
  from .._unvmap import unvmap_all_p, unvmap_any_p, unvmap_max_p
  from ..debug._announce_transform import announce_jaxpr_p
  from ._loop import maybe_set_p, select_if_vmap_p
  from ._noinline import noinline_p
  from ._nontraceable import nonbatchable_p, nondifferentiable_backward_p, nontraceable_p
label_desc: Use image node_id 7 for calling a global function with example usage: finalise_eval_jaxpr(jaxpr, consts) and returns: _safe_map, unknown