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
a9aca7be
Commit
a9aca7be
authored
Sep 20, 2021
by
rusty1s
Browse files
add __eq__
parent
fdc31cc4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
0 deletions
+38
-0
test/test_tensor.py
test/test_tensor.py
+16
-0
torch_sparse/tensor.py
torch_sparse/tensor.py
+22
-0
No files found.
test/test_tensor.py
View file @
a9aca7be
...
...
@@ -37,3 +37,19 @@ def test_to_symmetric(device):
[
6
,
0
,
5
],
[
3
,
5
,
0
],
]
def
test_equal
():
row
=
torch
.
tensor
([
0
,
0
,
0
,
1
,
1
])
col
=
torch
.
tensor
([
0
,
1
,
2
,
0
,
2
])
value
=
torch
.
arange
(
1
,
6
)
matA
=
SparseTensor
(
row
=
row
,
col
=
col
,
value
=
value
)
matB
=
SparseTensor
(
row
=
row
,
col
=
col
,
value
=
value
)
col
=
torch
.
tensor
([
0
,
1
,
2
,
0
,
1
])
matC
=
SparseTensor
(
row
=
row
,
col
=
col
,
value
=
value
)
assert
id
(
matA
)
!=
id
(
matB
)
assert
matA
==
matB
assert
id
(
matA
)
!=
id
(
matC
)
assert
matA
!=
matC
torch_sparse/tensor.py
View file @
a9aca7be
...
...
@@ -197,6 +197,28 @@ class SparseTensor(object):
self
.
storage
.
clear_cache_
()
return
self
def
__eq__
(
self
,
other
)
->
bool
:
if
not
isinstance
(
other
,
self
.
__class__
):
return
False
if
self
.
sizes
()
!=
other
.
sizes
():
return
False
rowptrA
,
colA
,
valueA
=
self
.
csr
()
rowptrB
,
colB
,
valueB
=
other
.
csr
()
if
valueA
is
None
and
valueB
is
not
None
:
return
False
if
valueA
is
not
None
and
valueB
is
None
:
return
False
if
not
torch
.
equal
(
rowptrA
,
rowptrB
):
return
False
if
not
torch
.
equal
(
colA
,
colB
):
return
False
if
valueA
is
None
and
valueB
is
None
:
return
True
return
torch
.
equal
(
valueA
,
valueB
)
# Utility functions #######################################################
def
fill_value_
(
self
,
fill_value
:
float
,
dtype
:
Optional
[
int
]
=
None
):
...
...
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