MCPcopy
hub / github.com/dmlc/dgl / coalesce

Method coalesce

python/dgl/sparse/sparse_matrix.py:432–461  ·  view source on GitHub ↗

Returns a coalesced sparse matrix. A coalesced sparse matrix satisfies the following properties: - the indices of the non-zero elements are unique, - the indices are sorted in lexicographical order. The coalescing process will accumulate the non-zero elements o

(self)

Source from the content-addressed store, hash-verified

430 return self.to(dtype=torch.long)
431
432 def coalesce(self):
433 """Returns a coalesced sparse matrix.
434
435 A coalesced sparse matrix satisfies the following properties:
436
437 - the indices of the non-zero elements are unique,
438 - the indices are sorted in lexicographical order.
439
440 The coalescing process will accumulate the non-zero elements of the same
441 indices by summation.
442
443 The function does not support autograd.
444
445 Returns
446 -------
447 SparseMatrix
448 The coalesced sparse matrix
449
450 Examples
451 --------
452 >>> indices = torch.tensor([[1, 0, 0, 0, 1], [1, 1, 1, 2, 2]])
453 >>> val = torch.tensor([0, 1, 2, 3, 4])
454 >>> A = dglsp.spmatrix(indices, val)
455 >>> A.coalesce()
456 SparseMatrix(indices=tensor([[0, 0, 1, 1],
457 [1, 2, 1, 2]]),
458 values=tensor([3, 3, 0, 4]),
459 shape=(2, 3), nnz=4)
460 """
461 return SparseMatrix(self.c_sparse_matrix.coalesce())
462
463 def has_duplicate(self):
464 """Returns ``True`` if the sparse matrix contains duplicate indices.

Callers 5

test_coalesceFunction · 0.80
ladies.pyFile · 0.80
multilayer_sampleFunction · 0.80
sample_subgraphsMethod · 0.80

Calls 1

SparseMatrixClass · 0.70

Tested by 1

test_coalesceFunction · 0.64