コード例 #1
0
    def test_fn(cond):
      def body():
        nonlocal i, j
        i = constant_op.constant(1)
        j = constant_op.constant(2)

      def orelse():
        nonlocal i, j
        i = constant_op.constant(-1)
        j = constant_op.constant(-2)

      def set_state(cond_vars):
        nonlocal i, j
        i, j = cond_vars

      i, j = None, None
      control_flow.if_stmt(
          cond=cond,
          body=body,
          orelse=orelse,
          get_state=lambda: (i, j),
          set_state=set_state,
          symbol_names=('i', 'j'),
          nouts=2)
      return i, j
コード例 #2
0
 def multi_return_if_stmt(self, cond):
   return control_flow.if_stmt(
       cond=cond,
       body=lambda: (1, 2),
       orelse=lambda: (-1, -2),
       get_state=lambda: (),
       set_state=lambda _: None)
コード例 #3
0
 def multi_return_if_stmt(self, cond):
   return control_flow.if_stmt(
       cond=cond,
       body=lambda: (1, 2),
       orelse=lambda: (-1, -2),
       get_state=lambda: (),
       set_state=lambda _: None)
コード例 #4
0
 def test_fn(cond):
     return control_flow.if_stmt(
         cond=cond,
         body=lambda: constant_op.constant(1),
         orelse=lambda: constant_op.constant(-1),
         get_state=lambda: (),
         set_state=lambda _: None)
コード例 #5
0
 def single_return_if_stmt(self, cond):
   return control_flow.if_stmt(
       cond=cond,
       body=lambda: 1,
       orelse=lambda: -1,
       get_state=lambda: (),
       set_state=lambda _: None)
コード例 #6
0
 def single_return_if_stmt(self, cond):
   return control_flow.if_stmt(
       cond=cond,
       body=lambda: 1,
       orelse=lambda: -1,
       get_state=lambda: (),
       set_state=lambda _: None)
コード例 #7
0
 def test_fn(cond):
     return control_flow.if_stmt(cond=cond,
                                 body=lambda: (1, 2),
                                 orelse=lambda: (-1, -2),
                                 get_state=lambda: (),
                                 set_state=lambda _: None,
                                 basic_symbol_names=('_', ),
                                 composite_symbol_names=())
コード例 #8
0
        def test_fn(cond):
            def body():
                nonlocal i
                i = 1

            def orelse():
                nonlocal i
                i = -1

            i = None
            control_flow.if_stmt(cond=cond,
                                 body=body,
                                 orelse=orelse,
                                 get_state=None,
                                 set_state=None,
                                 symbol_names=('i', ),
                                 nouts=1)
            return i
コード例 #9
0
 def _basic_cond(self, true_value, false_value):
     # Eager cond had different semantics, we don't test those here.
     with func_graph.FuncGraph('tmp').as_default():
         return control_flow.if_stmt(cond=constant_op.constant(True),
                                     body=true_value,
                                     orelse=false_value,
                                     get_state=lambda: (),
                                     set_state=lambda _: None,
                                     basic_symbol_names=('s', ),
                                     composite_symbol_names=())
コード例 #10
0
        def test_fn(cond):
            def body():
                nonlocal i, j
                i = 1
                j = 2

            def orelse():
                nonlocal i, j
                i = -1
                j = -2

            i, j = None, None
            control_flow.if_stmt(cond=cond,
                                 body=body,
                                 orelse=orelse,
                                 get_state=None,
                                 set_state=None,
                                 symbol_names=('i', 'j'),
                                 nouts=2)
            return i, j
コード例 #11
0
    def _basic_cond(self, body_fn, else_fn):
        def body():
            nonlocal x
            x = body_fn()

        def orelse():
            nonlocal x
            x = else_fn()

        def set_state(cond_vars):
            nonlocal x
            x, = cond_vars

        x = 0
        control_flow.if_stmt(cond=constant_op.constant(True),
                             body=body,
                             orelse=orelse,
                             get_state=lambda: (x, ),
                             set_state=set_state,
                             symbol_names=('x', ),
                             nouts=1)
        return x
コード例 #12
0
        def test_fn(cond):
            def body():
                nonlocal i
                i = constant_op.constant(1)

            def orelse():
                nonlocal i
                i = constant_op.constant(-1.0)

            def set_state(cond_vars):
                nonlocal i
                i, = cond_vars

            i = None
            control_flow.if_stmt(cond=cond,
                                 body=body,
                                 orelse=orelse,
                                 get_state=lambda: (i, ),
                                 set_state=set_state,
                                 symbol_names=('i', ),
                                 nouts=0)
            return i
コード例 #13
0
    def _fixed_cond(self, cond_val):
        def body():
            nonlocal x
            x = 1

        def orelse():
            nonlocal x
            x = -1

        def set_state(cond_vars):
            nonlocal x
            x, = cond_vars

        x = 0
        control_flow.if_stmt(cond=cond_val,
                             body=body,
                             orelse=orelse,
                             get_state=lambda: (x, ),
                             set_state=set_state,
                             symbol_names=('x', ),
                             nouts=1)
        return x
コード例 #14
0
    def _basic_cond(self, body_fn, else_fn):
        def body():
            nonlocal x
            x = body_fn()

        def orelse():
            nonlocal x
            x = else_fn()

        def set_state(cond_vars):
            nonlocal x
            x, = cond_vars

        x = 0
        # Eager cond had different semantics, we don't test those here.
        with func_graph.FuncGraph('tmp').as_default():
            control_flow.if_stmt(cond=constant_op.constant(True),
                                 body=body,
                                 orelse=orelse,
                                 get_state=lambda: (x, ),
                                 set_state=set_state,
                                 symbol_names=('x', ),
                                 nouts=1)
        return x
コード例 #15
0
 def single_return_if_stmt(self, cond):
   return control_flow.if_stmt(cond=cond, body=lambda: 1, orelse=lambda: -1)
コード例 #16
0
 def multi_return_if_stmt(self, cond):
   return control_flow.if_stmt(
       cond=cond, body=lambda: (1, 2), orelse=lambda: (-1, -2))
コード例 #17
0
 def multi_return_if_stmt(self, cond):
   return control_flow.if_stmt(
       cond=cond, body=lambda: (1, 2), orelse=lambda: (-1, -2))
コード例 #18
0
 def single_return_if_stmt(self, cond):
   return control_flow.if_stmt(cond=cond, body=lambda: 1, orelse=lambda: -1)
コード例 #19
0
 def test_python(self):
   self.assertEqual(1, control_flow.if_stmt(True, lambda: 1, lambda: -1))
   self.assertEqual(-1, control_flow.if_stmt(False, lambda: 1, lambda: -1))
コード例 #20
0
 def test_if_stmt(cond):
   return control_flow.if_stmt(
       cond=cond,
       body=lambda: 1,
       orelse=lambda: -1)
コード例 #21
0
 def test_fn(cond):
     return control_flow.if_stmt(cond=cond,
                                 body=lambda: (1, 2),
                                 orelse=lambda: (-1, -2),
                                 get_state=lambda: (),
                                 set_state=lambda _: None)
コード例 #22
0
 def test_if_stmt(cond):
     return control_flow.if_stmt(cond=cond,
                                 body=lambda: 1,
                                 orelse=lambda: -1)
コード例 #23
0
 def test_python(self):
     self.assertEqual(1, control_flow.if_stmt(True, lambda: 1, lambda: -1))
     self.assertEqual(-1, control_flow.if_stmt(False, lambda: 1,
                                               lambda: -1))