Ejemplo n.º 1
0
def calculate_value_slowly(
        expr: expression.Expression,
        destinations: Optional[Sequence[expression.Expression]] = None,
        options: Optional[calculate_options.Options] = None
) -> prensor.NodeTensor:
    """A calculation of the node tensor of an expression, without optimization.

  This will not do any common subexpression elimination or caching of
  node tensors, and will likely be very slow for larger operations.

  Args:
    expr: The expression to calculate.
    destinations: Where the calculation will be used (None implies directly)
    options: Calculation options for individual calculations

  Returns:
    The node tensor of the expression.
  """
    new_options = calculate_options.get_default_options(
    ) if options is None else options

    source_node_tensors = [
        calculate_value_slowly(x, [expr], new_options)
        for x in expr.get_source_expressions()
    ]
    real_dest = [] if destinations is None else destinations
    return expr.calculate(source_node_tensors, real_dest, new_options)
Ejemplo n.º 2
0
    def __init__(self, expr: expression.Expression):
        """Construct a node in the graph.

    Args:
      expr: must be the result of _get_earliest_equal_calculation(...)
    """

        self.expression = expr
        self.sources = [
            _get_earliest_equal_calculation(x)
            for x in expr.get_source_expressions()
        ]
        self.destinations = []  # type: List[_ExpressionNode]
        self.value = None