I have a mx1 dense matrix D and a mxm sparse matrix S. I implemented that by torch.mul(S.to_dense(), D), and transformed the result into a sparse tensor, but the GPU memory is not enough and running on CPU is too slow for large m. I wonder if there is a fast/sparse implementation of torch_geometric for this, without converting S to a dense matrix (converting D to sparse is acceptable \ (•◡•) /). Thanks for your help ≧◠◡◠≦✌
You can do the following:
row, col = edge_index # Indices of S
edge_weight # Values of S
D_row = D[row]
out = D_row * edge_weight
Thanks for your kind and timely reply. By the way, I changed the last line 'out = D_row * edge_weight' into 'out = D_row * edge_weight.squeeze()', that really works ^_^
Hi, I have another question:
If I want to put a sparse mask M on a sparse matrix S, except for implementation via M * S, how can I operate on edges and indices to save time and memory?
I am not sure I understand, but what about removing the edges in S that also lie in M?
Sorry, maybe my description is not clear enough. What I want to do is to preserve the edges in S that the mask sparse matrix M also contains (or remove the edges that M doesn't have), so that the indices of target sparse matrix S are exactly the same as M.
So, how can I implement this? (Maybe how to finding out the common edges they have and delete the others?)
There is no PyTorch function for that, but can use numpys isin1d function for that. You can convert sparse indices to 1d via:
idx = N * row + col
Thanks for your kind and fast reply, I will have a try on that conversion. I thought there could be an implementation without using 'M * S' (sad...T_T).
Most helpful comment
You can do the following: