From 91b0a9ab23e5adf3f71429773780cd3487e7858e Mon Sep 17 00:00:00 2001 From: wangchaochaohu Date: Mon, 16 Mar 2020 21:17:56 +0800 Subject: [PATCH] remnove the unsed unittest test=develop (#22999) * remove the fill_constant_batch_size_like, gaussian_random_batch_size_like and uniform_random_batch_size_like_cn three Op unittest --- .../fluid/tests/unittests/CMakeLists.txt | 5 +- .../test_fill_constant_batch_size_like_op.py | 108 ------------------ ...test_gaussian_random_batch_size_like_op.py | 48 -------- .../test_uniform_random_batch_size_like_op.py | 44 ------- 4 files changed, 1 insertion(+), 204 deletions(-) delete mode 100644 python/paddle/fluid/tests/unittests/test_fill_constant_batch_size_like_op.py delete mode 100644 python/paddle/fluid/tests/unittests/test_gaussian_random_batch_size_like_op.py delete mode 100644 python/paddle/fluid/tests/unittests/test_uniform_random_batch_size_like_op.py diff --git a/python/paddle/fluid/tests/unittests/CMakeLists.txt b/python/paddle/fluid/tests/unittests/CMakeLists.txt index e0068e7b8d6..f3ed3b49959 100644 --- a/python/paddle/fluid/tests/unittests/CMakeLists.txt +++ b/python/paddle/fluid/tests/unittests/CMakeLists.txt @@ -216,11 +216,9 @@ set(TEST_OPS_WITH_GC test_concat_op test_elementwise_add_op test_elementwise_sub_op - test_fill_constant_batch_size_like_op test_fill_zeros_like2_op test_gather_op test_gather_nd_op - test_gaussian_random_batch_size_like_op test_linear_chain_crf_op test_lod_reset_op test_lookup_table_op @@ -238,8 +236,7 @@ set(TEST_OPS_WITH_GC test_sequence_slice_op test_slice_op test_space_to_depth_op - test_squared_l2_distance_op - test_uniform_random_batch_size_like_op) + test_squared_l2_distance_op) foreach(TEST_OP ${TEST_OPS_WITH_GC}) list(REMOVE_ITEM TEST_OPS ${TEST_OP}) diff --git a/python/paddle/fluid/tests/unittests/test_fill_constant_batch_size_like_op.py b/python/paddle/fluid/tests/unittests/test_fill_constant_batch_size_like_op.py deleted file mode 100644 index 4a19298fecc..00000000000 --- a/python/paddle/fluid/tests/unittests/test_fill_constant_batch_size_like_op.py +++ /dev/null @@ -1,108 +0,0 @@ -# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from __future__ import print_function - -import unittest -import numpy as np -import paddle.fluid as fluid -from op_test import OpTest - - -class TestFillConstantBatchSizeLikeWhenFirstDimIsBatchSize(OpTest): - def setUp(self): - self.op_type = "fill_constant_batch_size_like" - self.inputs = {'Input': np.random.random((219, 232)).astype("float32")} - self.attrs = {'value': 3.5, 'shape': [-1, 132, 7]} - - out = np.random.random((219, 132, 7)).astype("float32") - out.fill(3.5) - self.outputs = {'Out': out} - - def test_check_output(self): - self.check_output() - - -class TestFillConstantBatchSizeLikeWhenSecondDimIsBatchSize(OpTest): - def setUp(self): - self.op_type = "fill_constant_batch_size_like" - self.inputs = {'Input': np.random.random((219, 232)).astype("float32")} - self.attrs = { - 'value': 3.5, - 'shape': [132, -1, 7], - 'input_dim_idx': 0, - 'output_dim_idx': 1 - } - - out = np.random.random((132, 219, 7)).astype("float32") - out.fill(3.5) - self.outputs = {'Out': out} - - def test_check_output(self): - self.check_output() - - -class TestFillConstantBatchSizeLikeInt64(OpTest): - def setUp(self): - self.op_type = "fill_constant_batch_size_like" - self.inputs = {'Input': np.random.random((219, 232)).astype("int64")} - self.attrs = {'value': 5894589485094, 'shape': [-1, 132, 7]} - - out = np.random.random((219, 132, 7)).astype("int64") - out.fill(5894589485094) - self.outputs = {'Out': out} - - def test_check_output(self): - self.check_output() - - -class TestFillConstantBatchSizeLikeWithLoDTensor(OpTest): - def setUp(self): - self.op_type = "fill_constant_batch_size_like" - self.inputs = { - 'Input': (np.random.random((31, 28)).astype("float32"), - [[9, 14, 8]]) - } - self.attrs = { - 'value': 3.5, - 'shape': [-1, 16], - 'input_dim_idx': 0, - 'output_dim_idx': 0 - } - - out = np.random.random((3, 16)).astype("float32") - out.fill(3.5) - self.outputs = {'Out': out} - - def test_check_output(self): - self.check_output() - - -# Test python API -class TestFillConstantBatchSizeLikeAPI(unittest.TestCase): - def test_api(self): - like = fluid.layers.fill_constant( - shape=[1, 200], value=10, dtype='int64') - out = fluid.layers.fill_constant_batch_size_like( - input=like, shape=[2, 300], value=1315454564656, dtype='int64') - exe = fluid.Executor(place=fluid.CPUPlace()) - res, = exe.run(fluid.default_main_program(), fetch_list=[out]) - - assert np.array_equal( - res[0], np.full( - [300], 1315454564656, dtype="int64")) - - -if __name__ == "__main__": - unittest.main() diff --git a/python/paddle/fluid/tests/unittests/test_gaussian_random_batch_size_like_op.py b/python/paddle/fluid/tests/unittests/test_gaussian_random_batch_size_like_op.py deleted file mode 100644 index 9a0631fa26a..00000000000 --- a/python/paddle/fluid/tests/unittests/test_gaussian_random_batch_size_like_op.py +++ /dev/null @@ -1,48 +0,0 @@ -# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserve. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from __future__ import print_function - -import unittest -import numpy as np -from op_test import OpTest - - -class TestGaussianRandomBatchSizeLike(OpTest): - def setUp(self): - self.op_type = "gaussian_random_batch_size_like" - self.inputs = {'Input': np.zeros((500, 2000), dtype="float32")} - self.attrs = {'mean': 1., 'std': 2., 'shape': [-1, 2000]} - self.outputs = {'Out': np.zeros((500, 2000), dtype='float32')} - - def test_check_output(self): - self.check_output_customized(self.verify_output) - - def verify_output(self, outs): - self.assertEqual(outs[0].shape, (500, 2000)) - hist, _ = np.histogram(outs[0], range=(-3, 5)) - hist = hist.astype("float32") - hist /= float(outs[0].size) - data = np.random.normal(size=(500, 2000), loc=1, scale=2) - hist2, _ = np.histogram(data, range=(-3, 5)) - hist2 = hist2.astype("float32") - hist2 /= float(outs[0].size) - self.assertTrue( - np.allclose( - hist, hist2, rtol=0, atol=0.01), - "hist: " + str(hist) + " hist2: " + str(hist2)) - - -if __name__ == "__main__": - unittest.main() diff --git a/python/paddle/fluid/tests/unittests/test_uniform_random_batch_size_like_op.py b/python/paddle/fluid/tests/unittests/test_uniform_random_batch_size_like_op.py deleted file mode 100644 index 7b8be24d9da..00000000000 --- a/python/paddle/fluid/tests/unittests/test_uniform_random_batch_size_like_op.py +++ /dev/null @@ -1,44 +0,0 @@ -# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserve. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from __future__ import print_function - -import unittest -import numpy as np -from op_test import OpTest - - -class TestUniformRandomBatchSizeLike(OpTest): - def setUp(self): - self.op_type = "uniform_random_batch_size_like" - self.inputs = {'Input': np.zeros((500, 2000), dtype="float32")} - self.attrs = {'min': 1., 'max': 2., 'shape': [-1, 2000]} - self.outputs = {'Out': np.zeros((500, 2000), dtype='float32')} - - def test_check_output(self): - self.check_output_customized(self.verify_output) - - def verify_output(self, outs): - self.assertEqual(outs[0].shape, (500, 2000)) - hist, _ = np.histogram(outs[0], range=(1, 2)) - hist = hist.astype("float32") - hist /= float(outs[0].size) - prob = 0.1 * np.ones((10)) - self.assertTrue( - np.allclose( - hist, prob, rtol=0, atol=0.01), "hist: " + str(hist)) - - -if __name__ == "__main__": - unittest.main() -- GitLab