未验证 提交 c77eb1fd 编写于 作者: T Tao Luo 提交者: GitHub

zero-dim support for gcd and lcm (#50950)

上级 dda74715
......@@ -282,6 +282,8 @@ binary_int_api_list = [
paddle.bitwise_and,
paddle.bitwise_or,
paddle.bitwise_xor,
paddle.gcd,
paddle.lcm,
]
......
......@@ -4449,15 +4449,19 @@ def gcd(x, y, name=None):
y = paddle.broadcast_to(y, shape)
x = paddle.abs(x)
y = paddle.abs(y)
# TODO(zhouwei25): Support 0D for not_equal tensor with scalar
zero = paddle.full([], 0)
def _gcd_cond_fn(x, y):
return paddle.any(y != 0)
# return paddle.any(y != 0)
return paddle.any(y != zero)
def _gcd_body_fn(x, y):
# paddle.mod will raise an error when any element of y is 0. To avoid
# that, we change those zeros to ones. Their values don't matter because
# they won't be used.
y_not_equal_0 = y != 0
# y_not_equal_0 = y != 0
y_not_equal_0 = y != zero
y_safe = paddle.where(y_not_equal_0, y, paddle.ones(y.shape, y.dtype))
x, y = (
paddle.where(y_not_equal_0, y, x),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册