From 807bff4ab146e7d391f548b580c3904623713924 Mon Sep 17 00:00:00 2001 From: helen88 Date: Fri, 11 Mar 2022 15:45:05 +0800 Subject: [PATCH] update square & sigmoid unittest (#40404) --- .../unittests/xpu/test_activation_op_xpu.py | 52 ++++++++++++++++--- 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/xpu/test_activation_op_xpu.py b/python/paddle/fluid/tests/unittests/xpu/test_activation_op_xpu.py index 6a7e5f08b5..d50c0fecde 100644 --- a/python/paddle/fluid/tests/unittests/xpu/test_activation_op_xpu.py +++ b/python/paddle/fluid/tests/unittests/xpu/test_activation_op_xpu.py @@ -84,13 +84,33 @@ class XPUTestSigmoidOP(XPUOpTestWrapper): def set_case(self): self.op_type = "sigmoid" self.dtype = self.in_type + self.init_config() + out = 1 / (1 + np.exp(-self.x)) - x = np.random.uniform(-1, 1, [11, 17]).astype(self.dtype) - out = 1 / (1 + np.exp(-x)) self.attrs = {'use_xpu': True} - self.inputs = {'X': OpTest.np_dtype_to_fluid_dtype(x)} + self.inputs = {'X': OpTest.np_dtype_to_fluid_dtype(self.x)} self.outputs = {'Out': out} + def init_config(self): + self.x = np.random.uniform(-1, 1, [11, 17]).astype(self.dtype) + + class XPUTestSigmoid2(XPUTestSigmoid): + def init_config(self): + self.x = np.random.uniform(-2, 2, [100]).astype(self.dtype) + + class XPUTestSigmoid3(XPUTestSigmoid): + def init_config(self): + self.x = np.random.uniform(-2, 2, [10, 12, 15]).astype(self.dtype) + + class XPUTestSigmoid4(XPUTestSigmoid): + def init_config(self): + self.x = np.random.uniform(-2, 2, [19, 19]).astype(self.dtype) + + class XPUTestSigmoid5(XPUTestSigmoid): + def init_config(self): + self.x = np.random.uniform(-2, 2, + [10, 20, 30, 40]).astype(self.dtype) + support_types = get_xpu_op_support_types('sigmoid') for stype in support_types: @@ -292,14 +312,32 @@ class XPUTestSquareOP(XPUOpTestWrapper): def set_case(self): self.op_type = "square" self.dtype = self.in_type - - x = np.random.uniform(-1, 1, [11, 17]).astype(self.dtype) - out = np.square(x) + self.init_config() + out = np.square(self.x) self.attrs = {'use_xpu': True} - self.inputs = {'X': OpTest.np_dtype_to_fluid_dtype(x)} + self.inputs = {'X': OpTest.np_dtype_to_fluid_dtype(self.x)} self.outputs = {'Out': out} + def init_config(self): + self.x = np.random.uniform(-1, 1, [11, 17]).astype(self.dtype) + + class XPUTestSquare2(XPUTestSquare): + def init_config(self): + self.x = np.random.uniform(-2, 2, [100]).astype(self.dtype) + + class XPUTestSquare3(XPUTestSquare): + def init_config(self): + self.x = np.random.uniform(-2, 2, [1, 15, 19]).astype(self.dtype) + + class XPUTestSquare4(XPUTestSquare): + def init_config(self): + self.x = np.random.uniform(-2, 2, [100, 10]).astype(self.dtype) + + class XPUTestSquare5(XPUTestSquare): + def init_config(self): + self.x = np.random.uniform(-2, 2, [1, 2, 5, 17]).astype(self.dtype) + support_types = get_xpu_op_support_types('square') for stype in support_types: -- GitLab