Merge pull request #39541 from bhack:partial_decorate
PiperOrigin-RevId: 312132452 Change-Id: I6264d95cb73caf6ddca26567ddad035e94d3ac74
This commit is contained in:
commit
dfd659da71
@ -20,6 +20,7 @@ from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
|
||||
from tensorflow.python.eager import def_function
|
||||
from tensorflow.python.eager import context
|
||||
from tensorflow.python.framework import constant_op
|
||||
from tensorflow.python.framework import dtypes
|
||||
@ -186,6 +187,25 @@ class MapFnTest(test.TestCase):
|
||||
self.assertAllEqual(-nums, received[1])
|
||||
self.assertAllEqual(nums, received[2])
|
||||
|
||||
@test_util.run_in_graph_and_eager_modes
|
||||
def testMap_autograph_indirect(self):
|
||||
|
||||
def test_function(x):
|
||||
cond = constant_op.constant(-1)
|
||||
if cond == 0:
|
||||
result = x
|
||||
else:
|
||||
result = x
|
||||
return result
|
||||
|
||||
@def_function.function
|
||||
def map_call(x):
|
||||
return map_fn.map_fn(test_function, x)
|
||||
|
||||
x = constant_op.constant([1])
|
||||
y = map_call(x)
|
||||
self.assertAllEqual([1], self.evaluate(y))
|
||||
|
||||
@test_util.run_in_graph_and_eager_modes
|
||||
def testMapShape(self):
|
||||
x = constant_op.constant([[1, 2, 3], [4, 5, 6]])
|
||||
|
@ -22,6 +22,8 @@ from __future__ import print_function
|
||||
|
||||
import re
|
||||
|
||||
from tensorflow.python.autograph.core import ag_ctx as autograph_ctx
|
||||
from tensorflow.python.autograph.impl import api as autograph
|
||||
from tensorflow.python.eager import context
|
||||
from tensorflow.python.framework import constant_op
|
||||
from tensorflow.python.framework import ops
|
||||
@ -477,7 +479,9 @@ def map_fn(fn,
|
||||
elems_value_flat = _elems_value_batchable_to_flat(elems_value_batchable,
|
||||
elems_flat_signature)
|
||||
elems_value = elems_unflatten(elems_value_flat)
|
||||
result_value = fn(elems_value)
|
||||
ag_ctx = autograph_ctx.control_status_ctx()
|
||||
autographed_fn = autograph.tf_convert(fn, ag_ctx)
|
||||
result_value = autographed_fn(elems_value)
|
||||
nest.assert_same_structure(fn_output_signature or elems, result_value)
|
||||
result_value_flat = nest.flatten(result_value)
|
||||
result_value_batchable = _result_value_flat_to_batchable(
|
||||
|
Loading…
Reference in New Issue
Block a user