Calculate elementwise absolute value of x, requiring x to be a SparseCooTensor or SparseCsrTensor. .. math:: out = |x| Parameters: x (Tensor): The input Sparse Tensor with data type float32, float64, complex64, complex128. name (str|None, optional): Name for t
(x: Tensor, name: str | None = None)
| 706 | |
| 707 | |
| 708 | def abs(x: Tensor, name: str | None = None) -> Tensor: |
| 709 | """ |
| 710 | Calculate elementwise absolute value of x, requiring x to be a SparseCooTensor or SparseCsrTensor. |
| 711 | |
| 712 | .. math:: |
| 713 | |
| 714 | out = |x| |
| 715 | |
| 716 | Parameters: |
| 717 | x (Tensor): The input Sparse Tensor with data type float32, float64, complex64, complex128. |
| 718 | name (str|None, optional): Name for the operation (optional, default is None). |
| 719 | For more information, please refer to :ref:`api_guide_Name`. |
| 720 | |
| 721 | Returns: |
| 722 | A Sparse Tensor with the same data type and shape as ``x`` . |
| 723 | |
| 724 | Examples: |
| 725 | .. code-block:: pycon |
| 726 | |
| 727 | >>> import paddle |
| 728 | |
| 729 | >>> dense_x = paddle.to_tensor([-2, 0, 3], dtype='float32') |
| 730 | >>> sparse_x = dense_x.to_sparse_coo(1) |
| 731 | >>> out = paddle.sparse.abs(sparse_x) |
| 732 | >>> out |
| 733 | Tensor(shape=[3], dtype=paddle.float32, place=Place(cpu), stop_gradient=True, |
| 734 | indices=[[0, 2]], |
| 735 | values=[2., 3.]) |
| 736 | """ |
| 737 | assert in_dynamic_or_pir_mode(), ( |
| 738 | "Currently, Sparse API only support dynamic mode or pir mode." |
| 739 | ) |
| 740 | return _C_ops.sparse_abs(x) |
| 741 | |
| 742 | |
| 743 | def coalesce(x: Tensor, name: str | None = None) -> Tensor: |
no test coverage detected