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

Add API paddle.neg() and paddle.lgamma(), along with some unittests for paddle.neg(). #33248

Merged
merged 10 commits into from
Jun 9, 2021
2 changes: 2 additions & 0 deletions python/paddle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@
from .tensor.math import broadcast_shape # noqa: F401
from .tensor.math import conj # noqa: F401
from .tensor.math import neg # noqa: F401
from .tensor.math import lgamma # noqa: F401

from .tensor.random import multinomial # noqa: F401
from .tensor.random import standard_normal # noqa: F401
Expand Down Expand Up @@ -424,6 +425,7 @@
'broadcast_shape',
'conj',
'neg',
'lgamma',
'square',
'divide',
'ceil',
Expand Down
14 changes: 14 additions & 0 deletions python/paddle/fluid/layers/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
'round',
'reciprocal',
'square',
'lgamma',
]

__inplace_unary_func__ = [
Expand Down Expand Up @@ -396,6 +397,19 @@

""")

add_sample_code(globals()["lgamma"], r"""
Examples:
.. code-block:: python

import paddle

x = paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])
out = paddle.lgamma(x)
print(out)
# [1.31452441, 1.76149750, 2.25271273, 1.09579802]

""")

add_sample_code(globals()["softplus"], r"""
Examples:
.. code-block:: python
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/fluid/tests/unittests/test_neg_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class TestNegOp(unittest.TestCase):
def setUp(self):
self.init_dtype_type()
self.input = np.random.random((32, 8)).astype(self.dtype)
self.input = (np.random.random((32, 8)) * 100).astype(self.dtype)

def init_dtype_type(self):
self.dtype = np.float64
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 @@ -163,6 +163,8 @@
from .math import any # noqa: F401
from .math import broadcast_shape # noqa: F401
from .math import conj # noqa: F401
from .math import neg # noqa: F401
from .math import lgamma # noqa: F401

from .random import multinomial # noqa: F401
from .random import standard_normal # noqa: F401
Expand Down Expand Up @@ -280,6 +282,8 @@
'isnan',
'broadcast_shape',
'conj',
'neg',
'lgamma',
'equal',
'equal_all',
'greater_equal',
Expand Down
3 changes: 2 additions & 1 deletion python/paddle/tensor/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
from ..fluid.layers import sqrt # noqa: F401
from ..fluid.layers import sqrt_ # noqa: F401
from ..fluid.layers import sin # noqa: F401
from ..fluid.layers import lgamma # noqa: F401

from ..fluid.layers import multiplex # noqa: F401
from ..fluid import layers
Expand Down Expand Up @@ -2290,7 +2291,7 @@ def neg(x, name=None):
name (str, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.

Returns:
out (Tensor): The negative of input. The shape and data type are the same with input.
out (Tensor): The negative of input Tensor. The shape and data type are the same with input Tensor.

Examples:
.. code-block:: python
Expand Down