diff --git a/python/paddle/__init__.py b/python/paddle/__init__.py index 24bef2bf0af37c..045e6445ae0783 100644 --- a/python/paddle/__init__.py +++ b/python/paddle/__init__.py @@ -265,7 +265,9 @@ less_equal, less_equal_, less_than, + less_than as less, less_than_, + less_than_ as less_, logical_and, logical_and_, logical_not, @@ -858,6 +860,8 @@ 'full_like', 'less_than', 'less_than_', + 'less', + 'less_', 'kron', 'clip', 'Tensor', diff --git a/python/paddle/tensor/__init__.py b/python/paddle/tensor/__init__.py index 6cb01ba1e3da24..823d25356f7726 100644 --- a/python/paddle/tensor/__init__.py +++ b/python/paddle/tensor/__init__.py @@ -128,6 +128,8 @@ less_equal, less_equal_, less_than, + less_than as less, + less_than as less_, less_than_, logical_and, logical_and_, @@ -628,6 +630,8 @@ 'less_equal_', 'less_than', 'less_than_', + 'less', + 'less_', 'logical_and', 'logical_and_', 'logical_not', diff --git a/test/legacy_test/test_inplace.py b/test/legacy_test/test_inplace.py index 22a844690a0953..6c5d8274aceca8 100755 --- a/test/legacy_test/test_inplace.py +++ b/test/legacy_test/test_inplace.py @@ -1430,6 +1430,14 @@ def non_inplace_api_processing(self, var): return paddle.less_than(var, self.y) +class TestDygraphInplaceLess(TestDygraphInplaceLogicAnd): + def inplace_api_processing(self, var): + return paddle.less_(var, self.y) + + def non_inplace_api_processing(self, var): + return paddle.less(var, self.y) + + class TestDygraphInplaceLessEqual(TestDygraphInplaceLogicAnd): def inplace_api_processing(self, var): return paddle.less_equal_(var, self.y) diff --git a/test/legacy_test/test_layers.py b/test/legacy_test/test_layers.py index 3bbdaa40b1fbab..5a0e6283b59c9c 100644 --- a/test/legacy_test/test_layers.py +++ b/test/legacy_test/test_layers.py @@ -399,6 +399,7 @@ def test_compare(self): a = paddle.static.data(name='a', shape=[-1, 1], dtype='int64') b = paddle.static.data(name='b', shape=[-1, 1], dtype='int64') cond = paddle.less_than(x=a, y=b) + cond_ = paddle.less(x=a, y=b) static_ret = self.get_static_graph_result( feed={"a": value_a, "b": value_b}, fetch_list=[cond] )[0] @@ -406,9 +407,11 @@ def test_compare(self): da = paddle.to_tensor(value_a) db = paddle.to_tensor(value_b) dcond = paddle.less_than(x=da, y=db) + dcond_ = paddle.less(x=da, y=db) for i in range(len(static_ret)): self.assertTrue(dcond.numpy()[i] == static_ret[i]) + self.assertTrue(dcond_.numpy()[i] == static_ret[i]) # less equal with self.static_graph(): diff --git a/test/legacy_test/test_math_op_patch_pir.py b/test/legacy_test/test_math_op_patch_pir.py index ccb80af41ee081..52b62ebbb2af6d 100644 --- a/test/legacy_test/test_math_op_patch_pir.py +++ b/test/legacy_test/test_math_op_patch_pir.py @@ -316,6 +316,7 @@ def test_less(self): res_np_c = paddle.less_than( paddle.to_tensor(x_np), paddle.to_tensor(y_np) ) + res_np_c_ = paddle.less(paddle.to_tensor(x_np), paddle.to_tensor(y_np)) res_np_d = x_np.__lt__(y_np) res_np_e = x_np <= y_np res_np_f = paddle.less_equal( @@ -332,18 +333,20 @@ def test_less(self): z = paddle.static.data(name="z", shape=[-1, 1], dtype='float32') b = x < y c = x.less_than(y) + c_ = x.less(y) d = x.__lt__(y) e = x <= y f = x.less_equal(y) g = x.__le__(y) h = x <= z - (b_np, c_np, d_np, e_np, f_np, g_np, h_np) = exe.run( + (b_np, c_np, c_np_, d_np, e_np, f_np, g_np, h_np) = exe.run( main_program, feed={"x": x_np, "y": y_np, "z": z_np}, - fetch_list=[b, c, d, e, f, g, h], + fetch_list=[b, c, c_, d, e, f, g, h], ) np.testing.assert_array_equal(res_np_b, b_np) np.testing.assert_array_equal(res_np_c, c_np) + np.testing.assert_array_equal(res_np_c_, c_np_) np.testing.assert_array_equal(res_np_d, d_np) np.testing.assert_array_equal(res_np_e, e_np) np.testing.assert_array_equal(res_np_f, f_np) diff --git a/test/legacy_test/test_math_op_patch_var_base.py b/test/legacy_test/test_math_op_patch_var_base.py index 5d5ece13679736..63dd6bdeacef9c 100644 --- a/test/legacy_test/test_math_op_patch_var_base.py +++ b/test/legacy_test/test_math_op_patch_var_base.py @@ -445,6 +445,17 @@ def test_less_than(self): res = a < b np.testing.assert_array_equal(res.numpy(), a_np < b_np) + def test_less(self): + a_np = np.random.random(self.shape).astype(self.dtype) + b_np = np.random.random(self.shape).astype(self.dtype) + with base.dygraph.guard(): + a = paddle.to_tensor(a_np) + b = paddle.to_tensor(b_np) + res_tensor = a.less(b) + res_paddle = paddle.less(a, b) + np.testing.assert_array_equal(res_tensor.numpy(), a_np < b_np) + np.testing.assert_array_equal(res_paddle.numpy(), a_np < b_np) + def test_less_equal(self): a_np = np.random.random(self.shape).astype(self.dtype) b_np = np.random.random(self.shape).astype(self.dtype)