示例#1
0
def _test_if(x):
    y = ops.Const(1)
    with ops.If(ops.GT([x, ops.Const(50)])):
        ops.Const(2, blob_out=y)
    with ops.If(ops.LT([x, ops.Const(50)])):
        ops.Const(3, blob_out=y)
        ops.stop()
        ops.Const(4, blob_out=y)
    return y
示例#2
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)
示例#3
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))