Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
torch-sparse
Commits
af9127e3
Commit
af9127e3
authored
Feb 19, 2020
by
rusty1s
Browse files
fix permute
parent
904b1d48
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
24 deletions
+19
-24
test/test_permute.py
test/test_permute.py
+17
-0
torch_sparse/permute.py
torch_sparse/permute.py
+2
-24
No files found.
test/test_permute.py
0 → 100644
View file @
af9127e3
import
pytest
import
torch
from
torch_sparse.tensor
import
SparseTensor
from
.utils
import
devices
,
tensor
@
pytest
.
mark
.
parametrize
(
'device'
,
devices
)
def
test_permute
(
device
):
row
,
col
=
tensor
([[
0
,
0
,
1
,
2
,
2
],
[
0
,
1
,
0
,
1
,
2
]],
torch
.
long
,
device
)
value
=
tensor
([
1
,
2
,
3
,
4
,
5
],
torch
.
float
,
device
)
adj
=
SparseTensor
(
row
=
row
,
col
=
col
,
value
=
value
)
row
,
col
,
value
=
adj
.
permute
(
torch
.
tensor
([
1
,
0
,
2
])).
coo
()
assert
row
.
tolist
()
==
[
0
,
1
,
1
,
2
,
2
]
assert
col
.
tolist
()
==
[
1
,
0
,
1
,
0
,
2
]
print
(
value
)
torch_sparse/permute.py
View file @
af9127e3
import
torch
import
torch
from
torch_sparse.storage
import
SparseStorage
from
torch_sparse.tensor
import
SparseTensor
from
torch_sparse.tensor
import
SparseTensor
def
permute
(
src
:
SparseTensor
,
perm
:
torch
.
Tensor
)
->
SparseTensor
:
def
permute
(
src
:
SparseTensor
,
perm
:
torch
.
Tensor
)
->
SparseTensor
:
assert
src
.
is_symmetric
()
assert
src
.
is_quadratic
()
return
src
.
index_select
(
0
,
perm
).
index_select
(
1
,
perm
)
row
,
col
,
value
=
src
.
coo
()
row
=
perm
[
row
]
col
=
perm
[
col
]
if
value
is
not
None
:
value
=
value
[
row
]
rowcount
=
src
.
storage
.
_rowcount
if
rowcount
is
not
None
:
rowcount
=
rowcount
[
perm
]
colcount
=
src
.
storage
.
_colcount
if
colcount
is
not
None
:
colcount
=
colcount
[
perm
]
storage
=
SparseStorage
(
row
=
row
,
rowptr
=
None
,
col
=
col
,
value
=
value
,
sparse_sizes
=
src
.
sparse_sizes
(),
rowcount
=
rowcount
,
colptr
=
None
,
colcount
=
colcount
,
csr2csc
=
None
,
csc2csr
=
None
,
is_sorted
=
False
)
return
src
.
from_storage
(
storage
)
SparseTensor
.
permute
=
lambda
self
,
perm
:
permute
(
self
,
perm
)
SparseTensor
.
permute
=
lambda
self
,
perm
:
permute
(
self
,
perm
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment