Match behavior of py_func in graph and eager.
authorAlexandre Passos <apassos@google.com>
Tue, 27 Mar 2018 18:09:50 +0000 (11:09 -0700)
committerTensorFlower Gardener <gardener@tensorflow.org>
Tue, 27 Mar 2018 18:11:54 +0000 (11:11 -0700)
PiperOrigin-RevId: 190641841

tensorflow/python/ops/script_ops.py

index 1b4111b..96fb024 100644 (file)
@@ -334,7 +334,11 @@ def py_func(func, inp, Tout, stateful=True, name=None):
     result = func(*[x.numpy() for x in inp])
     result = nest.flatten(result)
 
-    return [x if x is None else ops.convert_to_tensor(x) for x in result]
+    result = [x if x is None else ops.convert_to_tensor(x) for x in result]
+    if len(result) == 1:
+      # Mimic the automatic unwrapping in graph-mode py_func
+      result, = result
+    return result
 
   return _internal_py_func(
       func=func, inp=inp, Tout=Tout, stateful=stateful, eager=False, name=name)