Fix undefined behavior in tf.raw_ops.Switch
in eager mode.
PiperOrigin-RevId: 332578058 Change-Id: I9727571d2f21476b10d8aa27c1b7176564b76ac9
This commit is contained in:
parent
d8c69c287f
commit
92d5b97a0a
@ -307,7 +307,12 @@ Status KernelAndDeviceOp::Run(
|
||||
if (outputs != nullptr) {
|
||||
outputs->clear();
|
||||
for (int i = 0; i < context.num_outputs(); ++i) {
|
||||
outputs->push_back(Tensor(*context.mutable_output(i)));
|
||||
const auto* output_tensor = context.mutable_output(i);
|
||||
if (output_tensor != nullptr) {
|
||||
outputs->push_back(Tensor(*output_tensor));
|
||||
} else {
|
||||
outputs->push_back(Tensor());
|
||||
}
|
||||
}
|
||||
}
|
||||
return Status::OK();
|
||||
|
@ -4581,6 +4581,14 @@ class ControlFlowTest(test.TestCase, parameterized.TestCase):
|
||||
result = control_flow_ops.merge([v_f, v_t])
|
||||
self.evaluate(result)
|
||||
|
||||
def testSwitchEagerMode(self):
|
||||
if not context.executing_eagerly():
|
||||
return
|
||||
input_data = [1, 2, 3, 4]
|
||||
vf, vt = control_flow_ops.switch(input_data, False)
|
||||
self.assertAllEqual(vf, input_data)
|
||||
self.assertAllEqual(vt, [])
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def testQIntArgAndRet(self):
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user