class_docstr: A Theano compilation Mode that makes the compiled function automatically
  detect NaNs and Infs and detect an error if they occur.
  
  Parameters
  ----------
  nan_is_error : bool
      If True, raise an error anytime a NaN is encountered.
  inf_is_error : bool
      If True, raise an error anytime an Inf is encountered.  Note that some
      pylearn2 modules currently use np.inf as a default value (e.g.
      mlp.max_pool) and these will cause an error if inf_is_error is True.
  big_is_error : bool
      If True, raise an error when a value greater than 1e10 is encountered.
  
  Note
  ----
      We ignore the linker parameter
class_docstr_tok: ["A","Theano","compilation","Mode","that","makes","the","compiled","function","automatically","detect","NaNs","and","Infs","and","detect","an","error","if","they","occur",".","Parameters","--","--","--","--","--","nan_is_error",":","bool","If","True",",","raise","an","error","anytime","a","NaN","is","encountered",".","inf_is_error",":","bool","If","True",",","raise","an","error","anytime","an","Inf","is","encountered",".","Note","that","some","pylearn2","modules","currently","use","np.inf","as","a","default","value","(","e.g",".","mlp.max_pool",")","and","these","will","cause","an","error","if","inf_is_error","is","True",".","big_is_error",":","bool","If","True",",","raise","an","error","when","a","value","greater","than","1e10","is","encountered",".","Note","--","--","We","ignore","the","linker","parameter"]
code: def __init__(
      self,
      nan_is_error=None,
      inf_is_error=None,
      big_is_error=None,
      optimizer="default",
      linker=None,
  ):
      self.provided_optimizer = optimizer
      if nan_is_error is None:
          nan_is_error = config.NanGuardMode.nan_is_error
      if inf_is_error is None:
          inf_is_error = config.NanGuardMode.inf_is_error
      if big_is_error is None:
          big_is_error = config.NanGuardMode.big_is_error
  
      assert nan_is_error or inf_is_error or big_is_error
  
      def do_check_on(value, nd, var=None):
          """
          Checks `value` for NaNs / Infs. If detected, raises an exception
          and / or prints information about `nd`, `f`, and `is_input` to
          help the user determine the cause of the invalid values.
  
          Parameters
          ----------
          value : numpy.ndarray
              The value to be checked.
          nd : theano.gof.Apply
              The Apply node being executed.
          var : theano.gof.Variable
              Not used if nd is there. Otherwise, used to print the stack
              trace for inputs of the graph.
  
          """
          error = False
          sio = StringIO()
          if nan_is_error:
              if contains_nan(value, nd, var):
                  print("NaN detected", file=sio)
                  error = True
          if inf_is_error:
              if contains_inf(value, nd, var):
                  print("Inf detected", file=sio)
                  error = True
          if big_is_error:
              err = False
              if not _is_numeric_value(value, var):
                  err = False
              elif pygpu_available and isinstance(value, GpuArray):
                  err = f_gpua_absmax(value.reshape(value.size)) > 1e10
              else:
                  err = np.abs(value).max() > 1e10
              if err:
                  print("Big value detected", file=sio)
                  error = True
          if error:
              if nd:
                  print(
                      "NanGuardMode found an error in the "
                      "output of a node in this variable:",
                      file=sio,
                  )
                  print(
                      theano.printing.debugprint(nd, file="str"),
                      file=sio,
                  )
              else:
                  print(
                      "NanGuardMode found an error in an input of the "
                      "graph.",
                      file=sio,
                  )
              # Add the stack trace
              if nd:
                  var = nd.outputs[0]
              print(
                  theano.gof.utils.get_variable_trace_string(var),
                  file=sio,
              )
              msg = sio.getvalue()
              if config.NanGuardMode.action == "raise":
                  raise AssertionError(msg)
              elif config.NanGuardMode.action == "pdb":
                  print(msg)
                  import pdb
  
                  pdb.set_trace()
              elif config.NanGuardMode.action == "warn":
                  logger.error(msg)
  
      def nan_check(node, thunk, storage_map, compute_map):
          for var in node.outputs:
              if compute_map[var][0] and getattr(
                  var.tag, "nan_guard_mode_check", True
              ):
                  do_check_on(storage_map[var][0], node)
  
      def nan_check_input(var, value):
          if getattr(var.tag, "nan_guard_mode_check", True):
              do_check_on(value, None, var=var)
  
      wrap_linker = theano.gof.vm.VM_Linker(
          callback=nan_check, callback_input=nan_check_input
      )
      super(NanGuardMode, self).__init__(
          wrap_linker, optimizer=self.provided_optimizer
      )
  
file_path: Theano/theano/compile/nanguardmode.py
imports: from __future__ import absolute_import, print_function, division
  import logging
  from six.moves import StringIO
  import numpy
  import theano
  from theano import config
  import theano.tensor
  from theano.compile import Mode
  from theano.compat import ValuesView
  from .mode import get_mode
label_desc: Use image node_id 1 to create a new NanGuardMode object from inherited base classes: Mode with example: obj = NanGuardMode(nan_is_error, inf_is_error, big_is_error, optimizer, linker)