-
Notifications
You must be signed in to change notification settings - Fork 5.9k
[API Compatibility] Add out support for 11 APIs #74592
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
Changes from 4 commits
2ef9c85
fdce7a4
145a9b6
e5ce1cb
a7b2aba
11a2970
bee131a
8346a92
32a1211
af8a3df
e547119
19ecd26
1f59707
b3b39f5
d4a9f4f
2240405
f120923
4a56b23
a8782fb
a25be34
0d583ad
2c1a8de
1d6858d
e375769
7829ddf
6761f5b
685c288
6303236
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3170,15 +3170,19 @@ def _memcpy(input, place=None, output=None) -> paddle.Tensor: | |
|
|
||
|
|
||
| def complex( | ||
| real: paddle.Tensor, imag: paddle.Tensor, out=None, name: str | None = None | ||
| real: paddle.Tensor, | ||
| imag: paddle.Tensor, | ||
| *, | ||
| out: paddle.Tensor | None = None, | ||
| name: str | None = None, | ||
| ) -> paddle.Tensor: | ||
| """Return a complex tensor given the real and image component. | ||
|
|
||
| Args: | ||
| real (Tensor): The real component. The data type should be 'float32' or 'float64'. | ||
| imag (Tensor): The image component. The data type should be the same as ``real``. | ||
| name(str|None, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None. | ||
| out (Tensor|None, optional): The output tensor. Default: None. | ||
| name(str|None, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None. | ||
|
|
||
| Returns: | ||
| Tensor, The output tensor. The data type is 'complex64' or 'complex128', with the same precision as ``real`` and ``imag``. | ||
|
|
@@ -3392,14 +3396,19 @@ def triu_indices( | |
|
|
||
|
|
||
| def polar( | ||
| abs: paddle.Tensor, angle: paddle.Tensor, name: str | None = None | ||
| abs: paddle.Tensor, | ||
| angle: paddle.Tensor, | ||
| *, | ||
| out: paddle.Tensor | None = None, | ||
| name: str | None = None, | ||
|
||
| ) -> paddle.Tensor: | ||
| """Return a Cartesian coordinates corresponding to the polar coordinates complex tensor given the ``abs`` and ``angle`` component. | ||
|
|
||
| Args: | ||
| abs (Tensor): The abs component. The data type should be 'float32' or 'float64'. | ||
| angle (Tensor): The angle component. The data type should be the same as ``abs``. | ||
| name(str|None, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None. | ||
| out (Tensor, optional): The output tensor. If set, the result will be stored in this tensor. Default is None. | ||
| name (str|None, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None. | ||
|
|
||
| Returns: | ||
| Tensor, The output tensor. The data type is 'complex64' or 'complex128', with the same precision as ``abs`` and ``angle``. | ||
|
|
@@ -3428,7 +3437,9 @@ def polar( | |
| angle, 'angle', ['float32', 'float64'], 'paddle.polar' | ||
| ) | ||
|
|
||
| return paddle.complex(abs * paddle.cos(angle), abs * paddle.sin(angle)) | ||
| return paddle.complex( | ||
| abs * paddle.cos(angle), abs * paddle.sin(angle), out=out, name=name | ||
| ) | ||
|
|
||
|
|
||
| @dygraph_only | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -153,7 +153,10 @@ def _get_reduce_axis_with_tensor(axis, x): | |
| return reduce_all, axis | ||
|
|
||
|
|
||
| def log(x: Tensor, name: str | None = None) -> Tensor: | ||
| @ParamAliasDecorator({"x": ["input"]}) | ||
| def log( | ||
| x: Tensor, *, out: Tensor | None = None, name: str | None = None | ||
| ) -> Tensor: | ||
| r""" | ||
| Calculates the natural log of the given input Tensor, element-wise. | ||
|
|
||
|
|
@@ -163,6 +166,7 @@ def log(x: Tensor, name: str | None = None) -> Tensor: | |
|
|
||
| Args: | ||
| x (Tensor): Input Tensor. Must be one of the following types: int32, int64, float16, bfloat16, float32, float64, complex64, complex128. | ||
| out (Tensor, optional): The output Tensor. If set, the result will be stored in this tensor. Default is None. | ||
| name (str|None): The default value is None. Normally there is no need for user to set this property. For more information, please refer to :ref:`api_guide_Name` | ||
|
|
||
|
|
||
|
|
@@ -183,7 +187,7 @@ def log(x: Tensor, name: str | None = None) -> Tensor: | |
| [1.94591010, 2.07944155, 2.19722462]]) | ||
| """ | ||
| if in_dynamic_or_pir_mode(): | ||
| return _C_ops.log(x) | ||
| return _C_ops.log(x, out=out) | ||
| else: | ||
| check_variable_and_dtype( | ||
| x, | ||
|
|
@@ -519,7 +523,13 @@ def scale_( | |
|
|
||
|
|
||
| @ParamAliasDecorator({"x": ["input"], "y": ["exponent"]}) | ||
| def pow(x: Tensor, y: float | Tensor, name: str | None = None) -> Tensor: | ||
| def pow( | ||
| x: Tensor, | ||
| y: float | Tensor, | ||
| *, | ||
| out: Tensor | None = None, | ||
| name: str | None = None, | ||
| ) -> Tensor: | ||
| """ | ||
| Compute the power of Tensor elements. The equation is: | ||
|
|
||
|
|
@@ -540,6 +550,7 @@ def pow(x: Tensor, y: float | Tensor, name: str | None = None) -> Tensor: | |
| input: An alias for ``x`` , with identical behavior. | ||
| y (float|int|Tensor): If it is an N-D Tensor, its data type should be the same as `x`. | ||
| exponent: An alias for ``y`` , with identical behavior. | ||
| out (Tensor, optional): The output tensor. If set, the result will be stored in this tensor. Default is None. | ||
| name (str|None, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`. | ||
|
|
||
| Returns: | ||
|
|
@@ -575,9 +586,9 @@ def pow(x: Tensor, y: float | Tensor, name: str | None = None) -> Tensor: | |
| # in dynamic graph mode | ||
| if in_dynamic_or_pir_mode(): | ||
| if isinstance(y, (int, float)): | ||
| return _C_ops.pow(x, y) | ||
| return _C_ops.pow(x, y, out=out) | ||
| elif isinstance(y, (paddle.Tensor, Variable, paddle.pir.Value)): | ||
| return _C_ops.elementwise_pow(x, y) | ||
| return _C_ops.elementwise_pow(x, y, out=out) | ||
| else: | ||
| raise TypeError( | ||
| f"y must be scalar, Tensor(in dygraph mode), Value(in pir mode) but received: {type(y)}" | ||
|
|
@@ -1120,7 +1131,10 @@ def remainder_(x: Tensor, y: Tensor, name: str | None = None) -> Tensor: | |
| """ | ||
|
|
||
|
|
||
| def multiply(x: Tensor, y: Tensor, name: str | None = None) -> Tensor: | ||
| @ParamAliasDecorator({"x": ["input"], "y": ["other"]}) | ||
| def multiply( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个能下沉吗
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个不在 ops.yaml 中 |
||
| x: Tensor, y: Tensor, *, out: Tensor | None = None, name: str | None = None | ||
| ) -> Tensor: | ||
| """ | ||
| multiply two tensors element-wise. The equation is: | ||
|
|
||
|
|
@@ -1138,6 +1152,7 @@ def multiply(x: Tensor, y: Tensor, name: str | None = None) -> Tensor: | |
| Args: | ||
| x (Tensor): the input tensor, its data type should be one of bfloat16, float16, float32, float64, int32, int64, bool, complex64, complex128. | ||
| y (Tensor): the input tensor, its data type should be one of bfloat16, float16, float32, float64, int32, int64, bool, complex64, complex128. | ||
| out (Tensor|None, optional): The output tensor. If set, the result will be stored in this tensor. Default is None. | ||
| name (str|None, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`. | ||
|
|
||
| Returns: | ||
|
|
@@ -1166,7 +1181,7 @@ def multiply(x: Tensor, y: Tensor, name: str | None = None) -> Tensor: | |
|
|
||
| """ | ||
| if in_dynamic_or_pir_mode(): | ||
| return _C_ops.multiply(x, y) | ||
| return _C_ops.multiply(x, y, out=out) | ||
| else: | ||
| return _elementwise_op(LayerHelper('elementwise_mul', **locals())) | ||
|
|
||
|
|
@@ -5077,12 +5092,16 @@ def prod( | |
| return out | ||
|
|
||
|
|
||
| def sign(x: Tensor, name: str | None = None) -> Tensor: | ||
| @ParamAliasDecorator({"x": ["input"]}) | ||
| def sign( | ||
| x: Tensor, *, out: Tensor | None = None, name: str | None = None | ||
| ) -> Tensor: | ||
| """ | ||
| Returns sign of every element in `x`: For real numbers, 1 for positive, -1 for negative and 0 for zero. For complex numbers, the return value is a complex number with unit magnitude. If a complex number element is zero, the result is 0+0j. | ||
|
|
||
| Args: | ||
| x (Tensor): The input tensor. The data type can be uint8, int8, int16, int32, int64, bfloat16, float16, float32, float64, complex64 or complex128. | ||
| out (Tensor|None, optional): The output tensor. If set, the result will be stored in this tensor. Default is None. | ||
| name (str|None, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`. | ||
|
|
||
| Returns: | ||
|
|
@@ -5100,7 +5119,7 @@ def sign(x: Tensor, name: str | None = None) -> Tensor: | |
| [ 1., 0., -1., 1.]) | ||
| """ | ||
| if in_dynamic_or_pir_mode(): | ||
| return _C_ops.sign(x) | ||
| return _C_ops.sign(x, out=out) | ||
| else: | ||
| check_variable_and_dtype( | ||
| x, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以帮忙给这个 API 也加一下类型提示么?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done