MCPcopy Create free account
hub / github.com/DropEdge/DropEdge / sparse_mx_to_torch_sparse_tensor

Function sparse_mx_to_torch_sparse_tensor

src/utils.py:26–33  ·  view source on GitHub ↗

Convert a scipy sparse matrix to a torch sparse tensor.

(sparse_mx)

Source from the content-addressed store, hash-verified

24 return adj, features
25
26def sparse_mx_to_torch_sparse_tensor(sparse_mx):
27 """Convert a scipy sparse matrix to a torch sparse tensor."""
28 sparse_mx = sparse_mx.tocoo().astype(np.float32)
29 indices = torch.from_numpy(
30 np.vstack((sparse_mx.row, sparse_mx.col)).astype(np.int64))
31 values = torch.from_numpy(sparse_mx.data)
32 shape = torch.Size(sparse_mx.shape)
33 return torch.sparse.FloatTensor(indices, values, shape)
34
35
36

Callers 3

_preprocess_adjMethod · 0.90
load_citationFunction · 0.85
load_reddit_dataFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected