From 49fd93aba815f9f74f167c935da42d85e8de0ca0 Mon Sep 17 00:00:00 2001 From: Jacques Pienaar Date: Wed, 9 May 2018 11:06:45 -0700 Subject: [PATCH] Avoid rebuilding the graph for every run. * Use placeholder to avoid building the graph for every run in testIf. * Update file comment. PiperOrigin-RevId: 195997713 --- tensorflow/python/kernel_tests/functional_ops_test.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tensorflow/python/kernel_tests/functional_ops_test.py b/tensorflow/python/kernel_tests/functional_ops_test.py index 35a274e..d3cf671 100644 --- a/tensorflow/python/kernel_tests/functional_ops_test.py +++ b/tensorflow/python/kernel_tests/functional_ops_test.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================== -"""Tests for tensorflow.kernels.bcast_ops.""" +"""Tests for tensorflow.kernels.functional_ops.""" from __future__ import absolute_import from __future__ import division @@ -670,13 +670,12 @@ class FunctionalOpsTest(test.TestCase): with self.test_session(use_gpu=False) as sess: - def Run(x): - return sess.run( - functional_ops.If(math_ops.greater(x, 0), [x], Twice, Thrice))[0] + x = array_ops.placeholder(dtypes.float32) + ret = functional_ops.If(math_ops.greater(x, 0), [x], Twice, Thrice)[0] - self.assertAllEqual(Run(9.), 18.) - self.assertAllEqual(Run(-8.), -23.) - self.assertAllEqual(Run(0.), 1.) + self.assertAllEqual(sess.run(ret, feed_dict={x: 9.}), 18.) + self.assertAllEqual(sess.run(ret, feed_dict={x: -8.}), -23.) + self.assertAllEqual(sess.run(ret, feed_dict={x: 0.}), 1.) def testWhile(self): -- 2.7.4