From 040b4cbce7084b8340e075af4797f81359c2bbf4 Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Tue, 2 Jan 2018 10:45:56 -0800 Subject: [PATCH] Remove using directives. Test appertaining to ops have been moved into namespace tensorflow::ops; all other tests now use explicit using-declarations. Some tests are now using unnamed namespaces more aggressively to make as many names internal as possible. PiperOrigin-RevId: 180564422 --- tensorflow/cc/client/client_session_test.cc | 11 ++++++-- tensorflow/cc/framework/cc_ops_test.cc | 7 +++-- .../cc/framework/gradient_checker_test.cc | 12 +++++++-- tensorflow/cc/framework/gradients_test.cc | 14 ++++++++-- tensorflow/cc/gradients/array_grad_test.cc | 4 +-- .../cc/gradients/data_flow_grad_test.cc | 7 +++-- tensorflow/cc/gradients/grad_testutil.cc | 8 +++--- tensorflow/cc/gradients/math_grad_test.cc | 26 +++++++++++++++++-- tensorflow/cc/gradients/nn_grad_test.cc | 16 ++++++++++-- tensorflow/core/graph/graph_partition_test.cc | 18 ++++++------- tensorflow/core/kernels/decode_wav_op_test.cc | 6 +++-- tensorflow/core/kernels/encode_wav_op_test.cc | 6 +++-- tensorflow/core/kernels/mfcc_op_test.cc | 6 +++-- .../core/kernels/quantized_add_op_test.cc | 12 ++++----- .../kernels/quantized_instance_norm_test.cc | 14 +++++----- .../core/kernels/quantized_mul_op_test.cc | 12 ++++----- .../core/kernels/spectrogram_op_test.cc | 6 +++-- 17 files changed, 122 insertions(+), 63 deletions(-) diff --git a/tensorflow/cc/client/client_session_test.cc b/tensorflow/cc/client/client_session_test.cc index dfbac9788e1..ea5cf5a1f12 100644 --- a/tensorflow/cc/client/client_session_test.cc +++ b/tensorflow/cc/client/client_session_test.cc @@ -23,7 +23,13 @@ limitations under the License. #include "tensorflow/core/platform/test.h" namespace tensorflow { -using namespace ops; // NOLINT(build/namespaces) +namespace { + +using ops::Add; +using ops::Const; +using ops::Mul; +using ops::Placeholder; +using ops::Sub; TEST(ClientSessionTest, Basic) { Scope root = Scope::NewRootScope(); @@ -89,4 +95,5 @@ TEST(ClientSessionTest, MultiThreaded) { test::ExpectTensorEqual(outputs[0], test::AsTensor({-1, 2}, {2})); } -} // end namespace tensorflow +} // namespace +} // namespace tensorflow diff --git a/tensorflow/cc/framework/cc_ops_test.cc b/tensorflow/cc/framework/cc_ops_test.cc index 5da23036eaa..ac05e3cf95b 100644 --- a/tensorflow/cc/framework/cc_ops_test.cc +++ b/tensorflow/cc/framework/cc_ops_test.cc @@ -22,8 +22,7 @@ limitations under the License. #include "tensorflow/core/lib/core/status_test_util.h" namespace tensorflow { -using namespace ops; // NOLINT(build/namespaces) - +namespace ops { namespace { Output Linear(const Scope& scope, Input x, Input w, Input b) { @@ -39,8 +38,6 @@ void GetColocationConstraints(const Output& tensor, constraints)); } -} // namespace - TEST(CCOpTest, Basic) { Scope root = Scope::NewRootScope(); auto c = Const(root, {{1, 1}}); @@ -249,4 +246,6 @@ TEST(CCOpTest, InvalidFinalize) { string::npos); } +} // namespace +} // namespace ops } // namespace tensorflow diff --git a/tensorflow/cc/framework/gradient_checker_test.cc b/tensorflow/cc/framework/gradient_checker_test.cc index fdc457f40af..d4f0a7f5ab3 100644 --- a/tensorflow/cc/framework/gradient_checker_test.cc +++ b/tensorflow/cc/framework/gradient_checker_test.cc @@ -24,10 +24,18 @@ limitations under the License. #include "tensorflow/core/util/equal_graph_def.h" namespace tensorflow { -using namespace ops; // NOLINT(build/namespaces) - namespace { +using ops::Complex; +using ops::Const; +using ops::MatMul; +using ops::Placeholder; +using ops::Real; +using ops::Split; +using ops::Square; +using ops::Stack; +using ops::Unstack; + TEST(GradientCheckerTest, BasicFloat) { Scope scope = Scope::NewRootScope(); TensorShape shape({2, 4, 3}); diff --git a/tensorflow/cc/framework/gradients_test.cc b/tensorflow/cc/framework/gradients_test.cc index 07a062e704e..26e3170ad8e 100644 --- a/tensorflow/cc/framework/gradients_test.cc +++ b/tensorflow/cc/framework/gradients_test.cc @@ -26,10 +26,20 @@ limitations under the License. #include "tensorflow/core/util/equal_graph_def.h" namespace tensorflow { -using namespace ops; // NOLINT(build/namespaces) - namespace { +using ops::Assign; +using ops::Const; +using ops::Identity; +using ops::MatMul; +using ops::OnesLike; +using ops::Placeholder; +using ops::Square; +using ops::Stack; +using ops::StopGradient; +using ops::Unstack; +using ops::Variable; + // TODO(andydavis) Add more unit tests once more gradient functions are ported. class GradientsTest : public ::testing::Test { protected: diff --git a/tensorflow/cc/gradients/array_grad_test.cc b/tensorflow/cc/gradients/array_grad_test.cc index 455d7330c10..4a215fcc929 100644 --- a/tensorflow/cc/gradients/array_grad_test.cc +++ b/tensorflow/cc/gradients/array_grad_test.cc @@ -23,11 +23,11 @@ limitations under the License. #include "tensorflow/core/lib/core/status_test_util.h" namespace tensorflow { +namespace { + using namespace ops; // NOLINT(build/namespaces) using ops::internal::MirrorPadGrad; -namespace { - class ArrayGradTest : public ::testing::Test { protected: ArrayGradTest() : scope_(Scope::NewRootScope()) {} diff --git a/tensorflow/cc/gradients/data_flow_grad_test.cc b/tensorflow/cc/gradients/data_flow_grad_test.cc index 734dfd3af97..0ba3c0e27b1 100644 --- a/tensorflow/cc/gradients/data_flow_grad_test.cc +++ b/tensorflow/cc/gradients/data_flow_grad_test.cc @@ -23,10 +23,13 @@ limitations under the License. #include "tensorflow/core/lib/random/random.h" namespace tensorflow { -using namespace ops; // NOLINT(build/namespaces) - namespace { +using ops::Const; +using ops::DynamicPartition; +using ops::DynamicStitch; +using ops::Placeholder; + class DataFlowGradTest : public ::testing::Test { protected: DataFlowGradTest() : scope_(Scope::NewRootScope()) {} diff --git a/tensorflow/cc/gradients/grad_testutil.cc b/tensorflow/cc/gradients/grad_testutil.cc index 04b29d4e8b2..304117d3719 100644 --- a/tensorflow/cc/gradients/grad_testutil.cc +++ b/tensorflow/cc/gradients/grad_testutil.cc @@ -18,16 +18,14 @@ limitations under the License. #include "tensorflow/cc/framework/grad_op_registry.h" namespace tensorflow { -using namespace ops; // NOLINT(build/namespaces) - namespace test { Status CallGradFunction(const Scope& scope, const Operation& op, const std::vector& grad_inputs, std::vector* grad_outputs) { - GradFunc grad_fn; - TF_RETURN_IF_ERROR( - GradOpRegistry::Global()->Lookup(op.node()->type_string(), &grad_fn)); + ops::GradFunc grad_fn; + TF_RETURN_IF_ERROR(ops::GradOpRegistry::Global()->Lookup( + op.node()->type_string(), &grad_fn)); TF_RETURN_IF_ERROR(grad_fn(scope, op, grad_inputs, grad_outputs)); TF_RETURN_IF_ERROR(scope.status()); return Status::OK(); diff --git a/tensorflow/cc/gradients/math_grad_test.cc b/tensorflow/cc/gradients/math_grad_test.cc index b94d797711c..7f076960b57 100644 --- a/tensorflow/cc/gradients/math_grad_test.cc +++ b/tensorflow/cc/gradients/math_grad_test.cc @@ -23,10 +23,31 @@ limitations under the License. #include "tensorflow/core/lib/random/random.h" namespace tensorflow { -using namespace ops; // NOLINT(build/namespaces) - namespace { +using ops::Abs; +using ops::Add; +using ops::AddN; +using ops::BatchMatMul; +using ops::Const; +using ops::Div; +using ops::Greater; +using ops::MatMul; +using ops::Max; +using ops::Maximum; +using ops::Mean; +using ops::Min; +using ops::Minimum; +using ops::Mul; +using ops::Placeholder; +using ops::Pow; +using ops::Prod; +using ops::RealDiv; +using ops::SquaredDifference; +using ops::Sub; +using ops::Sum; +using ops::Where3; + // TODO(andydavis) Test gradient function against numeric gradients output. // TODO(andydavis) As more gradients are added move common test functions // to a testutil library. @@ -83,6 +104,7 @@ class CWiseUnaryGradTest : public ::testing::Test { Output y; switch (op_type) { + using namespace ops; // NOLINT(build/namespaces) case ABS: y = Abs(scope_, x); break; diff --git a/tensorflow/cc/gradients/nn_grad_test.cc b/tensorflow/cc/gradients/nn_grad_test.cc index f9063e83650..0cfe5f6e3c4 100644 --- a/tensorflow/cc/gradients/nn_grad_test.cc +++ b/tensorflow/cc/gradients/nn_grad_test.cc @@ -23,10 +23,22 @@ limitations under the License. #include "tensorflow/core/lib/random/random.h" namespace tensorflow { -using namespace ops; // NOLINT(build/namespaces) - namespace { +using ops::BiasAdd; +using ops::Conv2D; +using ops::Elu; +using ops::L2Loss; +using ops::LogSoftmax; +using ops::LRN; +using ops::MaxPool; +using ops::MaxPoolV2; +using ops::Placeholder; +using ops::Relu; +using ops::Relu6; +using ops::Selu; +using ops::Softmax; + class NNGradTest : public ::testing::Test { protected: NNGradTest() : scope_(Scope::NewRootScope()) {} diff --git a/tensorflow/core/graph/graph_partition_test.cc b/tensorflow/core/graph/graph_partition_test.cc index 20822ecb1dd..7bbfcc9ca20 100644 --- a/tensorflow/core/graph/graph_partition_test.cc +++ b/tensorflow/core/graph/graph_partition_test.cc @@ -43,8 +43,6 @@ limitations under the License. namespace tensorflow { -using strings::StrCat; - // from graph_partition.cc extern Status TopologicalSortNodesWithTimePriority( const GraphDef* gdef, std::vector>* nodes, @@ -52,6 +50,14 @@ extern Status TopologicalSortNodesWithTimePriority( namespace { +using ops::_Recv; +using ops::_Send; +using ops::Const; +using ops::Identity; +using ops::LoopCond; +using ops::NextIteration; +using strings::StrCat; + const char gpu_device[] = "/job:a/replica:0/task:0/device:GPU:0"; string SplitByDevice(const Node* node) { return node->assigned_device_name(); } @@ -232,7 +238,6 @@ class GraphPartitionTest : public ::testing::Test { }; TEST_F(GraphPartitionTest, SingleDevice) { - using namespace ::tensorflow::ops; // NOLINT(build/namespaces) auto a1 = FloatInput(in_.WithOpName("A1")); Combine(in_.WithOpName("A2"), a1, a1); @@ -245,7 +250,6 @@ TEST_F(GraphPartitionTest, SingleDevice) { } TEST_F(GraphPartitionTest, CrossDeviceData) { - using namespace ::tensorflow::ops; // NOLINT(build/namespaces) auto a1 = FloatInput(in_.WithOpName("A1")); auto b1 = FloatInput(in_.WithOpName("B1")); Combine(in_.WithOpName("B2"), a1, b1); @@ -267,7 +271,6 @@ TEST_F(GraphPartitionTest, CrossDeviceData) { } TEST_F(GraphPartitionTest, CrossDeviceControl) { - using namespace ::tensorflow::ops; // NOLINT(build/namespaces) auto a1 = FloatInput(in_.WithOpName("A1")); auto b1 = FloatInput(in_.WithOpName("B1")); Combine(in_.WithOpName("B2").WithControlDependencies(a1), b1, b1); @@ -291,7 +294,6 @@ TEST_F(GraphPartitionTest, CrossDeviceControl) { } TEST_F(GraphPartitionTest, CrossDeviceData_MultiUse) { - using namespace ::tensorflow::ops; // NOLINT(build/namespaces) auto a1 = FloatInput(in_.WithOpName("A1")); auto b1 = FloatInput(in_.WithOpName("B1")); Combine(in_.WithOpName("B2"), a1, b1); @@ -315,7 +317,6 @@ TEST_F(GraphPartitionTest, CrossDeviceData_MultiUse) { } TEST_F(GraphPartitionTest, CrossDeviceControl_MultiUse) { - using namespace ::tensorflow::ops; // NOLINT(build/namespaces) auto a1 = FloatInput(in_.WithOpName("A1")); auto b1 = FloatInput(in_.WithOpName("B1")); Combine(in_.WithOpName("B2").WithControlDependencies(a1), b1, b1); @@ -341,7 +342,6 @@ TEST_F(GraphPartitionTest, CrossDeviceControl_MultiUse) { } TEST_F(GraphPartitionTest, CrossDevice_DataControl) { - using namespace ::tensorflow::ops; // NOLINT(build/namespaces) auto a1 = FloatInput(in_.WithOpName("A1")); auto b1 = FloatInput(in_.WithOpName("B1")); Combine(in_.WithOpName("B2"), a1, b1); @@ -372,7 +372,6 @@ TEST_F(GraphPartitionTest, CrossDevice_DataControl) { } TEST_F(GraphPartitionTest, CrossDeviceLoopSimple) { - using namespace ::tensorflow::ops; // NOLINT(build/namespaces) auto a1 = BoolInput(in_.WithOpName("A1")); auto a2 = ::tensorflow::ops::internal::Enter(in_.WithOpName("A2"), a1, "foo"); auto a3 = ::tensorflow::ops::Merge(in_.WithOpName("A3"), @@ -386,7 +385,6 @@ TEST_F(GraphPartitionTest, CrossDeviceLoopSimple) { } TEST_F(GraphPartitionTest, CrossDeviceLoopSimple1) { - using namespace ::tensorflow::ops; // NOLINT(build/namespaces) auto a1 = BoolInput(in_.WithOpName("A1")); auto a2 = ::tensorflow::ops::internal::Enter(in_.WithOpName("B2"), a1, "foo"); auto a3 = ::tensorflow::ops::Merge(in_.WithOpName("A3"), diff --git a/tensorflow/core/kernels/decode_wav_op_test.cc b/tensorflow/core/kernels/decode_wav_op_test.cc index fc323a5e042..84dc649daba 100644 --- a/tensorflow/core/kernels/decode_wav_op_test.cc +++ b/tensorflow/core/kernels/decode_wav_op_test.cc @@ -32,8 +32,8 @@ limitations under the License. #include "tensorflow/core/platform/test.h" namespace tensorflow { - -using namespace ops; // NOLINT(build/namespaces) +namespace ops { +namespace { TEST(DecodeWavOpTest, DecodeWavTest) { Scope root = Scope::NewRootScope(); @@ -121,4 +121,6 @@ TEST(DecodeWavOpTest, DecodeWav_ShapeFn) { INFER_ERROR("channels must be non-negative, got -2", op, "[]"); } +} // namespace +} // namespace ops } // namespace tensorflow diff --git a/tensorflow/core/kernels/encode_wav_op_test.cc b/tensorflow/core/kernels/encode_wav_op_test.cc index 34138ac9a04..b3c61e2c995 100644 --- a/tensorflow/core/kernels/encode_wav_op_test.cc +++ b/tensorflow/core/kernels/encode_wav_op_test.cc @@ -31,8 +31,8 @@ limitations under the License. #include "tensorflow/core/platform/test.h" namespace tensorflow { - -using namespace ops; // NOLINT(build/namespaces) +namespace ops { +namespace { TEST(EncodeWavOpTest, EncodeWavTest) { Scope root = Scope::DisabledShapeInferenceScope(); @@ -77,4 +77,6 @@ TEST(EncodeWavOpTest, EncodeWavTest) { EXPECT_EQ(44100, sample_rate); } +} // namespace +} // namespace ops } // namespace tensorflow diff --git a/tensorflow/core/kernels/mfcc_op_test.cc b/tensorflow/core/kernels/mfcc_op_test.cc index 57391128f9e..43e2a4594f0 100644 --- a/tensorflow/core/kernels/mfcc_op_test.cc +++ b/tensorflow/core/kernels/mfcc_op_test.cc @@ -31,8 +31,8 @@ limitations under the License. #include "tensorflow/core/platform/test.h" namespace tensorflow { - -using namespace ops; // NOLINT(build/namespaces) +namespace ops { +namespace { TEST(MfccOpTest, SimpleTest) { Scope root = Scope::DisabledShapeInferenceScope(); @@ -74,4 +74,6 @@ TEST(MfccOpTest, SimpleTest) { 1e-3); } +} // namespace +} // namespace ops } // namespace tensorflow diff --git a/tensorflow/core/kernels/quantized_add_op_test.cc b/tensorflow/core/kernels/quantized_add_op_test.cc index 90bd145ad0c..376fe34c4b5 100644 --- a/tensorflow/core/kernels/quantized_add_op_test.cc +++ b/tensorflow/core/kernels/quantized_add_op_test.cc @@ -32,9 +32,7 @@ limitations under the License. #include "tensorflow/core/platform/test.h" namespace tensorflow { - -using namespace ops; // NOLINT(build/namespaces) - +namespace ops { namespace { void TestAdd(const std::vector& x_shape, @@ -184,8 +182,6 @@ void TimeAdd(const std::vector& x_shape, << ", total_duration=" << total_duration; } -} // namespace - void TestManualScalar() { TestAdd( {10}, {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f}, 0.0f, @@ -276,10 +272,12 @@ void BenchmarkVectorPlusTensor() { TimeAdd({100000, 100}, {100}, 1); } -} // end namespace tensorflow +} // namespace +} // namespace ops +} // namespace tensorflow #define RUN_TEST(t) \ - TEST(QuantizedAddOpTest, t) { tensorflow::t(); } + TEST(QuantizedAddOpTest, t) { tensorflow::ops::t(); } RUN_TEST(TestManualScalar); RUN_TEST(TestManualVector); diff --git a/tensorflow/core/kernels/quantized_instance_norm_test.cc b/tensorflow/core/kernels/quantized_instance_norm_test.cc index d2b15ee20bb..896fe046e7e 100644 --- a/tensorflow/core/kernels/quantized_instance_norm_test.cc +++ b/tensorflow/core/kernels/quantized_instance_norm_test.cc @@ -22,6 +22,8 @@ limitations under the License. #include "tensorflow/core/framework/tensor_testutil.h" namespace tensorflow { +namespace ops { +namespace { void ReferenceImpl(const quint8* inp, float inp_min, float inp_max, const TensorShape& shape, float var_eps, float* out) { @@ -78,10 +80,6 @@ void ReferenceImpl(const quint8* inp, float inp_min, float inp_max, } } -using namespace ops; // NOLINT(build/namespaces) - -namespace { - void Expect(const Tensor& input, float x_min, float x_max, bool output_range_given, float give_y_min, float given_y_max) { Scope root = Scope::NewRootScope(); @@ -123,8 +121,6 @@ void Expect(const Tensor& input, float x_min, float x_max, LOG(INFO) << "max diff " << max_diff(); } -} // end namespace - void TestBasic() { Tensor input_tensor(DT_QUINT8, {1, 4, 4, 32}); auto input = input_tensor.flat(); @@ -173,10 +169,12 @@ void TestClamp() { Expect(input_tensor, -10.0f, 10.0f, true, 0.0f, 1.0f); } -} // end namespace tensorflow +} // namespace +} // namespace ops +} // namespace tensorflow #define RUN_TEST(t) \ - TEST(QuantizedAddOpTest, t) { tensorflow::t(); } + TEST(QuantizedInstanceNormTest, t) { tensorflow::ops::t(); } RUN_TEST(TestBasic); RUN_TEST(TestZeroInput); diff --git a/tensorflow/core/kernels/quantized_mul_op_test.cc b/tensorflow/core/kernels/quantized_mul_op_test.cc index 5f858eb8ce0..b0550c8260c 100644 --- a/tensorflow/core/kernels/quantized_mul_op_test.cc +++ b/tensorflow/core/kernels/quantized_mul_op_test.cc @@ -32,9 +32,7 @@ limitations under the License. #include "tensorflow/core/platform/test.h" namespace tensorflow { - -using namespace ops; // NOLINT(build/namespaces) - +namespace ops { namespace { void TestMul(const std::vector& x_shape, @@ -184,8 +182,6 @@ void TimeMul(const std::vector& x_shape, << ", total_duration=" << total_duration; } -} // namespace - void TestManualScalar() { TestMul( {10}, {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f}, 0.0f, @@ -276,10 +272,12 @@ void BenchmarkVectorTimesTensor() { TimeMul({100000, 100}, {100}, 100); } -} // end namespace tensorflow +} // namespace +} // namespace ops +} // namespace tensorflow #define RUN_TEST(t) \ - TEST(QuantizedAddOpTest, t) { tensorflow::t(); } + TEST(QuantizedAddOpTest, t) { tensorflow::ops::t(); } RUN_TEST(TestManualScalar); RUN_TEST(TestManualVector); diff --git a/tensorflow/core/kernels/spectrogram_op_test.cc b/tensorflow/core/kernels/spectrogram_op_test.cc index 5c3cbeeeb93..d34a7c99ecb 100644 --- a/tensorflow/core/kernels/spectrogram_op_test.cc +++ b/tensorflow/core/kernels/spectrogram_op_test.cc @@ -31,8 +31,8 @@ limitations under the License. #include "tensorflow/core/platform/test.h" namespace tensorflow { - -using namespace ops; // NOLINT(build/namespaces) +namespace ops { +namespace { TEST(SpectrogramOpTest, SimpleTest) { Scope root = Scope::NewRootScope(); @@ -101,4 +101,6 @@ TEST(SpectrogramOpTest, SquaredTest) { test::AsTensor({0, 1, 4, 1, 0}, TensorShape({1, 1, 5})), 1e-3); } +} // namespace +} // namespace ops } // namespace tensorflow