code: def nan_to_num(g: jit_utils.GraphContext, input, nan, posinf, neginf):
      # Cannot create a int type tensor with inf/nan values, so we simply
      # return the original tensor
      if not symbolic_helper._is_fp(input):
          return input
      input_dtype = _type_utils.JitScalarType.from_value(input).dtype()
      if nan is None:
          nan = 0.0
      nan_cond = opset9.isnan(g, input)
      nan_result = g.op(
          "Where",
          nan_cond,
          g.op(
              "Constant", value_t=torch.tensor([nan], dtype=input_dtype)
          ),
          input,
      )
  
      # For None values of posinf, neginf we use the greatest/lowest finite
      # value representable by input’s dtype.
      finfo = torch.finfo(input_dtype)
      if posinf is None:
          posinf = finfo.max
      posinf_cond = opset9.logical_and(
          g,
          isinf(g, nan_result),
          opset9.gt(
              g,
              nan_result,
              g.op("Constant", value_t=torch.LongTensor([0])),
          ),
      )
      nan_posinf_result = g.op(
          "Where",
          posinf_cond,
          g.op(
              "Constant",
              value_t=torch.tensor([posinf], dtype=input_dtype),
          ),
          nan_result,
      )
  
      if neginf is None:
          neginf = finfo.min
      neginf_cond = opset9.logical_and(
          g,
          isinf(g, nan_posinf_result),
          opset9.lt(
              g,
              nan_posinf_result,
              g.op("Constant", value_t=torch.LongTensor([0])),
          ),
      )
      return g.op(
          "Where",
          neginf_cond,
          g.op(
              "Constant",
              value_t=torch.tensor([neginf], dtype=input_dtype),
          ),
          nan_posinf_result,
      )
  
imports: from __future__ import annotations
  import functools
  import sys
  import warnings
  from typing import List, Optional, Sequence, Tuple, Union
  import torch
  import torch._C._onnx
  import torch.onnx
  from torch import _C
  from torch.onnx import _constants, _type_utils, errors, symbolic_helper, symbolic_opset9
  from torch.onnx._globals import GLOBALS
  from torch.onnx._internal import _beartype, jit_utils, registration
label_desc: Use image node_id 25 for calling a global function with example usage: nan_to_num(g, input, nan, posinf, neginf) and returns: g, input