当前位置: 首页>>代码示例>>Python>>正文


Python api.converted_call函数代码示例

本文整理汇总了Python中tensorflow.python.autograph.impl.api.converted_call函数的典型用法代码示例。如果您正苦于以下问题:Python converted_call函数的具体用法?Python converted_call怎么用?Python converted_call使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了converted_call函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_fn

    def test_fn():
      res = TestResource()

      def f(y):
        return res.x + y

      opts = converter.ConversionOptions(recursive=True)
      api.converted_call(f, None, opts, (1,), {})
开发者ID:aritratony,项目名称:tensorflow,代码行数:8,代码来源:api_test.py

示例2: test_converted_call_builtin

  def test_converted_call_builtin(self):
    x = api.converted_call(range, None,
                           converter.ConversionOptions(recursive=True), (3,),
                           {})
    self.assertEqual((0, 1, 2), tuple(x))

    x = api.converted_call('compile', re,
                           converter.ConversionOptions(recursive=True),
                           ('mnas_v4_a.*\\/.*(weights|kernel):0$',), {})
    self.assertIsNotNone(x.match('mnas_v4_a/weights:0'))
开发者ID:aritratony,项目名称:tensorflow,代码行数:10,代码来源:api_test.py

示例3: test_fn

    def test_fn():
      res = TestResource()

      def f(y):

        def inner_f():
          return res.x + y

        return inner_f

      opts = converter.ConversionOptions()
      api.converted_call(f, None, opts, (1,), {})()
开发者ID:perfmjs,项目名称:tensorflow,代码行数:12,代码来源:api_test.py

示例4: test_converted_call_already_converted

  def test_converted_call_already_converted(self):

    def f(x):
      return x == 0

    x = api.converted_call(f, None, converter.ConversionOptions(),
                           (constant_op.constant(0),), {})
    self.assertTrue(self.evaluate(x))

    converted_f = api.to_graph(f)
    x = api.converted_call(converted_f, None, converter.ConversionOptions(),
                           (constant_op.constant(0),), {})
    self.assertTrue(self.evaluate(x))
开发者ID:kylin9872,项目名称:tensorflow,代码行数:13,代码来源:api_test.py

示例5: test_converted_call_already_converted

  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))
开发者ID:AnishShah,项目名称:tensorflow,代码行数:14,代码来源:api_test.py

示例6: test_converted_call_already_converted

  def test_converted_call_already_converted(self):

    def f(x):
      return x == 0

    with self.cached_session() as sess:
      x = api.converted_call(f, None, converter.ConversionOptions(),
                             constant_op.constant(0))
      self.assertTrue(sess.run(x))

      converted_f = api.to_graph(f)
      x = api.converted_call(converted_f, None, converter.ConversionOptions(),
                             constant_op.constant(0))
      self.assertTrue(sess.run(x))
开发者ID:abhinav-upadhyay,项目名称:tensorflow,代码行数:14,代码来源:api_test.py

示例7: test_converted_call_already_converted

  def test_converted_call_already_converted(self):

    def f(x):
      return x == 0

    x = api.converted_call(f, None, converter.ConversionOptions(recursive=True),
                           (constant_op.constant(0),), {})
    self.assertTrue(self.evaluate(x))

    converted_f = api.to_graph(
        f, experimental_optional_features=converter.Feature.ALL)
    x = api.converted_call(converted_f, None,
                           converter.ConversionOptions(recursive=True),
                           (constant_op.constant(0),), {})
    self.assertTrue(self.evaluate(x))
开发者ID:aritratony,项目名称:tensorflow,代码行数:15,代码来源:api_test.py

示例8: test_converted_call_numpy

  def test_converted_call_numpy(self):

    opts = converter.ConversionOptions(recursive=True)

    x = api.converted_call(np.arange, None, opts, (5,), {})

    self.assertAllEqual(x, list(range(5)))
开发者ID:aritratony,项目名称:tensorflow,代码行数:7,代码来源:api_test.py

