code: def get_namedtuple(name):
      def getter_decorator(fn):
          try:
              argspec = inspect.getfullargspec(fn)
              get_index = argspec.args.index("get")
              defaults = argspec.defaults
          except:
              raise ValueError(
                  "`get_namedtuple` functions must have a `get` argument."
              )
  
          @wraps(fn)
          def getter_fn(*args, **kwargs):
              canonicalized_args = list(args)
  
              if "get" in kwargs:
                  get_is_not_tuple, get = canonicalize_get(
                      kwargs["get"]
                  )
                  kwargs["get"] = get
              elif get_index < len(args):
                  get_is_not_tuple, get = canonicalize_get(
                      args[get_index]
                  )
                  canonicalized_args[get_index] = get
              elif defaults is None:
                  raise ValueError(
                      "`get_namedtuple` function must have a `get` argument provided or "
                      "set by default."
                  )
              else:
                  get_is_not_tuple, get = canonicalize_get(
                      defaults[get_index - len(args)]
                  )
  
              fn_out = fn(*canonicalized_args, **kwargs)
  
              @nt_tree_fn()
              def canonicalize_output(out):
                  if get is None:
                      if isinstance(out, dict):
                          ReturnType = _named_tuple_factory(
                              name, tuple(out.keys())
                          )
                          out = ReturnType(*out.values())
                      return out
  
                  out = _output_to_dict(out)
  
                  if get_is_not_tuple:
                      if isinstance(out, types.GeneratorType):
                          return (output[get[0]] for output in out)
                      else:
                          return out[get[0]]
  
                  ReturnType = _named_tuple_factory(name, get)
                  if isinstance(out, types.GeneratorType):
                      return (
                          ReturnType(*tuple(output[g] for g in get))
                          for output in out
                      )
                  else:
                      return ReturnType(*tuple(out[g] for g in get))
  
              return canonicalize_output(fn_out)
  
          return getter_fn
  
      return getter_decorator
  
imports: from collections import namedtuple
  import functools
  import inspect
  import operator
  import types
  from typing import Any, Callable, Iterable, Optional, Sequence, Sized, TypeVar, Union
  import warnings
  import jax
  from jax import core
  from jax import random
  import jax.numpy
  from jax.tree_util import tree_all
  from jax.tree_util import tree_map
  import numpy
label_desc: Use image node_id 9 for calling a global function with example usage: get_namedtuple(name) and returns: getter_decorator, getter_fn, canonicalize_output, out, unknown, ReturnType, unknown, out