code: def float32_to_float8e4m3(  # pylint: disable=too-many-statements
      fval: float,
      scale: float = 1.0,
      fn: bool = True,
      uz: bool = False,
      saturate: bool = True,
  ) -> int:
      """
      Convert a float32 value to a float8, e4m3 (as int).
  
      :param fval: float to convert
      :param scale: scale, divide *fval* by *scale* before casting it
      :param fn: no infinite values
      :param uz: no negative zero
      :param saturate: if True, any value out of range included inf becomes the maximum value,
          otherwise, it becomes NaN. The description of operator Cast fully describes the
          differences.
      :return: converted float
  
      See :ref:`onnx-detail-float8` for technical details.
      """
      if not fn:
          raise NotImplementedError(
              "float32_to_float8e4m3 not implemented with fn=False."
          )
      x = fval / scale
      b = int.from_bytes(struct.pack("<f", np.float32(x)), "little")
      ret = (b & 0x80000000) >> 24  # sign
      if uz:
          if (b & 0x7FC00000) == 0x7FC00000:
              return 0x80
          if np.isinf(x):
              if saturate:
                  return ret | 0x7F
              return 0x80
          e = (b & 0x7F800000) >> 23  # exponent
          m = b & 0x007FFFFF  # mantissa
  
          if e != 0:
              if e < 116:
                  pass
              elif e < 117:
                  ret |= 1
                  if (m >> 23) & 1:
                      # rounding
                      ret += 1
              elif e < 120:  # 127 - 8 + 1
                  d = 119 - e
                  ret |= 1 << (2 - d)
                  ret |= m >> (21 + d)
                  if (m >> (20 + d)) & 1:
                      # rounding
                      ret += 1
              elif e < 135:  # 127 + 8
                  ex = e - 119  # 127 - 8
                  if ex == 0:
                      ret |= 0x4
                      ret |= m >> 21
                  else:
                      ret |= ex << 3
                      ret |= m >> 20
                  if m & 0x80000:
                      if (ret & 0x7F) < 0x7F:
                          # rounding
                          ret += 1
                      elif not saturate:
                          return 0x80
              elif saturate:
                  ret |= 0x7F  # 01111110
              else:
                  ret = 0x80
          elif m == 0:
              # -0
              ret = 0
          return int(ret)
      else:
          if (b & 0x7FC00000) == 0x7FC00000:
              return 0x7F | ret
          if np.isinf(x):
              if saturate:
                  return ret | 126
              return 0x7F | ret
          e = (b & 0x7F800000) >> 23  # exponent
          m = b & 0x007FFFFF  # mantissa
  
          if e != 0:
              if e < 117:
                  pass
              elif e < 118:
                  ret |= 1
                  if (m >> 23) & 1:
                      # rounding
                      ret += 1
              elif e < 121:  # 127 - 7 + 1
                  d = 120 - e
                  ret |= 1 << (2 - d)
                  ret |= m >> (21 + d)
                  if (m >> (20 + d)) & 1:
                      # rounding
                      ret += 1
              elif e < 136:  # 127 + 8 + 1
                  ex = e - 120  # 127 - 7
                  if ex == 0:
                      ret |= 0x4
                      ret |= m >> 21
                  else:
                      ret |= ex << 3
                      ret |= m >> 20
                      if (ret & 0x7F) == 0x7F:
                          ret &= 0xFE
                  if (m & 0x80000) and (
                      (m & 0x100000) or (m & 0x7C000)
                  ):  # round to nearest even
                      if (ret & 0x7F) < 0x7E:
                          # rounding
                          ret += 1
                      elif not saturate:
                          ret |= 0x7F
              elif saturate:
                  ret |= 126  # 01111110
              else:
                  ret |= 0x7F
          return int(ret)
  
imports: import collections.abc
  import numbers
  import struct
  from cmath import isnan
  from typing import Any, Callable, Dict, KeysView, List, Optional, Sequence, Tuple, TypeVar, Union, cast
  import google.protobuf.message
  import numpy
  from onnx import IR_VERSION, AttributeProto, FunctionProto, GraphProto, MapProto, ModelProto, NodeProto, OperatorSetIdProto, OptionalProto, SequenceProto, SparseTensorProto, TensorProto, TensorShapeProto, TrainingInfoProto, TypeProto, ValueInfoProto, defs, mapping
label_desc: Use image node_id 13 for calling a global function with example usage: float32_to_float8e4m3(fval, scale, fn, uz, saturate) and returns: int, int, int, int, unknown, unknown, unknown, unknown, int