From cdb81264994501b799bc3874be292be95f6deb78 Mon Sep 17 00:00:00 2001 From: Tao Luo Date: Thu, 14 Nov 2019 18:38:00 +0800 Subject: [PATCH] fix error message in expand API, and fix two error unit-tests (#21180) test=release/1.6 --- python/paddle/fluid/layers/nn.py | 4 ++-- python/paddle/fluid/tests/unittests/test_accuracy_op.py | 8 ++++---- python/paddle/fluid/tests/unittests/test_zeros_op.py | 7 +++---- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index 26486ef08f..5113e47528 100755 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -12985,8 +12985,8 @@ def expand(x, expand_times, name=None): """ if not isinstance(x, Variable): raise TypeError( - "The type of 'input' in reduce_sum must be Variable, but received %s" - % (type(x))) + "The type of 'input' in expand must be Variable, but received %s" % + (type(x))) if not isinstance(expand_times, (list, tuple, Variable)): raise ValueError( "Input expand_times must be an Variable, python list or tuple.") diff --git a/python/paddle/fluid/tests/unittests/test_accuracy_op.py b/python/paddle/fluid/tests/unittests/test_accuracy_op.py index 33ccecb77b..e7152a29e5 100755 --- a/python/paddle/fluid/tests/unittests/test_accuracy_op.py +++ b/python/paddle/fluid/tests/unittests/test_accuracy_op.py @@ -64,13 +64,13 @@ class TestAccuracyOpError(OpTest): # The input type of accuracy_op must be Variable. x1 = fluid.create_lod_tensor( np.array([[-1]]), [[1]], fluid.CPUPlace()) - self.assertRaises(TypeError, fluid.layers.accuracy, x1) + label = fluid.layers.data( + name='label', shape=[-1, 1], dtype="int32") + self.assertRaises(TypeError, fluid.layers.accuracy, x1, label) # The input dtype of accuracy_op must be float32 or float64. x2 = fluid.layers.data(name='x2', shape=[4], dtype="int32") - self.assertRaises(TypeError, fluid.layers.accuracy, x2) + self.assertRaises(TypeError, fluid.layers.accuracy, x2, label) x3 = fluid.layers.data(name='input', shape=[-1, 2], dtype="float16") - label = fluid.layers.data( - name='label', shape=[-1, 1], dtype="int32") fluid.layers.accuracy(input=x3, label=label) diff --git a/python/paddle/fluid/tests/unittests/test_zeros_op.py b/python/paddle/fluid/tests/unittests/test_zeros_op.py index 62ed6b56c6..1be2f4d047 100644 --- a/python/paddle/fluid/tests/unittests/test_zeros_op.py +++ b/python/paddle/fluid/tests/unittests/test_zeros_op.py @@ -28,10 +28,9 @@ class TestZerosOpError(OpTest): def test_errors(self): with program_guard(Program(), Program()): # The input dtype of zeros_op must be bool, float16, float32, float64, int32, int64. - x1 = fluid.layers.data(name='x1', shape=[4], dtype="int8") - self.assertRaises(TypeError, fluid.layers.zeros, x1) - x2 = fluid.layers.data(name='x2', shape=[4], dtype="uint8") - self.assertRaises(TypeError, fluid.layers.zeros, x2) + shape = [4] + dtype = "int8" + self.assertRaises(TypeError, fluid.layers.zeros, shape, dtype) if __name__ == "__main__": -- GitLab