Exemple #1
0
    def _get_variables(self):
        self.variables = set()
        self.applies = set()
        self.application_calls = set()
        self.updates = []

        def recursion(current):
            self.variables.add(current)

            if hasattr(current.tag, 'application_call'):
                logger.debug("found application call of {}".format(current))
                application_call = current.tag.application_call
                if application_call not in self.application_calls:
                    self.application_calls.add(application_call)
                    for av in application_call.auxiliary_variables:
                        av.tag.application_call = current.tag.application_call
                        recursion(av)
                    self.updates.extend(application_call.updates)
            if current.owner:
                owner = current.owner
                if owner not in self.applies:
                    if hasattr(owner.tag, 'updates'):
                        logger.debug(
                            "found updates in application of {}".format(owner))
                        self.updates.extend(owner.tag.updates.items())
                    self.applies.add(owner)
                for input_ in owner.inputs:
                    if input_ not in self.variables:
                        recursion(input_)

        for output in self.outputs:
            if output not in self.variables:
                recursion(output)
        self.inputs = [v for v in self.variables if is_graph_input(v)]
Exemple #2
0
    def has_inputs(self, variable):
        """Check if a variable depends on input variables.

        Returns
        -------
        bool
            ``True`` if the given variable depends on input variables,
            ``False`` otherwise.

        """
        if variable not in self._has_inputs:
            self._has_inputs[variable] = False
            if is_graph_input(variable):
                self._has_inputs[variable] = True
            elif getattr(variable, 'owner', None):
                for dependancy in variable.owner.inputs:
                    if self.has_inputs(dependancy):
                        self._has_inputs[variable] = True
        return self._has_inputs[variable]
Exemple #3
0
    def has_inputs(self, variable):
        """Check if a variable depends on input variables.

        Returns
        -------
        bool
            ``True`` if the given variable depends on input variables,
            ``False`` otherwise.

        """
        if variable not in self._has_inputs:
            self._has_inputs[variable] = False
            if is_graph_input(variable):
                self._has_inputs[variable] = True
            elif getattr(variable, 'owner', None):
                for dependancy in variable.owner.inputs:
                    if self.has_inputs(dependancy):
                        self._has_inputs[variable] = True
        return self._has_inputs[variable]
Exemple #4
0
 def inputs(self):
     """Inputs to the graph, excluding constants and shared variables."""
     return [var for var in self.variables if is_graph_input(var)]
Exemple #5
0
 def inputs(self):
     """Inputs to the graph, excluding constants and shared variables."""
     return [var for var in self.variables if is_graph_input(var)]