Пример #1
0
    def test_to_graph_basic(self):
        def test_fn(x, s):
            while tf.reduce_sum(x) > s:
                x //= 2
            return x

        compiled_fn = api.to_graph(test_fn)

        with self.test_session() as sess:
            x = compiled_fn(constant_op.constant([4, 8]), 4)
            self.assertListEqual([1, 2], sess.run(x).tolist())
Пример #2
0
  def test_to_graph_basic(self):

    def test_fn(x, s):
      while tf.reduce_sum(x) > s:
        x //= 2
      return x

    compiled_fn = api.to_graph(test_fn)

    with self.test_session() as sess:
      x = compiled_fn(constant_op.constant([4, 8]), 4)
      self.assertListEqual([1, 2], sess.run(x).tolist())
Пример #3
0
    def test_converted_call_already_converted(self):
        def f(x):
            return x == 0

        with self.test_session() as sess:
            x = api.converted_call(f, False, False, False, {},
                                   constant_op.constant(0))
            self.assertTrue(sess.run(x))

            converted_f = api.to_graph(f)
            x = api.converted_call(converted_f, False, False, False, {},
                                   constant_op.constant(0))
            self.assertTrue(sess.run(x))
Пример #4
0
  def test_converted_call_already_converted(self):

    def f(x):
      return x == 0

    with self.test_session() as sess:
      x = api.converted_call(f, False, False, {}, constant_op.constant(0))
      self.assertTrue(sess.run(x))

      converted_f = api.to_graph(f)
      x = api.converted_call(converted_f, False, False, {},
                             constant_op.constant(0))
      self.assertTrue(sess.run(x))
Пример #5
0
    def test_source_map_attribute_present(self):
        def test_fn(y):
            return y**2

        self.assertTrue(hasattr(api.to_graph(test_fn), 'ag_source_map'))
Пример #6
0
  def test_source_map_attribute_present(self):

    def test_fn(y):
      return y**2

    self.assertTrue(hasattr(api.to_graph(test_fn), 'ag_source_map'))