Esempio n. 1
0
 def refine(self, g, tick, known_inputs):
     if known_inputs["$test"]:
         subgraph = self.body_graph
     else:
         subgraph = self.orelse_graph
         
     refine.replace_task(g, tick, subgraph)
Esempio n. 2
0
    def refine(self, g, tick, known_inputs):
        if known_inputs["$test"]:
            subgraph = self.body_graph
        else:
            subgraph = self.orelse_graph

        refine.replace_task(g, tick, subgraph)
Esempio n. 3
0
 def test_unassigned_out(self):
     
     subgraph = G(
         C(START_TICK, "sin", 1, "x"),
         T(1, "subtask"),
         C(1, "y", FINAL_TICK, "sout")
     )
     
     g = G(
           C(START_TICK, "in", 1, "sin"),
           C(START_TICK, "sout2", 1, "sout2"),
           T(1, "task_to_replace"),
           C(1, "sout", FINAL_TICK, "out"),
           C(1, "sout2", FINAL_TICK, "out2")
           )
     
     expected  = G(
           C(START_TICK, "in", (1,1), "x"),
           T((1,1), "subtask"),
           C((1,1), "y", FINAL_TICK, "out"),
           C(START_TICK, "sout2", FINAL_TICK, "out2")
           )
     
     refine.replace_task(g, START_TICK + 1, subgraph)
     
     utils.assert_graph_equal(expected, g)
Esempio n. 4
0
 def test_passhtrough(self):
     
     subgraph = G(
         C(START_TICK, "sin", FINAL_TICK,"sout"),
     )
     
     g = G(
           C(START_TICK, "in", 1, "sin"),
           T(1, "task_to_replace"),
           C(1, "sout", FINAL_TICK, "out"),
           )
     
     expected  = G(
           C(START_TICK, "in", FINAL_TICK, "out"),
           )
     
     refine.replace_task(g, START_TICK + 1, subgraph)
     
     utils.assert_graph_equal(expected, g)
     
Esempio n. 5
0
 def refine(self, g, tick, known_inputs):
     if "$test" not in known_inputs:
         return
     if self.has_breaked_input and "$breaked" not in known_inputs:
         return
     
     if self.has_breaked_input and known_inputs["$breaked"]:
         # `break` was called. Abort iteration
         refine.replace_task(g, tick, graph.Graph())
     
     test = known_inputs["$test"]
     
     use_body = test == True
         
     if use_body:
         if self.is_tail:
             # the last tick item is the tail
             # the one before that is the iteration_tick
             # and then we have the tick of the original loop task.
             orig_for_tick = tick >> 2
             iteration_counter = tick._elements[-2] + 1
             iteration_tick = graph.START_TICK + iteration_counter << orig_for_tick
         else:
             # First iteration
             iteration_counter = 1
             iteration_tick = graph.START_TICK + iteration_counter << tick
             
         subgraph_tick = iteration_tick
         
         refine.replace_task(g, tick, self.body_graph, 
                             subgraph_tick=subgraph_tick)
     else:
         refine.replace_task(g, tick, self.orelse_graph)
Esempio n. 6
0
    def refine(self, g, tick, known_inputs):
        if "$test" not in known_inputs:
            return
        if self.has_breaked_input and "$breaked" not in known_inputs:
            return

        if self.has_breaked_input and known_inputs["$breaked"]:
            # `break` was called. Abort iteration
            refine.replace_task(g, tick, graph.Graph())

        test = known_inputs["$test"]

        use_body = test == True

        if use_body:
            if self.is_tail:
                # the last tick item is the tail
                # the one before that is the iteration_tick
                # and then we have the tick of the original loop task.
                orig_for_tick = tick >> 2
                iteration_counter = tick._elements[-2] + 1
                iteration_tick = graph.START_TICK + iteration_counter << orig_for_tick
            else:
                # First iteration
                iteration_counter = 1
                iteration_tick = graph.START_TICK + iteration_counter << tick

            subgraph_tick = iteration_tick

            refine.replace_task(g,
                                tick,
                                self.body_graph,
                                subgraph_tick=subgraph_tick)
        else:
            refine.replace_task(g, tick, self.orelse_graph)
Esempio n. 7
0
    def refine(self, g, tick, known_inputs):
        if "$iterator" not in known_inputs:
            return
        if self.has_breaked_input and "$breaked" not in known_inputs:
            return

        if self.has_breaked_input and known_inputs["$breaked"]:
            # `break` was called. Abort iteration
            refine.replace_task(g, tick, graph.Graph())

        iterator = known_inputs["$iterator"]

        try:
            item = next(iterator)
            use_body = True
        except StopIteration:
            use_body = False

        if use_body:
            if self.is_tail:
                # the last tick item is the for-tail
                # the prev. to last is the subgraph_tick
                # the one before that is the iteration_tick
                # and then we have the tick of the original for-loop task.
                orig_for_tick = tick >> 3
                #orig_for_tick = graph.Tick(tick._elements[:-3])
                iteration_counter = tick._elements[-3] + 1
                iteration_tick = graph.START_TICK + iteration_counter << orig_for_tick
            else:
                # First iteration
                iteration_counter = 1
                iteration_tick = graph.START_TICK + iteration_counter << tick

            item_tick = graph.START_TICK + 1 << iteration_tick
            subgraph_tick = graph.START_TICK + 2 << iteration_tick

            g.add_task(item_tick, ConstTask(item))
            item_endpoint = graph.Endpoint(item_tick, "value")

            refine.replace_task(g,
                                tick,
                                self.body_graph,
                                subgraph_tick=subgraph_tick,
                                additional_inputs={'$target': item_endpoint})
        else:
            refine.replace_task(g, tick, self.orelse_graph)
Esempio n. 8
0
 def refine(self, g, tick, known_inputs):
     if "$iterator" not in known_inputs:
         return
     if self.has_breaked_input and "$breaked" not in known_inputs:
         return
     
     if self.has_breaked_input and known_inputs["$breaked"]:
         # `break` was called. Abort iteration
         refine.replace_task(g, tick, graph.Graph())
     
     iterator = known_inputs["$iterator"]
     
     try:
         item = next(iterator)
         use_body = True
     except StopIteration:
         use_body = False
         
     if use_body:
         if self.is_tail:
             # the last tick item is the for-tail
             # the prev. to last is the subgraph_tick
             # the one before that is the iteration_tick
             # and then we have the tick of the original for-loop task.
             orig_for_tick = tick >> 3
             #orig_for_tick = graph.Tick(tick._elements[:-3])
             iteration_counter = tick._elements[-3] + 1
             iteration_tick = graph.START_TICK + iteration_counter << orig_for_tick
         else:
             # First iteration
             iteration_counter = 1
             iteration_tick = graph.START_TICK + iteration_counter << tick
             
         item_tick = graph.START_TICK + 1 << iteration_tick
         subgraph_tick = graph.START_TICK + 2 << iteration_tick
         
         g.add_task(item_tick, ConstTask(item))
         item_endpoint = graph.Endpoint(item_tick, "value")
         
         refine.replace_task(g, tick, self.body_graph, 
                             subgraph_tick=subgraph_tick, 
                             additional_inputs={'$target':item_endpoint})
     else:
         refine.replace_task(g, tick, self.orelse_graph)