示例9: test_converted_call_no_user_code

  def test_converted_call_no_user_code(self):

    def f(x):
      return len(x)

    opts = converter.ConversionOptions(internal_convert_user_code=False)

    # f should not be converted, causing len to error out.
    with self.assertRaisesRegexp(Exception,
                                 'object of type \'Tensor\' has no len()'):
      api.converted_call(f, None, opts, constant_op.constant([0]))

    # len on the other hand should work fine.
    x = api.converted_call(len, None, opts, constant_op.constant([0]))
    # The constant has static shape so the result is a primitive not a Tensor.
    self.assertEqual(x, 1)
开发者ID:abhinav-upadhyay,项目名称:tensorflow,代码行数:16,代码来源:api_test.py

示例10: test_converted_call_namedtuple

  def test_converted_call_namedtuple(self):

    opts = converter.ConversionOptions()

    x = api.converted_call(collections.namedtuple, None, opts,
                           ('TestNamedtuple', ('a', 'b')), {})

    self.assertTrue(inspect_utils.isnamedtuple(x))
开发者ID:perfmjs,项目名称:tensorflow,代码行数:8,代码来源:api_test.py

示例11: test_converted_call_functools_partial

  def test_converted_call_functools_partial(self):

    def test_fn(x, y, z):
      if x < 0:
        return -x, -y, -z
      return x, y, z

    x = api.converted_call(
        functools.partial(test_fn, constant_op.constant(-1), z=-3), None,
        converter.ConversionOptions(), (constant_op.constant(-2),), {})
    self.assertEqual((1, 2, 3), self.evaluate(x))

    x = api.converted_call(
        functools.partial(
            functools.partial(test_fn, constant_op.constant(-1)), z=-3), None,
        converter.ConversionOptions(), (constant_op.constant(-2),), {})
    self.assertEqual((1, 2, 3), self.evaluate(x))
开发者ID:perfmjs,项目名称:tensorflow,代码行数:17,代码来源:api_test.py

示例12: test_converted_call_namedtuple_via_collections

  def test_converted_call_namedtuple_via_collections(self):

    opts = converter.ConversionOptions(recursive=True)

    x = api.converted_call('namedtuple', collections, opts, ('TestNamedtuple',
                                                             ('a', 'b')), {})

    self.assertTrue(inspect_utils.isnamedtuple(x))
开发者ID:aritratony,项目名称:tensorflow,代码行数:8,代码来源:api_test.py

示例13: test_converted_call_tf_op_forced

  def test_converted_call_tf_op_forced(self):

    # TODO(mdan): Add the missing level of support to LOGICAL_EXPRESSIONS.
    opts = converter.ConversionOptions(
        force_conversion=True, optional_features=None)

    x = api.converted_call(gen_math_ops.add, None, opts, (1, 1), {})

    self.assertAllEqual(self.evaluate(x), 2)
开发者ID:aritratony,项目名称:tensorflow,代码行数:9,代码来源:api_test.py

示例14: test_converted_call_no_kwargs_allowed

  def test_converted_call_no_kwargs_allowed(self):

    def f(*args):
      # Note: np.broadcast rejects any **kwargs, even *{}
      return np.broadcast(args[:1])

    opts = converter.ConversionOptions(internal_convert_user_code=False)

    self.assertIsNotNone(api.converted_call(f, None, opts, (1, 2, 3, 4), None))
开发者ID:aritratony,项目名称:tensorflow,代码行数:9,代码来源:api_test.py

示例15: test_converted_call_function

  def test_converted_call_function(self):

    def test_fn(x):
      if x < 0:
        return -x
      return x

    x = api.converted_call(test_fn, None, converter.ConversionOptions(),
                           (constant_op.constant(-1),), {})
    self.assertEqual(1, self.evaluate(x))
开发者ID:perfmjs,项目名称:tensorflow,代码行数:10,代码来源:api_test.py


注:本文中的tensorflow.python.autograph.impl.api.converted_call函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。