code: def float_to_int(arr, int_type, nan2zero=True, infmax=False):
      """Convert floating point array `arr` to type `int_type`
  
      * Rounds numbers to nearest integer
      * Clips values to prevent overflows when casting
      * Converts NaN to 0 (for `nan2zero` == True)
  
      Casting floats to integers is delicate because the result is undefined
      and platform specific for float values outside the range of `int_type`.
      Define ``shared_min`` to be the minimum value that can be exactly
      represented in both the float type of `arr` and `int_type`. Define
      `shared_max` to be the equivalent maximum value.  To avoid undefined
      results we threshold `arr` at ``shared_min`` and ``shared_max``.
  
      Parameters
      ----------
      arr : array-like
          Array of floating point type
      int_type : object
          Numpy integer type
      nan2zero : {True, False, None}
          Whether to convert NaN value to zero.  Default is True.  If False, and
          NaNs are present, raise CastingError. If None, do not check for NaN
          values and pass through directly to the ``astype`` casting mechanism.
          In this last case, the resulting value is undefined.
      infmax : {False, True}
          If True, set np.inf values in `arr` to be `int_type` integer maximum
          value, -np.inf as `int_type` integer minimum.  If False, set +/- infs
          to be ``shared_min``, ``shared_max`` as defined above.  Therefore False
          gives faster conversion at the expense of infs that are further from
          infinity.
  
      Returns
      -------
      iarr : ndarray
          of type `int_type`
  
      Examples
      --------
      >>> float_to_int([np.nan, np.inf, -np.inf, 1.1, 6.6], np.int16)
      array([     0,  32767, -32768,      1,      7], dtype=int16)
  
      Notes
      -----
      Numpy relies on the C library to cast from float to int using the standard
      ``astype`` method of the array.
  
      Quoting from section F4 of the C99 standard:
  
          If the floating value is infinite or NaN or if the integral part of the
          floating value exceeds the range of the integer type, then the
          "invalid" floating-point exception is raised and the resulting value
          is unspecified.
  
      Hence we threshold at ``shared_min`` and ``shared_max`` to avoid casting to
      values that are undefined.
  
      See: https://en.wikipedia.org/wiki/C99 . There are links to the C99
      standard from that page.
      """
      arr = np.asarray(arr)
      flt_type = arr.dtype.type
      int_type = np.dtype(int_type).type
      # Deal with scalar as input; fancy indexing needs 1D
      shape = arr.shape
      arr = np.atleast_1d(arr)
      mn, mx = shared_range(flt_type, int_type)
      if nan2zero is None:
          seen_nans = False
      else:
          nans = np.isnan(arr)
          seen_nans = np.any(nans)
          if not nan2zero and seen_nans:
              raise CastingError("NaNs in array, nan2zero is False")
      iarr = np.clip(np.rint(arr), mn, mx).astype(int_type)
      if seen_nans:
          iarr[nans] = 0
      if not infmax:
          return iarr.reshape(shape)
      ii = np.iinfo(int_type)
      iarr[arr == np.inf] = ii.max
      if ii.min != int(mn):
          iarr[arr == -np.inf] = ii.min
      return iarr.reshape(shape)
  
imports: from __future__ import annotations
  import warnings
  from platform import machine, processor
  import numpy
  from .deprecated import deprecate_with_version
label_desc: Use image node_id 1 for calling a global function with example usage: float_to_int(arr, int_type, nan2zero, infmax) and returns: iarr, iarr