Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【Paddle Tensor No.22】: 新增 paddle.lessTensor.less #69270

Merged
merged 6 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions python/paddle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -858,6 +860,8 @@
'full_like',
'less_than',
'less_than_',
'less',
'less_',
'kron',
'clip',
'Tensor',
Expand Down
4 changes: 4 additions & 0 deletions python/paddle/tensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@
less_equal,
less_equal_,
less_than,
less_than as less,
less_than as less_,
less_than_,
logical_and,
logical_and_,
Expand Down Expand Up @@ -628,6 +630,8 @@
'less_equal_',
'less_than',
'less_than_',
'less',
'less_',
'logical_and',
'logical_and_',
'logical_not',
Expand Down
8 changes: 8 additions & 0 deletions test/legacy_test/test_inplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions test/legacy_test/test_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,16 +399,19 @@ 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]
with self.dynamic_graph():
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():
Expand Down
7 changes: 5 additions & 2 deletions test/legacy_test/test_math_op_patch_pir.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions test/legacy_test/test_math_op_patch_var_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down