class_docstr: Check if variables can be expressed without using variables in invalid.
  
  Parameters
  ----------
  valid_equivalent
      Provides a dictionary mapping some invalid variables to valid ones that
      can be used instead.
docstr: Go backwards in the graph, from out, and check if out is valid.
  
  If out is a valid node, (out, True) is returned.
  If out is not valid, but has an equivalent e, (e, False) is returned.
  If out is not valid and has no equivalent, None is returned.
docstr_tok: ["Go","backwards","in","the","graph",",","from","out",",","and","check","if","out","is","valid",".","If","out","is","a","valid","node",",","(","out",",","True",")","is","returned",".","If","out","is","not","valid",",","but","has","an","equivalent","e",",","(","e",",","False",")","is","returned",".","If","out","is","not","valid","and","has","no","equivalent",",","None","is","returned","."]
code: def check(self, out):
      """
      Go backwards in the graph, from out, and check if out is valid.
  
      If out is a valid node, (out, True) is returned.
      If out is not valid, but has an equivalent e, (e, False) is returned.
      If out is not valid and has no equivalent, None is returned.
  
      """
  
      def get_value(out):
          if out in self.valid:
              return out, True
          elif out in self.valid_equivalent:
              return self.valid_equivalent[out], False
          elif out in self.invalid:
              return None
          else:
              raise RuntimeError("This should not happen")
  
      q = [out]
      while q:
          out = q.pop()
          if out in self.valid:
              continue
          elif out in self.invalid:
              continue
  
          if out.owner is None:
              if isinstance(out, tensor.TensorConstant):
                  if hasattr(out, "fgraph") or getattr(
                      out, "cached", False
                  ):
                      # If out have an fgraph, we aren't sure if it
                      # is from the inner graph or outer graph, so
                      # clone it.
                      # As it will be used as is in an FunctionGraph
                      # (won't be cloned later), it can't be a
                      # cached variable
                      cloned_out = out.clone()
                      self.valid.add(cloned_out)
                      self.invalid.add(out)
                      self.valid_equivalent[out] = cloned_out
                  else:
                      self.valid.add(out)
                  continue
              else:
                  # This is an input node and it has not been
                  # explicitly marked as invalid so we can use it
                  self.valid.add(out)
                  continue
  
          # Process the input if needed
          continue_while = False
          for inp in out.owner.inputs:
              if inp not in self.valid and inp not in self.invalid:
                  q.append(out)
                  q.extend(out.owner.inputs)
                  continue_while = True
                  break
          if continue_while:
              continue
          inputs = [get_value(i) for i in out.owner.inputs]
  
          # If some inputs are invalid without equivalent, so is out
          if None in inputs:
              self.invalid.add(out)
              continue
  
          # If some inputs are invalid with equivalent,
          # an equivalent out should be built and returned
          all_inputs = [inp for (inp, is_valid) in inputs]
          equiv_inputs = [
              inp for (inp, is_valid) in inputs if not is_valid
          ]
          if equiv_inputs:
              cloned_node = out.owner.clone_with_new_inputs(all_inputs)
              cloned_out = cloned_node.outputs[out.index]
              self.invalid.add(out)
              self.valid.add(cloned_out)
              self.valid_equivalent[out] = cloned_out
              continue
  
          # All inputs are valid, so is out
          self.valid.add(out)
  
      return get_value(out)
  
imports: from __future__ import absolute_import, print_function, division
  import copy
  import logging
  import warnings
  from collections import OrderedDict
  import numpy
  import theano
  from theano.compat import izip
  from six import string_types, iteritems
  from six.moves import xrange
  from theano.compile.pfunc import rebuild_collect_shared
  from theano import gof, compat
  from theano import tensor, scalar
  from theano.tensor.basic import get_scalar_constant_value
label_desc: Use image node_id 2 for calling the Validator obj's underlying member method code with example usage: obj.check(out) and returns: get_value, out,  True, self,  False, None