Skip to content
Open
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
2 changes: 1 addition & 1 deletion paddle/phi/ops/yaml/python_api_info.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@
name : [paddle.poisson]
args_alias :
use_default_mapping : True

- op : nextafter
name : [paddle.nextafter, paddle.Tensor.nextafter]
args_alias :
Expand Down
38 changes: 30 additions & 8 deletions python/paddle/tensor/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -4249,14 +4249,26 @@ def multigammaln_(x: Tensor, p: int, name: str | None = None) -> Tensor:
return x


def neg(x: Tensor, name: str | None = None) -> Tensor:
@param_one_alias(["x", "input"])
def neg(
x: Tensor,
name: str | None = None,
*,
out: Tensor | None = None
) -> Tensor:
"""
This function computes the negative of the Tensor elementwisely.

Args:
x (Tensor): Input of neg operator, an N-D Tensor, with data type bfloat16, float16, float32, float64, int8, int16, int32,
int64, uint8, complex64, complex128.
name (str|None, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
x (Tensor): Input of neg operator, an N-D Tensor, with data type bfloat16,
float16, float32, float64, int8, int16, int32, int64, uint8,
complex64, complex128.
Alias: ``input``.
name (str|None, optional): Name for the operation (optional, default is None).
For more information, please refer to :ref:`api_guide_Name`.

Keyword args:
out (Tensor|None, optional): The output tensor. Default: None.

Returns:
out (Tensor): The negative of input Tensor. The shape and data type are the same with input Tensor.
Expand All @@ -4265,18 +4277,28 @@ def neg(x: Tensor, name: str | None = None) -> Tensor:
.. code-block:: pycon

>>> import paddle

>>> x = paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])
>>> out = paddle.neg(x)
>>> out
Tensor(shape=[4], dtype=float32, place=Place(cpu), stop_gradient=True,
[ 0.40000001, 0.20000000, -0.10000000, -0.30000001])
"""

return scale(
x, scale=-1.0, bias=0.0, bias_after_scale=True, act=None, name=name
ret = scale(
x,
scale=-1.0,
bias=0.0,
bias_after_scale=True,
act=None,
name=name,
)

if out is not None:
paddle.assign(ret, out)
return out

return ret


@inplace_apis_in_dygraph_only
def neg_(x: Tensor, name: str | None = None) -> Tensor:
Expand Down Expand Up @@ -6899,4 +6921,4 @@ def cartesian_prod(x: Sequence[Tensor], name: str | None = None) -> Tensor:
return x[0]

coordinates = paddle.stack(paddle.meshgrid(x), axis=-1)
return paddle.reshape(coordinates, [-1, len(x)])
return paddle.reshape(coordinates, [-1, len(x)])
Loading
Loading