coalesce

paddle.Tensor. coalesce ( self, name=None )

the coalesced operator include sorted and merge, after coalesced, the indices of x is sorted and unique.

Parameters
  • x (Tensor) – the input SparseCooTensor.

  • name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

Returns

return the SparseCooTensor after coalesced.

Return type

Tensor

Examples

>>> import paddle

>>> indices = [[0, 0, 1], [1, 1, 2]]
>>> values = [1.0, 2.0, 3.0]
>>> sp_x = paddle.sparse.sparse_coo_tensor(indices, values)
>>> sp_x = sp_x.coalesce()
>>> print(sp_x.indices())
Tensor(shape=[2, 2], dtype=int64, place=Place(cpu), stop_gradient=True,
[[0, 1],
[1, 2]])
>>> print(sp_x.values())
Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=True,
[3., 3.])