def __init__(self, inputs, outputs, features=None, clone=True): """ Create an FunctionGraph which operates on the subgraph bound by the inputs and outputs sets. This class keeps a pointer to the inputs and outputs, and also modifies them. #TODO: document what variables are[not] set in the FunctionGraph when a feature is added via the constructor. How constructed is the FunctionGraph? :param clone: If true, we will clone the graph. This is useful to remove the constant cache problem. """ if clone: inputs, outputs = graph.clone(inputs, outputs) self.execute_callbacks_time = 0 self.execute_callbacks_times = {} if features is None: features = [] # XXX: Unless I'm missing something (but there's no documentation, # so I probably am) this should be a set. self._features = [] # All apply nodes in the subgraph defined by inputs and # outputs are cached in this field self.apply_nodes = set() # Ditto for variable nodes self.variables = set() self.inputs = list(inputs) self.outputs = outputs for f in features: self.attach_feature(f) self.attach_feature(toolbox.ReplaceValidate()) for input in self.inputs: if input.owner is not None: raise ValueError("One of the provided inputs is the output of" "an already existing node. " "If that is okay, either discard that " "input's owner or use graph.clone.") self.__setup_r__(input) self.variables.add(input) self.__import_r__(outputs, reason="init") for i, output in enumerate(outputs): output.clients.append(('output', i)) self.node_locks = {} self.variable_locks = {} self.profile = None
def __init__(self, inputs, outputs, features=None, clone=True): if clone: inputs, outputs = graph.clone(inputs, outputs) self.execute_callbacks_time = 0 self.execute_callbacks_times = {} if features is None: features = [] # XXX: Unless I'm missing something (but there's no documentation, # so I probably am) this should be a set. self._features = [] # All apply nodes in the subgraph defined by inputs and # outputs are cached in this field self.apply_nodes = set() # Ditto for variable nodes. # It must contain all fgraph.inputs and all apply_nodes # outputs even if they aren't used in the graph. self.variables = set() self.inputs = list(inputs) self.outputs = outputs for f in features: self.attach_feature(f) self.attach_feature(toolbox.ReplaceValidate()) for input in self.inputs: if input.owner is not None: raise ValueError("One of the provided inputs is the output of" "an already existing node. " "If that is okay, either discard that " "input's owner or use graph.clone.") self.__setup_r__(input) self.variables.add(input) for output in outputs: self.__import_r__(output, reason="init") for i, output in enumerate(outputs): output.clients.append(('output', i)) self.node_locks = {} self.variable_locks = {} self.profile = None
def add_requirements(self, fgraph): fgraph.attach_feature(toolbox.ReplaceValidate())
def __init__(self, inputs, outputs, features=None, clone=True, update_mapping=None): """ Create an FunctionGraph which operates on the subgraph bound by the inputs and outputs sets. Parameters ---------- inputs : list of variables Inputs nodes of the graph, usually declared by the user outputs : list of variables Outputs nodes of the graph. clone : boolean If true, we will clone the graph. This is useful to remove the constant cache problem. update_mapping : dictionary Mapping between the inputs with updates and the outputs corresponding to their updates. """ if clone: inputs, outputs = graph.clone(inputs, outputs) self.execute_callbacks_time = 0 self.execute_callbacks_times = {} if features is None: features = [] # XXX: Unless I'm missing something (but there's no documentation, # so I probably am) this should be a set. self._features = [] # All apply nodes in the subgraph defined by inputs and # outputs are cached in this field self.apply_nodes = set() # Ditto for variable nodes. # It must contain all fgraph.inputs and all apply_nodes # outputs even if they aren't used in the graph. self.variables = set() self.inputs = list(inputs) self.outputs = outputs for f in features: self.attach_feature(f) self.attach_feature(toolbox.ReplaceValidate()) for input in self.inputs: if input.owner is not None: raise ValueError("One of the provided inputs is the output of" "an already existing node. " "If that is okay, either discard that " "input's owner or use graph.clone.") self.__setup_r__(input) self.variables.add(input) for output in outputs: self.__import_r__(output, reason="init") for i, output in enumerate(outputs): output.clients.append(("output", i)) self.profile = None self.update_mapping = update_mapping
def add_requirements(self, env): env.extend(toolbox.ReplaceValidate()) env.extend(DestroyHandler())
def add_requirements(self, env): env.extend(toolbox.ReplaceValidate())
def __init__(self, inputs, outputs, features=None, clone=True, update_mapping=None): """ Create an FunctionGraph which operates on the subgraph bound by the inputs and outputs sets. Parameters ---------- inputs : list of theano.gof.graph.Variable Inputs nodes of the graph, usually declared by the user outputs : list of theano.gof.graph.Variable Outputs nodes of the graph. clone : boolean If true, we will clone the graph. This is useful to remove the constant cache problem. features : list of theano.gof.toolbox.Feature A list of features to be added to the `FunctionGraph`. update_mapping : dict Mapping between the inputs with updates and the outputs corresponding to their updates. """ if clone: inputs, outputs = clone_graph(inputs, outputs) if not isinstance(inputs, list): raise TypeError("Argument `inputs` should be a list") if not isinstance(outputs, list): raise TypeError("Argument `outputs` should be a list") self.execute_callbacks_time = 0 self.execute_callbacks_times = {} if features is None: features = [] self._features = [] # All apply nodes in the subgraph defined by inputs and # outputs are cached in this field self.apply_nodes = set() # Ditto for variable nodes. # It must contain all fgraph.inputs and all apply_nodes # outputs even if they aren't used in the graph. self.variables = set() # TODO FIXME: We should *not* be using a list created elsewhere! self.outputs = outputs self.clients = {} for f in features: self.attach_feature(f) self.attach_feature(toolbox.ReplaceValidate()) self.inputs = [] for in_var in inputs: if in_var.owner is not None: raise ValueError("One of the provided inputs is the output of " "an already existing node. " "If that is okay, either discard that " "input's owner or use graph.clone.") self.add_input(in_var, check=False) for output in outputs: self.import_var(output, reason="init") for i, output in enumerate(outputs): self.clients[output].append(("output", i)) self.profile = None self.update_mapping = update_mapping