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
6c5e08e7
Commit
6c5e08e7
authored
Jan 17, 2020
by
rusty1s
Browse files
offset implementation
parent
d8a8ebab
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
9 deletions
+17
-9
test/test_diag.py
test/test_diag.py
+13
-4
torch_sparse/diag.py
torch_sparse/diag.py
+4
-5
No files found.
test/test_diag.py
View file @
6c5e08e7
...
...
@@ -8,16 +8,25 @@ from .utils import dtypes, devices, tensor
@
pytest
.
mark
.
parametrize
(
'dtype,device'
,
product
(
dtypes
,
devices
))
def
test_
cat
(
dtype
,
device
):
def
test_
remove_diag
(
dtype
,
device
):
index
=
tensor
([[
0
,
0
,
1
,
2
],
[
0
,
1
,
2
,
2
]],
torch
.
long
,
device
)
value
=
tensor
([
1
,
2
,
3
,
4
],
dtype
,
device
)
mat
=
SparseTensor
(
index
,
value
)
mat
.
fill_cache_
()
mat
=
mat
.
remove_diag
()
index
,
value
=
mat
.
coo
()
assert
index
.
tolist
()
==
[[
0
,
1
],
[
1
,
2
]]
assert
value
.
tolist
()
==
[
2
,
3
]
assert
mat
.
storage
.
index
.
tolist
()
==
[[
0
,
1
],
[
1
,
2
]]
assert
mat
.
storage
.
value
.
tolist
()
==
[
2
,
3
]
assert
len
(
mat
.
cached_keys
())
==
2
assert
mat
.
storage
.
rowcount
.
tolist
()
==
[
1
,
1
,
0
]
assert
mat
.
storage
.
colcount
.
tolist
()
==
[
0
,
1
,
1
]
mat
=
SparseTensor
(
index
,
value
)
mat
.
fill_cache_
()
mat
=
mat
.
remove_diag
(
k
=
1
)
assert
mat
.
storage
.
index
.
tolist
()
==
[[
0
,
2
],
[
0
,
2
]]
assert
mat
.
storage
.
value
.
tolist
()
==
[
1
,
4
]
assert
len
(
mat
.
cached_keys
())
==
2
assert
mat
.
storage
.
rowcount
.
tolist
()
==
[
1
,
0
,
1
]
assert
mat
.
storage
.
colcount
.
tolist
()
==
[
1
,
0
,
1
]
torch_sparse/diag.py
View file @
6c5e08e7
import
torch
def
add_diag
(
src
,
value
=
None
,
k
=
0
):
pass
...
...
@@ -9,14 +6,16 @@ def remove_diag(src, k=0):
index
,
value
=
src
.
coo
()
row
,
col
=
index
mask
=
row
==
col
if
k
==
0
else
row
==
(
col
+
k
)
inv_mask
=
~
mask
inv_mask
=
row
!=
col
if
k
==
0
else
row
!=
(
col
-
k
)
index
=
index
[:,
inv_mask
]
if
src
.
has_value
():
value
=
value
[
inv_mask
]
if
src
.
storage
.
has_rowcount
()
or
src
.
storage
.
has_colcount
():
mask
=
~
inv_mask
rowcount
=
None
if
src
.
storage
.
has_rowcount
():
rowcount
=
src
.
storage
.
rowcount
.
clone
()
...
...
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