|
27 | 27 | from paddle.utils.decorator_utils import ( |
28 | 28 | ParamAliasDecorator, |
29 | 29 | reshape_decorator, |
| 30 | + param_one_alias, |
| 31 | + param_two_alias, |
30 | 32 | view_decorator, |
31 | 33 | ) |
32 | 34 | from paddle.utils.inplace_utils import inplace_apis_in_dygraph_only |
@@ -3471,7 +3473,7 @@ def squeeze_( |
3471 | 3473 | return _C_ops.squeeze_(input, axes) |
3472 | 3474 |
|
3473 | 3475 |
|
3474 | | -@ParamAliasDecorator({"x": ["input"], "axis": ["dim"]}) |
| 3476 | +@param_two_alias(["x", "input"], ["axis", "dim"]) |
3475 | 3477 | def unique_consecutive( |
3476 | 3478 | x: Tensor, |
3477 | 3479 | return_inverse: bool = False, |
@@ -6297,7 +6299,83 @@ def as_real(x: Tensor, name: str | None = None) -> Tensor: |
6297 | 6299 | return out |
6298 | 6300 |
|
6299 | 6301 |
|
6300 | | -@ParamAliasDecorator({"x": ["input"], "axis": ["dim"]}) |
| 6302 | +def view_as_complex(input: Tensor) -> Tensor: |
| 6303 | + """Return a complex tensor that is a view of the input real tensor . |
| 6304 | +
|
| 6305 | + The data type of the input tensor is 'float32' or 'float64', and the data |
| 6306 | + type of the returned tensor is 'complex64' or 'complex128', respectively. |
| 6307 | +
|
| 6308 | + The shape of the input tensor is ``(* ,2)``, (``*`` means arbitrary shape), i.e. |
| 6309 | + the size of the last axis should be 2, which represent the real and imag part |
| 6310 | + of a complex number. The shape of the returned tensor is ``(*,)``. |
| 6311 | +
|
| 6312 | + The complex tensor is a view of the input real tensor, meaning that it shares the same memory with real tensor. |
| 6313 | +
|
| 6314 | + The image below demonstrates the case that a real 3D-tensor with shape [2, 3, 2] is transformed into a complex 2D-tensor with shape [2, 3]. |
| 6315 | +
|
| 6316 | + .. image:: https://githubraw.cdn.bcebos.com/PaddlePaddle/docs/develop/docs/images/api_legend/as_complex.png |
| 6317 | + :width: 500 |
| 6318 | + :alt: Illustration of as_complex |
| 6319 | + :align: center |
| 6320 | +
|
| 6321 | + Args: |
| 6322 | + input (Tensor): The input tensor. Data type is 'float32' or 'float64'. |
| 6323 | +
|
| 6324 | + Returns: |
| 6325 | + Tensor, The output. Data type is 'complex64' or 'complex128', sharing the same memory with input. |
| 6326 | +
|
| 6327 | + Examples: |
| 6328 | + .. code-block:: python |
| 6329 | +
|
| 6330 | + >>> import paddle |
| 6331 | + >>> x = paddle.arange(12, dtype=paddle.float32).reshape([2, 3, 2]) |
| 6332 | + >>> y = paddle.as_complex(x) |
| 6333 | + >>> print(y) |
| 6334 | + Tensor(shape=[2, 3], dtype=complex64, place=Place(cpu), stop_gradient=True, |
| 6335 | + [[1j , (2+3j) , (4+5j) ], |
| 6336 | + [(6+7j) , (8+9j) , (10+11j)]]) |
| 6337 | + """ |
| 6338 | + |
| 6339 | + return as_complex(x=input) |
| 6340 | + |
| 6341 | + |
| 6342 | +def view_as_real(input: Tensor) -> Tensor: |
| 6343 | + """Return a real tensor that is a view of the input complex tensor. |
| 6344 | +
|
| 6345 | + The data type of the input tensor is 'complex64' or 'complex128', and the data |
| 6346 | + type of the returned tensor is 'float32' or 'float64', respectively. |
| 6347 | +
|
| 6348 | + When the shape of the input tensor is ``(*, )``, (``*`` means arbitrary shape), |
| 6349 | + the shape of the output tensor is ``(*, 2)``, i.e. the shape of the output is |
| 6350 | + the shape of the input appended by an extra ``2``. |
| 6351 | +
|
| 6352 | + The real tensor is a view of the input complex tensor, meaning that it shares the same memory with complex tensor. |
| 6353 | +
|
| 6354 | + Args: |
| 6355 | + input (Tensor): The input tensor. Data type is 'complex64' or 'complex128'. |
| 6356 | +
|
| 6357 | + Returns: |
| 6358 | + Tensor, The output. Data type is 'float32' or 'float64', sharing the same memory with input. |
| 6359 | +
|
| 6360 | + Examples: |
| 6361 | + .. code-block:: python |
| 6362 | +
|
| 6363 | + >>> import paddle |
| 6364 | + >>> x = paddle.arange(12, dtype=paddle.float32).reshape([2, 3, 2]) |
| 6365 | + >>> y = paddle.as_complex(x) |
| 6366 | + >>> z = paddle.as_real(y) |
| 6367 | + >>> print(z) |
| 6368 | + Tensor(shape=[2, 3, 2], dtype=float32, place=Place(cpu), stop_gradient=True, |
| 6369 | + [[[0. , 1. ], |
| 6370 | + [2. , 3. ], |
| 6371 | + [4. , 5. ]], |
| 6372 | + [[6. , 7. ], |
| 6373 | + [8. , 9. ], |
| 6374 | + [10., 11.]]]) |
| 6375 | + """ |
| 6376 | + return as_real(x=input) |
| 6377 | + |
| 6378 | + |
6301 | 6379 | def repeat_interleave( |
6302 | 6380 | x: Tensor, |
6303 | 6381 | repeats: int | Tensor, |
|
0 commit comments