Esempio n. 1
0
  def test_str(self):
    arg_spec = function_utils.SimpleArgSpec(
        args=[], varargs=[], keywords=[], defaults=[])
    self.assertEqual('()', str(arg_spec))

    arg_spec = function_utils.SimpleArgSpec(
        args=[1, 2, 3], varargs=[], keywords=[], defaults=[])
    self.assertEqual('(args=[1, 2, 3])', str(arg_spec))

    arg_spec = function_utils.SimpleArgSpec(
        args=[1], varargs=[2., True], keywords={'a': 'b'}, defaults={'x': 3})
    self.assertEqual(
        "(args=[1], varargs=[2.0, True], kwargs={'a': 'b'}, defaults={'x': 3})",
        str(arg_spec))
Esempio n. 2
0
 def test_get_defun_argspec_with_untyped_non_eager_defun(self):
   # In a non-eager function with no input signature, the same restrictions as
   # in a typed eager function apply.
   fn = tf.function(lambda x, y, *z: None)
   self.assertEqual(
       function_utils.get_argspec(fn),
       function_utils.SimpleArgSpec(
           args=['x', 'y'], varargs='z', keywords=None, defaults=None))
Esempio n. 3
0
 def test_get_defun_argspec_with_typed_non_eager_defun(self):
   # In a non-eager function with a defined input signature, **kwargs or
   # default values are not allowed, but *args are, and the input signature may
   # overlap with *args.
   fn = tf.function(lambda x, y, *z: None, (
       tf.TensorSpec(None, tf.int32),
       tf.TensorSpec(None, tf.bool),
       tf.TensorSpec(None, tf.float32),
       tf.TensorSpec(None, tf.float32),
   ))
   self.assertEqual(
       function_utils.get_argspec(fn),
       function_utils.SimpleArgSpec(
           args=['x', 'y'], varargs='z', keywords=None, defaults=None))