diff --git a/python/paddle/tensor/__init__.py b/python/paddle/tensor/__init__.py index 4271ee22d4c9823acbb92ac0eeeb209ea5982741..b0f75696edd6f4c3509a0586225c52b6baf598e1 100644 --- a/python/paddle/tensor/__init__.py +++ b/python/paddle/tensor/__init__.py @@ -348,6 +348,7 @@ tensor_method_func = [ # noqa 'logit', 'exp', 'exp_', + 'expm1', 'floor', 'floor_', 'increment', diff --git a/test/xpu/test_accuracy_op_xpu.py b/test/xpu/test_accuracy_op_xpu.py index a87f6c084351ce805ad86a4ef558bbaf132d4679..714a11a67bf0be9a5b3272b7505d7ca60057e918 100755 --- a/test/xpu/test_accuracy_op_xpu.py +++ b/test/xpu/test_accuracy_op_xpu.py @@ -48,11 +48,9 @@ class XPUTestAccuracyOp(XPUOpTestWrapper): num_correct += 1 break self.outputs = { - 'Accuracy': np.array([num_correct / float(n)]).astype( - self.dtype - ), - 'Correct': np.array([num_correct]).astype("int32"), - 'Total': np.array([n]).astype("int32"), + 'Accuracy': np.array(num_correct / float(n)).astype(self.dtype), + 'Correct': np.array(num_correct).astype("int32"), + 'Total': np.array(n).astype("int32"), } self.attrs = {'use_xpu': True} diff --git a/test/xpu/test_expand_as_v2_op_xpu.py b/test/xpu/test_expand_as_v2_op_xpu.py index 586761c9aeac42567a05bbaea053c8b1ae9b0b10..1843748e8ae0cc01d94c0b8ff0829da2e8479c8d 100644 --- a/test/xpu/test_expand_as_v2_op_xpu.py +++ b/test/xpu/test_expand_as_v2_op_xpu.py @@ -93,7 +93,7 @@ class XPUTestExpandAsV2Op(XPUOpTestWrapper): def set_inputs(self): x = np.random.rand(1, 1, 7, 16).astype(self.dtype) self.inputs = {'X': x} - target_tensor = np.random.rand(1, 1, 7, 16).astype(self.dtype) + target_tensor = np.random.rand(4, 6, 7, 16).astype(self.dtype) self.attrs = {'target_shape': target_tensor.shape} def set_output(self): @@ -105,7 +105,7 @@ class XPUTestExpandAsV2Op(XPUOpTestWrapper): def set_inputs(self): x = np.random.rand(1, 1, 7, 16, 1).astype(self.dtype) self.inputs = {'X': x} - target_tensor = np.random.rand(1, 1, 7, 16, 1).astype(self.dtype) + target_tensor = np.random.rand(4, 6, 7, 16, 1).astype(self.dtype) self.attrs = {'target_shape': target_tensor.shape} def set_output(self): @@ -117,7 +117,7 @@ class XPUTestExpandAsV2Op(XPUOpTestWrapper): def set_inputs(self): x = np.random.rand(1, 1, 7, 16, 1, 1).astype(self.dtype) self.inputs = {'X': x} - target_tensor = np.random.rand(1, 1, 7, 16, 1, 1).astype(self.dtype) + target_tensor = np.random.rand(4, 6, 7, 16, 1, 1).astype(self.dtype) self.attrs = {'target_shape': target_tensor.shape} def set_output(self): @@ -129,8 +129,8 @@ class XPUTestExpandAsV2Op(XPUOpTestWrapper): # Test python API class TestExpandAsV2API(unittest.TestCase): def test_api(self): - input1 = np.random.random([12, 14]).astype("float32") - input2 = np.random.random([2, 12, 14]).astype("float32") + x_np = np.random.random([12, 14]).astype("float32") + y_np = np.random.random([2, 12, 14]).astype("float32") x = paddle.static.data(name='x', shape=[12, 14], dtype="float32") y = paddle.static.data( @@ -144,10 +144,10 @@ class TestExpandAsV2API(unittest.TestCase): exe = fluid.Executor(place=fluid.XPUPlace(0)) res_1 = exe.run( fluid.default_main_program(), - feed={"x": input1, "target_tensor": input2}, + feed={"x": x_np, "target_tensor": y_np}, fetch_list=[out_1], ) - assert np.array_equal(res_1[0], np.tile(input1, (2, 1, 1))) + assert np.array_equal(res_1[0], np.tile(x_np, (2, 1, 1))) support_types = get_xpu_op_support_types('expand_as_v2') diff --git a/test/xpu/test_gather_nd_op_xpu.py b/test/xpu/test_gather_nd_op_xpu.py index e642afffb44cffcfcea1b321e5135ebda8f96f5d..fb1c9c476dd190846257e2f37ce0f9dd33c73523 100644 --- a/test/xpu/test_gather_nd_op_xpu.py +++ b/test/xpu/test_gather_nd_op_xpu.py @@ -81,13 +81,13 @@ class XPUTestGatherNd(XPUOpTestWrapper): def init_data(self): self.xnp = np.random.random((5, 20)).astype(self.in_type) self.inp = np.array([1]).astype("int32") - self.output = self.xnp[self.inp] + self.output = self.xnp[tuple(self.inp)] class XPUTestGatherNdOpWithIndex2(XPUTestGatherNdBase): def init_data(self): self.xnp = np.random.random((5, 20)).astype(self.in_type) self.inp = np.array([1]).astype("int64") - self.output = self.xnp[self.inp] + self.output = self.xnp[tuple(self.inp)] class XPUTestGatherNdOpWithLowIndex1(XPUTestGatherNdBase): def init_data(self): diff --git a/test/xpu/test_nll_loss_op_xpu.py b/test/xpu/test_nll_loss_op_xpu.py index 71ce382933449c8af9624c04c1658be0ff8e2dcd..8d343d1f7e8b8e009e42dea3bbd3bcb1eb8ab2dd 100644 --- a/test/xpu/test_nll_loss_op_xpu.py +++ b/test/xpu/test_nll_loss_op_xpu.py @@ -45,16 +45,16 @@ def nll_loss_1d( out[i] = -logs[i][cur_target] * cur_weight if reduction == 'sum': out = np.sum(out) - total_weight = np.array([total_weight]).astype(dtype) + total_weight = np.array(total_weight).astype(dtype) return {'Out': out, 'Total_weight': total_weight} elif reduction == 'mean': out = np.sum(out) if total_weight != 0: out /= total_weight - total_weight = np.array([total_weight]).astype(dtype) + total_weight = np.array(total_weight).astype(dtype) return {'Out': out, 'Total_weight': total_weight} elif reduction == 'none': - total_weight = np.array([0]).astype(dtype) + total_weight = np.array(0).astype(dtype) return {'Out': out, 'Total_weight': total_weight} @@ -79,16 +79,16 @@ def nll_loss_2d( out[i][h][w] = -logs[i][cur_target][h][w] * cur_weight if reduction == 'sum': out = np.sum(out) - total_weight = np.array([total_weight]).astype(dtype) + total_weight = np.array(total_weight).astype(dtype) return {'Out': out, 'Total_weight': total_weight} elif reduction == 'mean': out = np.sum(out) if total_weight != 0: out /= total_weight - total_weight = np.array([total_weight]).astype(dtype) + total_weight = np.array(total_weight).astype(dtype) return {'Out': out, 'Total_weight': total_weight} elif reduction == 'none': - total_weight = np.array([0]).astype(dtype) + total_weight = np.array(0).astype(dtype) return {'Out': out, 'Total_weight': total_weight} diff --git a/test/xpu/test_reduce_any_op_xpu.py b/test/xpu/test_reduce_any_op_xpu.py index 5b4e0740cfacc4e90c96241da684a2db6614bc1d..d4bdc87dc925f86fc7b6a889913c712efec9ce4a 100644 --- a/test/xpu/test_reduce_any_op_xpu.py +++ b/test/xpu/test_reduce_any_op_xpu.py @@ -40,8 +40,8 @@ class XPUTestReduceAnyOp(XPUOpTestWrapper): self.op_type = 'reduce_any' self.attrs = { 'use_xpu': True, - 'reduce_all': True, - 'keep_dim': True, + 'reduce_all': False, + 'keep_dim': False, 'dim': (3, 5, 4), } self.inputs = { @@ -76,7 +76,7 @@ class XPUTestReduceAnyOp(XPUOpTestWrapper): self.op_type = 'reduce_any' self.attrs = { 'use_xpu': True, - 'reduce_all': True, + 'reduce_all': False, 'keep_dim': False, 'dim': (3, 6), } diff --git a/test/xpu/test_size_op_xpu.py b/test/xpu/test_size_op_xpu.py index d7a0a5a1e54427d7afe7036dbeb62cf56428ef6f..b34a089938ca2d669c31a740ee0db27a8d9546f3 100644 --- a/test/xpu/test_size_op_xpu.py +++ b/test/xpu/test_size_op_xpu.py @@ -43,7 +43,7 @@ class XPUTestSizeOP(XPUOpTestWrapper): self.inputs = { 'Input': x, } - self.outputs = {'Out': np.array([np.size(x)])} + self.outputs = {'Out': np.array(np.size(x))} def initTestCase(self): self.shape = (6, 56, 8, 55) diff --git a/test/xpu/test_unbind_op_xpu.py b/test/xpu/test_unbind_op_xpu.py index 87c1d7d25c6538e077c5b4095c1e7eac71ceddc6..fa77e80fb68061d8ee851f3d007d1f8c25b87f13 100644 --- a/test/xpu/test_unbind_op_xpu.py +++ b/test/xpu/test_unbind_op_xpu.py @@ -97,7 +97,9 @@ class XPUTestUnbindOP(XPUOpTestWrapper): pass def outReshape(self): - pass + self.out[0] = self.out[0].reshape((2, 2)) + self.out[1] = self.out[1].reshape((2, 2)) + self.out[2] = self.out[2].reshape((2, 2)) def setAxis(self): pass diff --git a/test/xpu/test_where_index_xpu.py b/test/xpu/test_where_index_xpu.py index cca29f573733650d02eea1f5983b51bbaa5e1b52..70c4a3454e8a4d520775c942cd49dc1369019af9 100644 --- a/test/xpu/test_where_index_xpu.py +++ b/test/xpu/test_where_index_xpu.py @@ -58,7 +58,7 @@ class XPUTestWhereIndexOp(XPUOpTestWrapper): self.inputs = { 'Condition': np.array([False, False, False]).astype(self.dtype), } - self.outputs = {'Out': np.array([], dtype='int64')} + self.outputs = {'Out': np.array([], dtype='int64').reshape(0, 1)} class TestRank2(TestWhereIndexOp): def init_data(self):