Commit 729b4fb2 authored by rusty1s's avatar rusty1s
Browse files

faster transpose

parent fc650310
...@@ -29,11 +29,15 @@ def transpose(index, value, m, n, coalesced=True): ...@@ -29,11 +29,15 @@ def transpose(index, value, m, n, coalesced=True):
def t(src): def t(src):
(row, col), value = src.coo() index, value = src.coo()
csr2csc = src.storage.csr2csc csr2csc = src.storage.csr2csc
new_index = torch.empty_like(index)
torch.index_select(index[1], 0, csr2csc, out=new_index[0])
torch.index_select(index[0], 0, csr2csc, out=new_index[1])
storage = src.storage.__class__( storage = src.storage.__class__(
index=torch.stack([col, row], dim=0)[:, csr2csc], index=new_index,
value=value[csr2csc] if src.has_value() else None, value=value[csr2csc] if src.has_value() else None,
sparse_size=src.sparse_size()[::-1], sparse_size=src.sparse_size()[::-1],
rowcount=src.storage._colcount, rowcount=src.storage._colcount,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment