code: def detect_nan(fgraph, i, node, fn):
      from pytensor.printing import debugprint
  
      for output in fn.outputs:
          if (
              not isinstance(
                  output[0],
                  (np.random.RandomState, np.random.Generator),
              )
              and np.isnan(output[0]).any()
          ):
              print("*** NaN detected ***")
              debugprint(node)
              print("Inputs : %s" % [input[0] for input in fn.inputs])
              print(
                  "Outputs: %s" % [output[0] for output in fn.outputs]
              )
              break
  
file_path: pytensor/pytensor/compile/monitormode.py
imports: import numpy
  from pytensor.compile.mode import Mode
  from pytensor.configdefaults import config
  from pytensor.link.basic import WrapLinkerMany
  from pytensor.link.c.basic import OpWiseCLinker
label_desc: Use image node_id 1 for calling a global function with example usage: detect_nan(fgraph, i, node, fn) without return types