code: def lgamma(
      x: np.ndarray,
      /,
      *,
      out: Optional[np.ndarray] = None,
  ) -> np.ndarray:
      def func(x):
          if not np.isfinite(x):
              if np.isnan(x):
                  return x  # lgamma(nan) = nan
              else:
                  return np.inf  # lgamma(+-inf) = +inf
  
          if x == np.floor(x) and x <= 2.0:
              if x <= 0.0:
                  return np.inf  # lgamma(n) = inf for integers n <= 0
              else:
                  return 0.0  # lgamma(1) = lgamma(2) = 0.0
  
          absx = np.abs(x)
          if absx < 1e-20:
              return -np.log(absx)
  
          # Lanczos' formula
          r = np.log(lanczos_sum(absx)) - lanczos_g
          r += (absx - 0.5) * (np.log(absx + lanczos_g - 0.5) - 1)
  
          if x < 0.0:
              # Use reflection formula to get value for negative x.
              r = (
                  np.log(np.pi)
                  - np.log(np.abs(sinpi(absx)))
                  - np.log(absx)
                  - r
              )
  
          if np.isinf(r):
              raise OverflowError("Range error in lgamma")
  
          return r
  
      # Vectorize 'func' for element-wise operations on 'x', output matching 'x' dtype.
      vfunc = np.vectorize(func, otypes=[x.dtype])
      return vfunc(x)
  
imports: from typing import Optional, Union, Tuple, List, Sequence
  import numpy
  import numpy.typing
  import ivy
  from ivy import promote_types_of_inputs
  from ivy.functional.backends.numpy.helpers import _scalar_output_to_0d_array
  from ivy.func_wrapper import with_unsupported_dtypes
  from .None import backend_version
label_desc: Use image node_id 26 for calling a global function with example usage: lgamma() and returns: vfunc, r, unknown, x, np, np, int