code: def maybe_downcast_numeric(
      result: ArrayLike, dtype: DtypeObj, do_round: bool = False
  ) -> ArrayLike:
      """
      Subset of maybe_downcast_to_dtype restricted to numeric dtypes.
  
      Parameters
      ----------
      result : ndarray or ExtensionArray
      dtype : np.dtype or ExtensionDtype
      do_round : bool
  
      Returns
      -------
      ndarray or ExtensionArray
      """
      if not isinstance(dtype, np.dtype) or not isinstance(
          result.dtype, np.dtype
      ):
          # e.g. SparseDtype has no itemsize attr
          return result
  
      def trans(x):
          if do_round:
              return x.round()
          return x
  
      if dtype.kind == result.dtype.kind:
          # don't allow upcasts here (except if empty)
          if result.dtype.itemsize <= dtype.itemsize and result.size:
              return result
  
      if is_bool_dtype(dtype) or is_integer_dtype(dtype):
          if not result.size:
              # if we don't have any elements, just astype it
              return trans(result).astype(dtype)
  
          # do a test on the first element, if it fails then we are done
          r = result.ravel()
          arr = np.array([r[0]])
  
          if isna(arr).any():
              # if we have any nulls, then we are done
              return result
  
          elif not isinstance(
              r[0], (np.integer, np.floating, int, float, bool)
          ):
              # a comparable, e.g. a Decimal may slip in here
              return result
  
          if (
              issubclass(result.dtype.type, (np.object_, np.number))
              and notna(result).all()
          ):
              new_result = trans(result).astype(dtype)
              if (
                  new_result.dtype.kind == "O"
                  or result.dtype.kind == "O"
              ):
                  # np.allclose may raise TypeError on object-dtype
                  if (new_result == result).all():
                      return new_result
              else:
                  if np.allclose(new_result, result, rtol=0):
                      return new_result
  
      elif (
          issubclass(dtype.type, np.floating)
          and not is_bool_dtype(result.dtype)
          and not is_string_dtype(result.dtype)
      ):
          with warnings.catch_warnings():
              warnings.filterwarnings(
                  "ignore",
                  "overflow encountered in cast",
                  RuntimeWarning,
              )
              new_result = result.astype(dtype)
  
          # Adjust tolerances based on floating point size
          size_tols = {4: 5e-4, 8: 5e-8, 16: 5e-16}
  
          atol = size_tols.get(new_result.dtype.itemsize, 0.0)
  
          # Check downcast float values are still equal within 7 digits when
          # converting from float64 to float32
          if np.allclose(
              new_result, result, equal_nan=True, rtol=0.0, atol=atol
          ):
              return new_result
  
      elif dtype.kind == result.dtype.kind == "c":
          new_result = result.astype(dtype)
  
          if np.array_equal(new_result, result, equal_nan=True):
              # TODO: use tolerance like we do for float?
              return new_result
  
      return result
  
imports: from __future__ import annotations
  import datetime
  import functools
  from typing import TYPE_CHECKING, Any, Literal, Sized, TypeVar, cast, overload
  import warnings
  import numpy
  from pandas._libs import lib
  from pandas._libs.missing import NA, NAType, checknull
  from pandas._libs.tslibs import NaT, OutOfBoundsDatetime, OutOfBoundsTimedelta, Timedelta, Timestamp, get_unit_from_dtype, is_supported_unit
  from pandas._libs.tslibs.timedeltas import array_to_timedelta64
  from pandas._typing import ArrayLike, Dtype, DtypeObj, NumpyIndexT, Scalar, npt
  from pandas.errors import IntCastingNaNError, LossySetitemError
  from pandas.core.dtypes.common import ensure_int8, ensure_int16, ensure_int32, ensure_int64, ensure_object, ensure_str, is_bool, is_bool_dtype, is_complex, is_complex_dtype, is_datetime64_dtype, is_extension_array_dtype, is_float, is_float_dtype, is_integer, is_integer_dtype, is_numeric_dtype, is_object_dtype, is_scalar, is_signed_integer_dtype, is_string_dtype, is_timedelta64_dtype, is_unsigned_integer_dtype, pandas_dtype
  from pandas.core.dtypes.dtypes import BaseMaskedDtype, CategoricalDtype, DatetimeTZDtype, ExtensionDtype, IntervalDtype, PandasExtensionDtype, PeriodDtype
  from pandas.core.dtypes.generic import ABCExtensionArray, ABCIndex, ABCSeries
  from pandas.core.dtypes.inference import is_list_like
  from pandas.core.dtypes.missing import is_valid_na_for_dtype, isna, na_value_for_dtype, notna
  from pandas.io._util import _arrow_dtype_mapping
label_desc: Use image node_id 12 for calling a global function with example usage: maybe_downcast_numeric(result, dtype, do_round) and returns: result, result, x, x, result, trans, result, result, new_result, new_result, new_result, new_result