예제 #1
0
def example_loop():
    with Task():
        total = ops.Const(0)
        total_large = ops.Const(0)
        total_small = ops.Const(0)
        total_tiny = ops.Const(0)
        with ops.loop(10) as loop:
            outer = ops.Mul([loop.iter(), ops.Const(10)])
            with ops.loop(loop.iter()) as inner:
                val = ops.Add([outer, inner.iter()])
                with ops.If(ops.GE([val, ops.Const(80)])) as c:
                    ops.Add([total_large, val], [total_large])
                with c.Elif(ops.GE([val, ops.Const(50)])) as c:
                    ops.Add([total_small, val], [total_small])
                with c.Else():
                    ops.Add([total_tiny, val], [total_tiny])
                ops.Add([total, val], total)
예제 #2
0
 def _actual_loop(self):
     total = ops.Const(0)
     total_large = ops.Const(0)
     total_small = ops.Const(0)
     total_tiny = ops.Const(0)
     with ops.loop(10) as loop:
         outer = ops.Mul([loop.iter(), ops.Const(10)])
         with ops.loop(loop.iter()) as inner:
             val = ops.Add([outer, inner.iter()])
             with ops.If(ops.GE([val, ops.Const(80)])) as c:
                 ops.Add([total_large, val], [total_large])
             with c.Elif(ops.GE([val, ops.Const(50)])) as c:
                 ops.Add([total_small, val], [total_small])
             with c.Else():
                 ops.Add([total_tiny, val], [total_tiny])
             ops.Add([total, val], total)
     return map(final_output, (total, total_large, total_small, total_tiny))