From 8e2d38bbfd578afe311015917cb54d21fe2bca5e Mon Sep 17 00:00:00 2001 From: Gunhan Gulsoy Date: Fri, 10 Jan 2020 14:39:19 -0800 Subject: [PATCH] Explicitly capture variables in lambdas. MSVC does not like implicit capture. PiperOrigin-RevId: 289168006 Change-Id: Ic5aa1b75677c4cf10af3177c578e2898e97a98d0 --- .../distributed_runtime/eager/eager_service_impl_test.cc | 2 +- tensorflow/core/kernels/crop_and_resize_op_test.cc | 6 +++--- .../core/kernels/data/unbounded_thread_pool_test.cc | 3 ++- tensorflow/core/kernels/mirror_pad_op_test.cc | 8 ++++---- tensorflow/core/lib/jpeg/jpeg_mem_unittest.cc | 2 +- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/tensorflow/core/distributed_runtime/eager/eager_service_impl_test.cc b/tensorflow/core/distributed_runtime/eager/eager_service_impl_test.cc index a2c15daf0b3..1fd063f617b 100644 --- a/tensorflow/core/distributed_runtime/eager/eager_service_impl_test.cc +++ b/tensorflow/core/distributed_runtime/eager/eager_service_impl_test.cc @@ -611,7 +611,7 @@ TEST_F(FunctionWithRemoteInputsTest, KernelAndDeviceFuncTest) { flr, eager_pflr_.get(), std::move(input_dev_ptrs), {}, /*runner=*/nullptr, /*collective_executor=*/nullptr, local_device, fdef_.signature().name(), [ctx](const int64 step_id) { return ctx->CreateRendezvous(step_id); }, - []() { return op_id; })); + [=]() { return op_id; })); // Instantiate MatMulFunction on remote_device. const NodeDef node_def = MatMulFunctionNodeDef(); diff --git a/tensorflow/core/kernels/crop_and_resize_op_test.cc b/tensorflow/core/kernels/crop_and_resize_op_test.cc index 31bf886854a..6e852e4f63d 100644 --- a/tensorflow/core/kernels/crop_and_resize_op_test.cc +++ b/tensorflow/core/kernels/crop_and_resize_op_test.cc @@ -422,7 +422,7 @@ TEST_F(CropAndResizeOpTest, TestWithSharding) { // ... (altogether 999 lines) // 0, 1, 2, ..., 998 AddInput(TensorShape({1, kLength, kLength, 1}), - [](int i) -> float { return i % kLength; }); + [=](int i) -> float { return i % kLength; }); AddInputFromArray(TensorShape({2, 4}), {0, 0, 0.5, 0.5, 0.5, 0.5, 1, 1}); AddInputFromArray(TensorShape({2}), {0, 0}); @@ -436,7 +436,7 @@ TEST_F(CropAndResizeOpTest, TestWithSharding) { // ... (altogether 500 lines) // 0, 1, 2, ..., 499 Tensor result1(allocator(), DT_FLOAT, TensorShape({1, kHalf, kHalf, 1})); - test::FillFn(&result1, [](int i) -> float { return i % kHalf; }); + test::FillFn(&result1, [=](int i) -> float { return i % kHalf; }); // Result 2: // 499, 500, 501, ..., 998 @@ -444,7 +444,7 @@ TEST_F(CropAndResizeOpTest, TestWithSharding) { // 499, 500, 501, ..., 998 Tensor result2(allocator(), DT_FLOAT, TensorShape({1, kHalf, kHalf, 1})); test::FillFn(&result2, - [](int i) -> float { return i % kHalf + kHalf - 1; }); + [=](int i) -> float { return i % kHalf + kHalf - 1; }); // Expected result is the concat of the two tensors. Tensor expected(allocator(), DT_FLOAT, TensorShape({2, kHalf, kHalf, 1})); diff --git a/tensorflow/core/kernels/data/unbounded_thread_pool_test.cc b/tensorflow/core/kernels/data/unbounded_thread_pool_test.cc index 3604be86473..7f3d91f3b61 100644 --- a/tensorflow/core/kernels/data/unbounded_thread_pool_test.cc +++ b/tensorflow/core/kernels/data/unbounded_thread_pool_test.cc @@ -33,7 +33,8 @@ TEST(UnboundedThreadPool, ConcurrentThreadCreation) { const int kNumThreadsToCreate = 10; std::atomic i(0); for (int j = 0; j < kNumThreadsToCreate; ++j) { - threads.push_back(thread_factory->StartThread("", [&i, thread_factory]() { + threads.push_back(thread_factory->StartThread("", [=, &i, + &thread_factory]() { std::vector> nested_threads; for (int k = 0; k < kNumThreadsToCreate; ++k) { nested_threads.push_back( diff --git a/tensorflow/core/kernels/mirror_pad_op_test.cc b/tensorflow/core/kernels/mirror_pad_op_test.cc index 6cb6e72deb6..55e89e1458b 100644 --- a/tensorflow/core/kernels/mirror_pad_op_test.cc +++ b/tensorflow/core/kernels/mirror_pad_op_test.cc @@ -98,13 +98,13 @@ TEST_F(MirrorPadOpTest, TestMirrorPadReflectLargeInput) { // ... (altogether 1000 lines) // 0, 1, 2, ..., 999 AddInput(TensorShape({1, kInput, kInput, 1}), - [](int i) -> float { return i % kInput; }); + [=](int i) -> float { return i % kInput; }); AddInputFromArray(TensorShape({4, 2}), {0, 0, kPad, kPad, kPad, kPad, 0, 0}); TF_ASSERT_OK(RunOpKernel()); Tensor expected(allocator(), DT_FLOAT, TensorShape({1, kOutput, kOutput, 1})); - test::FillFn(&expected, [](int i) -> float { + test::FillFn(&expected, [=](int i) -> float { i = i % kOutput; if (0 <= i && i < kPad) return kPad - i; @@ -132,13 +132,13 @@ TEST_F(MirrorPadOpTest, TestMirrorPadSymmetricLargeInput) { // ... (altogether 1000 lines) // 0, 1, 2, ..., 999 AddInput(TensorShape({1, kInput, kInput, 1}), - [](int i) -> float { return i % kInput; }); + [=](int i) -> float { return i % kInput; }); AddInputFromArray(TensorShape({4, 2}), {0, 0, kPad, kPad, kPad, kPad, 0, 0}); TF_ASSERT_OK(RunOpKernel()); Tensor expected(allocator(), DT_FLOAT, TensorShape({1, kOutput, kOutput, 1})); - test::FillFn(&expected, [](int i) -> float { + test::FillFn(&expected, [=](int i) -> float { i = i % kOutput; if (0 <= i && i < kPad) return kPad - i - 1; diff --git a/tensorflow/core/lib/jpeg/jpeg_mem_unittest.cc b/tensorflow/core/lib/jpeg/jpeg_mem_unittest.cc index bec84dbf0ae..ac8f657d20d 100644 --- a/tensorflow/core/lib/jpeg/jpeg_mem_unittest.cc +++ b/tensorflow/core/lib/jpeg/jpeg_mem_unittest.cc @@ -365,7 +365,7 @@ TEST(JpegMemTest, Jpeg2) { const std::unique_ptr imgdata2(new uint8[flags.stride * in_h]); CHECK(imgdata2.get() == Uncompress(cpdata2.c_str(), cpdata2.length(), flags, nullptr /* nwarn */, - [&imgdata2](int w, int h, int c) { + [=, &imgdata2](int w, int h, int c) { CHECK_EQ(w, in_w); CHECK_EQ(h, in_h); CHECK_EQ(c, 3);