code: def _copy_func(f):
      """Based on http://stackoverflow.com/a/6528148/190597 (Glenn Maynard)"""
      g = types.FunctionType(
          f.__code__,
          f.__globals__,
          name=f.__name__,
          argdefs=f.__defaults__,
          closure=f.__closure__,
      )
      g = functools.update_wrapper(g, f)
      g.__kwdefaults__ = f.__kwdefaults__
      return g
  
imports: from __future__ import annotations
  from typing import TYPE_CHECKING, Callable, Dict, Tuple, Any, cast
  import functools
  import numpy
  import math
  import types
  import warnings
  from numpy import trapz
  from scipy.special import roots_legendre
  from scipy.special import gammaln
label_desc: Use image node_id 1 for calling a global function with example usage: _copy_func(f) and returns: g