original_docstring: Convert a scipy sparse matrix to a torch sparse tensor.
docstring: Convert a scipy sparse matrix to a torch sparse tensor.
docstring_tokens: Convert a scipy sparse matrix to a torch sparse tensor .
code: def sparse_mx_to_torch_sparse_tensor(sparse_mx):
      """Convert a scipy sparse matrix to a torch sparse tensor."""
      sparse_mx = sparse_mx.tocoo().astype(np.float32)
      indices = torch.from_numpy(
          np.vstack((sparse_mx.row, sparse_mx.col)).astype(np.int64))
      values = torch.from_numpy(sparse_mx.data)
      shape = torch.Size(sparse_mx.shape)
      return torch.sparse.FloatTensor(indices, values, shape)
code_tokens: def sparse_mx_to_torch_sparse_tensor ( sparse_mx ) : sparse_mx = sparse_mx . tocoo ( ) . astype ( np . float32 ) indices = torch . from_numpy ( np . vstack ( ( sparse_mx . row , sparse_mx . col ) ) . astype ( np . int64 ) ) values = torch . from_numpy ( sparse_mx . data ) shape = torch . Size ( sparse_mx . shape ) return torch . sparse . FloatTensor ( indices , values , shape )
short_docstring: Convert a scipy sparse matrix to a torch sparse tensor.
short_docstring_tokens: Convert a scipy sparse matrix to a torch sparse tensor .
comment: """Convert a scipy sparse matrix to a torch sparse tensor."""