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

【Hackathon 5th No.1】 为 Paddle 新增 copysign API -part #57785

Merged
merged 73 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
9e4cbf6
add copysign op
cocoshe Sep 26, 2023
8396602
fix codestyle
cocoshe Oct 19, 2023
f4cd7f1
fix conflict
cocoshe Nov 11, 2023
390b2d9
codestyle
cocoshe Nov 14, 2023
0413912
fix test
cocoshe Nov 16, 2023
9aa2850
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
cocoshe Nov 16, 2023
b923632
fix std bug
cocoshe Nov 16, 2023
ed681d1
Merge branch 'develop' of https://github.com/cocoshe/Paddle into develop
cocoshe Nov 16, 2023
03d75c6
Merge branch 'develop' into develop
cocoshe Dec 1, 2023
3ae286f
merge init
cocoshe Dec 1, 2023
a3dfdbe
merge init
cocoshe Dec 1, 2023
dbaefa3
merge init
cocoshe Dec 1, 2023
b02ca12
add static cast
cocoshe Dec 1, 2023
ccadeb3
add std
cocoshe Dec 1, 2023
6b785c2
static cast
cocoshe Dec 1, 2023
24fab40
static cast
cocoshe Dec 1, 2023
bdc577b
copysignf
cocoshe Dec 2, 2023
c244d4b
static cast to float input
cocoshe Dec 2, 2023
2e57ad2
float input
cocoshe Dec 2, 2023
6831d85
static cast to double input
cocoshe Dec 2, 2023
dd12864
fix
cocoshe Dec 2, 2023
1477a0f
add inplace test
cocoshe Dec 2, 2023
065df10
fix api
cocoshe Dec 2, 2023
41ef0e7
fix cast when grad
cocoshe Dec 2, 2023
87e77b3
modify paddle.cast_ to cast_
cocoshe Dec 2, 2023
5bcf730
remove cast in python api
cocoshe Dec 5, 2023
a16666e
support fp16 && bf16
cocoshe Dec 5, 2023
2599b12
set grad y to zero
cocoshe Dec 5, 2023
fd6886e
fix en doc
cocoshe Dec 5, 2023
df3897c
support number input
cocoshe Dec 9, 2023
4e1b29c
add hostdevice
cocoshe Dec 9, 2023
72e6b0a
refactor kernel
cocoshe Dec 11, 2023
a24a00d
fix nan when backward
cocoshe Dec 11, 2023
349ebac
add broadcast unit test
cocoshe Dec 11, 2023
6181a85
modify .cu
cocoshe Dec 11, 2023
d65e19a
Merge branch 'develop' into develop
cocoshe Dec 12, 2023
1cc02ca
Update __init__.py
cocoshe Dec 12, 2023
e567e18
Update __init__.py
cocoshe Dec 12, 2023
f692f51
Merge branch 'develop' into develop
cocoshe Dec 18, 2023
2d9e4f0
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
cocoshe Dec 19, 2023
73e1883
for ci test
cocoshe Dec 20, 2023
56cecf4
static float
cocoshe Dec 20, 2023
c718f5a
codestyle
cocoshe Dec 20, 2023
a81f9cb
static double
cocoshe Dec 20, 2023
63e3fb7
fix broadcast, try coverage
cocoshe Dec 20, 2023
3927283
Delete paddle/phi/kernels/funcs/broadcast_function.h
cocoshe Dec 21, 2023
8145f8c
remove unused
cocoshe Dec 21, 2023
0a587ae
Update math.py
cocoshe Dec 22, 2023
1b4199d
Update math.py
cocoshe Dec 22, 2023
2d69b81
fix en doc
cocoshe Dec 22, 2023
04f7ca5
add test for output dtype, integer unsupported for now
cocoshe Dec 25, 2023
b9e0251
update
cocoshe Dec 28, 2023
fda6647
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
cocoshe Dec 28, 2023
91aea3f
update
cocoshe Dec 28, 2023
5fe32ca
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
cocoshe Jan 3, 2024
d5bc812
fix
cocoshe Jan 3, 2024
d564078
fix
cocoshe Jan 3, 2024
147c310
add cast for input
cocoshe Jan 5, 2024
c32ee61
fix
cocoshe Jan 5, 2024
4e7e279
add pir test
cocoshe Jan 5, 2024
8c14454
fix doc
cocoshe Jan 5, 2024
395db45
fix doc
cocoshe Jan 6, 2024
6e6c04c
fix doc
cocoshe Jan 7, 2024
110b472
detail doc
cocoshe Jan 8, 2024
ca0ff53
adjust for MSVC
cocoshe Jan 8, 2024
e1f8f49
fix
cocoshe Jan 8, 2024
6327baa
Update python/paddle/tensor/math.py
cocoshe Jan 9, 2024
baed47b
Update python/paddle/tensor/math.py
cocoshe Jan 9, 2024
59df646
fix doc output dtype, fix Equation
cocoshe Jan 9, 2024
731a965
Merge branch 'develop' into develop
cocoshe Jan 10, 2024
984f25b
codestyle
cocoshe Jan 10, 2024
1e8c37e
codestyle
cocoshe Jan 10, 2024
c6ad009
Update math.py
cocoshe Jan 10, 2024
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
Prev Previous commit
Next Next commit
fix conflict
  • Loading branch information
cocoshe committed Nov 11, 2023
commit f4cd7f1f25c2e051714d644831eeac38fbe75059
2 changes: 1 addition & 1 deletion paddle/phi/api/yaml/backward.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@
kernel :
func : conv3d_transpose_grad
data_type : x

- backward_op : copysign_grad
forward : copysign (Tensor x, Tensor y) -> Tensor(out)
args : (Tensor x, Tensor y, Tensor out_grad)
Expand Down
8 changes: 8 additions & 0 deletions python/paddle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,8 @@
polygamma_,
copysign,
copysign_,
hypot,
hypot_,
)

from .tensor.random import (
Expand Down Expand Up @@ -914,4 +916,10 @@
'polygamma_',
'copysign',
'copysign_',
'masked_fill',
'masked_fill_',
'hypot',
'hypot_',
'index_fill',
"index_fill_",
]
6 changes: 6 additions & 0 deletions python/paddle/tensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,10 @@
from .math import polygamma_ # noqa: F401
from .math import copysign # noqa: F401
from .math import copysign_ # noqa: F401
from .math import renorm # noqa: F401
from .math import renorm_ # noqa: F401
from .math import hypot # noqa: F401
from .math import hypot_ # noqa: F401

from .random import multinomial # noqa: F401
from .random import standard_normal # noqa: F401
Expand Down Expand Up @@ -729,6 +733,8 @@
'normal_',
'copysign',
'copysign_',
'index_fill',
'index_fill_',
]

# this list used in math_op_patch.py for magic_method bind
Expand Down
53 changes: 53 additions & 0 deletions python/paddle/tensor/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -7024,3 +7024,56 @@ def copysign_(x, y):
y = paddle.broadcast_to(y, out_shape)

return _C_ops.copysign_(x, y)


def hypot(x, y, name=None):
"""
Calculate the length of the hypotenuse of a right-angle triangle. The equation is:

.. math::
out = {\\sqrt{x^2 + y^2}}

Args:
x (Tensor): The input Tensor, the data type is float32, float64, int32 or int64.
y (Tensor): The input Tensor, the data type is float32, float64, int32 or int64.
name (str, optional): Name for the operation (optional, default is None).For more information, please refer to :ref:`api_guide_Name`.

Returns:
out (Tensor): An N-D Tensor. If x, y have different shapes and are "broadcastable", the resulting tensor shape is the shape of x and y after broadcasting. If x, y have the same shape, its shape is the same as x and y. And the data type is float32 or float64.

Examples:

.. code-block:: python

>>> import paddle

>>> x = paddle.to_tensor([3], dtype='float32')
>>> y = paddle.to_tensor([4], dtype='float32')
>>> res = paddle.hypot(x, y)
>>> print(res)
Tensor(shape=[1], dtype=float32, place=Place(cpu), stop_gradient=True,
[5.])

"""
if not isinstance(x, (paddle.Tensor, Variable)):
raise TypeError(f"x must be tensor type, but got {type(x)}")
if not isinstance(y, (paddle.Tensor, Variable)):
raise TypeError(f"y must be tensor type, but got {type(y)}")

out = (paddle.pow(x, 2) + paddle.pow(y, 2)).sqrt()
return out


@inplace_apis_in_dygraph_only
def hypot_(x, y, name=None):
r"""
Inplace version of ``hypot`` API, the output Tensor will be inplaced with input ``x``.
Please refer to :ref:`api_paddle_hypot`.
"""
if not isinstance(x, (paddle.Tensor, Variable)):
raise TypeError(f"x must be tensor type, but got {type(x)}")
if not isinstance(y, (paddle.Tensor, Variable)):
raise TypeError(f"y must be tensor type, but got {type(y)}")

out = x.pow_(2).add_(y.pow(2)).sqrt_()
return out
You are viewing a condensed version of this merge commit. You can view the full changes here.