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
c86527dc
"git@developer.sourcefind.cn:OpenDAS/ollama.git" did not exist on "7a01ad76143973199bd6965c13476d2d04f10f75"
Commit
c86527dc
authored
Feb 03, 2020
by
rusty1s
Browse files
test eye
parent
925f9567
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
36 deletions
+43
-36
test/test_eye.py
test/test_eye.py
+42
-35
torch_sparse/tensor.py
torch_sparse/tensor.py
+1
-1
No files found.
test/test_eye.py
View file @
c86527dc
from
itertools
import
product
import
pytest
import
torch
from
torch_sparse.tensor
import
SparseTensor
from
.utils
import
dtypes
,
devices
...
...
@@ -8,38 +9,44 @@ from .utils import dtypes, devices
@
pytest
.
mark
.
parametrize
(
'dtype,device'
,
product
(
dtypes
,
devices
))
def
test_eye
(
dtype
,
device
):
mat
=
SparseTensor
.
eye
(
3
,
dtype
=
dtype
,
device
=
device
)
assert
mat
.
storage
.
row
.
tolist
()
==
[
0
,
1
,
2
]
assert
mat
.
storage
.
rowptr
.
tolist
()
==
[
0
,
1
,
2
,
3
]
assert
mat
.
storage
.
col
.
tolist
()
==
[
0
,
1
,
2
]
assert
mat
.
storage
.
value
.
tolist
()
==
[
1
,
1
,
1
]
assert
len
(
mat
.
cached_keys
())
==
0
mat
=
SparseTensor
.
eye
(
3
,
dtype
=
dtype
,
device
=
device
,
has_value
=
False
)
assert
mat
.
storage
.
row
.
tolist
()
==
[
0
,
1
,
2
]
assert
mat
.
storage
.
rowptr
.
tolist
()
==
[
0
,
1
,
2
,
3
]
assert
mat
.
storage
.
col
.
tolist
()
==
[
0
,
1
,
2
]
assert
mat
.
storage
.
value
is
None
assert
len
(
mat
.
cached_keys
())
==
0
mat
=
SparseTensor
.
eye
(
3
,
4
,
dtype
=
dtype
,
device
=
device
,
fill_cache
=
True
)
assert
mat
.
storage
.
row
.
tolist
()
==
[
0
,
1
,
2
]
assert
mat
.
storage
.
rowptr
.
tolist
()
==
[
0
,
1
,
2
,
3
]
assert
mat
.
storage
.
col
.
tolist
()
==
[
0
,
1
,
2
]
assert
len
(
mat
.
cached_keys
())
==
5
assert
mat
.
storage
.
rowcount
.
tolist
()
==
[
1
,
1
,
1
]
assert
mat
.
storage
.
colptr
.
tolist
()
==
[
0
,
1
,
2
,
3
,
3
]
assert
mat
.
storage
.
colcount
.
tolist
()
==
[
1
,
1
,
1
,
0
]
assert
mat
.
storage
.
csr2csc
.
tolist
()
==
[
0
,
1
,
2
]
assert
mat
.
storage
.
csc2csr
.
tolist
()
==
[
0
,
1
,
2
]
mat
=
SparseTensor
.
eye
(
4
,
3
,
dtype
=
dtype
,
device
=
device
,
fill_cache
=
True
)
assert
mat
.
storage
.
row
.
tolist
()
==
[
0
,
1
,
2
]
assert
mat
.
storage
.
rowptr
.
tolist
()
==
[
0
,
1
,
2
,
3
,
3
]
assert
mat
.
storage
.
col
.
tolist
()
==
[
0
,
1
,
2
]
assert
len
(
mat
.
cached_keys
())
==
5
assert
mat
.
storage
.
rowcount
.
tolist
()
==
[
1
,
1
,
1
,
0
]
assert
mat
.
storage
.
colptr
.
tolist
()
==
[
0
,
1
,
2
,
3
]
assert
mat
.
storage
.
colcount
.
tolist
()
==
[
1
,
1
,
1
]
assert
mat
.
storage
.
csr2csc
.
tolist
()
==
[
0
,
1
,
2
]
assert
mat
.
storage
.
csc2csr
.
tolist
()
==
[
0
,
1
,
2
]
options
=
torch
.
tensor
(
0
,
dtype
=
dtype
,
device
=
device
)
mat
=
SparseTensor
.
eye
(
3
,
options
=
options
)
assert
mat
.
storage
.
sparse_sizes
()
==
(
3
,
3
)
assert
mat
.
storage
.
row
().
tolist
()
==
[
0
,
1
,
2
]
assert
mat
.
storage
.
rowptr
().
tolist
()
==
[
0
,
1
,
2
,
3
]
assert
mat
.
storage
.
col
().
tolist
()
==
[
0
,
1
,
2
]
assert
mat
.
storage
.
value
().
tolist
()
==
[
1
,
1
,
1
]
assert
mat
.
storage
.
num_cached_keys
()
==
0
mat
=
SparseTensor
.
eye
(
3
,
options
=
options
,
has_value
=
False
)
assert
mat
.
storage
.
sparse_sizes
()
==
(
3
,
3
)
assert
mat
.
storage
.
row
().
tolist
()
==
[
0
,
1
,
2
]
assert
mat
.
storage
.
rowptr
().
tolist
()
==
[
0
,
1
,
2
,
3
]
assert
mat
.
storage
.
col
().
tolist
()
==
[
0
,
1
,
2
]
assert
mat
.
storage
.
value
()
is
None
assert
mat
.
storage
.
num_cached_keys
()
==
0
mat
=
SparseTensor
.
eye
(
3
,
4
,
options
=
options
,
fill_cache
=
True
)
assert
mat
.
storage
.
sparse_sizes
()
==
(
3
,
4
)
assert
mat
.
storage
.
row
().
tolist
()
==
[
0
,
1
,
2
]
assert
mat
.
storage
.
rowptr
().
tolist
()
==
[
0
,
1
,
2
,
3
]
assert
mat
.
storage
.
col
().
tolist
()
==
[
0
,
1
,
2
]
assert
mat
.
storage
.
num_cached_keys
()
==
5
assert
mat
.
storage
.
rowcount
().
tolist
()
==
[
1
,
1
,
1
]
assert
mat
.
storage
.
colptr
().
tolist
()
==
[
0
,
1
,
2
,
3
,
3
]
assert
mat
.
storage
.
colcount
().
tolist
()
==
[
1
,
1
,
1
,
0
]
assert
mat
.
storage
.
csr2csc
().
tolist
()
==
[
0
,
1
,
2
]
assert
mat
.
storage
.
csc2csr
().
tolist
()
==
[
0
,
1
,
2
]
mat
=
SparseTensor
.
eye
(
4
,
3
,
options
=
options
,
fill_cache
=
True
)
assert
mat
.
storage
.
sparse_sizes
()
==
(
4
,
3
)
assert
mat
.
storage
.
row
().
tolist
()
==
[
0
,
1
,
2
]
assert
mat
.
storage
.
rowptr
().
tolist
()
==
[
0
,
1
,
2
,
3
,
3
]
assert
mat
.
storage
.
col
().
tolist
()
==
[
0
,
1
,
2
]
assert
mat
.
storage
.
num_cached_keys
()
==
5
assert
mat
.
storage
.
rowcount
().
tolist
()
==
[
1
,
1
,
1
,
0
]
assert
mat
.
storage
.
colptr
().
tolist
()
==
[
0
,
1
,
2
,
3
]
assert
mat
.
storage
.
colcount
().
tolist
()
==
[
1
,
1
,
1
]
assert
mat
.
storage
.
csr2csc
().
tolist
()
==
[
0
,
1
,
2
]
assert
mat
.
storage
.
csc2csr
().
tolist
()
==
[
0
,
1
,
2
]
torch_sparse/tensor.py
View file @
c86527dc
...
...
@@ -64,7 +64,7 @@ class SparseTensor(object):
rowptr
=
torch
.
arange
(
M
+
1
,
dtype
=
torch
.
long
,
device
=
row
.
device
)
if
M
>
N
:
rowptr
[
N
+
1
:]
=
M
rowptr
[
N
+
1
:]
=
N
value
:
Optional
[
torch
.
Tensor
]
=
None
if
has_value
:
...
...
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